<commit_before>iron-tera
-------


This is a [Tera](https://github.com/Keats/tera/) middleware for [Iron](https://github.com/iron/iron/).

After the initial template engine is created, you can render templates in a given handler using either a Tera `Context`, or a value that implementes serde's `Serialize`.

```rust
fn main() {
    let mut router = Router::new();
    router.get("/user", user_handler, "user");

    let mut chain = Chain::new(router);
    let teng = TeraEngine::new("src/examples/templates/**/*"); // create tera engine from these templates
    chain.link_after(teng);

    Iron::new(chain).http("localhost:5000").unwrap();
}

fn user_handler(_: &mut Request) -> IronResult<Response> {
    let mut resp = Response::new();

    // Use a context
    let mut context = Context::new();
    context.add("username", &"Bob");
    context.add("numbers", &vec![1, 2, 3]);<commit_msg>add import to README.md example<commit_after>iron-tera
-------


This is a [Tera](https://github.com/Keats/tera/) middleware for [Iron](https://github.com/iron/iron/).

After the initial template engine is created, you can render templates in a given handler using either a Tera `Context`, or a value that implementes serde's `Serialize`.

```rust
extern crate iron_tera;

use iron_tera::{TeraEngine, Template, TemplateMode};

fn main() {
    let mut router = Router::new();
    router.get("/user", user_handler, "user");

    let mut chain = Chain::new(router);
    let teng = TeraEngine::new("src/examples/templates/**/*"); // create tera engine from these templates
    chain.link_after(teng);

    Iron::new(chain).http("localhost:5000").unwrap();
}

fn user_handler(_: &mut Request) -> IronResult<Response> {
    let mut resp = Response::new();

    // Use a context
    let mut context = Context::new();
    context.add("username", &"Bob");
    context.add("numbers", &vec![1, 2, 3]);
{'fraction_non_alphanumeric': 0.16728624535315986, 'fraction_numerical': 0.007434944237918215, 'mean_word_length': 3.9448818897637796, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '36370', 'n_tokens_mistral': 595, 'n_tokens_neox': 568, 'n_words': 174}