Actualiza y sanea piezas de código sensible
This commit is contained in:
parent
db3efa9ef9
commit
cac4c2f102
9 changed files with 29 additions and 29 deletions
|
|
@ -31,7 +31,7 @@ impl PageComponent for Block {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_render(&self, assets: &mut PageAssets) -> Markup {
|
fn default_render(&self, assets: &mut PageAssets) -> Markup {
|
||||||
let id = assets.required_id(self.name(), self.id());
|
let id = assets.serial_id(self.name(), self.id());
|
||||||
html! {
|
html! {
|
||||||
div id=(id) class="block" {
|
div id=(id) class="block" {
|
||||||
@if !self.title.is_empty() {
|
@if !self.title.is_empty() {
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,7 @@ impl PageComponent for Menu {
|
||||||
))
|
))
|
||||||
.add_jquery();
|
.add_jquery();
|
||||||
|
|
||||||
let id = assets.required_id(self.name(), self.id());
|
let id = assets.serial_id(self.name(), self.id());
|
||||||
html! {
|
html! {
|
||||||
ul id=(id) class="sm sm-clean" {
|
ul id=(id) class="sm sm-clean" {
|
||||||
(self.render_items(assets))
|
(self.render_items(assets))
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use crate::config::SETTINGS;
|
||||||
use crate::core::all;
|
use crate::core::all;
|
||||||
use crate::core::theme::{Markup, PreEscaped, Theme, find_theme, html};
|
use crate::core::theme::{Markup, PreEscaped, Theme, find_theme, html};
|
||||||
|
|
||||||
pub static DEFAULT_THEME: Lazy<&dyn Theme> = Lazy::new(|| {
|
static DEFAULT_THEME: Lazy<&dyn Theme> = Lazy::new(|| {
|
||||||
for t in all::THEMES.read().unwrap().iter() {
|
for t in all::THEMES.read().unwrap().iter() {
|
||||||
if t.name().to_lowercase() == SETTINGS.app.theme.to_lowercase() {
|
if t.name().to_lowercase() == SETTINGS.app.theme.to_lowercase() {
|
||||||
return *t;
|
return *t;
|
||||||
|
|
@ -183,7 +183,7 @@ impl JavaScript {
|
||||||
// Page assets.
|
// Page assets.
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
pub struct Assets {
|
pub struct PageAssets {
|
||||||
theme : &'static dyn Theme,
|
theme : &'static dyn Theme,
|
||||||
favicon : Option<Favicon>,
|
favicon : Option<Favicon>,
|
||||||
metadata : Vec<(String, String)>,
|
metadata : Vec<(String, String)>,
|
||||||
|
|
@ -193,9 +193,9 @@ pub struct Assets {
|
||||||
id_counter : u32,
|
id_counter : u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Assets {
|
impl PageAssets {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Assets {
|
PageAssets {
|
||||||
theme : *DEFAULT_THEME,
|
theme : *DEFAULT_THEME,
|
||||||
favicon : None,
|
favicon : None,
|
||||||
metadata : Vec::new(),
|
metadata : Vec::new(),
|
||||||
|
|
@ -206,8 +206,8 @@ impl Assets {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn using_theme(&mut self, theme_id: &str) -> &mut Self {
|
pub fn using_theme(&mut self, theme_name: &str) -> &mut Self {
|
||||||
self.theme = find_theme(theme_id).unwrap_or(*DEFAULT_THEME);
|
self.theme = find_theme(theme_name).unwrap_or(*DEFAULT_THEME);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -291,7 +291,7 @@ impl Assets {
|
||||||
|
|
||||||
// Assets EXTRAS.
|
// Assets EXTRAS.
|
||||||
|
|
||||||
pub fn required_id(&mut self, prefix: &str, id: &str) -> String {
|
pub fn serial_id(&mut self, prefix: &str, id: &str) -> String {
|
||||||
if id.is_empty() {
|
if id.is_empty() {
|
||||||
let prefix = prefix.trim().replace(" ", "_").to_lowercase();
|
let prefix = prefix.trim().replace(" ", "_").to_lowercase();
|
||||||
let prefix = if prefix.is_empty() {
|
let prefix = if prefix.is_empty() {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use downcast_rs::{Downcast, impl_downcast};
|
||||||
|
|
||||||
use std::any::type_name;
|
use std::any::type_name;
|
||||||
|
|
||||||
pub trait Component: Downcast + Send + Sync {
|
pub trait PageComponent: Downcast + Send + Sync {
|
||||||
|
|
||||||
fn prepare() -> Self where Self: Sized;
|
fn prepare() -> Self where Self: Sized;
|
||||||
|
|
||||||
|
|
@ -39,4 +39,4 @@ pub trait Component: Downcast + Send + Sync {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_downcast!(Component);
|
impl_downcast!(PageComponent);
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,15 @@ use crate::core::response::page::{PageAssets, PageComponent, render_component};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Container(Vec<Arc<dyn PageComponent>>);
|
pub struct PageContainer(Vec<Arc<dyn PageComponent>>);
|
||||||
|
|
||||||
impl Container {
|
impl PageContainer {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Container(Vec::new())
|
PageContainer(Vec::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_with(component: impl PageComponent) -> Self {
|
pub fn new_with(component: impl PageComponent) -> Self {
|
||||||
let mut container = Container::new();
|
let mut container = PageContainer::new();
|
||||||
container.add(component);
|
container.add(component);
|
||||||
container
|
container
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,16 @@
|
||||||
pub mod assets;
|
mod assets;
|
||||||
pub use assets::Assets as PageAssets;
|
pub use assets::{
|
||||||
|
Favicon,
|
||||||
|
StyleSheet,
|
||||||
|
JavaScript, JSMode,
|
||||||
|
PageAssets,
|
||||||
|
};
|
||||||
|
|
||||||
mod component;
|
mod component;
|
||||||
pub use component::Component as PageComponent;
|
pub use component::PageComponent;
|
||||||
|
|
||||||
mod container;
|
mod container;
|
||||||
pub use container::Container as PageContainer;
|
pub use container::PageContainer;
|
||||||
|
|
||||||
mod page;
|
mod page;
|
||||||
pub use page::Page;
|
pub use page::Page;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use crate::core::response::page::{PageAssets, PageComponent, PageContainer};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub static DEFAULT_LANGUAGE: Lazy<Option<String>> = Lazy::new(|| {
|
static DEFAULT_LANGUAGE: Lazy<Option<String>> = Lazy::new(|| {
|
||||||
let language = SETTINGS.app.language[..2].to_lowercase();
|
let language = SETTINGS.app.language[..2].to_lowercase();
|
||||||
if !language.is_empty() {
|
if !language.is_empty() {
|
||||||
Some(language)
|
Some(language)
|
||||||
|
|
@ -16,7 +16,7 @@ pub static DEFAULT_LANGUAGE: Lazy<Option<String>> = Lazy::new(|| {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
pub static DEFAULT_DIRECTION: Lazy<Option<String>> = Lazy::new(|| {
|
static DEFAULT_DIRECTION: Lazy<Option<String>> = Lazy::new(|| {
|
||||||
let direction = SETTINGS.app.direction.to_lowercase();
|
let direction = SETTINGS.app.direction.to_lowercase();
|
||||||
match direction.as_str() {
|
match direction.as_str() {
|
||||||
"auto" => Some("auto".to_string()),
|
"auto" => Some("auto".to_string()),
|
||||||
|
|
@ -188,8 +188,8 @@ impl<'a> Page<'a> {
|
||||||
|
|
||||||
// Page EXTRAS.
|
// Page EXTRAS.
|
||||||
|
|
||||||
pub fn using_theme(&mut self, theme_id: &str) -> &mut Self {
|
pub fn using_theme(&mut self, theme_name: &str) -> &mut Self {
|
||||||
self.assets.using_theme(theme_id);
|
self.assets.using_theme(theme_name);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ pub trait Theme: Send + Sync {
|
||||||
/*
|
/*
|
||||||
Cómo usarlo:
|
Cómo usarlo:
|
||||||
|
|
||||||
match component.handle() {
|
match component.name() {
|
||||||
"block" => {
|
"block" => {
|
||||||
let block = component.downcast_mut::<Block>().unwrap();
|
let block = component.downcast_mut::<Block>().unwrap();
|
||||||
match block.template() {
|
match block.template() {
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,8 @@ pub use crate::trace;
|
||||||
pub use crate::localize;
|
pub use crate::localize;
|
||||||
|
|
||||||
pub use crate::core::theme::*;
|
pub use crate::core::theme::*;
|
||||||
|
|
||||||
pub use crate::core::module::*;
|
pub use crate::core::module::*;
|
||||||
|
|
||||||
pub use crate::core::response::page::*;
|
pub use crate::core::response::page::*;
|
||||||
pub use crate::core::response::page::assets::*;
|
|
||||||
|
|
||||||
pub use crate::core::server;
|
pub use crate::core::server;
|
||||||
|
|
||||||
pub use crate::base::theme::*;
|
|
||||||
pub use crate::base::component::*;
|
pub use crate::base::component::*;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue