🚧 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 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