In table can not process by function and other limation
Opened this issue · 0 comments
damody commented
#[derive(Clone, ZapperRunner, Serialize)]
#[filter = "checkshow/0s"]
struct Team {
idx: i32,
name: String,
score: u8,
}
fn checkshow(_data: &Team, _args: &[f64], input: &str, buffer: &mut String) {
if (_data.idx == 0) {
buffer.push_str("champion");
}
}
#[derive(ZapperEnv)]
#[runner = "Team"]
struct Provider {
year: u32,
}
pub fn teams(b: &mut criterion::Bencher, _: &usize) {
use serde_json::value::Map;
let template = "<html>
<head>
<title>{{year}}</title>
</head>
<body>
<h1>CSL {{year}}</h1>
<ul>
{{#each group as |p| ~}}
<li class=\"{{p.name | checkshow}}\">
<b>{{p.name}}</b>: {{p.score}}
</li>
{{/each~}}
</ul>
</body>
</html>";
// build up a group of 1000 (similar) people
let mut group = vec![
Team { idx: 0, name: "Jiangsu".into(), score: 43 },
Team { idx: 1, name: "Beijing".into(), score: 27 },
Team { idx: 2, name: "Guangzhou".into(), score: 22 },
Team { idx: 3, name: "Shandong".into(), score: 12 },
];
let mut data = Map::new();
data.insert("year".to_string(), to_json(&"2015".to_string()));
let mut handlebars = Handlebars::new();
handlebars
.register_template_string("table", template)
.unwrap();
b.iter(|| {
let mut data = data.clone();
data.insert("group".to_string(), to_json(&group));
handlebars.render("table", &data).unwrap()
});
}
In this template, I just need for loop index and input constant string
like {{"champion" | checkshow}} or move champion to ZapperEnv
But 1. ZapperEnv can't use filter function
But 2. the template can't input constant string,
So I modify struct "Team", add member called idx.
But I found only input string can output string.
So I modify {{p.idx | checkshow}} to {{p.name | checkshow}}
It's not work.
{{#each group as |p| ~}}
<li class=\"{{p.name | checkshow}}\">
<b>{{p.name}}</b>: {{p.score}}
</li>
{{/each~}}
// this part always get Error:"InvalidSyntax"
Why I do that?
To add zapper into this https://github.com/damody/template-benchmarks-rs
please fix zapper functional to run the benchmark.