🚧 Incopora recursos estáticos con "use_static!()"
This commit is contained in:
parent
32d068065e
commit
bcf403ab50
10 changed files with 35 additions and 21 deletions
|
|
@ -2,7 +2,7 @@ use pagetop::prelude::*;
|
|||
|
||||
use_handle!(THEME_ALINER);
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/aliner.rs"));
|
||||
use_static!(aliner);
|
||||
|
||||
pub struct Aliner;
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ impl ModuleTrait for Aliner {
|
|||
}
|
||||
|
||||
fn configure_service(&self, cfg: &mut service::web::ServiceConfig) {
|
||||
serve_static_files!(cfg, "/aliner", bundle_aliner);
|
||||
serve_static_files!(cfg, "/aliner", aliner);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use_handle!(THEME_BOOTSIER);
|
|||
|
||||
use_locale!(LOCALE_BOOTSIER, "src/locale");
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bootsier.rs"));
|
||||
use_static!(bootsier);
|
||||
|
||||
pub struct Bootsier;
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ impl ModuleTrait for Bootsier {
|
|||
}
|
||||
|
||||
fn configure_service(&self, cfg: &mut service::web::ServiceConfig) {
|
||||
serve_static_files!(cfg, "/bootsier", bundle_bootsier);
|
||||
serve_static_files!(cfg, "/bootsier", bootsier);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use pagetop_minimal::component::*;
|
|||
|
||||
use_handle!(THEME_BULMIX);
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bulmix.rs"));
|
||||
use_static!(bulmix);
|
||||
|
||||
pub struct Bulmix;
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ impl ModuleTrait for Bulmix {
|
|||
}
|
||||
|
||||
fn configure_service(&self, cfg: &mut service::web::ServiceConfig) {
|
||||
serve_static_files!(cfg, "/bulmix", bundle_bulmix);
|
||||
serve_static_files!(cfg, "/bulmix", bulmix);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use_handle!(MODULE_DEMOHOME);
|
|||
|
||||
use_locale!(LOCALE_DEMOHOME, "src/locale");
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/homedemo.rs"));
|
||||
use_static!(homedemo);
|
||||
|
||||
pub struct HomeDemo;
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ impl ModuleTrait for HomeDemo {
|
|||
}
|
||||
|
||||
fn configure_service(&self, cfg: &mut service::web::ServiceConfig) {
|
||||
serve_static_files!(cfg, "/homedemo", bundle_homedemo);
|
||||
serve_static_files!(cfg, "/homedemo", homedemo);
|
||||
cfg.route("/", service::web::get().to(demo));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use pagetop::prelude::*;
|
|||
|
||||
use_handle!(MODULE_JQUERY);
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/jquery.rs"));
|
||||
use_static!(jquery);
|
||||
|
||||
const JQUERY_PARAM: &str = "jquery.add";
|
||||
const JQUERY_SOURCE: &str = "/jquery/3.6.0/jquery.min.js";
|
||||
|
|
@ -15,7 +15,7 @@ impl ModuleTrait for JQuery {
|
|||
}
|
||||
|
||||
fn configure_service(&self, cfg: &mut service::web::ServiceConfig) {
|
||||
serve_static_files!(cfg, "/jquery", bundle_jquery);
|
||||
serve_static_files!(cfg, "/jquery", jquery);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ pub mod component;
|
|||
|
||||
use_handle!(MODULE_MEGAMENU);
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/megamenu.rs"));
|
||||
use_static!(megamenu);
|
||||
|
||||
pub struct MegaMenu;
|
||||
|
||||
|
|
@ -18,6 +18,6 @@ impl ModuleTrait for MegaMenu {
|
|||
}
|
||||
|
||||
fn configure_service(&self, cfg: &mut service::web::ServiceConfig) {
|
||||
serve_static_files!(cfg, "/megamenu", bundle_megamenu);
|
||||
serve_static_files!(cfg, "/megamenu", megamenu);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ pub mod module;
|
|||
|
||||
use_handle!(MODULE_MINIMAL);
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/minimal.rs"));
|
||||
use_static!(minimal);
|
||||
|
||||
pub struct Minimal;
|
||||
|
||||
|
|
@ -15,6 +15,6 @@ impl ModuleTrait for Minimal {
|
|||
}
|
||||
|
||||
fn configure_service(&self, cfg: &mut service::web::ServiceConfig) {
|
||||
serve_static_files!(cfg, "/minimal", bundle_minimal);
|
||||
serve_static_files!(cfg, "/minimal", minimal);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::prelude::*;
|
|||
|
||||
use_handle!(THEME_BASIC);
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/theme.rs"));
|
||||
use_static!(theme);
|
||||
|
||||
pub struct Basic;
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ impl ModuleTrait for Basic {
|
|||
}
|
||||
|
||||
fn configure_service(&self, cfg: &mut service::web::ServiceConfig) {
|
||||
serve_static_files!(cfg, "/theme", bundle_theme);
|
||||
serve_static_files!(cfg, "/theme", theme);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ pub use crate::{
|
|||
};
|
||||
|
||||
// Macros declarativas globales.
|
||||
pub use crate::{args, define_config, define_handle, define_locale, serve_static_files};
|
||||
pub use crate::{args, serve_static_files, use_config, use_handle, use_locale, use_static};
|
||||
|
||||
// Traducciones globales.
|
||||
pub use crate::LOCALE_PAGETOP;
|
||||
|
|
|
|||
|
|
@ -107,16 +107,30 @@ macro_rules! use_locale {
|
|||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! use_static {
|
||||
( $bundle:ident ) => {
|
||||
include!(concat!(env!("OUT_DIR"), "/", stringify!($bundle), ".rs"));
|
||||
};
|
||||
( $bundle:ident => $STATIC:ident ) => {
|
||||
include!(concat!(env!("OUT_DIR"), "/", stringify!($bundle), ".rs"));
|
||||
static $STATIC: LazyStatic<HashMapResources> = LazyStatic::new($bundle);
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! serve_static_files {
|
||||
( $cfg:ident, $dir:expr, $embed:ident ) => {{
|
||||
( $cfg:ident, $path:expr, $bundle:ident ) => {{
|
||||
let static_files = &$crate::config::SETTINGS.dev.static_files;
|
||||
if static_files.is_empty() {
|
||||
$cfg.service($crate::service::ResourceFiles::new($dir, $embed()));
|
||||
$cfg.service($crate::service::ResourceFiles::new($path, $bundle()));
|
||||
} else {
|
||||
$cfg.service(
|
||||
$crate::service::ActixFiles::new($dir, $crate::concat_string!(static_files, $dir))
|
||||
.show_files_listing(),
|
||||
$crate::service::ActixFiles::new(
|
||||
$path,
|
||||
$crate::concat_string!(static_files, $path),
|
||||
)
|
||||
.show_files_listing(),
|
||||
);
|
||||
}
|
||||
}};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue