pagetop_bootsier/
lib.rs

1use pagetop::prelude::*;
2
3// GLOBAL ******************************************************************************************
4
5include_files!(bootsier_bs);
6include_files!(bootsier_js);
7
8include_locales!(LOCALES_BOOTSIER);
9
10const BOOTSTRAP_VERSION: &str = "5.3.3"; // Versión de la librería Bootstrap.
11
12// API *********************************************************************************************
13
14pub mod config;
15
16pub mod bs;
17
18pub struct Bootsier;
19
20impl ExtensionTrait for Bootsier {
21    fn theme(&self) -> Option<ThemeRef> {
22        Some(&Bootsier)
23    }
24
25    fn actions(&self) -> Vec<ActionBox> {
26        actions![
27            //action::theme::BeforeRender::<Region>::new(&Self, before_render_region),
28            //action::theme::BeforePrepare::<Button>::new(&Self, before_prepare_button),
29            //action::theme::BeforePrepare::<Heading>::new(&Self, before_prepare_heading),
30            //action::theme::BeforePrepare::<Paragraph>::new(&Self, before_prepare_paragraph),
31            //action::theme::RenderComponent::<Error404>::new(&Self, render_error404),
32        ]
33    }
34
35    fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
36        include_files_service!(scfg, bootsier_bs => "/bootsier/bs");
37        include_files_service!(scfg, bootsier_js => "/bootsier/js");
38    }
39}
40
41impl ThemeTrait for Bootsier {
42    #[rustfmt::skip]
43    fn regions(&self) -> Vec<(&'static str, L10n)> {
44        vec![
45            ("region-header",         L10n::t("header",         &LOCALES_BOOTSIER)),
46            ("region-nav_branding",   L10n::t("nav_branding",   &LOCALES_BOOTSIER)),
47            ("region-nav_main",       L10n::t("nav_main",       &LOCALES_BOOTSIER)),
48            ("region-nav_additional", L10n::t("nav_additional", &LOCALES_BOOTSIER)),
49            ("region-breadcrumb",     L10n::t("breadcrumb",     &LOCALES_BOOTSIER)),
50            ("region-content",        L10n::t("content",        &LOCALES_BOOTSIER)),
51            ("region-sidebar_first",  L10n::t("sidebar_first",  &LOCALES_BOOTSIER)),
52            ("region-sidebar_second", L10n::t("sidebar_second", &LOCALES_BOOTSIER)),
53            ("region-footer",         L10n::t("footer",         &LOCALES_BOOTSIER)),
54        ]
55    }
56
57    fn render_page_body(&self, page: &mut Page) -> Markup {
58        html! {
59            body id=[page.body_id().get()] class=[page.body_classes().get()] {
60                //@if let Some(skip) = L10n::l("skip_to_content").using(page.context().langid()) {
61                //    div class="skip__to_content" {
62                //        a href=(concat_string!("#", skip_to_id)) { (skip) }
63                //    }
64                //}
65                (bs::Container::new()
66                    .with_id("container-wrapper")
67                    .with_breakpoint(bs::BreakPoint::FluidMax(config::SETTINGS.bootsier.max_width))
68                    .with_child(Region::of("region-content"))
69                    .render(page.context()))
70            }
71        }
72    }
73
74    fn after_render_page_body(&self, page: &mut Page) {
75        page.alter_assets(AssetsOp::AddStyleSheet(
76            StyleSheet::from("/bootsier/bs/bootstrap.min.css")
77                .with_version(BOOTSTRAP_VERSION)
78                .with_weight(-99),
79        ))
80        .alter_assets(AssetsOp::AddJavaScript(
81            JavaScript::defer("/bootsier/js/bootstrap.min.js")
82                .with_version(BOOTSTRAP_VERSION)
83                .with_weight(-99),
84        ));
85    }
86
87    /*
88
89            fn prepare_body(&self, page: &mut Page) -> PrepareMarkup {
90                let skip_to_id = page.body_skip_to().get().unwrap_or("content".to_owned());
91
92                PrepareMarkup::With(html! {
93                    body id=[page.body_id().get()] class=[page.body_classes().get()] {
94                        @if let Some(skip) = L10n::l("skip_to_content").using(page.context().langid()) {
95                            div class="skip__to_content" {
96                                a href=(concat_string!("#", skip_to_id)) { (skip) }
97                            }
98                        }
99                        (match page.context().layout() {
100                            "admin" => flex::Container::new()
101                                .add_item(flex::Item::region().with_id("top-menu"))
102                                .add_item(flex::Item::region().with_id("side-menu"))
103                                .add_item(flex::Item::region().with_id("content")),
104                            _ => flex::Container::new()
105                                .add_item(flex::Item::region().with_id("header"))
106                                .add_item(flex::Item::region().with_id("nav_branding"))
107                                .add_item(flex::Item::region().with_id("nav_main"))
108                                .add_item(flex::Item::region().with_id("nav_additional"))
109                                .add_item(flex::Item::region().with_id("breadcrumb"))
110                                .add_item(flex::Item::region().with_id("content"))
111                                .add_item(flex::Item::region().with_id("sidebar_first"))
112                                .add_item(flex::Item::region().with_id("sidebar_second"))
113                                .add_item(flex::Item::region().with_id("footer")),
114                        }.render(page.context()))
115                    }
116                })
117            }
118    */
119
120    /*
121    }
122
123    fn before_prepare_icon(i: &mut Icon, _cx: &mut Context) {
124        i.set_classes(
125            ClassesOp::Replace(i.font_size().to_string()),
126            with_font(i.font_size()),
127        );
128    }
129
130    #[rustfmt::skip]
131    fn before_prepare_button(b: &mut Button, _cx: &mut Context) {
132        b.set_classes(ClassesOp::Replace("button__tap".to_owned()), "btn");
133        b.set_classes(
134            ClassesOp::Replace(b.style().to_string()),
135            match b.style() {
136                StyleBase::Default => "btn-primary",
137                StyleBase::Info    => "btn-info",
138                StyleBase::Success => "btn-success",
139                StyleBase::Warning => "btn-warning",
140                StyleBase::Danger  => "btn-danger",
141                StyleBase::Light   => "btn-light",
142                StyleBase::Dark    => "btn-dark",
143                StyleBase::Link    => "btn-link",
144            },
145        );
146        b.set_classes(
147            ClassesOp::Replace(b.font_size().to_string()),
148            with_font(b.font_size()),
149        );
150    }
151
152    #[rustfmt::skip]
153    fn before_prepare_heading(h: &mut Heading, _cx: &mut Context) {
154        h.set_classes(
155            ClassesOp::Replace(h.size().to_string()),
156            match h.size() {
157                HeadingSize::ExtraLarge => "display-1",
158                HeadingSize::XxLarge    => "display-2",
159                HeadingSize::XLarge     => "display-3",
160                HeadingSize::Large      => "display-4",
161                HeadingSize::Medium     => "display-5",
162                _ => "",
163            },
164        );
165    }
166
167    fn before_prepare_paragraph(p: &mut Paragraph, _cx: &mut Context) {
168        p.set_classes(
169            ClassesOp::Replace(p.font_size().to_string()),
170            with_font(p.font_size()),
171        );
172    }
173
174    fn render_error404(_: &Error404, cx: &mut Context) -> Option<Markup> {
175        Some(html! {
176            div class="jumbotron" {
177                div class="media" {
178                    img
179                        src="/bootsier/images/caution.png"
180                        class="mr-4"
181                        style="width: 20%; max-width: 188px"
182                        alt="Caution!";
183                    div class="media-body" {
184                        h1 class="display-4" { ("RESOURCE NOT FOUND") }
185                        p class="lead" {
186                            (L10n::t("e404-description", &LOCALES_BOOTSIER)
187                                .escaped(cx.langid()))
188                        }
189                        hr class="my-4";
190                        p {
191                            (L10n::t("e404-description", &LOCALES_BOOTSIER)
192                                .escaped(cx.langid()))
193                        }
194                        a
195                            class="btn btn-primary btn-lg"
196                            href="/"
197                            role="button"
198                        {
199                            (L10n::t("back-homepage", &LOCALES_BOOTSIER)
200                                .escaped(cx.langid()))
201                        }
202                    }
203                }
204            }
205        })
206    */
207}
208
209/*
210#[rustfmt::skip]
211fn with_font(font_size: &FontSize) -> String {
212    String::from(match font_size {
213        FontSize::ExtraLarge => "fs-1",
214        FontSize::XxLarge    => "fs-2",
215        FontSize::XLarge     => "fs-3",
216        FontSize::Large      => "fs-4",
217        FontSize::Medium     => "fs-5",
218        _ => "",
219    })
220}
221*/