This commit is contained in:
Manuel Cillero 2023-11-11 13:43:44 +01:00
parent 13c7eb4ade
commit 258d42049f
7 changed files with 92 additions and 113 deletions

View file

@ -134,7 +134,7 @@ fn show_banner() {
let app_description = if !config::SETTINGS.app.description.is_empty() { let app_description = if !config::SETTINGS.app.description.is_empty() {
concat_string!("\n", config::SETTINGS.app.description) concat_string!("\n", config::SETTINGS.app.description)
} else { } else {
"".to_string() "".to_owned()
}; };
// Print banner. // Print banner.
println!( println!(

View file

@ -2,8 +2,6 @@ use crate::core::component::{Context, ContextOp};
use crate::html::{JavaScript, StyleSheet}; use crate::html::{JavaScript, StyleSheet};
use crate::Weight; use crate::Weight;
use std::fmt;
// Context parameters. // Context parameters.
pub const PARAM_BASE_WEIGHT: &str = "base.weight"; pub const PARAM_BASE_WEIGHT: &str = "base.weight";
pub const PARAM_BASE_INCLUDE_ICONS: &str = "base.include.icon"; pub const PARAM_BASE_INCLUDE_ICONS: &str = "base.include.icon";
@ -68,9 +66,9 @@ pub enum BreakPoint {
} }
#[rustfmt::skip] #[rustfmt::skip]
impl fmt::Display for BreakPoint { impl ToString for BreakPoint {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn to_string(&self) -> String {
let breakpoint = match self { String::from(match self {
BreakPoint::None => "pt-bp__none", BreakPoint::None => "pt-bp__none",
BreakPoint::SM => "pt-bp__sm", BreakPoint::SM => "pt-bp__sm",
BreakPoint::MD => "pt-bp__md", BreakPoint::MD => "pt-bp__md",
@ -79,8 +77,7 @@ impl fmt::Display for BreakPoint {
BreakPoint::X2L => "pt-bp__x2l", BreakPoint::X2L => "pt-bp__x2l",
BreakPoint::X3L => "pt-bp__x3l", BreakPoint::X3L => "pt-bp__x3l",
BreakPoint::X2K => "pt-bp__x2k", BreakPoint::X2K => "pt-bp__x2k",
}; })
write!(f, "{breakpoint}")
} }
} }
@ -102,9 +99,9 @@ pub enum FontSize {
} }
#[rustfmt::skip] #[rustfmt::skip]
impl fmt::Display for FontSize { impl ToString for FontSize {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn to_string(&self) -> String {
let font_size = match self { String::from(match self {
FontSize::ExtraLarge => "pt-fs__x3l", FontSize::ExtraLarge => "pt-fs__x3l",
FontSize::XxLarge => "pt-fs__x2l", FontSize::XxLarge => "pt-fs__x2l",
FontSize::XLarge => "pt-fs__xl", FontSize::XLarge => "pt-fs__xl",
@ -115,8 +112,7 @@ impl fmt::Display for FontSize {
FontSize::XSmall => "pt-fs__xs", FontSize::XSmall => "pt-fs__xs",
FontSize::XxSmall => "pt-fs__x2s", FontSize::XxSmall => "pt-fs__x2s",
FontSize::ExtraSmall => "pt-fs__x3s", FontSize::ExtraSmall => "pt-fs__x3s",
}; })
write!(f, "{font_size}")
} }
} }

View file

@ -5,8 +5,6 @@ pub use item::{Item, COMPONENT_BASE_FLEX_ITEM};
use crate::prelude::*; use crate::prelude::*;
use std::fmt;
// ************************************************************************************************* // *************************************************************************************************
#[derive(Default)] #[derive(Default)]
@ -20,23 +18,23 @@ pub enum Direction {
} }
#[rustfmt::skip] #[rustfmt::skip]
impl fmt::Display for Direction { impl ToString for Direction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn to_string(&self) -> String {
match self { match self {
Direction::Default => write!( Direction::Default => concat_string!(
f, "pt-flex__container pt-flex__row {}", BreakPoint::default() "pt-flex__container pt-flex__row ", BreakPoint::default().to_string()
), ),
Direction::Row(breakpoint) => write!( Direction::Row(breakpoint) => concat_string!(
f, "pt-flex__container pt-flex__row {breakpoint}" "pt-flex__container pt-flex__row ", breakpoint.to_string()
), ),
Direction::RowReverse(breakpoint) => write!( Direction::RowReverse(breakpoint) => concat_string!(
f, "pt-flex__container pt-flex__row pt-flex__reverse {breakpoint}" "pt-flex__container pt-flex__row pt-flex__reverse ", breakpoint.to_string()
), ),
Direction::Column(breakpoint) => write!( Direction::Column(breakpoint) => concat_string!(
f, "pt-flex__container pt-flex__col {breakpoint}" "pt-flex__container pt-flex__col ", breakpoint.to_string()
), ),
Direction::ColumnReverse(breakpoint) => write!( Direction::ColumnReverse(breakpoint) => concat_string!(
f, "pt-flex__container pt-flex__col pt-flex__reverse {breakpoint}" "pt-flex__container pt-flex__col pt-flex__reverse ", breakpoint.to_string()
), ),
} }
} }
@ -54,13 +52,13 @@ pub enum WrapAlign {
} }
#[rustfmt::skip] #[rustfmt::skip]
impl fmt::Display for WrapAlign { impl ToString for WrapAlign {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn to_string(&self) -> String {
match self { match self {
WrapAlign::Default => write!(f, ""), WrapAlign::Default => "".to_owned(),
WrapAlign::NoWrap => write!(f, "flex-nowrap"), WrapAlign::NoWrap => "flex-nowrap".to_owned(),
WrapAlign::Wrap(a) => write!(f, "pt-flex__wrap {a}"), WrapAlign::Wrap(a) => concat_string!("pt-flex__wrap ", a.to_string()),
WrapAlign::WrapReverse(a) => write!(f, "pt-flex__wrap-reverse {a}"), WrapAlign::WrapReverse(a) => concat_string!("pt-flex__wrap-reverse ", a.to_string()),
} }
} }
} }
@ -80,9 +78,9 @@ pub enum ContentAlign {
} }
#[rustfmt::skip] #[rustfmt::skip]
impl fmt::Display for ContentAlign { impl ToString for ContentAlign {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn to_string(&self) -> String {
let content_align = match self { String::from(match self {
ContentAlign::Default => "", ContentAlign::Default => "",
ContentAlign::Start => "pt-flex__align-start", ContentAlign::Start => "pt-flex__align-start",
ContentAlign::End => "pt-flex__align-end", ContentAlign::End => "pt-flex__align-end",
@ -90,8 +88,7 @@ impl fmt::Display for ContentAlign {
ContentAlign::Stretch => "pt-flex__align-stretch", ContentAlign::Stretch => "pt-flex__align-stretch",
ContentAlign::SpaceBetween => "pt-flex__align-space-between", ContentAlign::SpaceBetween => "pt-flex__align-space-between",
ContentAlign::SpaceAround => "pt-flex__align-space-around", ContentAlign::SpaceAround => "pt-flex__align-space-around",
}; })
write!(f, "{content_align}")
} }
} }
@ -110,9 +107,9 @@ pub enum ContentJustify {
} }
#[rustfmt::skip] #[rustfmt::skip]
impl fmt::Display for ContentJustify { impl ToString for ContentJustify {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn to_string(&self) -> String {
let content_justify = match self { String::from(match self {
ContentJustify::Default => "", ContentJustify::Default => "",
ContentJustify::Start => "pt-flex__justify-start", ContentJustify::Start => "pt-flex__justify-start",
ContentJustify::End => "pt-flex__justify-end", ContentJustify::End => "pt-flex__justify-end",
@ -120,8 +117,7 @@ impl fmt::Display for ContentJustify {
ContentJustify::SpaceBetween => "pt-flex__justify-space-between", ContentJustify::SpaceBetween => "pt-flex__justify-space-between",
ContentJustify::SpaceAround => "pt-flex__justify-space-around", ContentJustify::SpaceAround => "pt-flex__justify-space-around",
ContentJustify::SpaceEvenly => "pt-flex__justify-space-evenly", ContentJustify::SpaceEvenly => "pt-flex__justify-space-evenly",
}; })
write!(f, "{content_justify}")
} }
} }
@ -139,17 +135,16 @@ pub enum ItemAlign {
} }
#[rustfmt::skip] #[rustfmt::skip]
impl fmt::Display for ItemAlign { impl ToString for ItemAlign {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn to_string(&self) -> String {
let item_align = match self { String::from(match self {
ItemAlign::Default => "", ItemAlign::Default => "",
ItemAlign::Top => "pt-flex__item-top", ItemAlign::Top => "pt-flex__item-top",
ItemAlign::Bottom => "pt-flex__item-bottom", ItemAlign::Bottom => "pt-flex__item-bottom",
ItemAlign::Middle => "pt-flex__item-middle", ItemAlign::Middle => "pt-flex__item-middle",
ItemAlign::Stretch => "pt-flex__item-stretch", ItemAlign::Stretch => "pt-flex__item-stretch",
ItemAlign::Baseline => "pt-flex__item-baseline", ItemAlign::Baseline => "pt-flex__item-baseline",
}; })
write!(f, "{item_align}")
} }
} }
@ -166,14 +161,14 @@ pub enum Gap {
} }
#[rustfmt::skip] #[rustfmt::skip]
impl fmt::Display for Gap { impl ToString for Gap {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn to_string(&self) -> String {
match self { match self {
Gap::Default => write!(f, ""), Gap::Default => "".to_owned(),
Gap::Row(r) => write!(f, "row-gap: {r};"), Gap::Row(r) => concat_string!("row-gap: ", r.to_string(), ";"),
Gap::Column(c) => write!(f, "column-gap: {c};"), Gap::Column(c) => concat_string!("column-gap: ", c.to_string(), ";"),
Gap::Distinct(r, c) => write!(f, "gap: {r} {c};"), Gap::Distinct(r, c) => concat_string!("gap: ", r.to_string(), " ", c.to_string(), ";"),
Gap::Both(v) => write!(f, "gap: {v};"), Gap::Both(v) => concat_string!("gap: ", v.to_string(), ";"),
} }
} }
} }
@ -196,9 +191,9 @@ pub enum ItemGrow {
} }
#[rustfmt::skip] #[rustfmt::skip]
impl fmt::Display for ItemGrow { impl ToString for ItemGrow {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn to_string(&self) -> String {
let item_grow = match self { String::from(match self {
ItemGrow::Default => "", ItemGrow::Default => "",
ItemGrow::Is1 => "pt-flex__grow-1", ItemGrow::Is1 => "pt-flex__grow-1",
ItemGrow::Is2 => "pt-flex__grow-2", ItemGrow::Is2 => "pt-flex__grow-2",
@ -209,8 +204,7 @@ impl fmt::Display for ItemGrow {
ItemGrow::Is7 => "pt-flex__grow-7", ItemGrow::Is7 => "pt-flex__grow-7",
ItemGrow::Is8 => "pt-flex__grow-8", ItemGrow::Is8 => "pt-flex__grow-8",
ItemGrow::Is9 => "pt-flex__grow-9", ItemGrow::Is9 => "pt-flex__grow-9",
}; })
write!(f, "{item_grow}")
} }
} }
@ -232,9 +226,9 @@ pub enum ItemShrink {
} }
#[rustfmt::skip] #[rustfmt::skip]
impl fmt::Display for ItemShrink { impl ToString for ItemShrink {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn to_string(&self) -> String {
let item_shrink = match self { String::from(match self {
ItemShrink::Default => "", ItemShrink::Default => "",
ItemShrink::Is1 => "pt-flex__shrink-1", ItemShrink::Is1 => "pt-flex__shrink-1",
ItemShrink::Is2 => "pt-flex__shrink-2", ItemShrink::Is2 => "pt-flex__shrink-2",
@ -245,8 +239,7 @@ impl fmt::Display for ItemShrink {
ItemShrink::Is7 => "pt-flex__shrink-7", ItemShrink::Is7 => "pt-flex__shrink-7",
ItemShrink::Is8 => "pt-flex__shrink-8", ItemShrink::Is8 => "pt-flex__shrink-8",
ItemShrink::Is9 => "pt-flex__shrink-9", ItemShrink::Is9 => "pt-flex__shrink-9",
}; })
write!(f, "{item_shrink}")
} }
} }
@ -270,9 +263,9 @@ pub enum ItemSize {
} }
#[rustfmt::skip] #[rustfmt::skip]
impl fmt::Display for ItemSize { impl ToString for ItemSize {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn to_string(&self) -> String {
let item_size = match self { String::from(match self {
ItemSize::Default => "", ItemSize::Default => "",
ItemSize::Percent10 => "pt-flex__width-10", ItemSize::Percent10 => "pt-flex__width-10",
ItemSize::Percent20 => "pt-flex__width-20", ItemSize::Percent20 => "pt-flex__width-20",
@ -285,8 +278,7 @@ impl fmt::Display for ItemSize {
ItemSize::Percent75 => "pt-flex__width-75", ItemSize::Percent75 => "pt-flex__width-75",
ItemSize::Percent80 => "pt-flex__width-80", ItemSize::Percent80 => "pt-flex__width-80",
ItemSize::Percent90 => "pt-flex__width-90", ItemSize::Percent90 => "pt-flex__width-90",
}; })
write!(f, "{item_size}")
} }
} }
@ -310,9 +302,9 @@ pub enum ItemOffset {
} }
#[rustfmt::skip] #[rustfmt::skip]
impl fmt::Display for ItemOffset { impl ToString for ItemOffset {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn to_string(&self) -> String {
let item_offset = match self { String::from(match self {
ItemOffset::Default => "", ItemOffset::Default => "",
ItemOffset::Offset10 => "pt-flex__offset-10", ItemOffset::Offset10 => "pt-flex__offset-10",
ItemOffset::Offset20 => "pt-flex__offset-20", ItemOffset::Offset20 => "pt-flex__offset-20",
@ -325,7 +317,6 @@ impl fmt::Display for ItemOffset {
ItemOffset::Offset75 => "pt-flex__offset-75", ItemOffset::Offset75 => "pt-flex__offset-75",
ItemOffset::Offset80 => "pt-flex__offset-80", ItemOffset::Offset80 => "pt-flex__offset-80",
ItemOffset::Offset90 => "pt-flex__offset-90", ItemOffset::Offset90 => "pt-flex__offset-90",
}; })
write!(f, "{item_offset}")
} }
} }

View file

@ -1,7 +1,5 @@
use crate::prelude::*; use crate::prelude::*;
use std::fmt;
#[derive(Default)] #[derive(Default)]
pub enum ButtonType { pub enum ButtonType {
#[default] #[default]
@ -11,14 +9,13 @@ pub enum ButtonType {
} }
#[rustfmt::skip] #[rustfmt::skip]
impl fmt::Display for ButtonType { impl ToString for ButtonType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn to_string(&self) -> String {
let button_type = match self { String::from(match self {
ButtonType::Button => "button", ButtonType::Button => "button",
ButtonType::Submit => "submit", ButtonType::Submit => "submit",
ButtonType::Reset => "reset", ButtonType::Reset => "reset",
}; })
write!(f, "{button_type}")
} }
} }

View file

@ -1,7 +1,5 @@
use crate::prelude::*; use crate::prelude::*;
use std::fmt;
#[derive(Default)] #[derive(Default)]
pub enum HeadingType { pub enum HeadingType {
#[default] #[default]
@ -26,9 +24,9 @@ pub enum HeadingDisplay {
} }
#[rustfmt::skip] #[rustfmt::skip]
impl fmt::Display for HeadingDisplay { impl ToString for HeadingDisplay {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn to_string(&self) -> String {
let heading_display = match self { String::from(match self {
HeadingDisplay::ExtraLarge => "pt-heading__title-x3l", HeadingDisplay::ExtraLarge => "pt-heading__title-x3l",
HeadingDisplay::XxLarge => "pt-heading__title-x2l", HeadingDisplay::XxLarge => "pt-heading__title-x2l",
HeadingDisplay::XLarge => "pt-heading__title-xl", HeadingDisplay::XLarge => "pt-heading__title-xl",
@ -36,8 +34,7 @@ impl fmt::Display for HeadingDisplay {
HeadingDisplay::Medium => "pt-heading__title-m", HeadingDisplay::Medium => "pt-heading__title-m",
HeadingDisplay::Normal => "", HeadingDisplay::Normal => "",
HeadingDisplay::Subtitle => "pt-heading__subtitle", HeadingDisplay::Subtitle => "pt-heading__subtitle",
}; })
write!(f, "{heading_display}")
} }
} }

View file

@ -1,4 +1,4 @@
use std::fmt; use crate::concat_string;
// About pixels: Pixels (px) are relative to the viewing device. For low-dpi devices, 1px is one // About pixels: Pixels (px) are relative to the viewing device. For low-dpi devices, 1px is one
// device pixel (dot) of the display. For printers and high resolution screens 1px implies multiple // device pixel (dot) of the display. For printers and high resolution screens 1px implies multiple
@ -31,24 +31,24 @@ pub enum Value {
} }
#[rustfmt::skip] #[rustfmt::skip]
impl fmt::Display for Value { impl ToString for Value {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn to_string(&self) -> String {
match self { match self {
Value::None => write!(f, ""), Value::None => "".to_owned(),
Value::Auto => write!(f, "auto"), Value::Auto => "auto".to_owned(),
// Absolute value. // Absolute value.
Value::Cm(av) => write!(f, "{av}cm"), Value::Cm(av) => concat_string!(av.to_string(), "cm"),
Value::In(av) => write!(f, "{av}in"), Value::In(av) => concat_string!(av.to_string(), "in"),
Value::Mm(av) => write!(f, "{av}mm"), Value::Mm(av) => concat_string!(av.to_string(), "mm"),
Value::Pc(av) => write!(f, "{av}pc"), Value::Pc(av) => concat_string!(av.to_string(), "pc"),
Value::Pt(av) => write!(f, "{av}pt"), Value::Pt(av) => concat_string!(av.to_string(), "pt"),
Value::Px(av) => write!(f, "{av}px"), Value::Px(av) => concat_string!(av.to_string(), "px"),
// Relative value. // Relative value.
Value::RelEm(rv) => write!(f, "{rv}em"), Value::RelEm(rv) => concat_string!(rv.to_string(), "em"),
Value::RelPct(rv) => write!(f, "{rv}%"), Value::RelPct(rv) => concat_string!(rv.to_string(), "%"),
Value::RelRem(rv) => write!(f, "{rv}rem"), Value::RelRem(rv) => concat_string!(rv.to_string(), "rem"),
Value::RelVh(rv) => write!(f, "{rv}vh"), Value::RelVh(rv) => concat_string!(rv.to_string(), "vh"),
Value::RelVw(rv) => write!(f, "{rv}vw"), Value::RelVw(rv) => concat_string!(rv.to_string(), "vw"),
} }
} }
} }

View file

@ -99,7 +99,6 @@ pub(crate) use fluent_templates::StaticLoader as Locales;
use unic_langid::langid; use unic_langid::langid;
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt;
const LANGUAGE_SET_FAILURE: &str = "language_set_failure"; const LANGUAGE_SET_FAILURE: &str = "language_set_failure";
@ -245,13 +244,12 @@ impl L10n {
} }
} }
#[rustfmt::skip] impl ToString for L10n {
impl fmt::Display for L10n { fn to_string(&self) -> String {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.op { match &self.op {
L10nOp::None => write!(f, ""), L10nOp::None => "".to_owned(),
L10nOp::Text(text) => write!(f, "{text}"), L10nOp::Text(text) => text.to_owned(),
L10nOp::Translate(key) => write!(f, "{}", match self.locales { L10nOp::Translate(key) => match self.locales {
Some(locales) => locales Some(locales) => locales
.lookup_with_args( .lookup_with_args(
match key.as_str() { match key.as_str() {
@ -269,7 +267,7 @@ impl fmt::Display for L10n {
) )
.unwrap_or(key.to_owned()), .unwrap_or(key.to_owned()),
None => key.to_owned(), None => key.to_owned(),
}), },
} }
} }
} }