nickel-org / rust-mustache

mustache template library for rust
Other
202 stars 61 forks source link

Bug: Partials don't inherit indentation #78

Open a-lafrance opened 2 years ago

a-lafrance commented 2 years ago

When using a partial with indentation, only the first line is indented; the rest of the partial is rendered unindented. However, partials must inherit indentation as described in the spec, so I think this is a bug?

Here's a minimal example to reproduce the issue:

#[macro_use]
extern crate serde_derive;

use maplit::hashmap;
use std::io;

#[derive(Serialize)]
struct Person {
    name: String,
}

fn main() {
    let template = mustache::compile_path("greet_all.mustache").unwrap();
    let people = hashmap! { "people" => vec![
        Person { name: "Alice".to_string() },
        Person { name: "Bob".to_string() },
    ]};

    template.render(&mut io::stdout(), &people).unwrap();
    println!();
}

Given templates:

{{! greet.mustache }}
hello {{{name}}}
nice to see you today
{{! greet_all.mustache }}
{{#people}}
    {{> greet}}
{{/people}}

It should print:

    hello Alice
    nice to see you today

    hello Bob
    nice to see you today

But prints:

    hello Alice
nice to see you today

    hello Bob
nice to see you today