From ba15b7c06468cb6c52c8d2a53419fd83f9ebcb8b Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 29 Jun 2026 03:34:41 +0800 Subject: refactor: promote project to workspace with macros sub-crate --- just_template/src/lib.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 just_template/src/lib.rs (limited to 'just_template/src/lib.rs') diff --git a/just_template/src/lib.rs b/just_template/src/lib.rs new file mode 100644 index 0000000..7ff77f5 --- /dev/null +++ b/just_template/src/lib.rs @@ -0,0 +1,58 @@ +//! Template struct for storing template strings and their parameters. +//! +//! The template supports two types of parameters: +//! - Simple parameters: key-value pairs used to replace simple placeholders (`<<>>` format) in the template. +//! - Implementation parameters: for implementation blocks (`>>>>>>>>> block_name` and `@@@ >>> block_name` format), +//! can contain multiple parameter sets, each corresponding to an implementation instance. +//! +//! # Examples +//! ``` +//! use just_template::Template; +//! +//! let mut tmpl = Template::from("Hello, <<>>!".to_string()); +//! tmpl.insert_param("name".to_string(), "World".to_string()); +//! assert_eq!(tmpl.to_string(), "Hello, World!"); +//! ``` +//! +//! Using the `tmpl_param!` macro makes it easier to add simple parameters: +//! ``` +//! use just_template::{Template, tmpl_param}; +//! +//! let mut tmpl = Template::from("<<>> + <<>> = <<>>".to_string()); +//! tmpl_param!(tmpl, a = 1, b = 2, c = 3); +//! assert_eq!(tmpl.to_string(), "1 + 2 = 3"); +//! ``` +//! +//! Using the `tmpl!` macro adds implementation block parameters: +//! ``` +//! use just_template::{Template, tmpl}; +//! +//! let mut tmpl = Template::from(" +//! >>>>>>>>>> arms +//! @@@ >>> arms +//! <<>> => Some(<<>>::exec(data, params).await), +//! @@@ <<< +//! ".trim().to_string()); +//! tmpl!(tmpl, +//! arms { +//! crate_name = "my", +//! crate_name = "you", +//! } +//! ); +//! // Output the expanded template +//! let expanded = tmpl.to_string(); +//! assert_eq!(expanded, " +//! my => Some(my::exec(data, params).await), +//! you => Some(you::exec(data, params).await), +//! ".trim().to_string()); +//! ``` +mod template; +pub use template::*; // Re-export template to just_template + +pub mod expand; + +#[cfg(test)] +pub mod test; + +#[deprecated] +pub mod deprecated; -- cgit