Am 06.03.2013 10:08, schrieb Nathan M. Swan: > Announcing the release of embd, a low-level (i.e. small) API for > embedding D code into text: > > https://github.com/carlor/embd > > It's a bit of an inconvenient API, but it's customizable and gives the > client control in what gets passed to the template. > > I hope some of you find it useful! > > NMS
Great, finally something that works for plain text files! I guess a simple wrapper could make it work with a similar interface to vibe.d's Diet templates (slightly ugly with that struct because of the additional range template argument and not tested at all): struct renderEmbd(string FILE, ALIASES...) { class Context(R) : emdb.Context { R* _output; mixin(renderer); void write(string content, dchar evalCode){ if (evalCode == '=') filterHtmlEscape(*_output, content); else _output.put(content); } } static void opCall(R)(ref R output_range) { static Context!R ctx; if( !ctx ) ctx = new Context!R; ctx._output = &output_range; scope(exit) ctx._output = null; ctx.render!(import(FILE), `!=`, `<%`, `%>`)(); } } Usage: auto dst = appender!string(); renderEmbd!("userprofile.embd.html", username, title, biography)(dst);