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() {
concat_string!("\n", config::SETTINGS.app.description)
} else {
"".to_string()
"".to_owned()
};
// Print banner.
println!(

View file

@ -2,8 +2,6 @@ use crate::core::component::{Context, ContextOp};
use crate::html::{JavaScript, StyleSheet};
use crate::Weight;
use std::fmt;
// Context parameters.
pub const PARAM_BASE_WEIGHT: &str = "base.weight";
pub const PARAM_BASE_INCLUDE_ICONS: &str = "base.include.icon";
@ -68,9 +66,9 @@ pub enum BreakPoint {
}
#[rustfmt::skip]
impl fmt::Display for BreakPoint {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let breakpoint = match self {
impl ToString for BreakPoint {
fn to_string(&self) -> String {
String::from(match self {
BreakPoint::None => "pt-bp__none",
BreakPoint::SM => "pt-bp__sm",
BreakPoint::MD => "pt-bp__md",
@ -79,8 +77,7 @@ impl fmt::Display for BreakPoint {
BreakPoint::X2L => "pt-bp__x2l",
BreakPoint::X3L => "pt-bp__x3l",
BreakPoint::X2K => "pt-bp__x2k",
};
write!(f, "{breakpoint}")
})
}
}
@ -102,9 +99,9 @@ pub enum FontSize {
}
#[rustfmt::skip]
impl fmt::Display for FontSize {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let font_size = match self {
impl ToString for FontSize {
fn to_string(&self) -> String {
String::from(match self {
FontSize::ExtraLarge => "pt-fs__x3l",
FontSize::XxLarge => "pt-fs__x2l",
FontSize::XLarge => "pt-fs__xl",
@ -115,8 +112,7 @@ impl fmt::Display for FontSize {
FontSize::XSmall => "pt-fs__xs",
FontSize::XxSmall => "pt-fs__x2s",
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 std::fmt;
// *************************************************************************************************
#[derive(Default)]
@ -20,23 +18,23 @@ pub enum Direction {
}
#[rustfmt::skip]
impl fmt::Display for Direction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
impl ToString for Direction {
fn to_string(&self) -> String {
match self {
Direction::Default => write!(
f, "pt-flex__container pt-flex__row {}", BreakPoint::default()
Direction::Default => concat_string!(
"pt-flex__container pt-flex__row ", BreakPoint::default().to_string()
),
Direction::Row(breakpoint) => write!(
f, "pt-flex__container pt-flex__row {breakpoint}"
Direction::Row(breakpoint) => concat_string!(
"pt-flex__container pt-flex__row ", breakpoint.to_string()
),
Direction::RowReverse(breakpoint) => write!(
f, "pt-flex__container pt-flex__row pt-flex__reverse {breakpoint}"
Direction::RowReverse(breakpoint) => concat_string!(
"pt-flex__container pt-flex__row pt-flex__reverse ", breakpoint.to_string()
),
Direction::Column(breakpoint) => write!(
f, "pt-flex__container pt-flex__col {breakpoint}"
Direction::Column(breakpoint) => concat_string!(
"pt-flex__container pt-flex__col ", breakpoint.to_string()
),
Direction::ColumnReverse(breakpoint) => write!(
f, "pt-flex__container pt-flex__col pt-flex__reverse {breakpoint}"
Direction::ColumnReverse(breakpoint) => concat_string!(
"pt-flex__container pt-flex__col pt-flex__reverse ", breakpoint.to_string()
),
}
}
@ -54,13 +52,13 @@ pub enum WrapAlign {
}
#[rustfmt::skip]
impl fmt::Display for WrapAlign {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
impl ToString for WrapAlign {
fn to_string(&self) -> String {
match self {
WrapAlign::Default => write!(f, ""),
WrapAlign::NoWrap => write!(f, "flex-nowrap"),
WrapAlign::Wrap(a) => write!(f, "pt-flex__wrap {a}"),
WrapAlign::WrapReverse(a) => write!(f, "pt-flex__wrap-reverse {a}"),
WrapAlign::Default => "".to_owned(),
WrapAlign::NoWrap => "flex-nowrap".to_owned(),
WrapAlign::Wrap(a) => concat_string!("pt-flex__wrap ", a.to_string()),
WrapAlign::WrapReverse(a) => concat_string!("pt-flex__wrap-reverse ", a.to_string()),
}
}
}
@ -80,9 +78,9 @@ pub enum ContentAlign {
}
#[rustfmt::skip]
impl fmt::Display for ContentAlign {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let content_align = match self {
impl ToString for ContentAlign {
fn to_string(&self) -> String {
String::from(match self {
ContentAlign::Default => "",
ContentAlign::Start => "pt-flex__align-start",
ContentAlign::End => "pt-flex__align-end",
@ -90,8 +88,7 @@ impl fmt::Display for ContentAlign {
ContentAlign::Stretch => "pt-flex__align-stretch",
ContentAlign::SpaceBetween => "pt-flex__align-space-between",
ContentAlign::SpaceAround => "pt-flex__align-space-around",
};
write!(f, "{content_align}")
})
}
}
@ -110,9 +107,9 @@ pub enum ContentJustify {
}
#[rustfmt::skip]
impl fmt::Display for ContentJustify {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let content_justify = match self {
impl ToString for ContentJustify {
fn to_string(&self) -> String {
String::from(match self {
ContentJustify::Default => "",
ContentJustify::Start => "pt-flex__justify-start",
ContentJustify::End => "pt-flex__justify-end",
@ -120,8 +117,7 @@ impl fmt::Display for ContentJustify {
ContentJustify::SpaceBetween => "pt-flex__justify-space-between",
ContentJustify::SpaceAround => "pt-flex__justify-space-around",
ContentJustify::SpaceEvenly => "pt-flex__justify-space-evenly",
};
write!(f, "{content_justify}")
})
}
}
@ -139,17 +135,16 @@ pub enum ItemAlign {
}
#[rustfmt::skip]
impl fmt::Display for ItemAlign {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let item_align = match self {
impl ToString for ItemAlign {
fn to_string(&self) -> String {
String::from(match self {
ItemAlign::Default => "",
ItemAlign::Top => "pt-flex__item-top",
ItemAlign::Bottom => "pt-flex__item-bottom",
ItemAlign::Middle => "pt-flex__item-middle",
ItemAlign::Stretch => "pt-flex__item-stretch",
ItemAlign::Baseline => "pt-flex__item-baseline",
};
write!(f, "{item_align}")
})
}
}
@ -166,14 +161,14 @@ pub enum Gap {
}
#[rustfmt::skip]
impl fmt::Display for Gap {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
impl ToString for Gap {
fn to_string(&self) -> String {
match self {
Gap::Default => write!(f, ""),
Gap::Row(r) => write!(f, "row-gap: {r};"),
Gap::Column(c) => write!(f, "column-gap: {c};"),
Gap::Distinct(r, c) => write!(f, "gap: {r} {c};"),
Gap::Both(v) => write!(f, "gap: {v};"),
Gap::Default => "".to_owned(),
Gap::Row(r) => concat_string!("row-gap: ", r.to_string(), ";"),
Gap::Column(c) => concat_string!("column-gap: ", c.to_string(), ";"),
Gap::Distinct(r, c) => concat_string!("gap: ", r.to_string(), " ", c.to_string(), ";"),
Gap::Both(v) => concat_string!("gap: ", v.to_string(), ";"),
}
}
}
@ -196,9 +191,9 @@ pub enum ItemGrow {
}
#[rustfmt::skip]
impl fmt::Display for ItemGrow {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let item_grow = match self {
impl ToString for ItemGrow {
fn to_string(&self) -> String {
String::from(match self {
ItemGrow::Default => "",
ItemGrow::Is1 => "pt-flex__grow-1",
ItemGrow::Is2 => "pt-flex__grow-2",
@ -209,8 +204,7 @@ impl fmt::Display for ItemGrow {
ItemGrow::Is7 => "pt-flex__grow-7",
ItemGrow::Is8 => "pt-flex__grow-8",
ItemGrow::Is9 => "pt-flex__grow-9",
};
write!(f, "{item_grow}")
})
}
}
@ -232,9 +226,9 @@ pub enum ItemShrink {
}
#[rustfmt::skip]
impl fmt::Display for ItemShrink {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let item_shrink = match self {
impl ToString for ItemShrink {
fn to_string(&self) -> String {
String::from(match self {
ItemShrink::Default => "",
ItemShrink::Is1 => "pt-flex__shrink-1",
ItemShrink::Is2 => "pt-flex__shrink-2",
@ -245,8 +239,7 @@ impl fmt::Display for ItemShrink {
ItemShrink::Is7 => "pt-flex__shrink-7",
ItemShrink::Is8 => "pt-flex__shrink-8",
ItemShrink::Is9 => "pt-flex__shrink-9",
};
write!(f, "{item_shrink}")
})
}
}
@ -270,9 +263,9 @@ pub enum ItemSize {
}
#[rustfmt::skip]
impl fmt::Display for ItemSize {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let item_size = match self {
impl ToString for ItemSize {
fn to_string(&self) -> String {
String::from(match self {
ItemSize::Default => "",
ItemSize::Percent10 => "pt-flex__width-10",
ItemSize::Percent20 => "pt-flex__width-20",
@ -285,8 +278,7 @@ impl fmt::Display for ItemSize {
ItemSize::Percent75 => "pt-flex__width-75",
ItemSize::Percent80 => "pt-flex__width-80",
ItemSize::Percent90 => "pt-flex__width-90",
};
write!(f, "{item_size}")
})
}
}
@ -310,9 +302,9 @@ pub enum ItemOffset {
}
#[rustfmt::skip]
impl fmt::Display for ItemOffset {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let item_offset = match self {
impl ToString for ItemOffset {
fn to_string(&self) -> String {
String::from(match self {
ItemOffset::Default => "",
ItemOffset::Offset10 => "pt-flex__offset-10",
ItemOffset::Offset20 => "pt-flex__offset-20",
@ -325,7 +317,6 @@ impl fmt::Display for ItemOffset {
ItemOffset::Offset75 => "pt-flex__offset-75",
ItemOffset::Offset80 => "pt-flex__offset-80",
ItemOffset::Offset90 => "pt-flex__offset-90",
};
write!(f, "{item_offset}")
})
}
}

View file

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

View file

@ -1,7 +1,5 @@
use crate::prelude::*;
use std::fmt;
#[derive(Default)]
pub enum HeadingType {
#[default]
@ -26,9 +24,9 @@ pub enum HeadingDisplay {
}
#[rustfmt::skip]
impl fmt::Display for HeadingDisplay {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let heading_display = match self {
impl ToString for HeadingDisplay {
fn to_string(&self) -> String {
String::from(match self {
HeadingDisplay::ExtraLarge => "pt-heading__title-x3l",
HeadingDisplay::XxLarge => "pt-heading__title-x2l",
HeadingDisplay::XLarge => "pt-heading__title-xl",
@ -36,8 +34,7 @@ impl fmt::Display for HeadingDisplay {
HeadingDisplay::Medium => "pt-heading__title-m",
HeadingDisplay::Normal => "",
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
// device pixel (dot) of the display. For printers and high resolution screens 1px implies multiple
@ -31,24 +31,24 @@ pub enum Value {
}
#[rustfmt::skip]
impl fmt::Display for Value {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
impl ToString for Value {
fn to_string(&self) -> String {
match self {
Value::None => write!(f, ""),
Value::Auto => write!(f, "auto"),
Value::None => "".to_owned(),
Value::Auto => "auto".to_owned(),
// Absolute value.
Value::Cm(av) => write!(f, "{av}cm"),
Value::In(av) => write!(f, "{av}in"),
Value::Mm(av) => write!(f, "{av}mm"),
Value::Pc(av) => write!(f, "{av}pc"),
Value::Pt(av) => write!(f, "{av}pt"),
Value::Px(av) => write!(f, "{av}px"),
Value::Cm(av) => concat_string!(av.to_string(), "cm"),
Value::In(av) => concat_string!(av.to_string(), "in"),
Value::Mm(av) => concat_string!(av.to_string(), "mm"),
Value::Pc(av) => concat_string!(av.to_string(), "pc"),
Value::Pt(av) => concat_string!(av.to_string(), "pt"),
Value::Px(av) => concat_string!(av.to_string(), "px"),
// Relative value.
Value::RelEm(rv) => write!(f, "{rv}em"),
Value::RelPct(rv) => write!(f, "{rv}%"),
Value::RelRem(rv) => write!(f, "{rv}rem"),
Value::RelVh(rv) => write!(f, "{rv}vh"),
Value::RelVw(rv) => write!(f, "{rv}vw"),
Value::RelEm(rv) => concat_string!(rv.to_string(), "em"),
Value::RelPct(rv) => concat_string!(rv.to_string(), "%"),
Value::RelRem(rv) => concat_string!(rv.to_string(), "rem"),
Value::RelVh(rv) => concat_string!(rv.to_string(), "vh"),
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 std::collections::HashMap;
use std::fmt;
const LANGUAGE_SET_FAILURE: &str = "language_set_failure";
@ -245,13 +244,12 @@ impl L10n {
}
}
#[rustfmt::skip]
impl fmt::Display for L10n {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
impl ToString for L10n {
fn to_string(&self) -> String {
match &self.op {
L10nOp::None => write!(f, ""),
L10nOp::Text(text) => write!(f, "{text}"),
L10nOp::Translate(key) => write!(f, "{}", match self.locales {
L10nOp::None => "".to_owned(),
L10nOp::Text(text) => text.to_owned(),
L10nOp::Translate(key) => match self.locales {
Some(locales) => locales
.lookup_with_args(
match key.as_str() {
@ -269,7 +267,7 @@ impl fmt::Display for L10n {
)
.unwrap_or(key.to_owned()),
None => key.to_owned(),
}),
},
}
}
}