Temple v0.7.0: New API, Fewer Allocations

Dylan Knutson via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Sat Nov 22 16:32:18 PST 2014


Hey all,

I'd like to announce the release of Temple 0.7.0, a compile time
templating engine for D. It's been a while since the last major
release, and 0.7.0 brings a lot of changes and enhancements.

Temple is a library for embedding arbitrary D code in text
templates, similar to Vibe.d's Diet, or JS's Jade, but agnostic
about the format of the text that it should output (much more
similar to Ruby's ERB).

An example, dynamically rendering text with embedded D code:

---
auto hello = compile_temple!("Hello, <%= var.name %>");
auto ctx = new TempleContext;
ctx.name = "Walter";
writeln(hello.toString(ctx)); // Writes "Hello, Walter" to stdout
hello.render(stdout, ctx);    // also writes "Hello, Walter" to
stdout
---

Templates can be arbitrarily nested, and the library includes a
feature for 'yield'ing partial templates into a larger layout
template. The "Filter" feature can dynamically transform template
text as it's written to the output buffer, and can be used to
build concepts like Safe Strings and automatic HTML escaping
filters.

I encourage you to look at some of the examples in the (fairly
extensive) README.
Here's the GitHub repo: https://github.com/dymk/temple

For previous users of Temple, I'm sorry that the API has broken
backwards compatibility. If you'd like to keep the old API,
please keep tracking the 0.6.x versions. However, upgrading to
0.7.x should be a straightforward task of changing some 'alias'es
to 'auto', and 'Temple{etc}' to 'compile_temple_{etc}'. More
information on upgrading is available on the release page, here:
https://github.com/dymk/temple/releases/tag/v0.7.0

Thank you!
-- Dylan


More information about the Digitalmars-d-announce mailing list