1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
use pagetop::prelude::*;

static_locales!(LOCALES_HOMEDEMO);

static_files!(homedemo);

#[derive(AssignHandle)]
pub struct HomeDemo;

impl PackageTrait for HomeDemo {
    fn name(&self) -> L10n {
        L10n::t("package_name", &LOCALES_HOMEDEMO)
    }

    fn description(&self) -> L10n {
        L10n::t("package_description", &LOCALES_HOMEDEMO)
    }

    fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
        service_for_static_files!(scfg, homedemo => "/homedemo");
        scfg.route("/", service::web::get().to(demo));
    }
}

async fn demo(request: service::HttpRequest) -> ResultPage<Markup, ErrorPage> {
    Page::new(request)
        .with_title(L10n::t("page_title", &LOCALES_HOMEDEMO))
        .with_context(ContextOp::AddStyleSheet(StyleSheet::at(
            "/homedemo/css/styles.css",
        )))
        .with_body_classes(ClassesOp::Add, "default-homepage")
        .with_component_in("content", hello_world())
        .with_component_in("content", welcome())
        .with_component_in("content", about_pagetop())
        .with_component_in("content", promo_pagetop())
        .with_component_in("content", reporting_issues())
        .render()
}

fn hello_world() -> Wrapper {
    Wrapper::header().with_id("hello-world").add_component(
        flex::Container::new()
            .with_direction(flex::Direction::Column(BreakPoint::MD))
            .add_item(
                flex::Item::new()
                    .with_inner_classes(ClassesOp::Add, "hello-col-text")
                    .with_size(flex::ItemSize::Percent40)
                    .add_component(
                        Heading::h1(L10n::t("page_title", &LOCALES_HOMEDEMO))
                            .with_size(HeadingSize::Medium),
                    )
                    .add_component(
                        Paragraph::translated(L10n::t("hello_intro", &LOCALES_HOMEDEMO).with_arg(
                            "app",
                            format!(
                                "<span class=\"app-name\">{}</span>",
                                &config::SETTINGS.app.name,
                            ),
                        ))
                        .with_font_size(FontSize::Medium),
                    )
                    .add_component(Paragraph::translated(
                        L10n::t("hello_powered", &LOCALES_HOMEDEMO).with_arg(
                            "pagetop",
                            format!(
                                "<a href=\"{}\" target=\"_blank\">{}</a>",
                                "https://pagetop.cillero.es", "PageTop",
                            ),
                        ),
                    ))
                    .add_component(
                        Button::anchor(
                            "https://github.com/manuelcillero/pagetop",
                            L10n::t("hello_code", &LOCALES_HOMEDEMO),
                        )
                        .with_target(ButtonTarget::Blank)
                        .with_left_icon(Some(Icon::with("git")))
                        .with_classes(ClassesOp::Add, "code-link")
                        .with_font_size(FontSize::Medium),
                    )
                    .add_component(
                        Button::anchor("#welcome", L10n::t("hello_welcome", &LOCALES_HOMEDEMO))
                            .with_style(ButtonStyle::Link)
                            .with_left_icon(Some(Icon::with("arrow-down-circle-fill")))
                            .with_classes(ClassesOp::Add, "welcome-link")
                            .with_font_size(FontSize::Medium),
                    ),
            )
            .add_item(
                flex::Item::new()
                    .with_inner_classes(ClassesOp::Add, "hello-col-image")
                    .with_size(flex::ItemSize::Percent60)
                    .add_component(Image::with("/homedemo/images/header.svg")),
            ),
    )
}

fn welcome() -> Wrapper {
    Wrapper::section()
        .with_id("welcome")
        .with_classes(ClassesOp::Add, "welcome-col-text")
        .add_component(Heading::h2(L10n::t("welcome_page", &LOCALES_HOMEDEMO)))
        .add_component(
            Heading::h3(L10n::t("welcome_subtitle", &LOCALES_HOMEDEMO).with_arg(
                "app",
                format!(
                    "<span class=\"app-name\">{}</span>",
                    &config::SETTINGS.app.name
                ),
            ))
            .with_size(HeadingSize::Subtitle),
        )
        .add_component(
            Paragraph::translated(L10n::t("welcome_text1", &LOCALES_HOMEDEMO))
                .with_font_size(FontSize::Medium),
        )
        .add_component(Paragraph::translated(L10n::t(
            "welcome_text2",
            &LOCALES_HOMEDEMO,
        )))
}

fn about_pagetop() -> Wrapper {
    Wrapper::new().with_id("pagetop").add_component(
        flex::Container::new()
            .with_direction(flex::Direction::Column(BreakPoint::SM))
            .add_item(
                flex::Item::new()
                    .with_inner_classes(ClassesOp::Add, "pagetop-col-image")
                    .with_size(flex::ItemSize::Percent40)
                    .add_component(Image::with("/homedemo/images/about.svg")),
            )
            .add_item(
                flex::Item::new()
                    .with_inner_classes(ClassesOp::Add, "pagetop-col-text")
                    .add_component(Heading::h2(L10n::t("pagetop_title", &LOCALES_HOMEDEMO)))
                    .add_component(
                        Paragraph::translated(L10n::t("pagetop_text1", &LOCALES_HOMEDEMO))
                            .with_font_size(FontSize::Medium),
                    )
                    .add_component(Paragraph::translated(L10n::t(
                        "pagetop_text2",
                        &LOCALES_HOMEDEMO,
                    )))
                    .add_component(Paragraph::translated(
                        L10n::t("pagetop_text3", &LOCALES_HOMEDEMO)
                            .with_arg("href", "https://docs.rs/pagetop/latest/pagetop"),
                    )),
            ),
    )
}

fn promo_pagetop() -> Wrapper {
    Wrapper::new().with_id("promo").add_component(
        flex::Container::new()
            .with_direction(flex::Direction::Column(BreakPoint::MD))
            .add_item(
                flex::Item::new()
                    .with_inner_classes(ClassesOp::Add, "promo-col-text")
                    .with_size(flex::ItemSize::Percent60)
                    .add_component(Heading::h2(L10n::t(
                        "pagetop_promo_title",
                        &LOCALES_HOMEDEMO,
                    )))
                    .add_component(
                        Paragraph::translated(
                            L10n::t("pagetop_promo_text1", &LOCALES_HOMEDEMO).with_arg(
                                "pagetop",
                                format!(
                                    "<a href=\"{}\" target=\"_blank\">{}</a>",
                                    "https://crates.io/crates/pagetop", "PageTop",
                                ),
                            ),
                        )
                        .with_font_size(FontSize::Medium),
                    ),
            )
            .add_item(
                flex::Item::new()
                    .with_inner_classes(ClassesOp::Add, "promo-col-image")
                    .with_size(flex::ItemSize::Percent40)
                    .add_component(Image::with("/homedemo/images/pagetop.png")),
            ),
    )
}

fn reporting_issues() -> Wrapper {
    Wrapper::new().with_id("reporting").add_component(
        flex::Container::new()
            .with_direction(flex::Direction::Column(BreakPoint::MD))
            .add_item(
                flex::Item::new()
                    .with_inner_classes(ClassesOp::Add, "reporting-col-image")
                    .add_component(Image::with("/homedemo/images/support.jpg")),
            )
            .add_item(
                flex::Item::new()
                    .with_inner_classes(ClassesOp::Add, "reporting-col-text")
                    .with_size(flex::ItemSize::Percent50)
                    .add_component(Heading::h2(L10n::t(
                        "report_problems_title",
                        &LOCALES_HOMEDEMO,
                    )))
                    .add_component(
                        Paragraph::translated(L10n::t("report_problems_text1", &LOCALES_HOMEDEMO))
                            .with_font_size(FontSize::Medium),
                    )
                    .add_component(Paragraph::translated(L10n::t(
                        "report_problems_text2",
                        &LOCALES_HOMEDEMO,
                    ))),
            ),
    )
}