Actualiza la estructura de los recursos estáticos

Se prepara PageTop para permitir en el futuro compilar los fuentes
incluyendo los recursos estáticos dentro del ejecutable (tal y como está
ahora), o usando una carpeta externa "static".
This commit is contained in:
Manuel Cillero 2022-02-22 20:45:18 +01:00
parent 7f8b94eafe
commit eddb397bc7
35 changed files with 48 additions and 125 deletions

View file

@ -1,9 +1,9 @@
# FIGfonts
PageTop utiliza el paquete [figlet-rs](https://crates.io/crates/figlet-rs) de
*yuanbohan* para mostrar al inicio un rótulo con el nombre de la aplicación
usando [FIGlet](http://www.figlet.org/). Las fuentes incluidas en `resources`
son:
*yuanbohan*, que muestra al inicio de la ejecución un rótulo con el nombre de
la aplicación usando caracteres [FIGlet](http://www.figlet.org/). Las fuentes
incluidas en `resources` son:
* [slant.flf](http://www.figlet.org/fontdb_example.cgi?font=slant.flf)
por *Glenn Chappell*.

View file

@ -4,28 +4,30 @@ use std::env;
use std::path::Path;
fn main() {
resource_dir("./resources/assets")
resource_dir("./static/theme")
.with_generated_filename(
Path::new(env::var("OUT_DIR").unwrap().as_str())
.join("assets.rs")
.join("theme.rs")
)
.with_generated_fn("assets")
.build()
.unwrap();
resource_dir("./src/base/theme/aliner/assets")
resource_dir("./static/aliner")
.with_generated_filename(
Path::new(env::var("OUT_DIR").unwrap().as_str())
.join("aliner.rs")
)
.with_generated_fn("assets")
.build()
.unwrap();
resource_dir("./src/base/theme/bootsier/assets")
resource_dir("./static/bootsier")
.with_generated_filename(
Path::new(env::var("OUT_DIR").unwrap().as_str())
.join("bootsier.rs")
)
.with_generated_fn("assets")
.build()
.unwrap();
}

View file

@ -5,14 +5,14 @@ include!(concat!(env!("OUT_DIR"), "/aliner.rs"));
pub struct AlinerTheme;
impl Theme for AlinerTheme {
fn name(&self) -> &str {
"Aliner"
fn name(&self) -> String {
"Aliner".to_string()
}
fn configure_theme(&self, cfg: &mut server::web::ServiceConfig) {
cfg.service(actix_web_static_files::ResourceFiles::new(
"/aliner",
generate()
assets()
));
}

View file

@ -1,70 +0,0 @@
@font-face {
font-family: 'Nunito';
font-style: normal;
font-weight: 400;
src: url(/pagetop/fonts/nunito/cyrillic_ext_400.woff2) format('woff2');
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
@font-face {
font-family: 'Nunito';
font-style: normal;
font-weight: 400;
src: url(/pagetop/fonts/nunito/cyrillic_400.woff2) format('woff2');
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
font-family: 'Nunito';
font-style: normal;
font-weight: 400;
src: url(/pagetop/fonts/nunito/vietnamese_400.woff2) format('woff2');
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+1EA0-1EF9, U+20AB;
}
@font-face {
font-family: 'Nunito';
font-style: normal;
font-weight: 400;
src: url(/pagetop/fonts/nunito/latin_ext_400.woff2) format('woff2');
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
font-family: 'Nunito';
font-style: normal;
font-weight: 400;
src: url(/pagetop/fonts/nunito/latin_400.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
font-family: 'Nunito';
font-style: normal;
font-weight: 700;
src: url(/pagetop/fonts/nunito/cyrillic_ext_700.woff2) format('woff2');
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
@font-face {
font-family: 'Nunito';
font-style: normal;
font-weight: 700;
src: url(/pagetop/fonts/nunito/cyrillic_700.woff2) format('woff2');
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
font-family: 'Nunito';
font-style: normal;
font-weight: 700;
src: url(/pagetop/fonts/nunito/vietnamese_700.woff2) format('woff2');
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+1EA0-1EF9, U+20AB;
}
@font-face {
font-family: 'Nunito';
font-style: normal;
font-weight: 700;
src: url(/pagetop/fonts/nunito/latin_ext_700.woff2) format('woff2');
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
font-family: 'Nunito';
font-style: normal;
font-weight: 700;
src: url(/pagetop/fonts/nunito/latin_700.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -7,14 +7,14 @@ localize!("en-US", "src/base/theme/bootsier/locales");
pub struct BootsierTheme;
impl Theme for BootsierTheme {
fn name(&self) -> &str {
"Bootsier"
fn name(&self) -> String {
"Bootsier".to_string()
}
fn configure_theme(&self, cfg: &mut server::web::ServiceConfig) {
cfg.service(actix_web_static_files::ResourceFiles::new(
"/bootsier",
generate()
assets()
));
}
@ -26,15 +26,15 @@ impl Theme for BootsierTheme {
)
.add_stylesheet(
StyleSheet::source(
"/bootsier/css/bootstrap.min.css"
"/bootsier/css/bootstrap.min.css?v=5.1.3"
)
.with_weight(-99)
)
.add_javascript(
JavaScript::source(
"/bootsier/js/bootstrap.bundle.min.js"
"/bootsier/js/bootstrap.bundle.min.js?v=5.1.3"
)
.with_weight(-98)
.with_weight(-99)
)
.add_jquery();
}

View file

@ -3,7 +3,7 @@ use crate::prelude::*;
pub struct MinimalTheme;
impl Theme for MinimalTheme {
fn name(&self) -> &str {
"Minimal"
fn name(&self) -> String {
"Minimal".to_string()
}
}

View file

@ -6,7 +6,10 @@ use serde::Deserialize;
use std::env;
/// Carga los ajustes globales "clave = valor" al arrancar la aplicación.
/// Al arrancar la aplicación, carga los valores originales "clave = valor" de
/// los archivos de configuración. Con [`config_map`] se asignarán los ajustes
/// globales ([`SETTINGS`]); y se podrán asignar los ajustes específicos de la
/// aplicación, o también de un tema, módulo o componente.
pub static CONFIG: Lazy<Config> = Lazy::new(|| {
// Establece el modo de ejecución según el valor de la variable de entorno
// PAGETOP_RUN_MODE. Asume "default" por defecto.
@ -15,8 +18,7 @@ pub static CONFIG: Lazy<Config> = Lazy::new(|| {
// Inicializa los ajustes.
let mut settings = Config::default();
// Lee los ajustes combinando los archivos de configuración disponibles y
// asigna el modo de ejecución.
// Combina los archivos de configuración y asigna el modo de ejecución.
settings
.merge(
File::with_name(
@ -36,23 +38,13 @@ pub static CONFIG: Lazy<Config> = Lazy::new(|| {
});
#[macro_export]
/// Usar esta macro para obtener el valor de cualquier ajuste global, donde
/// clave y valor son cadenas de caracteres. Devuelve la cadena vacía si no
/// encuentra un ajuste para la clave.
macro_rules! config_get {
( $key:expr ) => {
$crate::config::CONFIG.get_str($key).unwrap_or("".to_string())
};
}
#[macro_export]
/// Carga los ajustes específicos de tu módulo o aplicación en una estructura
/// similar a [`SETTINGS`] con tipos de variables seguros. Genera un *panic!*
/// en caso de asignaciones no válidas.
/// Asigna los ajustes específicos de la aplicación, o de un tema, módulo o
/// componente, en una estructura similar a [`SETTINGS`] con tipos de variables
/// seguros. Produce un *panic!* en caso de asignaciones no válidas.
macro_rules! config_map {
( $COMMENT:expr, $CONF:ident, $TYPE:tt $(, $key:expr => $value:expr)* ) => {
( $COMM:expr, $CONF:ident, $TYPE:tt $(, $key:expr => $value:expr)* ) => {
$crate::doc_comment! {
concat!($COMMENT),
concat!($COMM),
pub static $CONF: $crate::Lazy<$TYPE> = $crate::Lazy::new(|| {
let mut settings = $crate::config::CONFIG.clone();
@ -101,7 +93,7 @@ pub struct Settings {
config_map!(r#"
Ajustes globales y valores predeterminados para las secciones *\[app\]*,
*\[log\]* y *\[webserver\]* específicas de PageTop.
*\[log\]* y *\[webserver\]* de PageTop.
"#,
SETTINGS, Settings,

View file

@ -1,6 +1,13 @@
use crate::core::{server, state};
include!(concat!(env!("OUT_DIR"), "/theme.rs"));
pub fn themes(cfg: &mut server::web::ServiceConfig) {
cfg.service(actix_web_static_files::ResourceFiles::new(
"/theme",
assets()
));
for t in state::THEMES.read().unwrap().iter() {
t.configure_theme(cfg);
}

View file

@ -228,7 +228,7 @@ impl Assets {
if !self.with_jquery {
self.add_javascript(
JavaScript::source(
"/assets/js/jquery.min.js?ver=3.6.0"
"/theme/js/jquery.min.js?v=3.6.0"
)
.with_weight(i8::MIN)
.with_mode(JSMode::Normal)

View file

@ -57,16 +57,16 @@ pub fn run(bootstrap: Option<fn()>) -> Result<Server, std::io::Error> {
if SETTINGS.app.startup_banner.to_lowercase() != "off" {
let figfont = figlet_rs::FIGfont::from_content(
match SETTINGS.app.startup_banner.to_lowercase().as_str() {
"slant" => include_str!("../../../resources/slant.flf"),
"small" => include_str!("../../../resources/small.flf"),
"speed" => include_str!("../../../resources/speed.flf"),
"starwars" => include_str!("../../../resources/starwars.flf"),
"slant" => include_str!("figfonts/slant.flf"),
"small" => include_str!("figfonts/small.flf"),
"speed" => include_str!("figfonts/speed.flf"),
"starwars" => include_str!("figfonts/starwars.flf"),
_ => {
trace::warn!(
"FIGfont \"{}\" not found for banner. Using \"{}\"",
SETTINGS.app.startup_banner, "Small"
);
include_str!("../../../resources/small.flf")
include_str!("figfonts/small.flf")
}
}
).unwrap();

View file

@ -5,10 +5,10 @@ use crate::base::component::Chunck;
/// Los temas deben implementar este "trait".
pub trait Theme: Send + Sync {
fn name(&self) -> &str;
fn name(&self) -> String;
fn description(&self) -> &str {
""
fn description(&self) -> String {
"".to_string()
}
#[allow(unused_variables)]
@ -41,7 +41,7 @@ pub trait Theme: Send + Sync {
fn render_page_body(&self, page: &mut Page) -> Markup {
html! {
body id="body" class=(page.body_classes()) {
body class=(page.body_classes()) {
@match page.template() {
"admin" => {
@for region in &["top-menu", "side-menu", "content"] {

View file

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Before After
Before After