Actualiza código y revisa constantes

This commit is contained in:
Manuel Cillero 2022-07-15 18:58:05 +02:00
parent e011c9269a
commit bc70527ecf
35 changed files with 356 additions and 317 deletions

View file

@ -1,6 +1,6 @@
use pagetop::prelude::*; use pagetop::prelude::*;
pub const ADMIN_MODULE: &str = "pagetop-admin::module::admin"; pub const MODULE_ADMIN: &str = "pagetop-admin::module::admin";
localize!("src/locales"); localize!("src/locales");
@ -10,7 +10,7 @@ pub struct Admin;
impl ModuleTrait for Admin { impl ModuleTrait for Admin {
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
ADMIN_MODULE MODULE_ADMIN
} }
fn name(&self) -> String { fn name(&self) -> String {

View file

@ -1,6 +1,6 @@
use pagetop::prelude::*; use pagetop::prelude::*;
pub const NODE_MODULE: &str = "pagetop-node::module::node"; pub const MODULE_NODE: &str = "pagetop-node::module::node";
localize!("src/locales"); localize!("src/locales");
@ -11,7 +11,7 @@ pub struct Node;
impl ModuleTrait for Node { impl ModuleTrait for Node {
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
NODE_MODULE MODULE_NODE
} }
fn name(&self) -> String { fn name(&self) -> String {

View file

@ -1,6 +1,6 @@
use pagetop::prelude::*; use pagetop::prelude::*;
pub const USER_MODULE: &str = "pagetop-user::module::user"; pub const MODULE_USER: &str = "pagetop-user::module::user";
localize!("src/locales"); localize!("src/locales");
@ -10,7 +10,7 @@ pub struct User;
impl ModuleTrait for User { impl ModuleTrait for User {
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
USER_MODULE MODULE_USER
} }
fn name(&self) -> String { fn name(&self) -> String {

View file

@ -1,44 +1,44 @@
mod container; mod container;
pub use container::{ pub use container::{
CONTAINER_COMPONENT, Container, ContainerType COMPONENT_CONTAINER, Container, ContainerType
}; };
pub mod grid; pub mod grid;
mod chunck; mod chunck;
pub use chunck::{ pub use chunck::{
CHUNCK_COMPONENT, Chunck COMPONENT_CHUNCK, Chunck
}; };
mod icon; mod icon;
pub use icon::{ pub use icon::{
ICON_COMPONENT, Icon COMPONENT_ICON, Icon
}; };
mod heading; mod heading;
pub use heading::{ pub use heading::{
HEADING_COMPONENT, Heading, HeadingDisplay, HeadingType COMPONENT_HEADING, Heading, HeadingDisplay, HeadingType
}; };
mod paragraph; mod paragraph;
pub use paragraph::{ pub use paragraph::{
PARAGRAPH_COMPONENT, Paragraph, ParagraphDisplay COMPONENT_PARAGRAPH, Paragraph, ParagraphDisplay
}; };
mod anchor; mod anchor;
pub use anchor::{ pub use anchor::{
ANCHOR_COMPONENT, Anchor, AnchorIcon, AnchorTarget, AnchorType COMPONENT_ANCHOR, Anchor, AnchorIcon, AnchorTarget, AnchorType
}; };
mod block; mod block;
pub use block::{ pub use block::{
BLOCK_COMPONENT, Block COMPONENT_BLOCK, Block
}; };
mod image; mod image;
pub use image::{ pub use image::{
IMAGE_COMPONENT, Image COMPONENT_IMAGE, Image
}; };
mod menu; mod menu;
pub use menu::{ pub use menu::{
MENU_COMPONENT, MENUITEM_COMPONENT, Menu, MenuItem, MenuItemType COMPONENT_MENU, COMPONENT_MENUITEM, Menu, MenuItem, MenuItemType
}; };
pub mod form; pub mod form;
pub use form::{ pub use form::{
FORM_COMPONENT, Form, FormMethod COMPONENT_FORM, Form, FormMethod
}; };

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const ANCHOR_COMPONENT: &str = "pagetop::component::anchor"; pub const COMPONENT_ANCHOR: &str = "pagetop::component::anchor";
pub enum AnchorType { pub enum AnchorType {
Button, Button,
@ -50,17 +50,17 @@ impl ComponentTrait for Anchor {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
ANCHOR_COMPONENT COMPONENT_ANCHOR
}
fn is_renderable(&self) -> bool {
(self.renderable)()
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {
self.weight self.weight
} }
fn is_renderable(&self, _: &InContext) -> bool {
(self.renderable)()
}
fn default_render(&self, context: &mut InContext) -> Markup { fn default_render(&self, context: &mut InContext) -> Markup {
let target = match &self.target() { let target = match &self.target() {
AnchorTarget::Blank => Some("_blank"), AnchorTarget::Blank => Some("_blank"),
@ -107,13 +107,13 @@ impl Anchor {
// Anchor BUILDER. // Anchor BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
self.alter_renderable(renderable); self.alter_weight(weight);
self self
} }
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
self.alter_weight(weight); self.alter_renderable(renderable);
self self
} }
@ -164,13 +164,13 @@ impl Anchor {
// Anchor ALTER. // Anchor ALTER.
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.renderable = renderable; self.weight = weight;
self self
} }
pub fn alter_weight(&mut self, weight: isize) -> &mut Self { pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.weight = weight; self.renderable = renderable;
self self
} }

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const BLOCK_COMPONENT: &str = "pagetop::component::block"; pub const COMPONENT_BLOCK: &str = "pagetop::component::block";
pub struct Block { pub struct Block {
renderable: fn() -> bool, renderable: fn() -> bool,
@ -26,17 +26,17 @@ impl ComponentTrait for Block {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
BLOCK_COMPONENT COMPONENT_BLOCK
}
fn is_renderable(&self) -> bool {
(self.renderable)()
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {
self.weight self.weight
} }
fn is_renderable(&self, _: &InContext) -> bool {
(self.renderable)()
}
fn default_render(&self, context: &mut InContext) -> Markup { fn default_render(&self, context: &mut InContext) -> Markup {
let id = context.required_id::<Block>(self.id()); let id = context.required_id::<Block>(self.id());
html! { html! {
@ -65,13 +65,13 @@ impl Block {
// Block BUILDER. // Block BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
self.alter_renderable(renderable); self.alter_weight(weight);
self self
} }
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
self.alter_weight(weight); self.alter_renderable(renderable);
self self
} }
@ -102,13 +102,13 @@ impl Block {
// Block ALTER. // Block ALTER.
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.renderable = renderable; self.weight = weight;
self self
} }
pub fn alter_weight(&mut self, weight: isize) -> &mut Self { pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.weight = weight; self.renderable = renderable;
self self
} }

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const CHUNCK_COMPONENT: &str = "pagetop::component::chunck"; pub const COMPONENT_CHUNCK: &str = "pagetop::component::chunck";
pub struct Chunck { pub struct Chunck {
renderable: fn() -> bool, renderable: fn() -> bool,
@ -20,17 +20,17 @@ impl ComponentTrait for Chunck {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
CHUNCK_COMPONENT COMPONENT_CHUNCK
}
fn is_renderable(&self) -> bool {
(self.renderable)()
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {
self.weight self.weight
} }
fn is_renderable(&self, _: &InContext) -> bool {
(self.renderable)()
}
fn default_render(&self, _: &mut InContext) -> Markup { fn default_render(&self, _: &mut InContext) -> Markup {
html! { (*self.html()) } html! { (*self.html()) }
} }
@ -51,13 +51,13 @@ impl Chunck {
// Chunck BUILDER. // Chunck BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
self.alter_renderable(renderable); self.alter_weight(weight);
self self
} }
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
self.alter_weight(weight); self.alter_renderable(renderable);
self self
} }
@ -73,13 +73,13 @@ impl Chunck {
// Chunck ALTER. // Chunck ALTER.
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.renderable = renderable; self.weight = weight;
self self
} }
pub fn alter_weight(&mut self, weight: isize) -> &mut Self { pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.weight = weight; self.renderable = renderable;
self self
} }

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const CONTAINER_COMPONENT: &str = "pagetop::component::container"; pub const COMPONENT_CONTAINER: &str = "pagetop::component::container";
pub enum ContainerType { Header, Footer, Main, Section, Wrapper } pub enum ContainerType { Header, Footer, Main, Section, Wrapper }
@ -30,17 +30,17 @@ impl ComponentTrait for Container {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
CONTAINER_COMPONENT COMPONENT_CONTAINER
}
fn is_renderable(&self) -> bool {
(self.renderable)()
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {
self.weight self.weight
} }
fn is_renderable(&self, _: &InContext) -> bool {
(self.renderable)()
}
fn default_render(&self, context: &mut InContext) -> Markup { fn default_render(&self, context: &mut InContext) -> Markup {
match self.container_type() { match self.container_type() {
ContainerType::Header => html! { ContainerType::Header => html! {
@ -115,13 +115,13 @@ impl Container {
// Container BUILDER. // Container BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
self.alter_renderable(renderable); self.alter_weight(weight);
self self
} }
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
self.alter_weight(weight); self.alter_renderable(renderable);
self self
} }
@ -152,13 +152,13 @@ impl Container {
// Container ALTER. // Container ALTER.
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.renderable = renderable; self.weight = weight;
self self
} }
pub fn alter_weight(&mut self, weight: isize) -> &mut Self { pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.weight = weight; self.renderable = renderable;
self self
} }

View file

@ -1,21 +1,21 @@
mod form; mod form;
pub use form::{ pub use form::{
FORM_COMPONENT, Form, FormMethod COMPONENT_FORM, Form, FormMethod
}; };
mod input; mod input;
pub use input::{ pub use input::{
INPUT_COMPONENT, Input, InputType COMPONENT_INPUT, Input, InputType
}; };
mod hidden; mod hidden;
pub use hidden::{ pub use hidden::{
HIDDEN_COMPONENT, Hidden COMPONENT_HIDDEN, Hidden
}; };
mod date; mod date;
pub use date::{ pub use date::{
DATE_COMPONENT, Date COMPONENT_DATE, Date
}; };
mod button; mod button;
pub use button::{ pub use button::{
BUTTON_COMPONENT, Button, ButtonType COMPONENT_BUTTON, Button, ButtonType
}; };

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const BUTTON_COMPONENT: &str = "pagetop::component::form::button"; pub const COMPONENT_BUTTON: &str = "pagetop::component::form::button";
pub enum ButtonType {Button, Reset, Submit} pub enum ButtonType {Button, Reset, Submit}
@ -33,17 +33,17 @@ impl ComponentTrait for Button {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
BUTTON_COMPONENT COMPONENT_BUTTON
}
fn is_renderable(&self) -> bool {
(self.renderable)()
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {
self.weight self.weight
} }
fn is_renderable(&self, _: &InContext) -> bool {
(self.renderable)()
}
fn default_render(&self, _: &mut InContext) -> Markup { fn default_render(&self, _: &mut InContext) -> Markup {
let button_type = match self.button_type() { let button_type = match self.button_type() {
ButtonType::Button => "button", ButtonType::Button => "button",
@ -104,13 +104,13 @@ impl Button {
// Button BUILDER. // Button BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
self.alter_renderable(renderable); self.alter_weight(weight);
self self
} }
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
self.alter_weight(weight); self.alter_renderable(renderable);
self self
} }
@ -146,13 +146,13 @@ impl Button {
// Button ALTER. // Button ALTER.
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.renderable = renderable; self.weight = weight;
self self
} }
pub fn alter_weight(&mut self, weight: isize) -> &mut Self { pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.weight = weight; self.renderable = renderable;
self self
} }

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const DATE_COMPONENT: &str = "pagetop::component::form::date"; pub const COMPONENT_DATE: &str = "pagetop::component::form::date";
pub struct Date { pub struct Date {
renderable : fn() -> bool, renderable : fn() -> bool,
@ -41,17 +41,17 @@ impl ComponentTrait for Date {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
DATE_COMPONENT COMPONENT_DATE
}
fn is_renderable(&self) -> bool {
(self.renderable)()
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {
self.weight self.weight
} }
fn is_renderable(&self, _: &InContext) -> bool {
(self.renderable)()
}
fn default_render(&self, _: &mut InContext) -> Markup { fn default_render(&self, _: &mut InContext) -> Markup {
let id = match self.name().get() { let id = match self.name().get() {
Some(name) => Some(concat_string!("edit-", name)), Some(name) => Some(concat_string!("edit-", name)),
@ -104,13 +104,13 @@ impl Date {
// Date BUILDER. // Date BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
self.alter_renderable(renderable); self.alter_weight(weight);
self self
} }
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
self.alter_weight(weight); self.alter_renderable(renderable);
self self
} }
@ -176,13 +176,13 @@ impl Date {
// Date ALTER. // Date ALTER.
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.renderable = renderable; self.weight = weight;
self self
} }
pub fn alter_weight(&mut self, weight: isize) -> &mut Self { pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.weight = weight; self.renderable = renderable;
self self
} }

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const FORM_COMPONENT: &str = "pagetop::component::form"; pub const COMPONENT_FORM: &str = "pagetop::component::form";
pub enum FormMethod {Get, Post} pub enum FormMethod {Get, Post}
@ -32,17 +32,17 @@ impl ComponentTrait for Form {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
FORM_COMPONENT COMPONENT_FORM
}
fn is_renderable(&self) -> bool {
(self.renderable)()
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {
self.weight self.weight
} }
fn is_renderable(&self, _: &InContext) -> bool {
(self.renderable)()
}
fn default_render(&self, context: &mut InContext) -> Markup { fn default_render(&self, context: &mut InContext) -> Markup {
let method = match self.method() { let method = match self.method() {
FormMethod::Get => None, FormMethod::Get => None,
@ -74,13 +74,13 @@ impl Form {
// Form BUILDER. // Form BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
self.alter_renderable(renderable); self.alter_weight(weight);
self self
} }
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
self.alter_weight(weight); self.alter_renderable(renderable);
self self
} }
@ -121,13 +121,13 @@ impl Form {
// Form ALTER. // Form ALTER.
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.renderable = renderable; self.weight = weight;
self self
} }
pub fn alter_weight(&mut self, weight: isize) -> &mut Self { pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.weight = weight; self.renderable = renderable;
self self
} }

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const HIDDEN_COMPONENT: &str = "pagetop::component::form::hidden"; pub const COMPONENT_HIDDEN: &str = "pagetop::component::form::hidden";
pub struct Hidden { pub struct Hidden {
weight: isize, weight: isize,
@ -18,7 +18,7 @@ impl ComponentTrait for Hidden {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
HIDDEN_COMPONENT COMPONENT_HIDDEN
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const INPUT_COMPONENT: &str = "pagetop::component::form::input"; pub const COMPONENT_INPUT: &str = "pagetop::component::form::input";
pub enum InputType {Email, Password, Search, Telephone, Textfield, Url} pub enum InputType {Email, Password, Search, Telephone, Textfield, Url}
@ -51,17 +51,17 @@ impl ComponentTrait for Input {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
INPUT_COMPONENT COMPONENT_INPUT
}
fn is_renderable(&self) -> bool {
(self.renderable)()
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {
self.weight self.weight
} }
fn is_renderable(&self, _: &InContext) -> bool {
(self.renderable)()
}
fn default_render(&self, _: &mut InContext) -> Markup { fn default_render(&self, _: &mut InContext) -> Markup {
let type_input = match self.input_type() { let type_input = match self.input_type() {
InputType::Email => "email", InputType::Email => "email",
@ -163,13 +163,13 @@ impl Input {
// Input BUILDER. // Input BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
self.alter_renderable(renderable); self.alter_weight(weight);
self self
} }
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
self.alter_weight(weight); self.alter_renderable(renderable);
self self
} }
@ -250,13 +250,13 @@ impl Input {
// Input ALTER. // Input ALTER.
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.renderable = renderable; self.weight = weight;
self self
} }
pub fn alter_weight(&mut self, weight: isize) -> &mut Self { pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.weight = weight; self.renderable = renderable;
self self
} }

View file

@ -1,8 +1,8 @@
mod row; mod row;
pub use row::{ pub use row::{
ROW_COMPONENT, Row COMPONENT_ROW, Row
}; };
mod column; mod column;
pub use column::{ pub use column::{
COLUMN_COMPONENT, Column, ColumnSize COMPONENT_COLUMN, Column, ColumnSize
}; };

View file

@ -1,6 +1,20 @@
use crate::prelude::*; use crate::prelude::*;
pub const COLUMN_COMPONENT: &str = "pagetop::component::grid::column"; pub const COMPONENT_COLUMN: &str = "pagetop::component::grid::column";
const SIZE_DEFAULT: &str = "col-md";
const SIZE_1_OF_12: &str = "col-md-1";
const SIZE_2_OF_12: &str = "col-md-2";
const SIZE_3_OF_12: &str = "col-md-3";
const SIZE_4_OF_12: &str = "col-md-4";
const SIZE_5_OF_12: &str = "col-md-5";
const SIZE_6_OF_12: &str = "col-md-6";
const SIZE_7_OF_12: &str = "col-md-7";
const SIZE_8_OF_12: &str = "col-md-8";
const SIZE_9_OF_12: &str = "col-md-9";
const SIZE_10_OF_12: &str = "col-md-10";
const SIZE_11_OF_12: &str = "col-md-11";
const SIZE_12_OF_12: &str = "col-md-12";
pub enum ColumnSize { pub enum ColumnSize {
Default, Default,
@ -33,7 +47,7 @@ impl ComponentTrait for Column {
renderable: render_always, renderable: render_always,
weight : 0, weight : 0,
id : IdentifierValue::new(), id : IdentifierValue::new(),
classes : Classes::new(), classes : Classes::new_with_default(SIZE_DEFAULT),
size : ColumnSize::Default, size : ColumnSize::Default,
components: ComponentsBundle::new(), components: ComponentsBundle::new(),
template : "default".to_owned(), template : "default".to_owned(),
@ -41,33 +55,15 @@ impl ComponentTrait for Column {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
COLUMN_COMPONENT COMPONENT_COLUMN
}
fn is_renderable(&self) -> bool {
(self.renderable)()
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {
self.weight self.weight
} }
fn before_render(&mut self, _context: &mut InContext) { fn is_renderable(&self, _: &InContext) -> bool {
match self.size() { (self.renderable)()
ColumnSize::Default => self.alter_classes(ClassesOp::SetDefault, "col-md"),
ColumnSize::Is1of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-1"),
ColumnSize::Is2of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-2"),
ColumnSize::Is3of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-3"),
ColumnSize::Is4of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-4"),
ColumnSize::Is5of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-5"),
ColumnSize::Is6of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-6"),
ColumnSize::Is7of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-7"),
ColumnSize::Is8of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-8"),
ColumnSize::Is9of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-9"),
ColumnSize::Is10of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-10"),
ColumnSize::Is11of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-11"),
ColumnSize::IsFull => self.alter_classes(ClassesOp::SetDefault, "col-md-12"),
};
} }
fn default_render(&self, context: &mut InContext) -> Markup { fn default_render(&self, context: &mut InContext) -> Markup {
@ -91,13 +87,13 @@ impl Column {
// Column BUILDER. // Column BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
self.alter_renderable(renderable); self.alter_weight(weight);
self self
} }
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
self.alter_weight(weight); self.alter_renderable(renderable);
self self
} }
@ -128,13 +124,13 @@ impl Column {
// Column ALTER. // Column ALTER.
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.renderable = renderable; self.weight = weight;
self self
} }
pub fn alter_weight(&mut self, weight: isize) -> &mut Self { pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.weight = weight; self.renderable = renderable;
self self
} }
@ -149,6 +145,21 @@ impl Column {
} }
pub fn alter_size(&mut self, size: ColumnSize) -> &mut Self { pub fn alter_size(&mut self, size: ColumnSize) -> &mut Self {
match size {
ColumnSize::Default => self.alter_classes(ClassesOp::SetDefault, SIZE_DEFAULT),
ColumnSize::Is1of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_1_OF_12),
ColumnSize::Is2of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_2_OF_12),
ColumnSize::Is3of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_3_OF_12),
ColumnSize::Is4of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_4_OF_12),
ColumnSize::Is5of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_5_OF_12),
ColumnSize::Is6of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_6_OF_12),
ColumnSize::Is7of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_7_OF_12),
ColumnSize::Is8of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_8_OF_12),
ColumnSize::Is9of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_9_OF_12),
ColumnSize::Is10of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_10_OF_12),
ColumnSize::Is11of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_11_OF_12),
ColumnSize::IsFull => self.alter_classes(ClassesOp::SetDefault, SIZE_12_OF_12),
};
self.size = size; self.size = size;
self self
} }

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const ROW_COMPONENT: &str = "pagetop::component::grid::row"; pub const COMPONENT_ROW: &str = "pagetop::component::grid::row";
pub struct Row { pub struct Row {
renderable: fn() -> bool, renderable: fn() -> bool,
@ -24,17 +24,17 @@ impl ComponentTrait for Row {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
ROW_COMPONENT COMPONENT_ROW
}
fn is_renderable(&self) -> bool {
(self.renderable)()
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {
self.weight self.weight
} }
fn is_renderable(&self, _: &InContext) -> bool {
(self.renderable)()
}
fn default_render(&self, context: &mut InContext) -> Markup { fn default_render(&self, context: &mut InContext) -> Markup {
html! { html! {
div id=[self.id().get()] class=[self.classes().get()] { div id=[self.id().get()] class=[self.classes().get()] {
@ -56,13 +56,13 @@ impl Row {
// Row BUILDER. // Row BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
self.alter_renderable(renderable); self.alter_weight(weight);
self self
} }
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
self.alter_weight(weight); self.alter_renderable(renderable);
self self
} }
@ -88,13 +88,13 @@ impl Row {
// Row ALTER. // Row ALTER.
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.renderable = renderable; self.weight = weight;
self self
} }
pub fn alter_weight(&mut self, weight: isize) -> &mut Self { pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.weight = weight; self.renderable = renderable;
self self
} }

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const HEADING_COMPONENT: &str = "pagetop::component::heading"; pub const COMPONENT_HEADING: &str = "pagetop::component::heading";
pub enum HeadingType { H1, H2, H3, H4, H5, H6 } pub enum HeadingType { H1, H2, H3, H4, H5, H6 }
@ -40,17 +40,17 @@ impl ComponentTrait for Heading {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
HEADING_COMPONENT COMPONENT_HEADING
}
fn is_renderable(&self) -> bool {
(self.renderable)()
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {
self.weight self.weight
} }
fn is_renderable(&self, _: &InContext) -> bool {
(self.renderable)()
}
fn default_render(&self, _: &mut InContext) -> Markup { fn default_render(&self, _: &mut InContext) -> Markup {
let id = self.id().get(); let id = self.id().get();
let classes = self.classes().get(); let classes = self.classes().get();
@ -100,13 +100,13 @@ impl Heading {
// Heading BUILDER. // Heading BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
self.alter_renderable(renderable); self.alter_weight(weight);
self self
} }
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
self.alter_weight(weight); self.alter_renderable(renderable);
self self
} }
@ -142,13 +142,13 @@ impl Heading {
// Heading ALTER. // Heading ALTER.
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.renderable = renderable; self.weight = weight;
self self
} }
pub fn alter_weight(&mut self, weight: isize) -> &mut Self { pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.weight = weight; self.renderable = renderable;
self self
} }

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const ICON_COMPONENT: &str = "pagetop::component::icon"; pub const COMPONENT_ICON: &str = "pagetop::component::icon";
pub struct Icon { pub struct Icon {
renderable: fn() -> bool, renderable: fn() -> bool,
@ -15,33 +15,29 @@ impl ComponentTrait for Icon {
renderable: render_always, renderable: render_always,
weight : 0, weight : 0,
icon_name : "question-circle-fill".to_owned(), icon_name : "question-circle-fill".to_owned(),
classes : Classes::new(), classes : Classes::new_with_default("bi-question-circle-fill"),
} }
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
ICON_COMPONENT COMPONENT_ICON
}
fn is_renderable(&self) -> bool {
(self.renderable)()
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {
self.weight self.weight
} }
fn before_render(&mut self, context: &mut InContext) { fn is_renderable(&self, _: &InContext) -> bool {
(self.renderable)()
}
fn default_render(&self, context: &mut InContext) -> Markup {
context context
.alter(InContextOp::StyleSheet(AssetsOp::Add( .alter(InContextOp::StyleSheet(AssetsOp::Add(
StyleSheet::located("/theme/icons/bootstrap-icons.css") StyleSheet::located("/theme/icons/bootstrap-icons.css")
.with_version("1.8.2") .with_version("1.8.2")
))); )));
self.alter_classes(ClassesOp::SetDefault, concat_string!("bi-", self.icon_name()).as_str());
}
fn default_render(&self, _context: &mut InContext) -> Markup {
html! { i class=[self.classes().get()] {}; } html! { i class=[self.classes().get()] {}; }
} }
@ -61,13 +57,13 @@ impl Icon {
// Icon BUILDER. // Icon BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
self.alter_renderable(renderable); self.alter_weight(weight);
self self
} }
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
self.alter_weight(weight); self.alter_renderable(renderable);
self self
} }
@ -83,18 +79,19 @@ impl Icon {
// Icon ALTER. // Icon ALTER.
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.renderable = renderable;
self
}
pub fn alter_weight(&mut self, weight: isize) -> &mut Self { pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight; self.weight = weight;
self self
} }
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.renderable = renderable;
self
}
pub fn alter_icon_name(&mut self, name: &str) -> &mut Self { pub fn alter_icon_name(&mut self, name: &str) -> &mut Self {
self.icon_name = name.to_owned(); self.icon_name = name.to_owned();
self.alter_classes(ClassesOp::SetDefault, concat_string!("bi-", self.icon_name).as_str());
self self
} }

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const IMAGE_COMPONENT: &str = "pagetop::component::image"; pub const COMPONENT_IMAGE: &str = "pagetop::component::image";
pub struct Image { pub struct Image {
renderable: fn() -> bool, renderable: fn() -> bool,
@ -24,17 +24,17 @@ impl ComponentTrait for Image {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
IMAGE_COMPONENT COMPONENT_IMAGE
}
fn is_renderable(&self) -> bool {
(self.renderable)()
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {
self.weight self.weight
} }
fn is_renderable(&self, _: &InContext) -> bool {
(self.renderable)()
}
fn default_render(&self, _: &mut InContext) -> Markup { fn default_render(&self, _: &mut InContext) -> Markup {
html! { html! {
img img
@ -60,13 +60,13 @@ impl Image {
// Image BUILDER. // Image BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
self.alter_renderable(renderable); self.alter_weight(weight);
self self
} }
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
self.alter_weight(weight); self.alter_renderable(renderable);
self self
} }
@ -92,13 +92,13 @@ impl Image {
// Image ALTER. // Image ALTER.
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.renderable = renderable; self.weight = weight;
self self
} }
pub fn alter_weight(&mut self, weight: isize) -> &mut Self { pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.weight = weight; self.renderable = renderable;
self self
} }

View file

@ -1,7 +1,7 @@
use crate::prelude::*; use crate::prelude::*;
pub const MENU_COMPONENT: &str = "pagetop::component::menu"; pub const COMPONENT_MENU: &str = "pagetop::component::menu";
pub const MENUITEM_COMPONENT: &str = "pagetop::component::menu_item"; pub const COMPONENT_MENUITEM: &str = "pagetop::component::menu_item";
pub enum MenuItemType { pub enum MenuItemType {
Label(String), Label(String),
@ -31,17 +31,17 @@ impl ComponentTrait for MenuItem {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
MENUITEM_COMPONENT COMPONENT_MENUITEM
}
fn is_renderable(&self) -> bool {
(self.renderable)()
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {
self.weight self.weight
} }
fn is_renderable(&self, _: &InContext) -> bool {
(self.renderable)()
}
fn default_render(&self, context: &mut InContext) -> Markup { fn default_render(&self, context: &mut InContext) -> Markup {
match self.item_type() { match self.item_type() {
MenuItemType::Label(label) => html! { MenuItemType::Label(label) => html! {
@ -142,28 +142,28 @@ impl MenuItem {
// MenuItem BUILDER. // MenuItem BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
self.alter_renderable(renderable);
self
}
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
self.alter_weight(weight); self.alter_weight(weight);
self self
} }
// MenuItem ALTER. pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
self.alter_renderable(renderable);
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.renderable = renderable;
self self
} }
// MenuItem ALTER.
pub fn alter_weight(&mut self, weight: isize) -> &mut Self { pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight; self.weight = weight;
self self
} }
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.renderable = renderable;
self
}
// MenuItem GETTERS. // MenuItem GETTERS.
pub fn item_type(&self) -> &MenuItemType { pub fn item_type(&self) -> &MenuItemType {
@ -195,18 +195,18 @@ impl ComponentTrait for Menu {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
MENU_COMPONENT COMPONENT_MENU
}
fn is_renderable(&self) -> bool {
(self.renderable)()
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {
self.weight self.weight
} }
fn before_render(&mut self, context: &mut InContext) { fn is_renderable(&self, _: &InContext) -> bool {
(self.renderable)()
}
fn default_render(&self, context: &mut InContext) -> Markup {
context context
.alter(InContextOp::StyleSheet(AssetsOp::Add( .alter(InContextOp::StyleSheet(AssetsOp::Add(
StyleSheet::located("/theme/menu/css/menu.css") StyleSheet::located("/theme/menu/css/menu.css")
@ -221,10 +221,9 @@ impl ComponentTrait for Menu {
.with_version("1.1.1") .with_version("1.1.1")
))) )))
.alter(InContextOp::AddJQuery); .alter(InContextOp::AddJQuery);
}
fn default_render(&self, context: &mut InContext) -> Markup {
let id = context.required_id::<Menu>(self.id()); let id = context.required_id::<Menu>(self.id());
html! { html! {
ul id=(id) class=[self.classes().get()] { ul id=(id) class=[self.classes().get()] {
(self.items().render(context)) (self.items().render(context))
@ -251,13 +250,13 @@ impl Menu {
// Menu BUILDER. // Menu BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
self.alter_renderable(renderable); self.alter_weight(weight);
self self
} }
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
self.alter_weight(weight); self.alter_renderable(renderable);
self self
} }
@ -283,13 +282,13 @@ impl Menu {
// Menu ALTER. // Menu ALTER.
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.renderable = renderable; self.weight = weight;
self self
} }
pub fn alter_weight(&mut self, weight: isize) -> &mut Self { pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.weight = weight; self.renderable = renderable;
self self
} }

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const PARAGRAPH_COMPONENT: &str = "pagetop::component::paragraph"; pub const COMPONENT_PARAGRAPH: &str = "pagetop::component::paragraph";
pub enum ParagraphDisplay { pub enum ParagraphDisplay {
XxLarge, XxLarge,
@ -35,17 +35,17 @@ impl ComponentTrait for Paragraph {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
PARAGRAPH_COMPONENT COMPONENT_PARAGRAPH
}
fn is_renderable(&self) -> bool {
(self.renderable)()
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {
self.weight self.weight
} }
fn is_renderable(&self, _: &InContext) -> bool {
(self.renderable)()
}
fn default_render(&self, _: &mut InContext) -> Markup { fn default_render(&self, _: &mut InContext) -> Markup {
html! { html! {
p id=[self.id().get()] class=[self.classes().get()] { (*self.html()) } p id=[self.id().get()] class=[self.classes().get()] { (*self.html()) }
@ -68,13 +68,13 @@ impl Paragraph {
// Paragraph BUILDER. // Paragraph BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
self.alter_renderable(renderable); self.alter_weight(weight);
self self
} }
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
self.alter_weight(weight); self.alter_renderable(renderable);
self self
} }
@ -105,13 +105,13 @@ impl Paragraph {
// Paragraph ALTER. // Paragraph ALTER.
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.renderable = renderable; self.weight = weight;
self self
} }
pub fn alter_weight(&mut self, weight: isize) -> &mut Self { pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
self.weight = weight; self.renderable = renderable;
self self
} }

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const DEMOPAGE_MODULE: &str = "pagetop::module::demopage"; pub const MODULE_DEMOPAGE: &str = "pagetop::module::demopage";
localize!("src/base/module/demopage/locales"); localize!("src/base/module/demopage/locales");
@ -8,7 +8,7 @@ pub struct Demopage;
impl ModuleTrait for Demopage { impl ModuleTrait for Demopage {
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
DEMOPAGE_MODULE MODULE_DEMOPAGE
} }
fn name(&self) -> String { fn name(&self) -> String {
@ -27,6 +27,9 @@ impl ModuleTrait for Demopage {
async fn demo() -> app::Result<Markup> { async fn demo() -> app::Result<Markup> {
Page::new() Page::new()
.with_title(l("page_title").as_str()) .with_title(l("page_title").as_str())
.with_context(InContextOp::StyleSheet(AssetsOp::Add(
StyleSheet::located("/theme/module/demopage/styles.css")
)))
.add_to("content", hello_world()) .add_to("content", hello_world())
.add_to("content", welcome()) .add_to("content", welcome())
.add_to("content", about_pagetop()) .add_to("content", about_pagetop())
@ -40,6 +43,7 @@ fn hello_world() -> Container {
.with_id("hello-world") .with_id("hello-world")
.with_component(grid::Row::new() .with_component(grid::Row::new()
.with_column(grid::Column::new() .with_column(grid::Column::new()
.with_classes(ClassesOp::Add, "hello-col-text")
.with_size(grid::ColumnSize::Is4of12) .with_size(grid::ColumnSize::Is4of12)
.with_component(Heading::h1(html! { .with_component(Heading::h1(html! {
(l("page_title")) (l("page_title"))
@ -63,6 +67,7 @@ fn hello_world() -> Container {
("Offered services") ("Offered services")
}) })
.with_left_icon(Icon::with("card-checklist")) .with_left_icon(Icon::with("card-checklist"))
.with_classes(ClassesOp::Add, "services-link")
) )
.with_component(Anchor::button("#", html! { .with_component(Anchor::button("#", html! {
("Get quote") ("Get quote")
@ -71,6 +76,7 @@ fn hello_world() -> Container {
) )
) )
.with_column(grid::Column::new() .with_column(grid::Column::new()
.with_classes(ClassesOp::Add, "hello-col-image")
.with_component(Image::image("/theme/images/demo-header.svg")) .with_component(Image::image("/theme/images/demo-header.svg"))
) )
) )
@ -78,13 +84,15 @@ fn hello_world() -> Container {
fn welcome() -> Container { fn welcome() -> Container {
Container::new() Container::new()
.with_id("visiting") .with_id("welcome")
.with_component(grid::Row::new() .with_component(grid::Row::new()
.with_column(grid::Column::new() .with_column(grid::Column::new()
.with_classes(ClassesOp::Add, "welcome-col-image")
.with_size(grid::ColumnSize::Is5of12) .with_size(grid::ColumnSize::Is5of12)
.with_component(Image::image("/theme/images/demo-visiting.svg")) .with_component(Image::image("/theme/images/demo-visiting.svg"))
) )
.with_column(grid::Column::new() .with_column(grid::Column::new()
.with_classes(ClassesOp::Add, "welcome-col-text")
.with_component(Heading::h2(html! { .with_component(Heading::h2(html! {
(t("welcome_to", &args!["app" => SETTINGS.app.name.as_str()])) (t("welcome_to", &args!["app" => SETTINGS.app.name.as_str()]))
})) }))

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const ALINER_THEME: &str = "pagetop::theme::aliner"; pub const THEME_ALINER: &str = "pagetop::theme::aliner";
include!(concat!(env!("OUT_DIR"), "/aliner.rs")); include!(concat!(env!("OUT_DIR"), "/aliner.rs"));
@ -8,7 +8,7 @@ pub struct Aliner;
impl ThemeTrait for Aliner { impl ThemeTrait for Aliner {
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
ALINER_THEME THEME_ALINER
} }
fn configure_service(&self, cfg: &mut app::web::ServiceConfig) { fn configure_service(&self, cfg: &mut app::web::ServiceConfig) {

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const BOOTSIER_THEME: &str = "pagetop::theme::bootsier"; pub const THEME_BOOTSIER: &str = "pagetop::theme::bootsier";
include!(concat!(env!("OUT_DIR"), "/bootsier.rs")); include!(concat!(env!("OUT_DIR"), "/bootsier.rs"));
@ -10,7 +10,7 @@ pub struct Bootsier;
impl ThemeTrait for Bootsier { impl ThemeTrait for Bootsier {
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
BOOTSIER_THEME THEME_BOOTSIER
} }
fn configure_service(&self, cfg: &mut app::web::ServiceConfig) { fn configure_service(&self, cfg: &mut app::web::ServiceConfig) {

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
pub const BULMIX_THEME: &str = "pagetop::theme::bulmix"; pub const THEME_BULMIX: &str = "pagetop::theme::bulmix";
include!(concat!(env!("OUT_DIR"), "/bulmix.rs")); include!(concat!(env!("OUT_DIR"), "/bulmix.rs"));
@ -8,7 +8,7 @@ pub struct Bulmix;
impl ThemeTrait for Bulmix { impl ThemeTrait for Bulmix {
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
BULMIX_THEME THEME_BULMIX
} }
fn configure_service(&self, cfg: &mut app::web::ServiceConfig) { fn configure_service(&self, cfg: &mut app::web::ServiceConfig) {
@ -34,14 +34,14 @@ impl ThemeTrait for Bulmix {
_context: &mut InContext _context: &mut InContext
) { ) {
match component.handler() { match component.handler() {
ANCHOR_COMPONENT => { COMPONENT_ANCHOR => {
let a = component_mut::<Anchor>(component); let a = component_mut::<Anchor>(component);
a.alter_classes(ClassesOp::SetDefault, match a.anchor_type() { a.alter_classes(ClassesOp::SetDefault, match a.anchor_type() {
AnchorType::Button => "button is-primary", AnchorType::Button => "button is-primary",
_ => "", _ => "",
}); });
}, },
HEADING_COMPONENT => { COMPONENT_HEADING => {
let h = component_mut::<Heading>(component); let h = component_mut::<Heading>(component);
h.alter_classes(ClassesOp::SetDefault, match h.display() { h.alter_classes(ClassesOp::SetDefault, match h.display() {
HeadingDisplay::XxLarge => "title is-1", HeadingDisplay::XxLarge => "title is-1",
@ -53,7 +53,7 @@ impl ThemeTrait for Bulmix {
HeadingDisplay::Subtitle => "subtitle", HeadingDisplay::Subtitle => "subtitle",
}); });
}, },
PARAGRAPH_COMPONENT => { COMPONENT_PARAGRAPH => {
let p = component_mut::<Paragraph>(component); let p = component_mut::<Paragraph>(component);
p.alter_classes(ClassesOp::SetDefault, match p.display() { p.alter_classes(ClassesOp::SetDefault, match p.display() {
ParagraphDisplay::XxLarge => "is-size-2", ParagraphDisplay::XxLarge => "is-size-2",
@ -64,7 +64,7 @@ impl ThemeTrait for Bulmix {
ParagraphDisplay::Normal => "", ParagraphDisplay::Normal => "",
}); });
}, },
grid::COLUMN_COMPONENT => { grid::COMPONENT_COLUMN => {
let col = component_mut::<grid::Column>(component); let col = component_mut::<grid::Column>(component);
col.alter_classes(ClassesOp::SetDefault, concat_string!("column", match col.size() { col.alter_classes(ClassesOp::SetDefault, concat_string!("column", match col.size() {
grid::ColumnSize::Default => "", grid::ColumnSize::Default => "",
@ -82,7 +82,7 @@ impl ThemeTrait for Bulmix {
grid::ColumnSize::IsFull => " is-12", grid::ColumnSize::IsFull => " is-12",
}, " content").as_str()); }, " content").as_str());
}, },
grid::ROW_COMPONENT => { grid::COMPONENT_ROW => {
let row = component_mut::<grid::Row>(component); let row = component_mut::<grid::Row>(component);
row.alter_classes(ClassesOp::SetDefault, "columns"); row.alter_classes(ClassesOp::SetDefault, "columns");
}, },
@ -96,7 +96,7 @@ impl ThemeTrait for Bulmix {
_context: &mut InContext _context: &mut InContext
) -> Option<Markup> { ) -> Option<Markup> {
match component.handler() { match component.handler() {
ICON_COMPONENT => { COMPONENT_ICON => {
let icon = component_ref::<Icon>(component); let icon = component_ref::<Icon>(component);
Some(html! { Some(html! {
span class="icon" { span class="icon" {

View file

@ -1,11 +1,11 @@
use crate::prelude::*; use crate::prelude::*;
pub const MINIMAL_THEME: &str = "pagetop::theme::minimal"; pub const THEME_MINIMAL: &str = "pagetop::theme::minimal";
pub struct Minimal; pub struct Minimal;
impl ThemeTrait for Minimal { impl ThemeTrait for Minimal {
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
MINIMAL_THEME THEME_MINIMAL
} }
} }

View file

@ -1,6 +1,6 @@
mod hook; mod hook;
pub use hook::{ pub use hook::{
BEFORE_RENDER_COMPONENT_HOOK, HOOK_BEFORE_RENDER_COMPONENT,
BeforeRenderComponentHook, BeforeRenderComponentHook,
}; };

View file

@ -12,9 +12,9 @@ static DEFAULT_THEME: Lazy<&dyn ThemeTrait> = Lazy::new(|| {
}); });
pub enum InContextOp { pub enum InContextOp {
SetTheme(&'static str),
AddMetadata(&'static str, &'static str), AddMetadata(&'static str, &'static str),
Favicon(Option<Favicon>), Favicon(Option<Favicon>),
SetTheme(&'static str),
StyleSheet(AssetsOp<StyleSheet>), StyleSheet(AssetsOp<StyleSheet>),
JavaScript(AssetsOp<JavaScript>), JavaScript(AssetsOp<JavaScript>),
AddJQuery, AddJQuery,
@ -45,15 +45,15 @@ impl InContext {
pub fn alter(&mut self, op: InContextOp) -> &mut Self { pub fn alter(&mut self, op: InContextOp) -> &mut Self {
match op { match op {
InContextOp::SetTheme(theme_name) => {
self.theme = theme_by_single_name(theme_name).unwrap_or(*DEFAULT_THEME);
},
InContextOp::AddMetadata(name, content) => { InContextOp::AddMetadata(name, content) => {
self.metadata.push((name.to_owned(), content.to_owned())); self.metadata.push((name.to_owned(), content.to_owned()));
}, },
InContextOp::Favicon(favicon) => { InContextOp::Favicon(favicon) => {
self.favicon = favicon; self.favicon = favicon;
}, },
InContextOp::SetTheme(theme_name) => {
self.theme = theme_by_single_name(theme_name).unwrap_or(*DEFAULT_THEME);
},
InContextOp::StyleSheet(css) => { InContextOp::StyleSheet(css) => {
self.stylesheets.alter(css); self.stylesheets.alter(css);
}, },

View file

@ -1,7 +1,7 @@
use crate::util; use crate::util;
use crate::html::{Markup, html}; use crate::html::{Markup, html};
use crate::core::hook::{hook_ref, run_hooks}; use crate::core::hook::{hook_ref, run_hooks};
use super::{BEFORE_RENDER_COMPONENT_HOOK, BeforeRenderComponentHook, InContext}; use super::{HOOK_BEFORE_RENDER_COMPONENT, BeforeRenderComponentHook, InContext};
pub use std::any::Any as AnyComponent; pub use std::any::Any as AnyComponent;
@ -18,16 +18,13 @@ pub trait ComponentTrait: AnyComponent + Send + Sync {
None None
} }
fn is_renderable(&self) -> bool {
true
}
fn weight(&self) -> isize { fn weight(&self) -> isize {
0 0
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn before_render(&mut self, context: &mut InContext) { fn is_renderable(&self, context: &InContext) -> bool {
true
} }
#[allow(unused_variables)] #[allow(unused_variables)]
@ -49,19 +46,16 @@ pub fn component_mut<C: 'static>(component: &mut dyn ComponentTrait) -> &mut C {
} }
pub fn render_component(component: &mut dyn ComponentTrait, context: &mut InContext) -> Markup { pub fn render_component(component: &mut dyn ComponentTrait, context: &mut InContext) -> Markup {
// Acciones del propio componente antes de renderizarlo.
component.before_render(context);
// Acciones de los módulos antes de renderizar el componente. // Acciones de los módulos antes de renderizar el componente.
run_hooks( run_hooks(
BEFORE_RENDER_COMPONENT_HOOK, HOOK_BEFORE_RENDER_COMPONENT,
|hook| hook_ref::<BeforeRenderComponentHook>(&**hook).run(component, context) |hook| hook_ref::<BeforeRenderComponentHook>(&**hook).run(component, context)
); );
// Acciones del tema antes de renderizar el componente. // Acciones del tema antes de renderizar el componente.
context.theme().before_render_component(component, context); context.theme().before_render_component(component, context);
match component.is_renderable() { match component.is_renderable(context) {
true => match context.theme().render_component(component, context) { true => match context.theme().render_component(component, context) {
Some(html) => html, Some(html) => html,
None => component.default_render(context) None => component.default_render(context)

View file

@ -1,7 +1,7 @@
use crate::core::hook::{HookTrait, AnyHook}; use crate::core::hook::{HookTrait, AnyHook};
use super::{ComponentTrait, InContext}; use super::{ComponentTrait, InContext};
pub const BEFORE_RENDER_COMPONENT_HOOK: &str = "pagetop::hook::before_render_component"; pub const HOOK_BEFORE_RENDER_COMPONENT: &str = "pagetop::hook::before_render_component";
pub struct BeforeRenderComponentHook { pub struct BeforeRenderComponentHook {
hook: Option<fn(&mut dyn ComponentTrait, &mut InContext)>, hook: Option<fn(&mut dyn ComponentTrait, &mut InContext)>,
@ -17,7 +17,7 @@ impl HookTrait for BeforeRenderComponentHook {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
BEFORE_RENDER_COMPONENT_HOOK HOOK_BEFORE_RENDER_COMPONENT
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {

View file

@ -1,6 +1,6 @@
mod hook; mod hook;
pub use hook::{ pub use hook::{
BEFORE_RENDER_PAGE_HOOK, HOOK_BEFORE_RENDER_PAGE,
BeforeRenderPageHook, BeforeRenderPageHook,
}; };

View file

@ -3,7 +3,7 @@ use crate::config::SETTINGS;
use crate::html::*; use crate::html::*;
use crate::core::hook::{hook_ref, run_hooks}; use crate::core::hook::{hook_ref, run_hooks};
use crate::core::component::*; use crate::core::component::*;
use super::{BEFORE_RENDER_PAGE_HOOK, BeforeRenderPageHook}; use super::{HOOK_BEFORE_RENDER_PAGE, BeforeRenderPageHook};
use std::collections::HashMap; use std::collections::HashMap;
@ -194,7 +194,7 @@ impl Page {
pub fn render(&mut self) -> app::Result<Markup> { pub fn render(&mut self) -> app::Result<Markup> {
// Acciones de los módulos antes de renderizar la página. // Acciones de los módulos antes de renderizar la página.
run_hooks( run_hooks(
BEFORE_RENDER_PAGE_HOOK, HOOK_BEFORE_RENDER_PAGE,
|hook| hook_ref::<BeforeRenderPageHook>(&**hook).run(self) |hook| hook_ref::<BeforeRenderPageHook>(&**hook).run(self)
); );

View file

@ -1,7 +1,7 @@
use crate::core::hook::{HookTrait, AnyHook}; use crate::core::hook::{HookTrait, AnyHook};
use super::Page; use super::Page;
pub const BEFORE_RENDER_PAGE_HOOK: &str = "pagetop::hook::before_render_page"; pub const HOOK_BEFORE_RENDER_PAGE: &str = "pagetop::hook::before_render_page";
pub struct BeforeRenderPageHook { pub struct BeforeRenderPageHook {
hook: Option<fn(&mut Page)>, hook: Option<fn(&mut Page)>,
@ -17,7 +17,7 @@ impl HookTrait for BeforeRenderPageHook {
} }
fn handler(&self) -> &'static str { fn handler(&self) -> &'static str {
BEFORE_RENDER_PAGE_HOOK HOOK_BEFORE_RENDER_PAGE
} }
fn weight(&self) -> isize { fn weight(&self) -> isize {

View file

@ -0,0 +1,30 @@
#hello-world {
padding: 2em 5%;
}
#hello-world a {
margin: .25em;
}
#hello-world a.services-link {
padding-left: 1.5em;
padding-right: 1.5em;
border-radius: 1.5em;
}
#welcome {
padding: 1em 5%;
}
#welcome .welcome-col-text {
padding-left: 5%;
}
/* Responsiveness */
@media (max-width: 992px) {
#hello-world .hello-col-text {
text-align: center;
}
#hello-world .hello-col-image {
padding-top: 5%;
}
#welcome .welcome-col-text {
text-align: center;
padding-left: 0;
}
}