✨ Añade componentes básicos traducibles Html/Text
This commit is contained in:
parent
6c76e3519c
commit
1d83bbc80a
20 changed files with 243 additions and 369 deletions
|
|
@ -5,64 +5,64 @@ use pagetop_minimal::component::*;
|
||||||
|
|
||||||
pub async fn summary(request: server::HttpRequest) -> ResultPage<Markup, FatalError> {
|
pub async fn summary(request: server::HttpRequest) -> ResultPage<Markup, FatalError> {
|
||||||
let top_menu = MegaMenu::new()
|
let top_menu = MegaMenu::new()
|
||||||
.with_item(MegaMenuItem::label(L10n::t("module_name", &LOCALE_ADMIN)))
|
.with_item(MegaMenuItem::label(Text::t("module_name", &LOCALE_ADMIN)))
|
||||||
.with_item(MegaMenuItem::link(
|
.with_item(MegaMenuItem::link(
|
||||||
L10n::n("Opción 2"),
|
Text::n("Opción 2"),
|
||||||
"https://www.google.es",
|
"https://www.google.es",
|
||||||
))
|
))
|
||||||
.with_item(MegaMenuItem::link_blank(
|
.with_item(MegaMenuItem::link_blank(
|
||||||
L10n::n("Opción 3"),
|
Text::n("Opción 3"),
|
||||||
"https://www.google.es",
|
"https://www.google.es",
|
||||||
))
|
))
|
||||||
.with_item(MegaMenuItem::submenu(
|
.with_item(MegaMenuItem::submenu(
|
||||||
L10n::n("Submenú 1"),
|
Text::n("Submenú 1"),
|
||||||
MegaMenu::new()
|
MegaMenu::new()
|
||||||
.with_item(MegaMenuItem::label(L10n::n("Opción 1")))
|
.with_item(MegaMenuItem::label(Text::n("Opción 1")))
|
||||||
.with_item(MegaMenuItem::label(L10n::n("Opción 2"))),
|
.with_item(MegaMenuItem::label(Text::n("Opción 2"))),
|
||||||
))
|
))
|
||||||
.with_item(MegaMenuItem::separator())
|
.with_item(MegaMenuItem::separator())
|
||||||
.with_item(MegaMenuItem::submenu(
|
.with_item(MegaMenuItem::submenu(
|
||||||
L10n::n("Submenú 2"),
|
Text::n("Submenú 2"),
|
||||||
MegaMenu::new()
|
MegaMenu::new()
|
||||||
.with_item(MegaMenuItem::label(L10n::n("Opción 1")))
|
.with_item(MegaMenuItem::label(Text::n("Opción 1")))
|
||||||
.with_item(MegaMenuItem::label(L10n::n("Opción 2"))),
|
.with_item(MegaMenuItem::label(Text::n("Opción 2"))),
|
||||||
))
|
))
|
||||||
.with_item(MegaMenuItem::label(L10n::n("Opción 4")));
|
.with_item(MegaMenuItem::label(Text::n("Opción 4")));
|
||||||
|
|
||||||
let side_menu = MegaMenu::new()
|
let side_menu = MegaMenu::new()
|
||||||
.with_item(MegaMenuItem::label(L10n::n("Opción 1")))
|
.with_item(MegaMenuItem::label(Text::n("Opción 1")))
|
||||||
.with_item(MegaMenuItem::link(
|
.with_item(MegaMenuItem::link(
|
||||||
L10n::n("Opción 2"),
|
Text::n("Opción 2"),
|
||||||
"https://www.google.es",
|
"https://www.google.es",
|
||||||
))
|
))
|
||||||
.with_item(MegaMenuItem::link_blank(
|
.with_item(MegaMenuItem::link_blank(
|
||||||
L10n::n("Opción 3"),
|
Text::n("Opción 3"),
|
||||||
"https://www.google.es",
|
"https://www.google.es",
|
||||||
))
|
))
|
||||||
.with_item(MegaMenuItem::submenu(
|
.with_item(MegaMenuItem::submenu(
|
||||||
L10n::n("Submenú 1"),
|
Text::n("Submenú 1"),
|
||||||
MegaMenu::new()
|
MegaMenu::new()
|
||||||
.with_item(MegaMenuItem::label(L10n::n("Opción 1")))
|
.with_item(MegaMenuItem::label(Text::n("Opción 1")))
|
||||||
.with_item(MegaMenuItem::label(L10n::n("Opción 2"))),
|
.with_item(MegaMenuItem::label(Text::n("Opción 2"))),
|
||||||
))
|
))
|
||||||
.with_item(MegaMenuItem::separator())
|
.with_item(MegaMenuItem::separator())
|
||||||
.with_item(MegaMenuItem::submenu(
|
.with_item(MegaMenuItem::submenu(
|
||||||
L10n::n("Submenú 2"),
|
Text::n("Submenú 2"),
|
||||||
MegaMenu::new()
|
MegaMenu::new()
|
||||||
.with_item(MegaMenuItem::label(L10n::n("Opción 1")))
|
.with_item(MegaMenuItem::label(Text::n("Opción 1")))
|
||||||
.with_item(MegaMenuItem::label(L10n::n("Opción 2"))),
|
.with_item(MegaMenuItem::label(Text::n("Opción 2"))),
|
||||||
))
|
))
|
||||||
.with_item(MegaMenuItem::label(L10n::n("Opción 4")));
|
.with_item(MegaMenuItem::label(Text::n("Opción 4")));
|
||||||
|
|
||||||
Page::new(request)
|
Page::new(request)
|
||||||
.with_context(ContextOp::Theme("Bootsier"))
|
.with_context(ContextOp::Theme("Bootsier"))
|
||||||
.with_title(L10n::n("Admin"))
|
.with_title(Text::n("Admin"))
|
||||||
.with_this_in("top-menu", top_menu)
|
.with_this_in("top-menu", top_menu)
|
||||||
.with_this_in(
|
.with_this_in(
|
||||||
"region-content",
|
"region-content",
|
||||||
grid::Row::new()
|
grid::Row::new()
|
||||||
.with_column(grid::Column::new().with_component(side_menu))
|
.with_column(grid::Column::new().with_component(side_menu))
|
||||||
.with_column(grid::Column::new().with_component(Html::with(html! {
|
.with_column(grid::Column::new().with_component(Html::n(html! {
|
||||||
p { "Columna 2"}
|
p { "Columna 2"}
|
||||||
}))),
|
}))),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ impl ModuleTrait for HomeDemo {
|
||||||
|
|
||||||
async fn demo(request: server::HttpRequest) -> ResultPage<Markup, FatalError> {
|
async fn demo(request: server::HttpRequest) -> ResultPage<Markup, FatalError> {
|
||||||
Page::new(request)
|
Page::new(request)
|
||||||
.with_title(L10n::t("page_title", &LOCALE_DEMOHOME))
|
.with_title(Text::t("page_title", &LOCALE_DEMOHOME))
|
||||||
.with_context(ContextOp::AddStyleSheet(StyleSheet::located(
|
.with_context(ContextOp::AddStyleSheet(StyleSheet::located(
|
||||||
"/homedemo/css/styles.css",
|
"/homedemo/css/styles.css",
|
||||||
)))
|
)))
|
||||||
|
|
@ -55,11 +55,11 @@ fn hello_world() -> Container {
|
||||||
.with_classes(ClassesOp::Add, "hello-col-text")
|
.with_classes(ClassesOp::Add, "hello-col-text")
|
||||||
.with_size(grid::ColumnSize::Is5of12)
|
.with_size(grid::ColumnSize::Is5of12)
|
||||||
.with_component(
|
.with_component(
|
||||||
Heading::h1(L10n::t("page_title", &LOCALE_DEMOHOME))
|
Heading::h1(Text::t("page_title", &LOCALE_DEMOHOME))
|
||||||
.with_display(HeadingDisplay::Medium),
|
.with_display(HeadingDisplay::Medium),
|
||||||
)
|
)
|
||||||
.with_component(
|
.with_component(
|
||||||
Paragraph::with(L10n::e("hello_intro", &LOCALE_DEMOHOME).with_arg(
|
Paragraph::with(Text::e("hello_intro", &LOCALE_DEMOHOME).with_arg(
|
||||||
"app",
|
"app",
|
||||||
format!(
|
format!(
|
||||||
"<span class=\"app-name\">{}</span>",
|
"<span class=\"app-name\">{}</span>",
|
||||||
|
|
@ -69,7 +69,7 @@ fn hello_world() -> Container {
|
||||||
.with_display(ParagraphDisplay::Small),
|
.with_display(ParagraphDisplay::Small),
|
||||||
)
|
)
|
||||||
.with_component(Paragraph::with(
|
.with_component(Paragraph::with(
|
||||||
L10n::e("hello_powered", &LOCALE_DEMOHOME).with_arg(
|
Text::e("hello_powered", &LOCALE_DEMOHOME).with_arg(
|
||||||
"pagetop",
|
"pagetop",
|
||||||
format!(
|
format!(
|
||||||
"<a href=\"{}\" target=\"_blank\">{}</a>",
|
"<a href=\"{}\" target=\"_blank\">{}</a>",
|
||||||
|
|
@ -80,14 +80,14 @@ fn hello_world() -> Container {
|
||||||
.with_component(
|
.with_component(
|
||||||
Anchor::button(
|
Anchor::button(
|
||||||
"https://github.com/manuelcillero/pagetop",
|
"https://github.com/manuelcillero/pagetop",
|
||||||
L10n::t("hello_code", &LOCALE_DEMOHOME),
|
Text::t("hello_code", &LOCALE_DEMOHOME),
|
||||||
)
|
)
|
||||||
.with_target(AnchorTarget::Blank)
|
.with_target(AnchorTarget::Blank)
|
||||||
.with_left_icon(Icon::with("git"))
|
.with_left_icon(Icon::with("git"))
|
||||||
.with_classes(ClassesOp::Add, "code-link"),
|
.with_classes(ClassesOp::Add, "code-link"),
|
||||||
)
|
)
|
||||||
.with_component(
|
.with_component(
|
||||||
Anchor::link("#welcome", L10n::t("hello_welcome", &LOCALE_DEMOHOME))
|
Anchor::link("#welcome", Text::t("hello_welcome", &LOCALE_DEMOHOME))
|
||||||
.with_left_icon(Icon::with("arrow-down-circle-fill"))
|
.with_left_icon(Icon::with("arrow-down-circle-fill"))
|
||||||
.with_classes(ClassesOp::Add, "welcome-link"),
|
.with_classes(ClassesOp::Add, "welcome-link"),
|
||||||
),
|
),
|
||||||
|
|
@ -104,9 +104,9 @@ fn welcome() -> Container {
|
||||||
Container::section()
|
Container::section()
|
||||||
.with_id("welcome")
|
.with_id("welcome")
|
||||||
.with_classes(ClassesOp::Add, "welcome-col-text")
|
.with_classes(ClassesOp::Add, "welcome-col-text")
|
||||||
.with_component(Heading::h2(L10n::t("welcome_page", &LOCALE_DEMOHOME)))
|
.with_component(Heading::h2(Text::t("welcome_page", &LOCALE_DEMOHOME)))
|
||||||
.with_component(
|
.with_component(
|
||||||
Heading::h3(L10n::e("welcome_subtitle", &LOCALE_DEMOHOME).with_arg(
|
Heading::h3(Text::e("welcome_subtitle", &LOCALE_DEMOHOME).with_arg(
|
||||||
"app",
|
"app",
|
||||||
format!(
|
format!(
|
||||||
"<span class=\"app-name\">{}</span>",
|
"<span class=\"app-name\">{}</span>",
|
||||||
|
|
@ -116,10 +116,10 @@ fn welcome() -> Container {
|
||||||
.with_display(HeadingDisplay::Subtitle),
|
.with_display(HeadingDisplay::Subtitle),
|
||||||
)
|
)
|
||||||
.with_component(
|
.with_component(
|
||||||
Paragraph::with(L10n::t("welcome_text1", &LOCALE_DEMOHOME))
|
Paragraph::with(Text::t("welcome_text1", &LOCALE_DEMOHOME))
|
||||||
.with_display(ParagraphDisplay::Small),
|
.with_display(ParagraphDisplay::Small),
|
||||||
)
|
)
|
||||||
.with_component(Paragraph::with(L10n::t("welcome_text2", &LOCALE_DEMOHOME)))
|
.with_component(Paragraph::with(Text::t("welcome_text2", &LOCALE_DEMOHOME)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn about_pagetop() -> Container {
|
fn about_pagetop() -> Container {
|
||||||
|
|
@ -134,14 +134,14 @@ fn about_pagetop() -> Container {
|
||||||
.with_column(
|
.with_column(
|
||||||
grid::Column::new()
|
grid::Column::new()
|
||||||
.with_classes(ClassesOp::Add, "pagetop-col-text")
|
.with_classes(ClassesOp::Add, "pagetop-col-text")
|
||||||
.with_component(Heading::h2(L10n::t("pagetop_title", &LOCALE_DEMOHOME)))
|
.with_component(Heading::h2(Text::t("pagetop_title", &LOCALE_DEMOHOME)))
|
||||||
.with_component(
|
.with_component(
|
||||||
Paragraph::with(L10n::t("pagetop_text1", &LOCALE_DEMOHOME))
|
Paragraph::with(Text::t("pagetop_text1", &LOCALE_DEMOHOME))
|
||||||
.with_display(ParagraphDisplay::Small),
|
.with_display(ParagraphDisplay::Small),
|
||||||
)
|
)
|
||||||
.with_component(Paragraph::with(L10n::t("pagetop_text2", &LOCALE_DEMOHOME)))
|
.with_component(Paragraph::with(Text::t("pagetop_text2", &LOCALE_DEMOHOME)))
|
||||||
.with_component(Paragraph::with(
|
.with_component(Paragraph::with(
|
||||||
L10n::e("pagetop_text3", &LOCALE_DEMOHOME).with_arg(
|
Text::e("pagetop_text3", &LOCALE_DEMOHOME).with_arg(
|
||||||
"pagetop_website",
|
"pagetop_website",
|
||||||
format!(
|
format!(
|
||||||
"<a href=\"{}\" target=\"_blank\">{}</a>",
|
"<a href=\"{}\" target=\"_blank\">{}</a>",
|
||||||
|
|
@ -160,12 +160,12 @@ fn promo_pagetop() -> Container {
|
||||||
.with_column(
|
.with_column(
|
||||||
grid::Column::new()
|
grid::Column::new()
|
||||||
.with_classes(ClassesOp::Add, "promo-col-text")
|
.with_classes(ClassesOp::Add, "promo-col-text")
|
||||||
.with_component(Heading::h2(L10n::t(
|
.with_component(Heading::h2(Text::t(
|
||||||
"pagetop_promo_title",
|
"pagetop_promo_title",
|
||||||
&LOCALE_DEMOHOME,
|
&LOCALE_DEMOHOME,
|
||||||
)))
|
)))
|
||||||
.with_component(
|
.with_component(
|
||||||
Paragraph::with(L10n::e("pagetop_promo_text1", &LOCALE_DEMOHOME).with_arg(
|
Paragraph::with(Text::e("pagetop_promo_text1", &LOCALE_DEMOHOME).with_arg(
|
||||||
"pagetop",
|
"pagetop",
|
||||||
format!(
|
format!(
|
||||||
"<a href=\"{}\" target=\"_blank\">{}</a>",
|
"<a href=\"{}\" target=\"_blank\">{}</a>",
|
||||||
|
|
@ -196,15 +196,15 @@ fn reporting_issues() -> Container {
|
||||||
grid::Column::new()
|
grid::Column::new()
|
||||||
.with_classes(ClassesOp::Add, "reporting-col-text")
|
.with_classes(ClassesOp::Add, "reporting-col-text")
|
||||||
.with_size(grid::ColumnSize::Is6of12)
|
.with_size(grid::ColumnSize::Is6of12)
|
||||||
.with_component(Heading::h2(L10n::t(
|
.with_component(Heading::h2(Text::t(
|
||||||
"report_problems_title",
|
"report_problems_title",
|
||||||
&LOCALE_DEMOHOME,
|
&LOCALE_DEMOHOME,
|
||||||
)))
|
)))
|
||||||
.with_component(
|
.with_component(
|
||||||
Paragraph::with(L10n::t("report_problems_text1", &LOCALE_DEMOHOME))
|
Paragraph::with(Text::t("report_problems_text1", &LOCALE_DEMOHOME))
|
||||||
.with_display(ParagraphDisplay::Small),
|
.with_display(ParagraphDisplay::Small),
|
||||||
)
|
)
|
||||||
.with_component(Paragraph::with(L10n::t(
|
.with_component(Paragraph::with(Text::t(
|
||||||
"report_problems_text2",
|
"report_problems_text2",
|
||||||
&LOCALE_DEMOHOME,
|
&LOCALE_DEMOHOME,
|
||||||
))),
|
))),
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ license = "Apache-2.0 OR MIT"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pagetop = { version = "0.0", path = "../pagetop" }
|
pagetop = { version = "0.0", path = "../pagetop" }
|
||||||
pagetop-jquery = { version = "0.0", path = "../pagetop-jquery" }
|
pagetop-jquery = { version = "0.0", path = "../pagetop-jquery" }
|
||||||
|
pagetop-minimal = { version = "0.0", path = "../pagetop-minimal" }
|
||||||
static-files = "0.2.3"
|
static-files = "0.2.3"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ use pagetop::prelude::*;
|
||||||
|
|
||||||
define_handle!(COMPONENT_MEGAMENUITEM);
|
define_handle!(COMPONENT_MEGAMENUITEM);
|
||||||
|
|
||||||
type Label = OneComponent<L10n>;
|
type Label = OneComponent<Text>;
|
||||||
|
type Content = OneComponent<Html>;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum MegaMenuItemType {
|
pub enum MegaMenuItemType {
|
||||||
|
|
@ -11,7 +12,7 @@ pub enum MegaMenuItemType {
|
||||||
Label(Label),
|
Label(Label),
|
||||||
Link(Label, String),
|
Link(Label, String),
|
||||||
LinkBlank(Label, String),
|
LinkBlank(Label, String),
|
||||||
Html(Markup),
|
Html(Content),
|
||||||
Submenu(Label, MegaMenu),
|
Submenu(Label, MegaMenu),
|
||||||
Separator,
|
Separator,
|
||||||
}
|
}
|
||||||
|
|
@ -58,8 +59,8 @@ impl ComponentTrait for MegaMenuItem {
|
||||||
a href=(path) target="_blank" { (label.render(rcx)) }
|
a href=(path) target="_blank" { (label.render(rcx)) }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
MegaMenuItemType::Html(html) => html! {
|
MegaMenuItemType::Html(content) => html! {
|
||||||
li class="html" { (*html) }
|
li class="html" { (content.render(rcx)) }
|
||||||
},
|
},
|
||||||
MegaMenuItemType::Submenu(label, menu) => html! {
|
MegaMenuItemType::Submenu(label, menu) => html! {
|
||||||
li class="submenu" {
|
li class="submenu" {
|
||||||
|
|
@ -85,35 +86,35 @@ impl ComponentTrait for MegaMenuItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MegaMenuItem {
|
impl MegaMenuItem {
|
||||||
pub fn label(label: L10n) -> Self {
|
pub fn label(label: Text) -> Self {
|
||||||
MegaMenuItem {
|
MegaMenuItem {
|
||||||
item_type: MegaMenuItemType::Label(OneComponent::new_with(label)),
|
item_type: MegaMenuItemType::Label(OneComponent::new_with(label)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn link(label: L10n, path: &str) -> Self {
|
pub fn link(label: Text, path: &str) -> Self {
|
||||||
MegaMenuItem {
|
MegaMenuItem {
|
||||||
item_type: MegaMenuItemType::Link(OneComponent::new_with(label), path.to_owned()),
|
item_type: MegaMenuItemType::Link(OneComponent::new_with(label), path.to_owned()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn link_blank(label: L10n, path: &str) -> Self {
|
pub fn link_blank(label: Text, path: &str) -> Self {
|
||||||
MegaMenuItem {
|
MegaMenuItem {
|
||||||
item_type: MegaMenuItemType::LinkBlank(OneComponent::new_with(label), path.to_owned()),
|
item_type: MegaMenuItemType::LinkBlank(OneComponent::new_with(label), path.to_owned()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn html(html: Markup) -> Self {
|
pub fn html(content: Html) -> Self {
|
||||||
MegaMenuItem {
|
MegaMenuItem {
|
||||||
item_type: MegaMenuItemType::Html(html),
|
item_type: MegaMenuItemType::Html(OneComponent::new_with(content)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn submenu(label: L10n, menu: MegaMenu) -> Self {
|
pub fn submenu(label: Text, menu: MegaMenu) -> Self {
|
||||||
MegaMenuItem {
|
MegaMenuItem {
|
||||||
item_type: MegaMenuItemType::Submenu(OneComponent::new_with(label), menu),
|
item_type: MegaMenuItemType::Submenu(OneComponent::new_with(label), menu),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ impl ModuleTrait for MegaMenu {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dependencies(&self) -> Vec<ModuleStaticRef> {
|
fn dependencies(&self) -> Vec<ModuleStaticRef> {
|
||||||
vec![&pagetop_jquery::JQuery]
|
vec![&pagetop_jquery::JQuery, &pagetop_minimal::Minimal]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure_service(&self, cfg: &mut server::web::ServiceConfig) {
|
fn configure_service(&self, cfg: &mut server::web::ServiceConfig) {
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ pub use container::{Container, ContainerType, COMPONENT_CONTAINER};
|
||||||
|
|
||||||
pub mod grid;
|
pub mod grid;
|
||||||
|
|
||||||
mod html;
|
|
||||||
pub use html::{Html, COMPONENT_HTML};
|
|
||||||
mod icon;
|
mod icon;
|
||||||
pub use icon::{Icon, COMPONENT_ICON};
|
pub use icon::{Icon, COMPONENT_ICON};
|
||||||
mod heading;
|
mod heading;
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ pub enum AnchorTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
type AnchorIcon = OneComponent<Icon>;
|
type AnchorIcon = OneComponent<Icon>;
|
||||||
type AnchorHtml = OneComponent<L10n>;
|
type AnchorHtml = OneComponent<Text>;
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
@ -34,7 +34,7 @@ pub struct Anchor {
|
||||||
classes : Classes,
|
classes : Classes,
|
||||||
anchor_type: AnchorType,
|
anchor_type: AnchorType,
|
||||||
href : AttributeValue,
|
href : AttributeValue,
|
||||||
html10n : AnchorHtml,
|
html : AnchorHtml,
|
||||||
left_icon : AnchorIcon,
|
left_icon : AnchorIcon,
|
||||||
right_icon : AnchorIcon,
|
right_icon : AnchorIcon,
|
||||||
target : AnchorTarget,
|
target : AnchorTarget,
|
||||||
|
|
@ -91,15 +91,15 @@ impl ComponentTrait for Anchor {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Anchor {
|
impl Anchor {
|
||||||
pub fn link(href: &str, html10n: L10n) -> Self {
|
pub fn link(href: &str, html: Text) -> Self {
|
||||||
Anchor::new().with_href(href).with_html(html10n)
|
Anchor::new().with_href(href).with_html(html)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn button(href: &str, html10n: L10n) -> Self {
|
pub fn button(href: &str, html: Text) -> Self {
|
||||||
Anchor::new()
|
Anchor::new()
|
||||||
.with_type(AnchorType::Button)
|
.with_type(AnchorType::Button)
|
||||||
.with_href(href)
|
.with_href(href)
|
||||||
.with_html(html10n)
|
.with_html(html)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn location(id: &str) -> Self {
|
pub fn location(id: &str) -> Self {
|
||||||
|
|
@ -152,8 +152,8 @@ impl Anchor {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fn_builder]
|
#[fn_builder]
|
||||||
pub fn alter_html(&mut self, html10n: L10n) -> &mut Self {
|
pub fn alter_html(&mut self, html: Text) -> &mut Self {
|
||||||
self.html10n.set(html10n);
|
self.html.set(html);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,7 +200,7 @@ impl Anchor {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn html(&self) -> &AnchorHtml {
|
pub fn html(&self) -> &AnchorHtml {
|
||||||
&self.html10n
|
&self.html
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn left_icon(&self) -> &AnchorIcon {
|
pub fn left_icon(&self) -> &AnchorIcon {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ pub enum ButtonType {
|
||||||
Reset,
|
Reset,
|
||||||
}
|
}
|
||||||
|
|
||||||
type ButtonValue = OneComponent<L10n>;
|
type ButtonValue = OneComponent<Text>;
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
@ -77,11 +77,11 @@ impl ComponentTrait for Button {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Button {
|
impl Button {
|
||||||
pub fn with(value: L10n) -> Self {
|
pub fn with(value: Text) -> Self {
|
||||||
Button::new().with_value(value)
|
Button::new().with_value(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn submit(value: L10n) -> Self {
|
pub fn submit(value: Text) -> Self {
|
||||||
let mut button = Button::new()
|
let mut button = Button::new()
|
||||||
.with_classes(ClassesOp::Replace("form-button"), "form-submit")
|
.with_classes(ClassesOp::Replace("form-button"), "form-submit")
|
||||||
.with_value(value);
|
.with_value(value);
|
||||||
|
|
@ -89,7 +89,7 @@ impl Button {
|
||||||
button
|
button
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset(value: L10n) -> Self {
|
pub fn reset(value: Text) -> Self {
|
||||||
let mut button = Button::new()
|
let mut button = Button::new()
|
||||||
.with_classes(ClassesOp::Replace("form-button"), "form-reset")
|
.with_classes(ClassesOp::Replace("form-button"), "form-reset")
|
||||||
.with_value(value);
|
.with_value(value);
|
||||||
|
|
@ -124,7 +124,7 @@ impl Button {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fn_builder]
|
#[fn_builder]
|
||||||
pub fn alter_value(&mut self, value: L10n) -> &mut Self {
|
pub fn alter_value(&mut self, value: Text) -> &mut Self {
|
||||||
self.value.set(value);
|
self.value.set(value);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ pub enum InputType {
|
||||||
Url,
|
Url,
|
||||||
}
|
}
|
||||||
|
|
||||||
type InputLabel = OneComponent<L10n>;
|
type InputLabel = OneComponent<Text>;
|
||||||
type InputHelpText = OneComponent<L10n>;
|
type InputHelpText = OneComponent<Text>;
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
@ -206,7 +206,7 @@ impl Input {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fn_builder]
|
#[fn_builder]
|
||||||
pub fn alter_label(&mut self, label: L10n) -> &mut Self {
|
pub fn alter_label(&mut self, label: Text) -> &mut Self {
|
||||||
self.label.set(label);
|
self.label.set(label);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
@ -281,7 +281,7 @@ impl Input {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fn_builder]
|
#[fn_builder]
|
||||||
pub fn alter_help_text(&mut self, help_text: L10n) -> &mut Self {
|
pub fn alter_help_text(&mut self, help_text: Text) -> &mut Self {
|
||||||
self.help_text.set(help_text);
|
self.help_text.set(help_text);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ pub enum HeadingDisplay {
|
||||||
Subtitle,
|
Subtitle,
|
||||||
}
|
}
|
||||||
|
|
||||||
type HeadingText = OneComponent<L10n>;
|
type HeadingText = OneComponent<Text>;
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
@ -80,37 +80,37 @@ impl ComponentTrait for Heading {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Heading {
|
impl Heading {
|
||||||
pub fn h1(text: L10n) -> Self {
|
pub fn h1(text: Text) -> Self {
|
||||||
Heading::new()
|
Heading::new()
|
||||||
.with_heading_type(HeadingType::H1)
|
.with_heading_type(HeadingType::H1)
|
||||||
.with_text(text)
|
.with_text(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn h2(text: L10n) -> Self {
|
pub fn h2(text: Text) -> Self {
|
||||||
Heading::new()
|
Heading::new()
|
||||||
.with_heading_type(HeadingType::H2)
|
.with_heading_type(HeadingType::H2)
|
||||||
.with_text(text)
|
.with_text(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn h3(text: L10n) -> Self {
|
pub fn h3(text: Text) -> Self {
|
||||||
Heading::new()
|
Heading::new()
|
||||||
.with_heading_type(HeadingType::H3)
|
.with_heading_type(HeadingType::H3)
|
||||||
.with_text(text)
|
.with_text(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn h4(text: L10n) -> Self {
|
pub fn h4(text: Text) -> Self {
|
||||||
Heading::new()
|
Heading::new()
|
||||||
.with_heading_type(HeadingType::H4)
|
.with_heading_type(HeadingType::H4)
|
||||||
.with_text(text)
|
.with_text(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn h5(text: L10n) -> Self {
|
pub fn h5(text: Text) -> Self {
|
||||||
Heading::new()
|
Heading::new()
|
||||||
.with_heading_type(HeadingType::H5)
|
.with_heading_type(HeadingType::H5)
|
||||||
.with_text(text)
|
.with_text(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn h6(text: L10n) -> Self {
|
pub fn h6(text: Text) -> Self {
|
||||||
Heading::new()
|
Heading::new()
|
||||||
.with_heading_type(HeadingType::H6)
|
.with_heading_type(HeadingType::H6)
|
||||||
.with_text(text)
|
.with_text(text)
|
||||||
|
|
@ -149,7 +149,7 @@ impl Heading {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fn_builder]
|
#[fn_builder]
|
||||||
pub fn alter_text(&mut self, text: L10n) -> &mut Self {
|
pub fn alter_text(&mut self, text: Text) -> &mut Self {
|
||||||
self.text.set(text);
|
self.text.set(text);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,84 +0,0 @@
|
||||||
use pagetop::prelude::*;
|
|
||||||
|
|
||||||
define_handle!(COMPONENT_HTML);
|
|
||||||
|
|
||||||
#[rustfmt::skip]
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct Html {
|
|
||||||
weight : isize,
|
|
||||||
renderable: Renderable,
|
|
||||||
html : HtmlMarkup,
|
|
||||||
template : String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ComponentTrait for Html {
|
|
||||||
fn new() -> Self {
|
|
||||||
Html::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle(&self) -> Handle {
|
|
||||||
COMPONENT_HTML
|
|
||||||
}
|
|
||||||
|
|
||||||
fn weight(&self) -> isize {
|
|
||||||
self.weight
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_renderable(&self, rcx: &RenderContext) -> bool {
|
|
||||||
(self.renderable.check)(rcx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn default_render(&self, _: &mut RenderContext) -> Markup {
|
|
||||||
html! { (*self.html()) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn as_ref_any(&self) -> &dyn AnyComponent {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Html {
|
|
||||||
pub fn with(html: Markup) -> Self {
|
|
||||||
Html::new().with_html(html)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Html BUILDER.
|
|
||||||
|
|
||||||
#[fn_builder]
|
|
||||||
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
|
|
||||||
self.weight = weight;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[fn_builder]
|
|
||||||
pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
|
|
||||||
self.renderable.check = check;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[fn_builder]
|
|
||||||
pub fn alter_html(&mut self, html: Markup) -> &mut Self {
|
|
||||||
self.html.markup = html;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[fn_builder]
|
|
||||||
pub fn alter_template(&mut self, template: &str) -> &mut Self {
|
|
||||||
self.template = template.to_owned();
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
// Html GETTERS.
|
|
||||||
|
|
||||||
pub fn html(&self) -> &Markup {
|
|
||||||
&self.html.markup
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn template(&self) -> &str {
|
|
||||||
self.template.as_str()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -41,7 +41,7 @@ impl ModuleTrait for Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn node(request: server::HttpRequest) -> ResultPage<Markup, FatalError> {
|
async fn node(request: server::HttpRequest) -> ResultPage<Markup, FatalError> {
|
||||||
Page::new(request).with_title(L10n::n("Nodo")).render()
|
Page::new(request).with_title(Text::n("Nodo")).render()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn before_render_page(page: &mut Page) {
|
fn before_render_page(page: &mut Page) {
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ impl ModuleTrait for User {
|
||||||
|
|
||||||
async fn login(request: server::HttpRequest) -> ResultPage<Markup, FatalError> {
|
async fn login(request: server::HttpRequest) -> ResultPage<Markup, FatalError> {
|
||||||
Page::new(request)
|
Page::new(request)
|
||||||
.with_title(L10n::n("Identificación del usuario"))
|
.with_title(Text::n("Identificación del usuario"))
|
||||||
.with_this_in(
|
.with_this_in(
|
||||||
"region-content",
|
"region-content",
|
||||||
Container::new()
|
Container::new()
|
||||||
|
|
@ -58,9 +58,9 @@ fn form_login() -> Form {
|
||||||
.with_element(
|
.with_element(
|
||||||
form_element::Input::textfield()
|
form_element::Input::textfield()
|
||||||
.with_name("name")
|
.with_name("name")
|
||||||
.with_label(L10n::t("username", &LOCALE_USER))
|
.with_label(Text::t("username", &LOCALE_USER))
|
||||||
.with_help_text(
|
.with_help_text(
|
||||||
L10n::t("username_help", &LOCALE_USER)
|
Text::t("username_help", &LOCALE_USER)
|
||||||
.with_arg("app", config::SETTINGS.app.name.to_owned()),
|
.with_arg("app", config::SETTINGS.app.name.to_owned()),
|
||||||
)
|
)
|
||||||
.with_autofocus(true),
|
.with_autofocus(true),
|
||||||
|
|
@ -68,8 +68,8 @@ fn form_login() -> Form {
|
||||||
.with_element(
|
.with_element(
|
||||||
form_element::Input::password()
|
form_element::Input::password()
|
||||||
.with_name("pass")
|
.with_name("pass")
|
||||||
.with_label(L10n::t("password", &LOCALE_USER))
|
.with_label(Text::t("password", &LOCALE_USER))
|
||||||
.with_help_text(L10n::t("password_help", &LOCALE_USER)),
|
.with_help_text(Text::t("password_help", &LOCALE_USER)),
|
||||||
)
|
)
|
||||||
.with_element(form_element::Button::submit(L10n::t("login", &LOCALE_USER)))
|
.with_element(form_element::Button::submit(Text::t("login", &LOCALE_USER)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,6 @@ pub(crate) use all::common_components;
|
||||||
mod renderable;
|
mod renderable;
|
||||||
pub use renderable::{IsRenderable, Renderable};
|
pub use renderable::{IsRenderable, Renderable};
|
||||||
|
|
||||||
mod html_markup;
|
mod basic;
|
||||||
pub use html_markup::HtmlMarkup;
|
pub use basic::{Html, COMPONENT_HTML};
|
||||||
|
pub use basic::{Text, COMPONENT_TEXT};
|
||||||
mod l10n;
|
|
||||||
pub use l10n::L10n;
|
|
||||||
|
|
|
||||||
143
pagetop/src/core/component/basic.rs
Normal file
143
pagetop/src/core/component/basic.rs
Normal file
|
|
@ -0,0 +1,143 @@
|
||||||
|
use crate::core::component::{AnyComponent, ComponentTrait, RenderContext};
|
||||||
|
use crate::html::{html, Markup, PreEscaped};
|
||||||
|
use crate::locale::{translate, Locale, Locales};
|
||||||
|
use crate::{define_handle, fn_builder, paste, Handle};
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
macro_rules! basic_components {
|
||||||
|
( $($COMPONENT_HANDLE:ident: $Component:ty => $TypeValue:ty),* ) => { $( paste! {
|
||||||
|
|
||||||
|
define_handle!($COMPONENT_HANDLE);
|
||||||
|
|
||||||
|
pub enum [< $Component Op >] {
|
||||||
|
None,
|
||||||
|
Value($TypeValue),
|
||||||
|
Translated(&'static str, &'static Locales),
|
||||||
|
Escaped(&'static str, &'static Locales),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct $Component {
|
||||||
|
op: [< $Component Op >],
|
||||||
|
args: HashMap<&'static str, String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for $Component {
|
||||||
|
fn default() -> Self {
|
||||||
|
$Component {
|
||||||
|
op: [< $Component Op >]::None,
|
||||||
|
args: HashMap::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ComponentTrait for $Component {
|
||||||
|
fn new() -> Self {
|
||||||
|
$Component::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle(&self) -> Handle {
|
||||||
|
$COMPONENT_HANDLE
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_render(&self, rcx: &mut RenderContext) -> Markup {
|
||||||
|
match self.op() {
|
||||||
|
[< $Component Op >]::None => html! {},
|
||||||
|
[< $Component Op >]::Value(value) => html! { (value) },
|
||||||
|
[< $Component Op >]::Translated(key, locales) => html! {
|
||||||
|
(translate(
|
||||||
|
key,
|
||||||
|
Locale::Using(
|
||||||
|
rcx.langid(),
|
||||||
|
locales,
|
||||||
|
&self.args().iter().fold(HashMap::new(), |mut args, (key, value)| {
|
||||||
|
args.insert(key.to_string(), value.to_owned().into());
|
||||||
|
args
|
||||||
|
})
|
||||||
|
)
|
||||||
|
))
|
||||||
|
},
|
||||||
|
[< $Component Op >]::Escaped(key, locales) => html! {
|
||||||
|
(PreEscaped(translate(
|
||||||
|
key,
|
||||||
|
Locale::Using(
|
||||||
|
rcx.langid(),
|
||||||
|
locales,
|
||||||
|
&self.args().iter().fold(HashMap::new(), |mut args, (key, value)| {
|
||||||
|
args.insert(key.to_string(), value.to_owned().into());
|
||||||
|
args
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_ref_any(&self) -> &dyn AnyComponent {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $Component {
|
||||||
|
pub fn n(value: $TypeValue) -> Self {
|
||||||
|
$Component {
|
||||||
|
op: [< $Component Op >]::Value(value),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn t(key: &'static str, locales: &'static Locales) -> Self {
|
||||||
|
$Component {
|
||||||
|
op: [< $Component Op >]::Translated(key, locales),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn e(key: &'static str, locales: &'static Locales) -> Self {
|
||||||
|
$Component {
|
||||||
|
op: [< $Component Op >]::Escaped(key, locales),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// $Component BUILDER.
|
||||||
|
|
||||||
|
#[fn_builder]
|
||||||
|
pub fn alter_op(&mut self, op: [< $Component Op >]) -> &mut Self {
|
||||||
|
self.op = op;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
#[fn_builder]
|
||||||
|
pub fn alter_arg(&mut self, arg: &'static str, value: String) -> &mut Self {
|
||||||
|
self.args.insert(arg, value);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clear_args(&mut self) -> &mut Self {
|
||||||
|
self.args.drain();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
// $Component GETTERS.
|
||||||
|
|
||||||
|
pub fn op(&self) -> &[< $Component Op >] {
|
||||||
|
&self.op
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn args(&self) -> &HashMap<&str, String> {
|
||||||
|
&self.args
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} )* };
|
||||||
|
}
|
||||||
|
|
||||||
|
basic_components!(
|
||||||
|
COMPONENT_HTML: Html => Markup,
|
||||||
|
COMPONENT_TEXT: Text => &'static str
|
||||||
|
);
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
use crate::core::component::{AnyComponent, ComponentTrait, RenderContext};
|
|
||||||
use crate::html::{html, Markup};
|
|
||||||
use crate::{define_handle, Handle};
|
|
||||||
|
|
||||||
define_handle!(HTML_MARKUP);
|
|
||||||
|
|
||||||
pub struct HtmlMarkup {
|
|
||||||
pub markup: Markup,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for HtmlMarkup {
|
|
||||||
fn default() -> Self {
|
|
||||||
HtmlMarkup { markup: html! {} }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ComponentTrait for HtmlMarkup {
|
|
||||||
fn new() -> Self {
|
|
||||||
HtmlMarkup::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle(&self) -> Handle {
|
|
||||||
HTML_MARKUP
|
|
||||||
}
|
|
||||||
|
|
||||||
fn default_render(&self, _rcx: &mut RenderContext) -> Markup {
|
|
||||||
html! {
|
|
||||||
(self.markup)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn as_ref_any(&self) -> &dyn AnyComponent {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HtmlMarkup {
|
|
||||||
pub fn with(mut self, html: Markup) -> Self {
|
|
||||||
self.markup = html;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,138 +0,0 @@
|
||||||
use crate::core::component::{AnyComponent, ComponentTrait, RenderContext};
|
|
||||||
use crate::html::{html, Markup, PreEscaped};
|
|
||||||
use crate::locale::{translate, Locale, Locales};
|
|
||||||
use crate::{define_handle, fn_builder, Handle};
|
|
||||||
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
define_handle!(COMPONENT_L10N);
|
|
||||||
|
|
||||||
#[rustfmt::skip]
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct L10n {
|
|
||||||
key : &'static str,
|
|
||||||
locales: Option<&'static Locales>,
|
|
||||||
args : HashMap<&'static str, String>,
|
|
||||||
escaped: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ComponentTrait for L10n {
|
|
||||||
fn new() -> Self {
|
|
||||||
L10n::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle(&self) -> Handle {
|
|
||||||
COMPONENT_L10N
|
|
||||||
}
|
|
||||||
|
|
||||||
fn default_render(&self, rcx: &mut RenderContext) -> Markup {
|
|
||||||
if let Some(locales) = self.locales() {
|
|
||||||
html! {
|
|
||||||
@if self.escaped() {
|
|
||||||
(PreEscaped(translate(
|
|
||||||
self.key(),
|
|
||||||
Locale::Using(
|
|
||||||
rcx.langid(),
|
|
||||||
locales,
|
|
||||||
&self.args().iter().fold(HashMap::new(), |mut args, (key, value)| {
|
|
||||||
args.insert(key.to_string(), value.to_owned().into());
|
|
||||||
args
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)))
|
|
||||||
} @else {
|
|
||||||
(translate(
|
|
||||||
self.key(),
|
|
||||||
Locale::Using(
|
|
||||||
rcx.langid(),
|
|
||||||
locales,
|
|
||||||
&self.args().iter().fold(HashMap::new(), |mut args, (key, value)| {
|
|
||||||
args.insert(key.to_string(), value.to_owned().into());
|
|
||||||
args
|
|
||||||
})
|
|
||||||
)
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
html! { (self.key()) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn as_ref_any(&self) -> &dyn AnyComponent {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl L10n {
|
|
||||||
pub fn n(text: &'static str) -> Self {
|
|
||||||
L10n {
|
|
||||||
key: text,
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn t(key: &'static str, locales: &'static Locales) -> Self {
|
|
||||||
L10n {
|
|
||||||
key,
|
|
||||||
locales: Some(locales),
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn e(key: &'static str, locales: &'static Locales) -> Self {
|
|
||||||
L10n {
|
|
||||||
key,
|
|
||||||
locales: Some(locales),
|
|
||||||
escaped: true,
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// HtmL10n BUILDER.
|
|
||||||
|
|
||||||
#[fn_builder]
|
|
||||||
pub fn alter_key(&mut self, key: &'static str) -> &mut Self {
|
|
||||||
self.key = key;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[fn_builder]
|
|
||||||
pub fn alter_locales(&mut self, locales: &'static Locales) -> &mut Self {
|
|
||||||
self.locales = Some(locales);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[fn_builder]
|
|
||||||
pub fn alter_arg(&mut self, arg: &'static str, value: String) -> &mut Self {
|
|
||||||
self.args.insert(arg, value);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn clear_args(&mut self) -> &mut Self {
|
|
||||||
self.args.drain();
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
// HtmL10n GETTERS.
|
|
||||||
|
|
||||||
pub fn key(&self) -> &str {
|
|
||||||
self.key
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn locales(&self) -> Option<&Locales> {
|
|
||||||
self.locales
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn args(&self) -> &HashMap<&str, String> {
|
|
||||||
&self.args
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn escaped(&self) -> bool {
|
|
||||||
self.escaped
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -94,8 +94,9 @@
|
||||||
//! println!("* {}\n", _t("shared-photos", Locale::With(&LOCALE_SAMPLE, &args)));
|
//! println!("* {}\n", _t("shared-photos", Locale::With(&LOCALE_SAMPLE, &args)));
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
//! Aunque normalmente usarás el componente [L10n](crate::core::component::L10n) para añadir textos
|
//! Aunque preferirás usar normalmente los componentes básicos [Text](crate::core::component::Text)
|
||||||
//! traducibles en las respuestas web según el contexto del renderizado.
|
//! y [Html](crate::core::component::Html) para incluir, en respuestas a las peticiones web, textos
|
||||||
|
//! y contenidos opcionalmente traducibles según el contexto de renderizado.
|
||||||
|
|
||||||
use crate::html::{Markup, PreEscaped};
|
use crate::html::{Markup, PreEscaped};
|
||||||
use crate::{args, config, trace, LazyStatic};
|
use crate::{args, config, trace, LazyStatic};
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ pub use error403::ERROR_403;
|
||||||
mod error404;
|
mod error404;
|
||||||
pub use error404::ERROR_404;
|
pub use error404::ERROR_404;
|
||||||
|
|
||||||
use crate::core::component::L10n;
|
use crate::core::component::Text;
|
||||||
use crate::response::{page::Page, ResponseError};
|
use crate::response::{page::Page, ResponseError};
|
||||||
use crate::server::http::{header::ContentType, StatusCode};
|
use crate::server::http::{header::ContentType, StatusCode};
|
||||||
use crate::server::{HttpRequest, HttpResponse};
|
use crate::server::{HttpRequest, HttpResponse};
|
||||||
|
|
@ -32,7 +32,7 @@ impl fmt::Display for FatalError {
|
||||||
FatalError::AccessDenied(request) => {
|
FatalError::AccessDenied(request) => {
|
||||||
let error_page = Page::new(request.clone());
|
let error_page = Page::new(request.clone());
|
||||||
if let Ok(page) = error_page
|
if let Ok(page) = error_page
|
||||||
.with_title(L10n::n("Error FORBIDDEN"))
|
.with_title(Text::n("Error FORBIDDEN"))
|
||||||
.with_this_in("region-content", error403::Error403)
|
.with_this_in("region-content", error403::Error403)
|
||||||
.with_template("error")
|
.with_template("error")
|
||||||
.render()
|
.render()
|
||||||
|
|
@ -46,7 +46,7 @@ impl fmt::Display for FatalError {
|
||||||
FatalError::NotFound(request) => {
|
FatalError::NotFound(request) => {
|
||||||
let error_page = Page::new(request.clone());
|
let error_page = Page::new(request.clone());
|
||||||
if let Ok(page) = error_page
|
if let Ok(page) = error_page
|
||||||
.with_title(L10n::n("Error RESOURCE NOT FOUND"))
|
.with_title(Text::n("Error RESOURCE NOT FOUND"))
|
||||||
.with_this_in("region-content", error404::Error404)
|
.with_this_in("region-content", error404::Error404)
|
||||||
.with_template("error")
|
.with_template("error")
|
||||||
.render()
|
.render()
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ use unic_langid::CharacterDirection;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
type PageTitle = OneComponent<L10n>;
|
type PageTitle = OneComponent<Text>;
|
||||||
type PageDescription = OneComponent<L10n>;
|
type PageDescription = OneComponent<Text>;
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
pub struct Page {
|
pub struct Page {
|
||||||
|
|
@ -60,13 +60,13 @@ impl Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fn_builder]
|
#[fn_builder]
|
||||||
pub fn alter_title(&mut self, title: L10n) -> &mut Self {
|
pub fn alter_title(&mut self, title: Text) -> &mut Self {
|
||||||
self.title.set(title);
|
self.title.set(title);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fn_builder]
|
#[fn_builder]
|
||||||
pub fn alter_description(&mut self, description: L10n) -> &mut Self {
|
pub fn alter_description(&mut self, description: Text) -> &mut Self {
|
||||||
self.description.set(description);
|
self.description.set(description);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue