Añade carga de archivos estáticos desde directorio
Con el ajuste de configuración "dev.static_files" se puede elegir entre integrar los archivos estáticos en el binario ejecutable (por defecto) o servirlos desde su propio directorio. Esto facilita el desarrollo al no tener que compilar cada vez que se modifican estos archivos.
This commit is contained in:
parent
3ee5859eae
commit
e3f592b3b0
18 changed files with 93 additions and 71 deletions
|
|
@ -1,12 +1,12 @@
|
|||
[app]
|
||||
name = "Drust"
|
||||
description = """\
|
||||
A modern Content Management System for sharing the world.\
|
||||
A modern web Content Management System to share your world.\
|
||||
"""
|
||||
language = "es-ES"
|
||||
#theme = "Aliner"
|
||||
#theme = "Minimal"
|
||||
theme = "Bootsier"
|
||||
language = "es-ES"
|
||||
|
||||
[database]
|
||||
db_type = "mysql"
|
||||
|
|
@ -16,3 +16,6 @@ db_pass = "DrU__#3T"
|
|||
|
||||
[log]
|
||||
tracing = "Info,sqlx::query=Warn"
|
||||
|
||||
[dev]
|
||||
#static_files = "pagetop/static"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ authors = [
|
|||
"Manuel Cillero <manuel@cillero.es>"
|
||||
]
|
||||
description = """\
|
||||
A modern Content Management System for sharing the world.\
|
||||
A modern web Content Management System to share your world.\
|
||||
"""
|
||||
homepage = "https://suitepro.cillero.es/projects/drust"
|
||||
repository = "https://gitlab.com/manuelcillero/drust"
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ authors = [
|
|||
"Manuel Cillero <manuel@cillero.es>"
|
||||
]
|
||||
description = """\
|
||||
Allows content to be submitted to the site and displayed on pages.\
|
||||
...\
|
||||
"""
|
||||
homepage = "https://suitepro.cillero.es/projects/drust"
|
||||
repository = "https://gitlab.com/manuelcillero/drust"
|
||||
homepage = "https://suitepro.cillero.es/projects/pagetop"
|
||||
repository = "https://gitlab.com/manuelcillero/pagetop"
|
||||
|
||||
[dependencies]
|
||||
pagetop = { path = "../pagetop" }
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ authors = [
|
|||
description = """\
|
||||
Allows content to be submitted to the site and displayed on pages.\
|
||||
"""
|
||||
homepage = "https://suitepro.cillero.es/projects/drust"
|
||||
repository = "https://gitlab.com/manuelcillero/drust"
|
||||
homepage = "https://suitepro.cillero.es/projects/pagetop"
|
||||
repository = "https://gitlab.com/manuelcillero/pagetop"
|
||||
|
||||
[dependencies]
|
||||
pagetop = { path = "../pagetop" }
|
||||
|
|
|
|||
|
|
@ -9,14 +9,10 @@ authors = [
|
|||
description = """\
|
||||
Allows content to be submitted to the site and displayed on pages.\
|
||||
"""
|
||||
homepage = "https://suitepro.cillero.es/projects/drust"
|
||||
repository = "https://gitlab.com/manuelcillero/drust"
|
||||
homepage = "https://suitepro.cillero.es/projects/pagetop"
|
||||
repository = "https://gitlab.com/manuelcillero/pagetop"
|
||||
|
||||
[dependencies]
|
||||
pagetop = { path = "../pagetop" }
|
||||
sea-orm = { version = "0.6.0" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
||||
[dependencies.sea-orm]
|
||||
version = "0.6.0"
|
||||
features = ["debug-print", "macros"]
|
||||
default-features = false
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
module_fullname = Usuario
|
||||
module_description = Gestion el registro de usuarios y el sistema de accesos.
|
||||
module_description = Gestiona el registro de usuarios y el sistema de accesos.
|
||||
|
||||
username = Nombre de usuario
|
||||
password = Contraseña
|
||||
|
|
|
|||
|
|
@ -7,10 +7,8 @@ authors = [
|
|||
"Manuel Cillero <manuel@cillero.es>"
|
||||
]
|
||||
description = """\
|
||||
PageTop es un proyecto personal para aprender Rust. Incluye algunos de los \
|
||||
crates más estables y populares para desarrollar soluciones web modulares, \
|
||||
extensibles y configurables. También es un sistema para la gestión de \
|
||||
contenidos web.\
|
||||
PageTop is an opinionated framework for using the most stable and popular \
|
||||
Rust packages to build modular, extensible and configurable web solutions.\
|
||||
"""
|
||||
homepage = "https://suitepro.cillero.es/projects/pagetop"
|
||||
repository = "https://gitlab.com/manuelcillero/pagetop"
|
||||
|
|
@ -44,6 +42,7 @@ unic-langid = "0.9.0"
|
|||
|
||||
actix-web = "3.3.3"
|
||||
actix-web-static-files = "3.0.5"
|
||||
actix-files = "0.4.1"
|
||||
|
||||
maud = { version = "0.23.0", features = ["actix-web"] }
|
||||
sycamore = { version = "0.7.1", features = ["ssr"] }
|
||||
|
|
@ -62,9 +61,6 @@ features = ["debug-print", "migration"]
|
|||
default-features = false
|
||||
optional = true
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
mysql = ["sea-orm", "sea-schema", "sea-orm/sqlx-mysql"]
|
||||
|
|
@ -74,5 +70,8 @@ sqlite = ["sea-orm", "sea-schema", "sea-orm/sqlx-sqlite"]
|
|||
[build-dependencies]
|
||||
actix-web-static-files = "3.0.5"
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
|
||||
|
||||
[lib]
|
||||
name = "pagetop"
|
||||
|
|
|
|||
|
|
@ -8,24 +8,20 @@ edition = "2021"
|
|||
|
||||
[dependencies.pagetop]
|
||||
path = "../pagetop"
|
||||
# Opcional. Por defecto se puede usar PageTop sin base de datos.
|
||||
# PageTop por defecto no requiere base de datos. Hay que habilitarla:
|
||||
features = ["mysql"]
|
||||
# features = ["postgres"]
|
||||
# features = ["sqlite"]
|
||||
# PageTop puede dar soporte a todas las bases de datos.
|
||||
# PageTop puede dar soporte a todas las bases de datos:
|
||||
# features = ["mysql", "postgres", "sqlite"]
|
||||
# Sólo cuando no se usen las características predeterminadas.
|
||||
# En estos casos hay que deshabilitar las características predeterminadas:
|
||||
default-features = false
|
||||
|
||||
[dependencies]
|
||||
# Requerido.
|
||||
actix-web = "3.3.3"
|
||||
# Opcional. Sólo si se usa la macro html!.
|
||||
# Opcional. Sólo si se usa la macro html!:
|
||||
maud = { version = "0.23.0" }
|
||||
# Opcional. Si se requiere serialización de estructuras de datos.
|
||||
# Opcional. Sólo si se usa base de datos:
|
||||
sea-orm = { version = "0.6.0" }
|
||||
# Opcional. Para la serialización de estructuras de datos:
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
||||
[dependencies.sea-orm]
|
||||
version = "0.6.0"
|
||||
features = ["debug-print", "macros"]
|
||||
default-features = false
|
||||
|
|
|
|||
|
|
@ -6,24 +6,11 @@ edition = "2021"
|
|||
# Ver más claves y sus definiciones en
|
||||
# https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies.pagetop]
|
||||
path = "../pagetop"
|
||||
# Opcional. Por defecto se puede usar PageTop sin base de datos.
|
||||
features = ["mysql"]
|
||||
# features = ["postgres"]
|
||||
# features = ["sqlite"]
|
||||
# PageTop puede dar soporte a todas las bases de datos.
|
||||
# features = ["mysql", "postgres", "sqlite"]
|
||||
# Sólo cuando no se usen las características predeterminadas.
|
||||
default-features = false
|
||||
|
||||
[dependencies]
|
||||
# Opcional. Sólo si se usa la macro html!.
|
||||
pagetop = { path = "../pagetop" }
|
||||
# Opcional. Sólo si se usa la macro html!:
|
||||
maud = { version = "0.23.0" }
|
||||
# Opcional. Si se requiere serialización de estructuras de datos.
|
||||
# Opcional. Sólo si se usa base de datos:
|
||||
sea-orm = { version = "0.6.0" }
|
||||
# Opcional. Para la serialización de estructuras de datos:
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
||||
[dependencies.sea-orm]
|
||||
version = "0.6.0"
|
||||
features = ["debug-print", "macros"]
|
||||
default-features = false
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ fn main() {
|
|||
Path::new(env::var("OUT_DIR").unwrap().as_str())
|
||||
.join("theme.rs")
|
||||
)
|
||||
.with_generated_fn("assets")
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
|
|
@ -18,7 +17,6 @@ fn main() {
|
|||
Path::new(env::var("OUT_DIR").unwrap().as_str())
|
||||
.join("aliner.rs")
|
||||
)
|
||||
.with_generated_fn("assets")
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
|
|
@ -27,7 +25,6 @@ fn main() {
|
|||
Path::new(env::var("OUT_DIR").unwrap().as_str())
|
||||
.join("bootsier.rs")
|
||||
)
|
||||
.with_generated_fn("assets")
|
||||
.build()
|
||||
.unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,3 +43,11 @@ max_pool_size = 5
|
|||
# Configuración del servidor web.
|
||||
bind_address = "localhost"
|
||||
bind_port = 8088
|
||||
|
||||
[dev]
|
||||
# Los archivos estáticos requeridos por temas y componentes incluidos en PageTop
|
||||
# se integran de manera predeterminada en el binario ejecutable. Sin embargo, es
|
||||
# útil servir estos archivos desde su propio directorio durante el desarrollo ya
|
||||
# que no requiere compilar cada vez que se modifican. En este caso, normalmente,
|
||||
# basta con indicar el directorio "pagetop/static".
|
||||
static_files = ""
|
||||
|
|
|
|||
|
|
@ -14,10 +14,7 @@ impl ThemeTrait for AlinerTheme {
|
|||
}
|
||||
|
||||
fn configure_theme(&self, cfg: &mut app::web::ServiceConfig) {
|
||||
cfg.service(actix_web_static_files::ResourceFiles::new(
|
||||
"/aliner",
|
||||
assets()
|
||||
));
|
||||
theme_static_files!(cfg, "/aliner");
|
||||
}
|
||||
|
||||
fn before_render_page(&self, page: &mut Page) {
|
||||
|
|
|
|||
|
|
@ -16,10 +16,7 @@ impl ThemeTrait for BootsierTheme {
|
|||
}
|
||||
|
||||
fn configure_theme(&self, cfg: &mut app::web::ServiceConfig) {
|
||||
cfg.service(actix_web_static_files::ResourceFiles::new(
|
||||
"/bootsier",
|
||||
assets()
|
||||
));
|
||||
theme_static_files!(cfg, "/bootsier");
|
||||
}
|
||||
|
||||
fn before_render_page(&self, page: &mut Page) {
|
||||
|
|
@ -61,7 +58,7 @@ impl ThemeTrait for BootsierTheme {
|
|||
div class="jumbotron" {
|
||||
div class="media" {
|
||||
img
|
||||
src="/bootsier/images/caution.png"
|
||||
src="/static/bootsier/images/caution.png"
|
||||
class="mr-4"
|
||||
style="width: 20%; max-width: 188px"
|
||||
alt="Caution!";
|
||||
|
|
|
|||
|
|
@ -104,12 +104,18 @@ pub struct Webserver {
|
|||
pub bind_port : u16,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Dev {
|
||||
pub static_files : String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Settings {
|
||||
pub app : App,
|
||||
pub log : Log,
|
||||
pub database : Database,
|
||||
pub webserver : Webserver,
|
||||
pub dev : Dev,
|
||||
}
|
||||
|
||||
config_map!(r#"
|
||||
|
|
@ -144,5 +150,8 @@ Ajustes globales y valores predeterminados para las secciones *\[app\]*,
|
|||
|
||||
// [webserver]
|
||||
"webserver.bind_address" => "localhost",
|
||||
"webserver.bind_port" => 8088
|
||||
"webserver.bind_port" => 8088,
|
||||
|
||||
// [dev]
|
||||
"dev.static_files" => ""
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{Lazy, app, base, run_now, trace};
|
||||
use crate::{Lazy, app, base, run_now, theme_static_files, trace};
|
||||
use crate::config::SETTINGS;
|
||||
use crate::db::migration::*;
|
||||
use crate::module::*;
|
||||
|
|
@ -84,10 +84,7 @@ pub fn theme_by_name(name: &str) -> Option<&'static dyn ThemeTrait> {
|
|||
}
|
||||
|
||||
pub fn themes(cfg: &mut app::web::ServiceConfig) {
|
||||
cfg.service(actix_web_static_files::ResourceFiles::new(
|
||||
"/theme",
|
||||
assets()
|
||||
));
|
||||
theme_static_files!(cfg, "/theme");
|
||||
|
||||
for t in THEMES.read().unwrap().iter() {
|
||||
t.configure_theme(cfg);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
//! Re-exporta recursos comunes.
|
||||
|
||||
pub use crate::args;
|
||||
// Macros.
|
||||
pub use crate::{
|
||||
args,
|
||||
theme_static_files,
|
||||
};
|
||||
|
||||
pub use crate::config::SETTINGS;
|
||||
pub use crate::trace;
|
||||
pub use crate::localize;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,24 @@ macro_rules! args {
|
|||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! theme_static_files {
|
||||
( $cfg:ident, $dir:expr ) => {{
|
||||
let static_files = &$crate::config::SETTINGS.dev.static_files;
|
||||
if static_files.is_empty() {
|
||||
$cfg.service(actix_web_static_files::ResourceFiles::new(
|
||||
$dir,
|
||||
generate()
|
||||
));
|
||||
} else {
|
||||
$cfg.service(actix_files::Files::new(
|
||||
$dir,
|
||||
&[static_files, $dir].join("")
|
||||
).show_files_listing());
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
pub fn valid_id(id: &str) -> Option<String> {
|
||||
let id = id.trim().replace(" ", "_").to_lowercase();
|
||||
match id.is_empty() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,16 @@
|
|||
html {
|
||||
background-color: white;
|
||||
padding: 1px 3px;
|
||||
}
|
||||
body {
|
||||
padding: 1px 3px;
|
||||
}
|
||||
div {
|
||||
padding: 1px 3px;
|
||||
margin: 5px;
|
||||
}
|
||||
h1, h2, h3, h4,h5, h6, p {
|
||||
background-color: snow;
|
||||
}
|
||||
* * {
|
||||
outline: 5px solid rgba(255,0,0,.1);
|
||||
|
|
@ -21,7 +32,9 @@ html {
|
|||
background: #faa;
|
||||
border-radius: 3px;
|
||||
font: normal normal 400 10px/1.2 monospace;
|
||||
vertical-align: middle;
|
||||
padding: 1px 3px;
|
||||
margin: 0 3px;
|
||||
}
|
||||
*::before {
|
||||
content: "(";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue