💬 Apps como "Sample" e Integra macro join_string!
This commit is contained in:
parent
5248b66702
commit
6701fb3e90
11 changed files with 60 additions and 57 deletions
|
|
@ -1,5 +1,5 @@
|
|||
[app]
|
||||
name = "My App"
|
||||
name = "Sample"
|
||||
description = "Developed with the amazing PageTop framework."
|
||||
# Default theme.
|
||||
theme = "Default"
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
[app]
|
||||
name = "Samples"
|
||||
#language = "es-ES"
|
||||
|
||||
[log]
|
||||
tracing = "Debug"
|
||||
|
|
@ -4,11 +4,10 @@ struct HelloName;
|
|||
|
||||
impl PackageTrait for HelloName {
|
||||
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||
scfg.service(hello_name);
|
||||
scfg.route("/hello/{name}", service::web::get().to(hello_name));
|
||||
}
|
||||
}
|
||||
|
||||
#[service::get("/hello/{name}")]
|
||||
async fn hello_name(
|
||||
request: HttpRequest,
|
||||
path: service::web::Path<String>,
|
||||
|
|
|
|||
|
|
@ -127,8 +127,7 @@ mod value;
|
|||
|
||||
use crate::config::data::ConfigData;
|
||||
use crate::config::file::File;
|
||||
|
||||
use concat_string::concat_string;
|
||||
use crate::join_string;
|
||||
|
||||
use std::sync::LazyLock;
|
||||
|
||||
|
|
@ -158,16 +157,16 @@ pub static CONFIG_VALUES: LazyLock<ConfigData> = LazyLock::new(|| {
|
|||
// Merge (optional) configuration files and set the execution mode.
|
||||
values
|
||||
// First, add the common configuration for all environments. Defaults to 'common.toml'.
|
||||
.merge(File::with_name(&concat_string!(config_dir, "/common.toml")).required(false))
|
||||
.merge(File::with_name(&join_string!(config_dir, "/common.toml")).required(false))
|
||||
.expect("Failed to merge common configuration (common.toml)")
|
||||
// Add the environment-specific configuration. Defaults to 'default.toml'.
|
||||
.merge(File::with_name(&concat_string!(config_dir, "/", rm, ".toml")).required(false))
|
||||
.merge(File::with_name(&join_string!(config_dir, "/", rm, ".toml")).required(false))
|
||||
.expect(&format!("Failed to merge {rm}.toml configuration"))
|
||||
// Add reserved local configuration for the environment. Defaults to 'local.default.toml'.
|
||||
.merge(File::with_name(&concat_string!(config_dir, "/local.", rm, ".toml")).required(false))
|
||||
.merge(File::with_name(&join_string!(config_dir, "/local.", rm, ".toml")).required(false))
|
||||
.expect("Failed to merge reserved local environment configuration")
|
||||
// Add common reserved local configuration. Defaults to 'local.toml'.
|
||||
.merge(File::with_name(&concat_string!(config_dir, "/local.toml")).required(false))
|
||||
.merge(File::with_name(&join_string!(config_dir, "/local.toml")).required(false))
|
||||
.expect("Failed to merge general reserved local configuration")
|
||||
// Save the execution mode.
|
||||
.set("app.run_mode", rm)
|
||||
|
|
|
|||
|
|
@ -3,12 +3,11 @@ use crate::core::theme::all::{theme_by_short_name, DEFAULT_THEME};
|
|||
use crate::core::theme::{ChildrenInRegions, ThemeRef};
|
||||
use crate::html::{html, Markup};
|
||||
use crate::html::{Assets, Favicon, JavaScript, StyleSheet};
|
||||
use crate::join_string;
|
||||
use crate::locale::{LanguageIdentifier, DEFAULT_LANGID};
|
||||
use crate::service::HttpRequest;
|
||||
use crate::util::TypeInfo;
|
||||
|
||||
use concat_string::concat_string;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::error::Error;
|
||||
use std::str::FromStr;
|
||||
|
|
@ -198,7 +197,7 @@ impl Context {
|
|||
prefix
|
||||
};
|
||||
self.id_counter += 1;
|
||||
concat_string!(prefix, "-", self.id_counter.to_string())
|
||||
join_string!(prefix, "-", self.id_counter.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use serde::Deserialize;
|
|||
|
||||
include_config!(SETTINGS: Settings => [
|
||||
// [app]
|
||||
"app.name" => "My App",
|
||||
"app.name" => "Sample",
|
||||
"app.description" => "Developed with the amazing PageTop framework.",
|
||||
"app.theme" => "",
|
||||
"app.language" => "en-US",
|
||||
|
|
@ -45,7 +45,7 @@ pub struct Settings {
|
|||
/// See [`Settings`].
|
||||
pub struct App {
|
||||
/// The name of the application.
|
||||
/// Default: *"My App"*.
|
||||
/// Default: *"Sample"*.
|
||||
pub name: String,
|
||||
/// A brief description of the application.
|
||||
/// Default: *"Developed with the amazing PageTop framework."*.
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
use crate::html::assets::AssetsTrait;
|
||||
use crate::html::{html, Markup};
|
||||
use crate::{AutoDefault, Weight};
|
||||
|
||||
use concat_string::concat_string;
|
||||
use crate::{join_string, AutoDefault, Weight};
|
||||
|
||||
#[derive(AutoDefault)]
|
||||
enum Source {
|
||||
|
|
@ -41,18 +39,18 @@ impl AssetsTrait for JavaScript {
|
|||
fn render(&self) -> Markup {
|
||||
match &self.source {
|
||||
Source::From(path) => html! {
|
||||
script src=(concat_string!(path, self.prefix, self.version)) {};
|
||||
script src=(join_string!(path, self.prefix, self.version)) {};
|
||||
},
|
||||
Source::Defer(path) => html! {
|
||||
script src=(concat_string!(path, self.prefix, self.version)) defer {};
|
||||
script src=(join_string!(path, self.prefix, self.version)) defer {};
|
||||
},
|
||||
Source::Async(path) => html! {
|
||||
script src=(concat_string!(path, self.prefix, self.version)) async {};
|
||||
script src=(join_string!(path, self.prefix, self.version)) async {};
|
||||
},
|
||||
Source::Inline(_, code) => html! {
|
||||
script { (code) };
|
||||
},
|
||||
Source::OnLoad(_, code) => html! { (concat_string!(
|
||||
Source::OnLoad(_, code) => html! { (join_string!(
|
||||
"document.addEventListener('DOMContentLoaded',function(){",
|
||||
code,
|
||||
"});"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
use crate::html::assets::AssetsTrait;
|
||||
use crate::html::{html, Markup, PreEscaped};
|
||||
use crate::{AutoDefault, Weight};
|
||||
|
||||
use concat_string::concat_string;
|
||||
use crate::{join_string, AutoDefault, Weight};
|
||||
|
||||
#[derive(AutoDefault)]
|
||||
enum Source {
|
||||
|
|
@ -45,7 +43,7 @@ impl AssetsTrait for StyleSheet {
|
|||
Source::From(path) => html! {
|
||||
link
|
||||
rel="stylesheet"
|
||||
href=(concat_string!(path, self.prefix, self.version))
|
||||
href=(join_string!(path, self.prefix, self.version))
|
||||
media=[self.media];
|
||||
},
|
||||
Source::Inline(_, code) => html! {
|
||||
|
|
|
|||
|
|
@ -121,6 +121,6 @@ pub mod base;
|
|||
// Prepara y ejecuta la aplicación.
|
||||
pub mod app;
|
||||
|
||||
// Prelude de PageTop ******************************************************************************
|
||||
// PRELUDE *****************************************************************************************
|
||||
|
||||
pub mod prelude;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ pub use crate::{AutoDefault, ComponentClasses, StaticResources, UniqueId, Weight
|
|||
// MACROS.
|
||||
|
||||
// crate::util
|
||||
pub use crate::kv;
|
||||
pub use crate::{join_string, kv};
|
||||
// crate::config
|
||||
pub use crate::include_config;
|
||||
// crate::locale
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::trace;
|
|||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
|
||||
// USEFUL FUNCTIONS ********************************************************************************
|
||||
// FUNCIONES ÚTILES ********************************************************************************
|
||||
|
||||
pub enum TypeInfo {
|
||||
FullName,
|
||||
|
|
@ -30,18 +30,18 @@ impl TypeInfo {
|
|||
fn partial(type_name: &'static str, start: isize, end: Option<isize>) -> &'static str {
|
||||
let maxlen = type_name.len();
|
||||
let mut segments = Vec::new();
|
||||
let mut segment_start = 0; // Start position of the current segment.
|
||||
let mut angle_brackets = 0; // Counter for tracking '<' and '>'.
|
||||
let mut previous_char = '\0'; // Initializes to a null character, no previous character.
|
||||
let mut segment_start = 0; // Posición de inicial del segmento actual.
|
||||
let mut angle_brackets = 0; // Contador para seguimiento de '<' y '>'.
|
||||
let mut previous_char = '\0'; // Se inicializa a carácter nulo, no hay aún carácter previo.
|
||||
|
||||
for (idx, c) in type_name.char_indices() {
|
||||
match c {
|
||||
':' if angle_brackets == 0 => {
|
||||
if previous_char == ':' {
|
||||
if segment_start < idx - 1 {
|
||||
segments.push((segment_start, idx - 1)); // Do not include last '::'.
|
||||
segments.push((segment_start, idx - 1)); // No incluye último '::'.
|
||||
}
|
||||
segment_start = idx + 1; // Next segment starts after '::'.
|
||||
segment_start = idx + 1; // El siguiente segmento comienza después de '::'.
|
||||
}
|
||||
}
|
||||
'<' => angle_brackets += 1,
|
||||
|
|
@ -51,12 +51,12 @@ impl TypeInfo {
|
|||
previous_char = c;
|
||||
}
|
||||
|
||||
// Include the last segment if there's any.
|
||||
// Incluye el último segmento si lo hubiese.
|
||||
if segment_start < maxlen {
|
||||
segments.push((segment_start, maxlen));
|
||||
}
|
||||
|
||||
// Calculates the start position.
|
||||
// Calcula la posición inicial.
|
||||
let start_pos = segments
|
||||
.get(if start >= 0 {
|
||||
start as usize
|
||||
|
|
@ -65,7 +65,7 @@ impl TypeInfo {
|
|||
})
|
||||
.map_or(0, |&(s, _)| s);
|
||||
|
||||
// Calculates the end position.
|
||||
// Calcula la posición final.
|
||||
let end_pos = segments
|
||||
.get(if let Some(end) = end {
|
||||
if end >= 0 {
|
||||
|
|
@ -78,30 +78,30 @@ impl TypeInfo {
|
|||
})
|
||||
.map_or(maxlen, |&(_, e)| e);
|
||||
|
||||
// Returns the partial string based on the calculated positions.
|
||||
// Devuelve la cadena parcial basada en las posiciones calculadas.
|
||||
&type_name[start_pos..end_pos]
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculates the absolute directory given a root path and a relative path.
|
||||
/// Calcula el directorio absoluto dado un directorio raíz y una ruta relativa.
|
||||
///
|
||||
/// # Arguments
|
||||
/// # Argumentos
|
||||
///
|
||||
/// * `root_path` - A string slice that holds the root path.
|
||||
/// * `relative_path` - A string slice that holds the relative path.
|
||||
/// * `root_path` - Contiene el directorio raíz.
|
||||
/// * `relative_path` - Contiene la ruta relativa.
|
||||
///
|
||||
/// # Returns
|
||||
/// # Devuelve
|
||||
///
|
||||
/// * `Ok` - If the operation is successful, returns the absolute directory as a `String`.
|
||||
/// * `Err` - If an I/O error occurs, returns an `io::Error`.
|
||||
/// * `Ok` - Si la operación es correcta devuelve el directorio absoluto como un `String`.
|
||||
/// * `Err` - Si ocurre un error de E/S, devuelve un `io::Error`.
|
||||
///
|
||||
/// # Errors
|
||||
/// # Errores
|
||||
///
|
||||
/// This function will return an error if:
|
||||
/// - The root path or relative path are invalid.
|
||||
/// - There is an issue with file system operations, such as reading the directory.
|
||||
/// Esta función devolverá un error si:
|
||||
/// - El directorio raíz o la ruta relativa son inválidos.
|
||||
/// - Hay un problema con las operaciones sobre el sistema de archivos, como leer el directorio.
|
||||
///
|
||||
/// # Examples
|
||||
/// # Ejemplos
|
||||
///
|
||||
/// ```rust#ignore
|
||||
/// let root = "/home/user";
|
||||
|
|
@ -138,11 +138,27 @@ pub fn absolute_dir(
|
|||
Ok(absolute_dir)
|
||||
}
|
||||
|
||||
// USEFUL MACROS ***********************************************************************************
|
||||
// MACROS ÚTILES ***********************************************************************************
|
||||
|
||||
/// Flexible concatenation of identifiers in macros.
|
||||
#[doc(hidden)]
|
||||
pub use paste::paste;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub use concat_string::concat_string;
|
||||
|
||||
/// Concatena varios fragmentos de cadenas en una cadena *String*.
|
||||
///
|
||||
/// Exporta la macro [`concat_string!`](https://docs.rs/concat-string), que permite concatenar de
|
||||
/// forma eficiente fragmentos de cadenas (*string slices*) en una cadena *String*. Acepta cualquier
|
||||
/// número de argumentos que implementen `AsRef<str>` y crea una cadena `String` con el tamaño
|
||||
/// adecuado, sin requerir cadenas de formato que puedan sobrecargar el rendimiento.
|
||||
#[macro_export]
|
||||
macro_rules! join_string {
|
||||
($($arg:tt)*) => {
|
||||
crate::util::concat_string!($($arg)*)
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
/// Macro para construir grupos de pares clave-valor.
|
||||
///
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue