aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md56
-rw-r--r--src/lib.rs24
-rw-r--r--src/test.rs8
3 files changed, 80 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..b659aec
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,56 @@
+# Changelog
+
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](https://keepachangelog.com/en/2.0.0/),
+and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+
+## [Unreleased]
+
+## [0.2.0] - 2026-06-29
+
+### Added
+
+- Simplified `tmpl!` macro syntax: supports `tmpl!(tmpl, block_name { key = val, ... })` form, removing the `+=` operator and parentheses around each parameter group
+- Old syntax `tmpl!(tmpl += { ... })` remains backward compatible
+
+### Changed
+
+- Documentation and test code unified to use the simplified `tmpl!` syntax
+
+## [0.1.3] - 2026-03-02
+
+### Fixed
+
+- Fixed the reading logic for implementation block regions in `expand.rs`
+
+## [0.1.2] - 2026-03-02
+
+### Added
+
+- Added `From<&str>` and `From<Cow<'_, str>>` trait implementations for `Template`
+
+## [0.1.1] - 2026-02-28
+
+### Changed
+
+- Refactored crate structure, moved macro definitions to `lib.rs`
+- Renamed `src/lib.rs` to `src/template.rs`
+
+## [0.1.0] - 2026-02-27
+
+### Added
+
+- `Template` struct, supporting template strings and two parameter types (simple parameters and implementation block parameters)
+- Template syntax: `<<<key>>>` for simple parameter substitution, `>>>>>>>>>> block_name` / `@@@ >>> block_name ... @@@ <<<` for implementation block regions
+- `tmpl!` macro: adds implementation block parameters to a template
+- `tmpl_param!` macro: adds simple parameters to a template
+- `Template::expand()` method: expands the template and returns the final string
+- Project initialization
+
+[unreleased]: https://github.com/catilgrass/just_template/compare/v0.2.0...HEAD
+[0.2.0]: https://github.com/catilgrass/just_template/compare/v0.1.3...v0.2.0
+[0.1.3]: https://github.com/catilgrass/just_template/compare/v0.1.2...v0.1.3
+[0.1.2]: https://github.com/catilgrass/just_template/compare/v0.1.1...v0.1.2
+[0.1.1]: https://github.com/catilgrass/just_template/compare/v0.1.0...v0.1.1
+[0.1.0]: https://github.com/catilgrass/just_template/releases/tag/v0.1.0
diff --git a/src/lib.rs b/src/lib.rs
index 704b310..cf9d66e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -33,12 +33,12 @@
//! <<<crate_name>>> => Some(<<<crate_name>>>::exec(data, params).await),
//! @@@ <<<
//! ".trim().to_string());
-//! tmpl!(tmpl += {
+//! tmpl!(tmpl,
//! arms {
-//! (crate_name = "my"),
-//! (crate_name = "you")
+//! crate_name = "my",
+//! crate_name = "you",
//! }
-//! });
+//! );
//! // Output the expanded template
//! let expanded = tmpl.to_string();
//! assert_eq!(expanded, "
@@ -63,6 +63,22 @@ macro_rules! tmpl_param {
#[macro_export]
macro_rules! tmpl {
+ ($template:ident, $($name:ident {
+ $($key:ident = $value:expr),* $(,)?
+ }),* $(,)?) => {{
+ $(
+ let $name = $template.add_impl(stringify!($name).to_string());
+ $(
+ $name.push({
+ let mut params = std::collections::HashMap::new();
+ params.insert(stringify!($key).to_string(), $value.to_string());
+ params
+ });
+ )*
+ )*
+ }};
+
+ // Old syntax
($template:ident += {
$($name:ident {
$(($($key:ident = $value:expr),* $(,)?)),*
diff --git a/src/test.rs b/src/test.rs
index a5ef801..91407fc 100644
--- a/src/test.rs
+++ b/src/test.rs
@@ -15,12 +15,12 @@ mod tests {
let mut tmpl = Template::from(input);
tmpl_param!(tmpl, func_name = "my_func");
- tmpl!(tmpl += {
+ tmpl!(tmpl,
arms {
- (crate_name = "my"),
- (crate_name = "you")
+ crate_name = "my",
+ crate_name = "you",
}
- });
+ );
let expanded = tmpl.expand().unwrap();
assert_eq!(expanded, expect);