🏷️ Introduce Weight type for element weights

This commit is contained in:
Manuel Cillero 2023-07-16 07:45:09 +02:00
parent 6df57a0c12
commit 941b7ae57b
28 changed files with 118 additions and 110 deletions

View file

@ -49,7 +49,7 @@ fn after_prepare_body(page: &mut Page) {
page.context().alter(ContextOp::AddJavaScript(
JavaScript::at("/jquery/jquery.min.js")
.with_version("3.6.0")
.with_weight(isize::MIN)
.with_weight(-99)
.with_mode(ModeJS::Normal),
));
}

View file

@ -23,7 +23,7 @@ pub enum MegaMenuItemType {
#[rustfmt::skip]
#[derive(Default)]
pub struct MegaMenuItem {
weight : isize,
weight : Weight,
renderable: Renderable,
item_type : MegaMenuItemType,
}
@ -37,7 +37,7 @@ impl ComponentTrait for MegaMenuItem {
COMPONENT_MEGAMENUITEM
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -124,8 +124,8 @@ impl MegaMenuItem {
// MegaMenuItem BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}
@ -151,7 +151,7 @@ actions_for_component!(MegaMenu);
#[rustfmt::skip]
#[derive(Default)]
pub struct MegaMenu {
weight : isize,
weight : Weight,
renderable: Renderable,
id : IdentifierValue,
classes : Classes,
@ -172,7 +172,7 @@ impl ComponentTrait for MegaMenu {
self.id.get()
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -220,8 +220,8 @@ impl MegaMenu {
// MegaMenu BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}

View file

@ -28,7 +28,7 @@ type AnchorHtml = OneComponent<L10n>;
#[rustfmt::skip]
#[derive(Default)]
pub struct Anchor {
weight : isize,
weight : Weight,
renderable : Renderable,
id : IdentifierValue,
classes : Classes,
@ -54,7 +54,7 @@ impl ComponentTrait for Anchor {
self.id.get()
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -105,8 +105,8 @@ impl Anchor {
// Anchor BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}

View file

@ -7,7 +7,7 @@ actions_for_component!(Block);
#[rustfmt::skip]
#[derive(Default)]
pub struct Block {
weight : isize,
weight : Weight,
renderable: Renderable,
id : IdentifierValue,
classes : Classes,
@ -29,7 +29,7 @@ impl ComponentTrait for Block {
self.id.get()
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -70,8 +70,8 @@ impl Block {
}
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}

View file

@ -17,7 +17,7 @@ pub enum ContainerType {
#[rustfmt::skip]
#[derive(Default)]
pub struct Container {
weight : isize,
weight : Weight,
renderable : Renderable,
id : IdentifierValue,
classes : Classes,
@ -42,7 +42,7 @@ impl ComponentTrait for Container {
self.id.get()
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -125,8 +125,8 @@ impl Container {
// Container BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}

View file

@ -15,7 +15,7 @@ type ButtonValue = OneComponent<L10n>;
#[rustfmt::skip]
#[derive(Default)]
pub struct Button {
weight : isize,
weight : Weight,
renderable : Renderable,
classes : Classes,
button_type: ButtonType,
@ -37,7 +37,7 @@ impl ComponentTrait for Button {
COMPONENT_BUTTON
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -93,8 +93,8 @@ impl Button {
// Button BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}

View file

@ -5,7 +5,7 @@ create_handle!(COMPONENT_DATE);
#[rustfmt::skip]
#[derive(Default)]
pub struct Date {
weight : isize,
weight : Weight,
renderable : Renderable,
classes : Classes,
name : AttributeValue,
@ -32,7 +32,7 @@ impl ComponentTrait for Date {
COMPONENT_DATE
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -78,8 +78,8 @@ impl Date {
// Date BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}

View file

@ -14,7 +14,7 @@ pub enum FormMethod {
#[rustfmt::skip]
#[derive(Default)]
pub struct Form {
weight : isize,
weight : Weight,
renderable: Renderable,
id : IdentifierValue,
classes : Classes,
@ -40,7 +40,7 @@ impl ComponentTrait for Form {
self.id.get()
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -79,8 +79,8 @@ impl Form {
// Form BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}

View file

@ -5,7 +5,7 @@ create_handle!(COMPONENT_HIDDEN);
#[rustfmt::skip]
#[derive(Default)]
pub struct Hidden {
weight: isize,
weight: Weight,
name : NameValue,
value : AttributeValue,
}
@ -19,7 +19,7 @@ impl ComponentTrait for Hidden {
COMPONENT_HIDDEN
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -39,8 +39,8 @@ impl Hidden {
// Hidden BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}

View file

@ -19,7 +19,7 @@ type InputHelpText = OneComponent<L10n>;
#[rustfmt::skip]
#[derive(Default)]
pub struct Input {
weight : isize,
weight : Weight,
renderable : Renderable,
classes : Classes,
input_type : InputType,
@ -52,7 +52,7 @@ impl ComponentTrait for Input {
COMPONENT_INPUT
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -166,8 +166,8 @@ impl Input {
// Input BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}

View file

@ -39,7 +39,7 @@ pub enum ColumnSize {
#[rustfmt::skip]
#[derive(Default)]
pub struct Column {
weight : isize,
weight : Weight,
renderable: Renderable,
id : IdentifierValue,
classes : Classes,
@ -61,7 +61,7 @@ impl ComponentTrait for Column {
self.id.get()
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -90,8 +90,8 @@ impl Column {
// Column BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}

View file

@ -9,7 +9,7 @@ actions_for_component!(Row);
#[rustfmt::skip]
#[derive(Default)]
pub struct Row {
weight : isize,
weight : Weight,
renderable: Renderable,
id : IdentifierValue,
classes : Classes,
@ -30,7 +30,7 @@ impl ComponentTrait for Row {
self.id.get()
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -59,8 +59,8 @@ impl Row {
// Row BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}

View file

@ -30,7 +30,7 @@ type HeadingText = OneComponent<L10n>;
#[rustfmt::skip]
#[derive(Default)]
pub struct Heading {
weight : isize,
weight : Weight,
renderable : Renderable,
id : IdentifierValue,
classes : Classes,
@ -53,7 +53,7 @@ impl ComponentTrait for Heading {
self.id.get()
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -115,8 +115,8 @@ impl Heading {
// Heading BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}

View file

@ -5,7 +5,7 @@ create_handle!(COMPONENT_ICON);
#[rustfmt::skip]
#[derive(Default)]
pub struct Icon {
weight : isize,
weight : Weight,
renderable: Renderable,
icon_name : String,
classes : Classes,
@ -20,7 +20,7 @@ impl ComponentTrait for Icon {
COMPONENT_ICON
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -47,8 +47,8 @@ impl Icon {
// Icon BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}

View file

@ -5,7 +5,7 @@ create_handle!(COMPONENT_IMAGE);
#[rustfmt::skip]
#[derive(Default)]
pub struct Image {
weight : isize,
weight : Weight,
renderable: Renderable,
id : IdentifierValue,
classes : Classes,
@ -26,7 +26,7 @@ impl ComponentTrait for Image {
self.id.get()
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -52,8 +52,8 @@ impl Image {
// Image BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}

View file

@ -16,7 +16,7 @@ pub enum ParagraphDisplay {
#[rustfmt::skip]
#[derive(Default)]
pub struct Paragraph {
weight : isize,
weight : Weight,
renderable: Renderable,
id : IdentifierValue,
classes : Classes,
@ -38,7 +38,7 @@ impl ComponentTrait for Paragraph {
self.id.get()
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -66,8 +66,8 @@ impl Paragraph {
// Paragraph BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}

View file

@ -1,4 +1,4 @@
use crate::Handle;
use crate::{Handle, Weight};
use std::any::Any;
@ -13,7 +13,7 @@ pub trait ActionTrait: BaseAction + Send + Sync {
fn handle(&self) -> Handle;
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
0
}
}

View file

@ -32,7 +32,7 @@ macro_rules! actions_for_component {
pub struct [<BeforePrepare $Component>] {
action: Option<[<Action $Component>]>,
weight: isize,
weight: Weight,
}
impl ActionTrait for [<BeforePrepare $Component>] {
@ -47,7 +47,7 @@ macro_rules! actions_for_component {
[<ACTION_BEFORE_PREPARE_ $Component:upper>]
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
}
@ -60,8 +60,8 @@ macro_rules! actions_for_component {
}
#[allow(dead_code)]
pub fn with_weight(mut self, weight: isize) -> Self {
self.weight = weight;
pub fn with_weight(mut self, value: Weight) -> Self {
self.weight = value;
self
}
@ -91,7 +91,7 @@ macro_rules! actions_for_component {
pub struct [<AfterPrepare $Component>] {
action: Option<[<Action $Component>]>,
weight: isize,
weight: Weight,
}
impl ActionTrait for [<AfterPrepare $Component>] {
@ -106,7 +106,7 @@ macro_rules! actions_for_component {
[<ACTION_AFTER_PREPARE_ $Component:upper>]
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
}
@ -119,8 +119,8 @@ macro_rules! actions_for_component {
}
#[allow(dead_code)]
pub fn with_weight(mut self, weight: isize) -> Self {
self.weight = weight;
pub fn with_weight(mut self, value: Weight) -> Self {
self.weight = value;
self
}

View file

@ -1,6 +1,6 @@
use crate::core::component::Context;
use crate::html::{html, Markup, PrepareMarkup};
use crate::{util, Handle};
use crate::{util, Handle, Weight};
use std::any::Any;
@ -31,7 +31,7 @@ pub trait ComponentTrait: BaseComponent + Send + Sync {
None
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
0
}

View file

@ -30,7 +30,9 @@ impl ThemeTrait for Basic {
fn before_prepare_body(&self, page: &mut Page) {
page.alter_favicon(Some(Favicon::new().with_icon("/theme/favicon.ico")))
.alter_context(ContextOp::AddStyleSheet(
StyleSheet::at("/theme/css/normalize.min.css").with_version("8.0.1"),
StyleSheet::at("/theme/css/normalize.min.css")
.with_version("8.0.1")
.with_weight(-99),
));
}
}

View file

@ -4,11 +4,12 @@ pub mod javascript;
pub mod stylesheet;
use crate::html::{html, Markup};
use crate::Weight;
pub trait AssetsTrait {
fn path(&self) -> &str;
fn weight(&self) -> isize;
fn weight(&self) -> Weight;
fn prepare(&self) -> Markup;
}

View file

@ -1,12 +1,13 @@
use crate::html::assets::AssetsTrait;
use crate::html::{html, Markup};
use crate::Weight;
#[rustfmt::skip]
#[derive(Default)]
pub struct HeadScript {
path : String,
code : String,
weight: isize,
weight: Weight,
}
impl AssetsTrait for HeadScript {
@ -14,7 +15,7 @@ impl AssetsTrait for HeadScript {
self.path.as_str()
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -39,8 +40,8 @@ impl HeadScript {
self
}
pub fn with_weight(mut self, weight: isize) -> Self {
self.weight = weight;
pub fn with_weight(mut self, value: Weight) -> Self {
self.weight = value;
self
}
}

View file

@ -1,12 +1,13 @@
use crate::html::assets::AssetsTrait;
use crate::html::{html, Markup};
use crate::Weight;
#[rustfmt::skip]
#[derive(Default)]
pub struct HeadStyles {
path : String,
styles: String,
weight: isize,
weight: Weight,
}
impl AssetsTrait for HeadStyles {
@ -14,7 +15,7 @@ impl AssetsTrait for HeadStyles {
self.path.as_str()
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -39,8 +40,8 @@ impl HeadStyles {
self
}
pub fn with_weight(mut self, weight: isize) -> Self {
self.weight = weight;
pub fn with_weight(mut self, value: Weight) -> Self {
self.weight = value;
self
}
}

View file

@ -1,5 +1,6 @@
use crate::html::assets::AssetsTrait;
use crate::html::{html, Markup};
use crate::Weight;
#[derive(Default, Eq, PartialEq)]
pub enum ModeJS {
@ -15,7 +16,7 @@ pub struct JavaScript {
path : String,
prefix : &'static str,
version: &'static str,
weight : isize,
weight : Weight,
mode : ModeJS,
}
@ -24,7 +25,7 @@ impl AssetsTrait for JavaScript {
self.path.as_str()
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -59,8 +60,8 @@ impl JavaScript {
self
}
pub fn with_weight(mut self, weight: isize) -> Self {
self.weight = weight;
pub fn with_weight(mut self, value: Weight) -> Self {
self.weight = value;
self
}

View file

@ -1,5 +1,6 @@
use crate::html::assets::AssetsTrait;
use crate::html::{html, Markup};
use crate::Weight;
pub enum TargetMedia {
Default,
@ -15,7 +16,7 @@ pub struct StyleSheet {
prefix : &'static str,
version: &'static str,
media : Option<&'static str>,
weight : isize,
weight : Weight,
}
impl AssetsTrait for StyleSheet {
@ -23,7 +24,7 @@ impl AssetsTrait for StyleSheet {
self.path.as_str()
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
@ -57,8 +58,8 @@ impl StyleSheet {
self
}
pub fn with_weight(mut self, weight: isize) -> Self {
self.weight = weight;
pub fn with_weight(mut self, value: Weight) -> Self {
self.weight = value;
self
}

View file

@ -1,9 +1,10 @@
//! The PageTop Prelude.
// Re-exports.
pub use crate::{
concat_string, fn_builder, paste, Handle, HashMapResources, LazyStatic, ResultExt,
};
// Re-exported macros.
pub use crate::{concat_string, fn_builder, paste};
// Global.
pub use crate::{Handle, HashMapResources, LazyStatic, ResultExt, Weight};
// Funciones y macros útiles.
pub use crate::util;
@ -11,7 +12,7 @@ pub use crate::{action, actions_for_component};
pub use crate::{create_handle, default_settings, kv};
pub use crate::{serve_static_files, static_files, static_locales};
// *************************************************************************************************
// API.
pub use crate::config;

View file

@ -1,13 +1,13 @@
use crate::core::action::{action_ref, run_actions, ActionTrait};
use crate::response::page::action::ActionPage;
use crate::response::page::Page;
use crate::{create_handle, Handle};
use crate::{create_handle, Handle, Weight};
create_handle!(ACTION_AFTER_PREPARE_BODY for Action);
pub struct ActionAfterPrepareBody {
action: Option<ActionPage>,
weight: isize,
weight: Weight,
}
impl ActionTrait for ActionAfterPrepareBody {
@ -22,7 +22,7 @@ impl ActionTrait for ActionAfterPrepareBody {
ACTION_AFTER_PREPARE_BODY
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
}
@ -33,8 +33,8 @@ impl ActionAfterPrepareBody {
self
}
pub fn with_weight(mut self, weight: isize) -> Self {
self.weight = weight;
pub fn with_weight(mut self, value: Weight) -> Self {
self.weight = value;
self
}

View file

@ -1,13 +1,13 @@
use crate::core::action::{action_ref, run_actions, ActionTrait};
use crate::response::page::action::ActionPage;
use crate::response::page::Page;
use crate::{create_handle, Handle};
use crate::{create_handle, Handle, Weight};
create_handle!(ACTION_BEFORE_PREPARE_BODY for Action);
pub struct ActionBeforePrepareBody {
action: Option<ActionPage>,
weight: isize,
weight: Weight,
}
impl ActionTrait for ActionBeforePrepareBody {
@ -22,7 +22,7 @@ impl ActionTrait for ActionBeforePrepareBody {
ACTION_BEFORE_PREPARE_BODY
}
fn weight(&self) -> isize {
fn weight(&self) -> Weight {
self.weight
}
}
@ -33,8 +33,8 @@ impl ActionBeforePrepareBody {
self
}
pub fn with_weight(mut self, weight: isize) -> Self {
self.weight = weight;
pub fn with_weight(mut self, value: Weight) -> Self {
self.weight = value;
self
}