On Fri, 25 Feb 2011 17:29:53 +0900, dennis luehring <dl.so...@gmx.net>
wrote:
Am 24.02.2011 18:57, schrieb Masahiro Nakagawa:
3 weeks ago, I discussed template engine with Goro Fuji(a.k.a Xslate
author).
In the process, I noticed D does not have template engine library.
So I wrote the D version of Mustache.
https://bitbucket.org/repeatedly/mustache4d/src
would be great to have this available at compiletime - something like an
write(ln) with typeckecks and block functionality :)
with a nice inner mixin that generates an frontend for the template-vars
a little bit like the
http://www.digitalmars.com/d/2.0/phobos/std_bitmanip.html bitfield!
template
example-style refering to your basic.d example
--- basic.mustache ---
Hello {{name:%s}}
You have just won ${{value:%i}}!
{{#in_ca}}
Well, ${{taxed_value:%f}}, after taxes.
{{/in_ca}}
-----------------------
alias MustacheEngine!(string,import("basic.mustache"))
My_Special_Template;
void main()
{
My_Special_Template my_special_template;
my_special_template.name = "Chris";
my_special_template.value = 10000;
auto in_ca_section = my_special_template.in_ca.create();
in_ca_section.taxted_value = 10000 - (10000 * 0.4);
write(my_special_template.render());
}
In the old days, I implemented the compile-time template engine using
similar approch :)