Crates.io | funcy |
lib.rs | funcy |
version | 1.0.0 |
source | src |
created_at | 2020-12-05 19:20:46.809614 |
updated_at | 2020-12-06 20:01:16.192466 |
description | Simple function based template engine |
homepage | https://github.com/camc/funcy |
repository | https://github.com/camc/funcy |
max_upload_size | |
id | 319916 |
size | 24,191 |
Funcy is a simple function based template engine.
struct Echo();
impl funcy::PlaceholderFunction for Echo {
fn placeholder_fn_handler<'a>(&mut self, _name: &'a str, arg: &'a str) -> Result<String, String> {
Ok(arg.to_string())
}
}
let mut tr = funcy::TemplateRenderer::with_template("<!$ echo Hello>, World!");
tr.set_placeholder_fn("echo", Box::new(Echo()));
assert_eq!(tr.render().unwrap(), "Hello, World!");
struct Counter(usize);
impl funcy::PlaceholderFunction for Counter {
fn placeholder_fn_handler<'a>(&mut self, _name: &'a str, _arg: &'a str) -> Result<String, String> {
self.0 += 1;
Ok(self.0.to_string())
}
}
let mut tr = funcy::TemplateRenderer::with_template("<!$ counter> <!$ counter> <!$ counter>")
let counter = Counter(0);
tr.set_placeholder_fn("counter", Box::new(counter));
assert_eq!(tr.render().unwrap(), "1 2 3");
Funcy is distributed under the Apache-2.0 license. See the LICENSE file.