Compare commits
No commits in common. "d495c05b965c7090a1e7a9360b6e6684aa47173a" and "2202a2350cc2a240422562e8bb37b75f6d864f1e" have entirely different histories.
d495c05b96
...
2202a2350c
4 changed files with 22 additions and 116 deletions
|
|
@ -1,85 +1,20 @@
|
||||||
//! Script de compilacion de activos estaticos.
|
use pagetop_build::StaticFilesBundle;
|
||||||
//!
|
|
||||||
//! Genera el directorio `static/` a partir de `assets/` y embebe su contenido en el binario:
|
|
||||||
//!
|
|
||||||
//! - `static/css/` - CSS compilado a partir de los archivos SCSS de `assets/`.
|
|
||||||
//! - `static/js/` - JS copiado desde `assets/`, renombrando AdminLTE a `bootsier.min.js`.
|
|
||||||
//! - `static/fonts/` - Fuentes copiadas desde `assets/`.
|
|
||||||
//!
|
|
||||||
//! Los archivos `.map` se copian a `static/js/` para uso en desarrollo pero no se incluyen en el
|
|
||||||
//! binario embebido.
|
|
||||||
|
|
||||||
use pagetop_build::{StaticFilesBundle, compile_scss, copy_file, copy_file_replacing, minify_js};
|
|
||||||
|
|
||||||
|
use std::env;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
// Regenera `static/` desde cero sólo si hay cambios en `assets/`.
|
StaticFilesBundle::from_scss("./static/scss/bootsier.scss", "bootstrap.min.css")
|
||||||
println!("cargo:rerun-if-changed=assets");
|
.with_name("bootsier_bs")
|
||||||
let _ = std::fs::remove_dir_all("static");
|
|
||||||
|
|
||||||
// CSS: Bootstrap 5.3.8 + AdminLTE 4.0.0 + Bootstrap Icons 1.13.1.
|
|
||||||
compile_scss("assets/bootsier.scss", "static/css/bootsier.min.css")?;
|
|
||||||
|
|
||||||
// JS: Bootstrap bundle.
|
|
||||||
copy_file(
|
|
||||||
"assets/bootstrap-5.3.8/js/bootstrap.bundle.min.js",
|
|
||||||
"static/js/bootsier.bundle.min.js",
|
|
||||||
)?;
|
|
||||||
copy_file(
|
|
||||||
"assets/bootstrap-5.3.8/js/bootstrap.bundle.min.js.map",
|
|
||||||
"static/js/bootsier.bundle.min.js.map",
|
|
||||||
)?;
|
|
||||||
// JS: AdminLTE renombrado a bootsier.extended.min.js.
|
|
||||||
copy_file_replacing(
|
|
||||||
"assets/adminlte-4.0.0/js/adminlte.min.js",
|
|
||||||
"static/js/bootsier.extended.min.js",
|
|
||||||
&[("adminlte.min.js.map", "bootsier.extended.min.js.map")],
|
|
||||||
)?;
|
|
||||||
copy_file(
|
|
||||||
"assets/adminlte-4.0.0/js/adminlte.min.js.map",
|
|
||||||
"static/js/bootsier.extended.min.js.map",
|
|
||||||
)?;
|
|
||||||
// JS: shell de Bootsier.
|
|
||||||
minify_js(
|
|
||||||
"assets/bootsier.shell.js",
|
|
||||||
"static/js/bootsier.shell.min.js",
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Fuentes: Bootstrap Icons.
|
|
||||||
copy_file(
|
|
||||||
"assets/bootstrap-icons-1.13.1/fonts/bootstrap-icons.woff2",
|
|
||||||
"static/fonts/bootsier.icons.woff2",
|
|
||||||
)?;
|
|
||||||
copy_file(
|
|
||||||
"assets/bootstrap-icons-1.13.1/fonts/bootstrap-icons.woff",
|
|
||||||
"static/fonts/bootsier.icons.woff",
|
|
||||||
)?;
|
|
||||||
// Fuentes: Source Sans 3 (SIL OFL 1.1).
|
|
||||||
copy_file(
|
|
||||||
"assets/adminlte-4.0.0/fonts/SourceSans3VF-Upright.otf.woff2",
|
|
||||||
"static/fonts/bootsier.font.woff2",
|
|
||||||
)?;
|
|
||||||
copy_file(
|
|
||||||
"assets/adminlte-4.0.0/fonts/SourceSans3VF-Italic.otf.woff2",
|
|
||||||
"static/fonts/bootsier.font.italic.woff2",
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Preparación de los paquetes para embeber en el binario.
|
|
||||||
StaticFilesBundle::from_dir("./static/css", None)
|
|
||||||
.with_name("bootsier_css")
|
|
||||||
.build()?;
|
.build()?;
|
||||||
|
StaticFilesBundle::from_dir("./static/js", Some(bootstrap_js_files))
|
||||||
StaticFilesBundle::from_dir("./static/js", Some(only_js_files))
|
|
||||||
.with_name("bootsier_js")
|
.with_name("bootsier_js")
|
||||||
.build()?;
|
|
||||||
|
|
||||||
StaticFilesBundle::from_dir("./static/fonts", None)
|
|
||||||
.with_name("bootsier_fonts")
|
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Los archivos .map no se embeben en el binario; solo se sirven desde disco en desarrollo.
|
fn bootstrap_js_files(path: &Path) -> bool {
|
||||||
fn only_js_files(path: &Path) -> bool {
|
let bootstrap_js = "bootstrap.bundle.min.js";
|
||||||
path.extension().map_or(false, |ext| ext == "js")
|
// No filtra durante el desarrollo, solo en la compilación "release".
|
||||||
|
env::var("PROFILE").unwrap_or_else(|_| "release".to_string()) != "release"
|
||||||
|
|| path.file_name().is_some_and(|f| f == bootstrap_js)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
//!
|
//!
|
||||||
//! Uso:
|
//! Uso:
|
||||||
//!
|
//!
|
||||||
//! ```rust,no_run
|
//! ```rust
|
||||||
//! # use pagetop::prelude::*;
|
//! # use pagetop::prelude::*;
|
||||||
//! use pagetop_bootsier::config;
|
//! use pagetop_bootsier::config;
|
||||||
//!
|
//!
|
||||||
|
|
@ -26,15 +26,12 @@ use serde::Deserialize;
|
||||||
include_config!(SETTINGS: Settings => [
|
include_config!(SETTINGS: Settings => [
|
||||||
// [bootsier]
|
// [bootsier]
|
||||||
"bootsier.max_width" => "1440px",
|
"bootsier.max_width" => "1440px",
|
||||||
// [dev]
|
|
||||||
"dev.bootsier_static_dir" => "",
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/// Ajustes para la sección [`Bootsier`] de [`SETTINGS`].
|
/// Ajustes para la sección [`Bootsier`] de [`SETTINGS`].
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
pub bootsier: Bootsier,
|
pub bootsier: Bootsier,
|
||||||
pub dev: Dev,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sección **`[bootsier]`** de la configuración. Forma parte de [`Settings`].
|
/// Sección **`[bootsier]`** de la configuración. Forma parte de [`Settings`].
|
||||||
|
|
@ -43,16 +40,3 @@ pub struct Bootsier {
|
||||||
/// Ancho máximo predeterminado para la página, por ejemplo "100%" o "90rem".
|
/// Ancho máximo predeterminado para la página, por ejemplo "100%" o "90rem".
|
||||||
pub max_width: UnitValue,
|
pub max_width: UnitValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sección **`[dev]`** de la configuración. Forma parte de [`Settings`].
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct Dev {
|
|
||||||
/// Directorio raíz de `static/` para servir los archivos estáticos propios de Bootsier.
|
|
||||||
///
|
|
||||||
/// Si se indica una ruta válida, absoluta o relativa al directorio del proyecto o del binario
|
|
||||||
/// en ejecución, los archivos estáticos se servirán desde disco. Útil para poder modificar los
|
|
||||||
/// archivos estáticos mientras la aplicación está en ejecución, sin necesidad de recompilar.
|
|
||||||
///
|
|
||||||
/// Si la cadena está vacía, se ignora este ajuste.
|
|
||||||
pub bootsier_static_dir: String,
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -134,17 +134,8 @@ impl Extension for Bootsier {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure_router(&self, router: Router) -> Router {
|
fn configure_router(&self, router: Router) -> Router {
|
||||||
let base = &config::SETTINGS.dev.bootsier_static_dir;
|
serve_static_files!(router, [bootsier_bs] => "/bootsier/bs");
|
||||||
let subdir = |s: &str| {
|
serve_static_files!(router, [bootsier_js] => "/bootsier/js");
|
||||||
if base.is_empty() {
|
|
||||||
String::new()
|
|
||||||
} else {
|
|
||||||
format!("{base}/{s}")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
serve_static_files!(router, [subdir("css"), bootsier_css] => "/bootsier/css");
|
|
||||||
serve_static_files!(router, [subdir("js"), bootsier_js] => "/bootsier/js");
|
|
||||||
serve_static_files!(router, [subdir("fonts"), bootsier_fonts] => "/bootsier/fonts");
|
|
||||||
router
|
router
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -157,19 +148,14 @@ impl Theme for Bootsier {
|
||||||
|
|
||||||
fn before_render_page_body(&self, page: &mut Page) {
|
fn before_render_page_body(&self, page: &mut Page) {
|
||||||
page.alter_assets(AssetsOp::AddStyleSheet(
|
page.alter_assets(AssetsOp::AddStyleSheet(
|
||||||
StyleSheet::from("/bootsier/css/bootsier.min.css")
|
StyleSheet::from("/bootsier/bs/bootstrap.min.css")
|
||||||
.with_version(ADMINLTE_VERSION)
|
|
||||||
.with_weight(-90),
|
|
||||||
))
|
|
||||||
.alter_assets(AssetsOp::AddJavaScript(
|
|
||||||
JavaScript::defer("/bootsier/js/bootsier.bundle.min.js")
|
|
||||||
.with_version(BOOTSTRAP_VERSION)
|
.with_version(BOOTSTRAP_VERSION)
|
||||||
.with_weight(-90),
|
.with_weight(-90),
|
||||||
))
|
))
|
||||||
.alter_assets(AssetsOp::AddJavaScript(
|
.alter_assets(AssetsOp::AddJavaScript(
|
||||||
JavaScript::defer("/bootsier/js/bootsier.extended.min.js")
|
JavaScript::defer("/bootsier/js/bootstrap.bundle.min.js")
|
||||||
.with_version(ADMINLTE_VERSION)
|
.with_version(BOOTSTRAP_VERSION)
|
||||||
.with_weight(-89),
|
.with_weight(-90),
|
||||||
))
|
))
|
||||||
.alter_child_in(
|
.alter_child_in(
|
||||||
&DefaultRegion::Footer,
|
&DefaultRegion::Footer,
|
||||||
|
|
|
||||||
|
|
@ -90,11 +90,12 @@ pub struct App {
|
||||||
/// Sección **`[dev]`** de la configuración. Forma parte de [`Settings`].
|
/// Sección **`[dev]`** de la configuración. Forma parte de [`Settings`].
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct Dev {
|
pub struct Dev {
|
||||||
/// Directorio raíz de `static/` para servir los archivos estáticos propios de PageTop.
|
/// Directorio desde el que servir los archivos estáticos de PageTop.
|
||||||
///
|
///
|
||||||
/// Si se indica una ruta válida, absoluta o relativa al directorio del proyecto o del binario
|
/// Por defecto, los archivos se integran en el binario de la aplicación. Si aquí se indica una
|
||||||
/// en ejecución, los archivos estáticos se servirán desde disco. Útil para poder modificar los
|
/// ruta válida, ya sea absoluta o relativa al directorio del proyecto o del binario en
|
||||||
/// archivos estáticos mientras la aplicación está en ejecución, sin necesidad de recompilar.
|
/// ejecución, se servirán desde el sistema de ficheros en su lugar. Esto es especialmente útil
|
||||||
|
/// en desarrollo, ya que evita recompilar el proyecto por cambios en estos archivos.
|
||||||
///
|
///
|
||||||
/// Si la cadena está vacía, se ignora este ajuste.
|
/// Si la cadena está vacía, se ignora este ajuste.
|
||||||
pub pagetop_static_dir: String,
|
pub pagetop_static_dir: String,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue