✨ New type query function using TypeInfo
This commit is contained in:
parent
4b1e34487d
commit
5e457eed3d
8 changed files with 104 additions and 46 deletions
|
|
@ -1,13 +1,14 @@
|
|||
use crate::base::component::add_base_assets;
|
||||
use crate::concat_string;
|
||||
use crate::core::component::AnyOp;
|
||||
use crate::core::theme::all::{theme_by_single_name, THEME_DEFAULT};
|
||||
use crate::core::theme::all::{theme_by_short_name, THEME_DEFAULT};
|
||||
use crate::core::theme::{ComponentsInRegions, ThemeRef};
|
||||
use crate::html::{html, Markup};
|
||||
use crate::html::{Assets, HeadScript, HeadStyles, JavaScript, StyleSheet};
|
||||
use crate::html::{ClassesOp, OptionClasses, OptionId};
|
||||
use crate::locale::{LanguageIdentifier, LANGID_DEFAULT};
|
||||
use crate::service::HttpRequest;
|
||||
use crate::{concat_string, util};
|
||||
use crate::util::TypeInfo;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
|
|
@ -78,7 +79,7 @@ impl Context {
|
|||
self.langid = langid;
|
||||
}
|
||||
AssetsOp::Theme(theme_name) => {
|
||||
self.theme = theme_by_single_name(theme_name).unwrap_or(*THEME_DEFAULT);
|
||||
self.theme = theme_by_short_name(theme_name).unwrap_or(*THEME_DEFAULT);
|
||||
}
|
||||
AssetsOp::Layout(layout) => {
|
||||
self.layout = layout;
|
||||
|
|
@ -199,7 +200,8 @@ impl Context {
|
|||
match id {
|
||||
Some(id) => id,
|
||||
None => {
|
||||
let prefix = util::single_type_name::<T>()
|
||||
let prefix = TypeInfo::ShortName
|
||||
.of::<T>()
|
||||
.trim()
|
||||
.replace(' ', "_")
|
||||
.to_lowercase();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ use crate::base::action;
|
|||
use crate::core::component::Context;
|
||||
use crate::core::AnyBase;
|
||||
use crate::html::{html, Markup, PrepareMarkup};
|
||||
use crate::{util, Weight};
|
||||
use crate::util::TypeInfo;
|
||||
use crate::Weight;
|
||||
|
||||
pub trait ComponentBase {
|
||||
fn render(&mut self, cx: &mut Context) -> Markup;
|
||||
|
|
@ -13,8 +14,8 @@ pub trait ComponentTrait: AnyBase + ComponentBase + Send + Sync {
|
|||
where
|
||||
Self: Sized;
|
||||
|
||||
fn name(&self) -> String {
|
||||
util::single_type_name::<Self>().to_owned()
|
||||
fn name(&self) -> &'static str {
|
||||
TypeInfo::ShortName.of::<Self>()
|
||||
}
|
||||
|
||||
fn description(&self) -> Option<String> {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ pub type PackageRef = &'static dyn PackageTrait;
|
|||
/// Los paquetes deben implementar este *trait*.
|
||||
pub trait PackageTrait: AnyBase + Send + Sync {
|
||||
fn name(&self) -> L10n {
|
||||
L10n::n(self.single_name())
|
||||
L10n::n(self.short_name())
|
||||
}
|
||||
|
||||
fn description(&self) -> L10n {
|
||||
|
|
|
|||
|
|
@ -11,20 +11,20 @@ pub static THEMES: LazyStatic<RwLock<Vec<ThemeRef>>> = LazyStatic::new(|| RwLock
|
|||
// DEFAULT THEME ***********************************************************************************
|
||||
|
||||
pub static THEME_DEFAULT: LazyStatic<ThemeRef> =
|
||||
LazyStatic::new(|| match theme_by_single_name(&config::SETTINGS.app.theme) {
|
||||
LazyStatic::new(|| match theme_by_short_name(&config::SETTINGS.app.theme) {
|
||||
Some(theme) => theme,
|
||||
None => &crate::base::theme::Inception,
|
||||
});
|
||||
|
||||
// THEME BY NAME ***********************************************************************************
|
||||
|
||||
pub fn theme_by_single_name(single_name: &str) -> Option<ThemeRef> {
|
||||
let single_name = single_name.to_lowercase();
|
||||
pub fn theme_by_short_name(short_name: &str) -> Option<ThemeRef> {
|
||||
let short_name = short_name.to_lowercase();
|
||||
match THEMES
|
||||
.read()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|t| t.single_name().to_lowercase() == single_name)
|
||||
.find(|t| t.short_name().to_lowercase() == short_name)
|
||||
{
|
||||
Some(theme) => Some(*theme),
|
||||
_ => None,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue