maciejhirsz/ramhorns

Add support for dot notation

thesurlydev opened this issue · 4 comments

For example,

{{#some_value}}
{{.}}
{{/some_value}}

I am looking to add this to the rust template benchmark but I think dot notation is required to do it properly.

It shouldn't be too hard to do, I've commented on this in previous issue.

@Th3Whit3Wolf I assume this is mostly for repeated sections?

@maciejhirsz yeah I have something like this

#[derive(Content)]
struct BigTable {
    table: Vec<Vec<usize>>,
}

static BIG_TABLE_TEMPLATE: &'static str = "<table>\
{{#table}}\
<tr>{{#.}}<td>{{.}}</td>{{/.}}</tr>\
{{/table}}\
</table>";

pub fn big_table(b: &mut criterion::Bencher<'_>, size: &usize) {
    let mut table = Vec::with_capacity(*size);
    for _ in 0..*size {
        let mut inner = Vec::with_capacity(*size);
        for i in 0..*size {
            inner.push(Value::Scalar((i as i32).into()));
        }
        table.push(Value::Array(inner));
    }

    let big_table_data = BigTable {
        table
    };

    let template = Template::new(BIG_TABLE_TEMPLATE).unwrap();

    b.iter(|| template.render(&big_table_data {

    }));
}

Where I need to access the value of a Vec<Vec<usize>>

Is there a way to do something like {{a.b.c}}, right now it doesn't seem to work.