diff options
Diffstat (limited to 'just_template_macros')
| -rw-r--r-- | just_template_macros/Cargo.toml | 8 | ||||
| l--------- | just_template_macros/LICENSE-APACHE | 1 | ||||
| l--------- | just_template_macros/LICENSE-MIT | 1 | ||||
| -rw-r--r-- | just_template_macros/README.md | 93 |
4 files changed, 103 insertions, 0 deletions
diff --git a/just_template_macros/Cargo.toml b/just_template_macros/Cargo.toml index c033d1b..894c5f2 100644 --- a/just_template_macros/Cargo.toml +++ b/just_template_macros/Cargo.toml @@ -4,6 +4,14 @@ version.workspace = true description.workspace = true authors.workspace = true edition.workspace = true +homepage.workspace = true +repository.workspace = true +license.workspace = true +keywords.workspace = true +categories.workspace = true + +readme = "README.md" +documentation = "https://docs.rs/just_template_macros" [lib] proc-macro = true diff --git a/just_template_macros/LICENSE-APACHE b/just_template_macros/LICENSE-APACHE new file mode 120000 index 0000000..e2a4dc6 --- /dev/null +++ b/just_template_macros/LICENSE-APACHE @@ -0,0 +1 @@ +D:/just_template/LICENSE-APACHE
\ No newline at end of file diff --git a/just_template_macros/LICENSE-MIT b/just_template_macros/LICENSE-MIT new file mode 120000 index 0000000..fa1766a --- /dev/null +++ b/just_template_macros/LICENSE-MIT @@ -0,0 +1 @@ +D:/just_template/LICENSE-MIT
\ No newline at end of file diff --git a/just_template_macros/README.md b/just_template_macros/README.md new file mode 100644 index 0000000..a45d77d --- /dev/null +++ b/just_template_macros/README.md @@ -0,0 +1,93 @@ +# just_template_macros + +> Proc-macro crate for [`just_template`](https://crates.io/crates/just_template). +> Provides the `tmpl!` macro. + +## `tmpl!` macro + +A unified macro for setting both simple parameters and implementation blocks +on a [`Template`](https://docs.rs/just_template). + +### Simple parameters + +```rust +use just_template::{Template, tmpl}; + +let mut tmpl = Template::from("Hello, <<<name>>>!".to_string()); + +tmpl!(tmpl, name = "World"); +// or, when the variable is named `tmpl`: +tmpl! { name = "World" }; + +assert_eq!(tmpl.expand().unwrap(), "Hello, World!"); +``` + +### Implementation blocks with arms + +```rust +use just_template::{Template, tmpl}; + +let mut tmpl = Template::from(r#" +>>>>>>>>>> arms +@@@ >>> arms + <<<value>>> => println!("<<<value>>>"), +@@@ <<< +"#.trim().to_string()); + +tmpl! { + arms { + value = "a", + value = "b", + } +}; + +let out = tmpl.expand().unwrap(); +// out contains: +// a => println!("a"), +// b => println!("b"), +``` + +### Mixed with multi-param arms + +```rust +use just_template::{Template, tmpl}; + +let mut tmpl = Template::from(r#" +>>>>>>>>>> arms +@@@ >>> arms + <<<name>>>: <<<value>>> +??? >>> extra + <<<name>>>.extra() +??? <<< +@@@ <<< +"#.trim().to_string()); + +tmpl! { + arms { + name = "foo", value = "1", + { + name = "bar", + value = "2", + extra = "" // enables the `extra` display block for this arm + } + } +}; + +let out = tmpl.expand().unwrap(); +// out contains: +// foo: 1 +// bar: 2 +// bar.extra() +``` + +### Call forms + +| Form | Example | Template variable | +|---|---|---| +| Explicit | `tmpl!(tmpl, key = val)` | First argument | +| Implicit | `tmpl! { key = val }` | Defaults to `tmpl` | + +Both forms accept the same body syntax: simple params (`key = val`), +implementation blocks (`name { arms }`), or a mix of both. + +For more details, see the [`just_template` documentation](https://docs.rs/just_template). |
