🧑‍💻 Swap Default for more versatile SmartDefault

This commit is contained in:
Manuel Cillero 2023-11-18 07:31:45 +01:00
parent e25cc16859
commit 5daa84283d
45 changed files with 93 additions and 106 deletions

View file

@ -40,6 +40,7 @@ itoa = "1.0.9"
nom = "7.1.3" nom = "7.1.3"
once_cell = "1.18.0" once_cell = "1.18.0"
paste = "1.0.14" paste = "1.0.14"
smart-default = "0.7.1"
substring = "1.4.5" substring = "1.4.5"
term_size = "0.3.2" term_size = "0.3.2"
toml = "0.8.8" toml = "0.8.8"

View file

@ -1,6 +1,6 @@
use crate::core::component::{Context, ContextOp}; use crate::core::component::{Context, ContextOp};
use crate::html::{JavaScript, StyleSheet}; use crate::html::{JavaScript, StyleSheet};
use crate::Weight; use crate::{SmartDefault, Weight};
// Context parameters. // Context parameters.
pub const PARAM_BASE_WEIGHT: &str = "base.weight"; pub const PARAM_BASE_WEIGHT: &str = "base.weight";
@ -57,7 +57,7 @@ pub(crate) fn add_base_assets(cx: &mut Context) {
// ************************************************************************************************* // *************************************************************************************************
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub enum BreakPoint { pub enum BreakPoint {
#[default] #[default]
None, /* Does not apply. Rest initially assume 1 pixel = 0.0625em */ None, /* Does not apply. Rest initially assume 1 pixel = 0.0625em */
@ -88,7 +88,7 @@ impl ToString for BreakPoint {
// ************************************************************************************************* // *************************************************************************************************
#[derive(Default)] #[derive(SmartDefault)]
pub enum FontSize { pub enum FontSize {
ExtraLarge, ExtraLarge,
XxLarge, XxLarge,

View file

@ -1,7 +1,7 @@
use crate::prelude::*; use crate::prelude::*;
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Block { pub struct Block {
id : OptionId, id : OptionId,
weight : Weight, weight : Weight,

View file

@ -1,31 +1,19 @@
use crate::prelude::*; use crate::prelude::*;
#[rustfmt::skip] #[rustfmt::skip]
#[derive(SmartDefault)]
pub struct Branding { pub struct Branding {
id : OptionId, id : OptionId,
weight : Weight, weight : Weight,
renderable: Renderable, renderable: Renderable,
#[default(_code = "config::SETTINGS.app.name.to_owned()")]
app_name : String, app_name : String,
slogan : OptionTranslated, slogan : OptionTranslated,
logo : ArcTypedComponent<Image>, logo : OptionComponent<Image>,
#[default(_code = "|_| \"/\"")]
frontpage : FnContextualPath, frontpage : FnContextualPath,
} }
#[rustfmt::skip]
impl Default for Branding {
fn default() -> Self {
Branding {
id : OptionId::default(),
weight : Weight::default(),
renderable: Renderable::default(),
app_name : config::SETTINGS.app.name.to_owned(),
slogan : OptionTranslated::default(),
logo : ArcTypedComponent::<Image>::default(),
frontpage : |_| "/",
}
}
}
impl_handle!(COMPONENT_BASE_BRANDING for Branding); impl_handle!(COMPONENT_BASE_BRANDING for Branding);
impl ComponentTrait for Branding { impl ComponentTrait for Branding {

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
#[derive(Default)] #[derive(SmartDefault)]
pub enum ButtonType { pub enum ButtonType {
#[default] #[default]
Link, Link,
@ -17,7 +17,7 @@ impl ToString for ButtonType {
} }
} }
#[derive(Default)] #[derive(SmartDefault)]
pub enum ButtonTarget { pub enum ButtonTarget {
#[default] #[default]
Default, Default,
@ -27,10 +27,8 @@ pub enum ButtonTarget {
Context(String), Context(String),
} }
type ButtonIcon = ArcTypedComponent<Icon>;
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Button { pub struct Button {
id : OptionId, id : OptionId,
weight : Weight, weight : Weight,

View file

@ -7,7 +7,7 @@ use crate::prelude::*;
// ************************************************************************************************* // *************************************************************************************************
#[derive(Default)] #[derive(SmartDefault)]
pub enum Direction { pub enum Direction {
#[default] #[default]
Default, Default,
@ -42,7 +42,7 @@ impl ToString for Direction {
// ************************************************************************************************* // *************************************************************************************************
#[derive(Default)] #[derive(SmartDefault)]
pub enum WrapAlign { pub enum WrapAlign {
#[default] #[default]
Default, Default,
@ -65,7 +65,7 @@ impl ToString for WrapAlign {
// ************************************************************************************************* // *************************************************************************************************
#[derive(Default)] #[derive(SmartDefault)]
pub enum ContentAlign { pub enum ContentAlign {
#[default] #[default]
Default, Default,
@ -94,7 +94,7 @@ impl ToString for ContentAlign {
// ************************************************************************************************* // *************************************************************************************************
#[derive(Default)] #[derive(SmartDefault)]
pub enum ContentJustify { pub enum ContentJustify {
#[default] #[default]
Default, Default,
@ -123,7 +123,7 @@ impl ToString for ContentJustify {
// ************************************************************************************************* // *************************************************************************************************
#[derive(Default)] #[derive(SmartDefault)]
pub enum ItemAlign { pub enum ItemAlign {
#[default] #[default]
Default, Default,
@ -150,7 +150,7 @@ impl ToString for ItemAlign {
// ************************************************************************************************* // *************************************************************************************************
#[derive(Default)] #[derive(SmartDefault)]
pub enum Gap { pub enum Gap {
#[default] #[default]
Default, Default,
@ -175,7 +175,7 @@ impl ToString for Gap {
// ************************************************************************************************* // *************************************************************************************************
#[derive(Default)] #[derive(SmartDefault)]
pub enum ItemGrow { pub enum ItemGrow {
#[default] #[default]
Default, Default,
@ -210,7 +210,7 @@ impl ToString for ItemGrow {
// ************************************************************************************************* // *************************************************************************************************
#[derive(Default)] #[derive(SmartDefault)]
pub enum ItemShrink { pub enum ItemShrink {
#[default] #[default]
Default, Default,
@ -245,7 +245,7 @@ impl ToString for ItemShrink {
// ************************************************************************************************* // *************************************************************************************************
#[derive(Default)] #[derive(SmartDefault)]
pub enum ItemSize { pub enum ItemSize {
#[default] #[default]
Default, Default,
@ -284,7 +284,7 @@ impl ToString for ItemSize {
// ************************************************************************************************* // *************************************************************************************************
#[derive(Default)] #[derive(SmartDefault)]
pub enum ItemOffset { pub enum ItemOffset {
#[default] #[default]
Default, Default,

View file

@ -1,7 +1,7 @@
use crate::prelude::*; use crate::prelude::*;
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Container { pub struct Container {
id : OptionId, id : OptionId,
weight : Weight, weight : Weight,

View file

@ -1,7 +1,7 @@
use crate::prelude::*; use crate::prelude::*;
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Item { pub struct Item {
id : OptionId, id : OptionId,
weight : Weight, weight : Weight,

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
#[derive(Default)] #[derive(SmartDefault)]
pub enum ButtonType { pub enum ButtonType {
#[default] #[default]
Button, Button,
@ -20,7 +20,7 @@ impl ToString for ButtonType {
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Button { pub struct Button {
weight : Weight, weight : Weight,
renderable : Renderable, renderable : Renderable,

View file

@ -1,7 +1,7 @@
use crate::prelude::*; use crate::prelude::*;
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Date { pub struct Date {
weight : Weight, weight : Weight,
renderable : Renderable, renderable : Renderable,

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
#[derive(Default)] #[derive(SmartDefault)]
pub enum FormMethod { pub enum FormMethod {
#[default] #[default]
Post, Post,
@ -8,7 +8,7 @@ pub enum FormMethod {
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Form { pub struct Form {
id : OptionId, id : OptionId,
weight : Weight, weight : Weight,

View file

@ -1,7 +1,7 @@
use crate::prelude::*; use crate::prelude::*;
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Hidden { pub struct Hidden {
weight: Weight, weight: Weight,
name : OptionName, name : OptionName,

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
#[derive(Default)] #[derive(SmartDefault)]
pub enum InputType { pub enum InputType {
#[default] #[default]
Textfield, Textfield,
@ -12,7 +12,7 @@ pub enum InputType {
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Input { pub struct Input {
weight : Weight, weight : Weight,
renderable : Renderable, renderable : Renderable,

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
#[derive(Default)] #[derive(SmartDefault)]
pub enum HeadingType { pub enum HeadingType {
#[default] #[default]
H1, H1,
@ -11,7 +11,7 @@ pub enum HeadingType {
H6, H6,
} }
#[derive(Default)] #[derive(SmartDefault)]
pub enum HeadingDisplay { pub enum HeadingDisplay {
ExtraLarge, ExtraLarge,
XxLarge, XxLarge,
@ -39,7 +39,7 @@ impl ToString for HeadingDisplay {
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Heading { pub struct Heading {
id : OptionId, id : OptionId,
weight : Weight, weight : Weight,

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
#[derive(Default)] #[derive(SmartDefault)]
pub struct Html(Markup); pub struct Html(Markup);
impl_handle!(COMPONENT_BASE_HTML for Html); impl_handle!(COMPONENT_BASE_HTML for Html);

View file

@ -1,7 +1,7 @@
use crate::prelude::*; use crate::prelude::*;
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Icon { pub struct Icon {
weight : Weight, weight : Weight,
renderable: Renderable, renderable: Renderable,

View file

@ -3,7 +3,7 @@ use crate::prelude::*;
const IMG_FLUID: &str = "pt-img__fluid"; const IMG_FLUID: &str = "pt-img__fluid";
const IMG_FIXED: &str = "pt-img__fixed"; const IMG_FIXED: &str = "pt-img__fixed";
#[derive(Default)] #[derive(SmartDefault)]
pub enum ImageSize { pub enum ImageSize {
#[default] #[default]
Auto, Auto,
@ -14,7 +14,7 @@ pub enum ImageSize {
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Image { pub struct Image {
id : OptionId, id : OptionId,
weight : Weight, weight : Weight,

View file

@ -5,7 +5,7 @@ use super::Submenu;
type Content = ArcTypedComponent<Html>; type Content = ArcTypedComponent<Html>;
type SubmenuItems = ArcTypedComponent<Submenu>; type SubmenuItems = ArcTypedComponent<Submenu>;
#[derive(Default)] #[derive(SmartDefault)]
pub enum ElementType { pub enum ElementType {
#[default] #[default]
Void, Void,
@ -16,7 +16,7 @@ pub enum ElementType {
// Element. // Element.
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Element { pub struct Element {
weight : Weight, weight : Weight,
renderable : Renderable, renderable : Renderable,

View file

@ -3,7 +3,7 @@ use crate::prelude::*;
use super::Element; use super::Element;
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Group { pub struct Group {
id : OptionId, id : OptionId,
weight : Weight, weight : Weight,

View file

@ -7,7 +7,7 @@ type Content = ArcTypedComponent<Html>;
type SubmenuItems = ArcTypedComponent<Submenu>; type SubmenuItems = ArcTypedComponent<Submenu>;
type MegamenuGroups = ArcTypedComponent<Megamenu>; type MegamenuGroups = ArcTypedComponent<Megamenu>;
#[derive(Default)] #[derive(SmartDefault)]
pub enum ItemType { pub enum ItemType {
#[default] #[default]
Void, Void,
@ -22,7 +22,7 @@ pub enum ItemType {
// Item. // Item.
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Item { pub struct Item {
weight : Weight, weight : Weight,
renderable : Renderable, renderable : Renderable,

View file

@ -3,7 +3,7 @@ use crate::prelude::*;
use super::Group; use super::Group;
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Megamenu { pub struct Megamenu {
id : OptionId, id : OptionId,
weight : Weight, weight : Weight,

View file

@ -3,7 +3,7 @@ use crate::prelude::*;
use super::Item; use super::Item;
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Menu { pub struct Menu {
id : OptionId, id : OptionId,
weight : Weight, weight : Weight,

View file

@ -3,7 +3,7 @@ use crate::prelude::*;
use super::Item; use super::Item;
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Submenu { pub struct Submenu {
id : OptionId, id : OptionId,
weight : Weight, weight : Weight,

View file

@ -1,7 +1,7 @@
use crate::prelude::*; use crate::prelude::*;
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Paragraph { pub struct Paragraph {
id : OptionId, id : OptionId,
weight : Weight, weight : Weight,

View file

@ -11,7 +11,7 @@ pub enum PoweredByLogo {
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct PoweredBy { pub struct PoweredBy {
weight : Weight, weight : Weight,
renderable: Renderable, renderable: Renderable,

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
#[derive(Default)] #[derive(SmartDefault)]
pub struct Translate(L10n); pub struct Translate(L10n);
impl_handle!(COMPONENT_BASE_TRANSLATE for Translate); impl_handle!(COMPONENT_BASE_TRANSLATE for Translate);

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
#[derive(Default)] #[derive(SmartDefault)]
pub enum WrapperType { pub enum WrapperType {
#[default] #[default]
Container, Container,
@ -11,7 +11,7 @@ pub enum WrapperType {
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct Wrapper { pub struct Wrapper {
id : OptionId, id : OptionId,
weight : Weight, weight : Weight,

View file

@ -1,10 +1,11 @@
use crate::core::action::ActionTrait; use crate::core::action::ActionTrait;
use crate::SmartDefault;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
pub type Action = Box<dyn ActionTrait>; pub type Action = Box<dyn ActionTrait>;
#[derive(Default)] #[derive(SmartDefault)]
pub struct ActionsList(Arc<RwLock<Vec<Action>>>); pub struct ActionsList(Arc<RwLock<Vec<Action>>>);
impl ActionsList { impl ActionsList {

View file

@ -1,19 +1,14 @@
use crate::core::component::Context; use crate::core::component::Context;
use crate::SmartDefault;
pub type FnIsRenderable = fn(cx: &Context) -> bool; pub type FnIsRenderable = fn(cx: &Context) -> bool;
#[derive(SmartDefault)]
pub struct Renderable { pub struct Renderable {
#[default(_code = "render_always")]
pub check: FnIsRenderable, pub check: FnIsRenderable,
} }
impl Default for Renderable {
fn default() -> Self {
Renderable {
check: render_always,
}
}
}
fn render_always(_cx: &Context) -> bool { fn render_always(_cx: &Context) -> bool {
true true
} }

View file

@ -1,6 +1,6 @@
use crate::core::component::{AnyComponents, ArcAnyComponent, ArcAnyOp}; use crate::core::component::{AnyComponents, ArcAnyComponent, ArcAnyOp};
use crate::core::theme::ThemeRef; use crate::core::theme::ThemeRef;
use crate::{Handle, LazyStatic}; use crate::{Handle, LazyStatic, SmartDefault};
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::RwLock; use std::sync::RwLock;
@ -11,7 +11,7 @@ static THEME_REGIONS: LazyStatic<RwLock<HashMap<Handle, ComponentsRegions>>> =
static COMMON_REGIONS: LazyStatic<RwLock<ComponentsRegions>> = static COMMON_REGIONS: LazyStatic<RwLock<ComponentsRegions>> =
LazyStatic::new(|| RwLock::new(ComponentsRegions::default())); LazyStatic::new(|| RwLock::new(ComponentsRegions::default()));
#[derive(Default)] #[derive(SmartDefault)]
pub struct ComponentsRegions(HashMap<&'static str, AnyComponents>); pub struct ComponentsRegions(HashMap<&'static str, AnyComponents>);
impl ComponentsRegions { impl ComponentsRegions {

View file

@ -4,7 +4,7 @@ pub mod javascript;
pub mod stylesheet; pub mod stylesheet;
use crate::html::{html, Markup}; use crate::html::{html, Markup};
use crate::Weight; use crate::{SmartDefault, Weight};
pub trait AssetsTrait { pub trait AssetsTrait {
fn path(&self) -> &str; fn path(&self) -> &str;
@ -14,7 +14,7 @@ pub trait AssetsTrait {
fn prepare(&self) -> Markup; fn prepare(&self) -> Markup;
} }
#[derive(Default)] #[derive(SmartDefault)]
pub struct Assets<T>(Vec<T>); pub struct Assets<T>(Vec<T>);
impl<T: AssetsTrait> Assets<T> { impl<T: AssetsTrait> Assets<T> {

View file

@ -1,9 +1,9 @@
use crate::html::assets::AssetsTrait; use crate::html::assets::AssetsTrait;
use crate::html::{html, Markup}; use crate::html::{html, Markup};
use crate::Weight; use crate::{SmartDefault, Weight};
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct HeadScript { pub struct HeadScript {
path : String, path : String,
code : String, code : String,

View file

@ -1,9 +1,9 @@
use crate::html::assets::AssetsTrait; use crate::html::assets::AssetsTrait;
use crate::html::{html, Markup}; use crate::html::{html, Markup};
use crate::Weight; use crate::{SmartDefault, Weight};
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct HeadStyles { pub struct HeadStyles {
path : String, path : String,
styles: String, styles: String,

View file

@ -1,6 +1,6 @@
use crate::html::assets::AssetsTrait; use crate::html::assets::AssetsTrait;
use crate::html::{html, Markup}; use crate::html::{html, Markup};
use crate::Weight; use crate::{SmartDefault, Weight};
#[derive(Default, Eq, PartialEq)] #[derive(Default, Eq, PartialEq)]
pub enum ModeJS { pub enum ModeJS {
@ -11,7 +11,7 @@ pub enum ModeJS {
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct JavaScript { pub struct JavaScript {
path : String, path : String,
prefix : &'static str, prefix : &'static str,

View file

@ -1,6 +1,6 @@
use crate::html::assets::AssetsTrait; use crate::html::assets::AssetsTrait;
use crate::html::{html, Markup}; use crate::html::{html, Markup};
use crate::Weight; use crate::{SmartDefault, Weight};
pub enum TargetMedia { pub enum TargetMedia {
Default, Default,
@ -10,7 +10,7 @@ pub enum TargetMedia {
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub struct StyleSheet { pub struct StyleSheet {
path : String, path : String,
prefix : &'static str, prefix : &'static str,

View file

@ -1,6 +1,7 @@
use crate::html::{html, Markup}; use crate::html::{html, Markup};
use crate::SmartDefault;
#[derive(Default)] #[derive(SmartDefault)]
pub struct Favicon(Vec<Markup>); pub struct Favicon(Vec<Markup>);
impl Favicon { impl Favicon {

View file

@ -9,7 +9,7 @@
//! **OptionClasses** assumes that the order of the classes is irrelevant //! **OptionClasses** assumes that the order of the classes is irrelevant
//! (<https://stackoverflow.com/a/1321712>), and duplicate classes will not be allowed. //! (<https://stackoverflow.com/a/1321712>), and duplicate classes will not be allowed.
use crate::fn_builder; use crate::{fn_builder, SmartDefault};
pub enum ClassesOp { pub enum ClassesOp {
Add, Add,
@ -20,7 +20,7 @@ pub enum ClassesOp {
Clear, Clear,
} }
#[derive(Default)] #[derive(SmartDefault)]
pub struct OptionClasses(Vec<String>); pub struct OptionClasses(Vec<String>);
impl OptionClasses { impl OptionClasses {

View file

@ -1,6 +1,6 @@
use crate::fn_builder; use crate::{fn_builder, SmartDefault};
#[derive(Default)] #[derive(SmartDefault)]
pub struct OptionId(Option<String>); pub struct OptionId(Option<String>);
impl OptionId { impl OptionId {

View file

@ -1,6 +1,6 @@
use crate::fn_builder; use crate::{fn_builder, SmartDefault};
#[derive(Default)] #[derive(SmartDefault)]
pub struct OptionName(Option<String>); pub struct OptionName(Option<String>);
impl OptionName { impl OptionName {

View file

@ -1,6 +1,6 @@
use crate::fn_builder; use crate::{fn_builder, SmartDefault};
#[derive(Default)] #[derive(SmartDefault)]
pub struct OptionString(Option<String>); pub struct OptionString(Option<String>);
impl OptionString { impl OptionString {

View file

@ -1,9 +1,8 @@
use crate::fn_builder;
use crate::html::Markup; use crate::html::Markup;
use crate::locale::{L10n, LanguageIdentifier}; use crate::locale::{L10n, LanguageIdentifier};
use crate::{fn_builder, SmartDefault};
#[derive(Default)] #[derive(SmartDefault)]
pub struct OptionTranslated(L10n); pub struct OptionTranslated(L10n);
impl OptionTranslated { impl OptionTranslated {

View file

@ -1,4 +1,4 @@
use crate::concat_string; use crate::{concat_string, SmartDefault};
// 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
@ -10,7 +10,7 @@ use crate::concat_string;
// About viewport: If the browser window size is 50cm wide, 1vw = 0.5cm. // About viewport: If the browser window size is 50cm wide, 1vw = 0.5cm.
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)] #[derive(SmartDefault)]
pub enum Value { pub enum Value {
#[default] #[default]
None, None,

View file

@ -101,7 +101,7 @@
#![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr(docsrs, feature(doc_cfg))]
// ************************************************************************************************* // *************************************************************************************************
// RE-EXPORTED MACROS. // RE-EXPORTED MACROS AND DERIVES.
// ************************************************************************************************* // *************************************************************************************************
pub use concat_string::concat_string; pub use concat_string::concat_string;
@ -109,6 +109,10 @@ pub use concat_string::concat_string;
/// Enables flexible identifier concatenation in macros, allowing new items with pasted identifiers. /// Enables flexible identifier concatenation in macros, allowing new items with pasted identifiers.
pub use paste::paste; pub use paste::paste;
/// Custom derive for automatically implementing the [Default](std::default::Default) trait with
/// customized default values.
pub use smart_default::SmartDefault;
pub use pagetop_macros::{fn_builder, main, test}; pub use pagetop_macros::{fn_builder, main, test};
// ************************************************************************************************* // *************************************************************************************************

View file

@ -88,7 +88,7 @@
//! ``` //! ```
use crate::html::{Markup, PreEscaped}; use crate::html::{Markup, PreEscaped};
use crate::{config, kv, LazyStatic, LOCALES_PAGETOP}; use crate::{config, kv, LazyStatic, SmartDefault, LOCALES_PAGETOP};
pub use fluent_templates; pub use fluent_templates;
pub use unic_langid::LanguageIdentifier; pub use unic_langid::LanguageIdentifier;
@ -169,7 +169,7 @@ macro_rules! static_locales {
}; };
} }
#[derive(Default)] #[derive(SmartDefault)]
enum L10nOp { enum L10nOp {
#[default] #[default]
None, None,
@ -177,7 +177,7 @@ enum L10nOp {
Translate(String), Translate(String),
} }
#[derive(Default)] #[derive(SmartDefault)]
pub struct L10n { pub struct L10n {
op: L10nOp, op: L10nOp,
locales: Option<&'static Locales>, locales: Option<&'static Locales>,

View file

@ -1,7 +1,7 @@
//! The PageTop Prelude. //! The PageTop Prelude.
// Re-exported macros. // Re-exported macros and derives.
pub use crate::{concat_string, fn_builder, main, paste, test}; pub use crate::{concat_string, fn_builder, main, paste, test, SmartDefault};
// Global. // Global.
pub use crate::{Handle, HasHandle, HashMapResources, LazyStatic, Weight}; pub use crate::{Handle, HasHandle, HashMapResources, LazyStatic, Weight};