♻️ Major code restructuring

This commit is contained in:
Manuel Cillero 2024-02-09 14:05:38 +01:00
parent a96e203bb3
commit fa66d628a0
221 changed files with 228 additions and 315 deletions

View file

@ -0,0 +1,21 @@
[package]
name = "pagetop-bulmix"
version = "0.0.12"
edition = "2021"
authors = [
"Manuel Cillero <manuel@cillero.es>"
]
description = """\
Theme for PageTop that uses the Bulma framework for page layout and components display.\
"""
homepage = "https://pagetop.cillero.es"
repository = "https://github.com/manuelcillero/pagetop"
license = "MIT OR Apache-2.0"
[dependencies]
pagetop = { version = "0.0", path = "../../" }
static-files = "0.2.3"
[build-dependencies]
pagetop-build = { version = "0.0", path = "../../helpers/pagetop-build" }

View file

@ -0,0 +1,27 @@
Tema para **PageTop** que utiliza el *framework* [Bulma](https://bulma.io/) para la composición de
páginas y visualización de componentes.
[PageTop](https://github.com/manuelcillero/pagetop/tree/main/pagetop), es un entorno de desarrollo
basado en algunos de los *crates* más estables y populares del ecosistema Rust para proporcionar
APIs, patrones de desarrollo y buenas prácticas para la creación de soluciones web SSR (*Server-Side
Rendering*).
# 🚧 Advertencia
**PageTop** sólo libera actualmente versiones de desarrollo. La API no es estable y los cambios son
constantes. No puede considerarse preparado hasta que se libere la versión **0.1.0**.
# 📜 Licencia
Este proyecto tiene licencia, de hecho tiene dos, puedes aplicar cualquiera de las siguientes a tu
elección:
* Licencia Apache versión 2.0
([LICENSE-APACHE](https://github.com/manuelcillero/pagetop/blob/main/LICENSE-APACHE) o
[http://www.apache.org/licenses/LICENSE-2.0]).
* Licencia MIT
([LICENSE-MIT](https://github.com/manuelcillero/pagetop/blob/main/LICENSE-MIT) o
[http://opensource.org/licenses/MIT]).

View file

@ -0,0 +1,7 @@
use pagetop_build::StaticFilesBundle;
fn main() -> std::io::Result<()> {
StaticFilesBundle::from_dir("./static")
.with_name("bulmix")
.build()
}

View file

@ -0,0 +1,159 @@
use pagetop::prelude::*;
static_files!(bulmix);
#[derive(AssignHandle)]
pub struct Bulmix;
impl PackageTrait for Bulmix {
fn theme(&self) -> Option<ThemeRef> {
Some(&Bulmix)
}
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
service_for_static_files!(scfg, bulmix => "/bulmix");
}
}
impl ThemeTrait for Bulmix {
fn after_prepare_body(&self, page: &mut Page) {
page.alter_favicon(Some(Favicon::new().with_icon("/base/favicon.ico")))
.alter_context(ContextOp::AddStyleSheet(
StyleSheet::at("/bulmix/css/bulma.min.css")
.with_version("0.9.4")
.with_weight(-99),
))
.alter_context(ContextOp::AddBaseAssets)
.alter_context(ContextOp::AddStyleSheet(
StyleSheet::at("/bulmix/css/styles.css").with_version("0.0.1"),
));
}
fn before_prepare_component(&self, component: &mut dyn ComponentTrait, _cx: &mut Context) {
match component.handle() {
h if Icon::matches_handle(h) => {
if let Some(i) = component_as_mut::<Icon>(component) {
match i.font_size() {
FontSize::ExtraLarge => {
i.replace_classes(i.font_size().to_string(), "is-size-1");
}
FontSize::XxLarge => {
i.replace_classes(i.font_size().to_string(), "is-size-2");
}
FontSize::XLarge => {
i.replace_classes(i.font_size().to_string(), "is-size-3");
}
FontSize::Large => {
i.replace_classes(i.font_size().to_string(), "is-size-4");
}
FontSize::Medium => {
i.replace_classes(i.font_size().to_string(), "is-size-5");
}
_ => {}
};
}
}
h if Button::matches_handle(h) => {
if let Some(b) = component_as_mut::<Button>(component) {
match b.style() {
ButtonStyle::Default => {
b.replace_classes(b.style().to_string(), "button is-primary");
}
ButtonStyle::Info => {
b.replace_classes(b.style().to_string(), "button is-info");
}
ButtonStyle::Success => {
b.replace_classes(b.style().to_string(), "button is-success");
}
ButtonStyle::Warning => {
b.replace_classes(b.style().to_string(), "button is-warning");
}
ButtonStyle::Danger => {
b.replace_classes(b.style().to_string(), "button is-danger");
}
ButtonStyle::Light => {
b.replace_classes(b.style().to_string(), "button is-light");
}
ButtonStyle::Dark => {
b.replace_classes(b.style().to_string(), "button is-dark");
}
ButtonStyle::Link => {
b.replace_classes(b.style().to_string(), "button is-text");
}
};
match b.font_size() {
FontSize::ExtraLarge => {
b.replace_classes(b.font_size().to_string(), "is-size-1");
}
FontSize::XxLarge => {
b.replace_classes(b.font_size().to_string(), "is-size-2");
}
FontSize::XLarge => {
b.replace_classes(b.font_size().to_string(), "is-size-3");
}
FontSize::Large => {
b.replace_classes(b.font_size().to_string(), "is-size-4");
}
FontSize::Medium => {
b.replace_classes(b.font_size().to_string(), "is-size-5");
}
_ => {}
};
}
}
h if Heading::matches_handle(h) => {
if let Some(h) = component_as_mut::<Heading>(component) {
match h.size() {
HeadingSize::Subtitle => {
h.replace_classes(h.size().to_string(), "subtitle")
}
_ => h.add_classes("title"),
};
}
}
h if Paragraph::matches_handle(h) => {
if let Some(p) = component_as_mut::<Paragraph>(component) {
p.add_classes("block");
match p.font_size() {
FontSize::ExtraLarge => {
p.replace_classes(p.font_size().to_string(), "is-size-1");
}
FontSize::XxLarge => {
p.replace_classes(p.font_size().to_string(), "is-size-2");
}
FontSize::XLarge => {
p.replace_classes(p.font_size().to_string(), "is-size-3");
}
FontSize::Large => {
p.replace_classes(p.font_size().to_string(), "is-size-4");
}
FontSize::Medium => {
p.replace_classes(p.font_size().to_string(), "is-size-5");
}
_ => {}
};
}
}
_ => {}
}
}
fn render_component(
&self,
component: &dyn ComponentTrait,
_cx: &mut Context,
) -> Option<Markup> {
match component.handle() {
h if Icon::matches_handle(h) => {
if let Some(i) = component_as_ref::<Icon>(component) {
return match i.icon_name().get() {
None => None,
_ => Some(html! { span class="icon" { i class=[i.classes().get()] {} } }),
};
}
None
}
_ => None,
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,11 @@
html {
scroll-behavior: smooth;
}
/* OVERRIDE COMPONENT STYLES */
/* Button component */
.is-link {
text-decoration: none;
}