funcy

Crates.iofuncy
lib.rsfuncy
version1.0.0
sourcesrc
created_at2020-12-05 19:20:46.809614
updated_at2020-12-06 20:01:16.192466
descriptionSimple function based template engine
homepagehttps://github.com/camc/funcy
repositoryhttps://github.com/camc/funcy
max_upload_size
id319916
size24,191
(camc)

documentation

https://docs.rs/funcy/

README

Funcy Crates.io Status Documentation

Funcy is a simple function based template engine.

Examples

Echo

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!");

Counter

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");

License

Funcy is distributed under the Apache-2.0 license. See the LICENSE file.

Commit count: 0

cargo fmt