embd 0.1.0 - embedded D
Nathan M. Swan
nathanmswan at gmail.com
Wed Mar 6 10:08:27 PST 2013
On Wednesday, 6 March 2013 at 11:29:51 UTC, Sönke Ludwig wrote:
> 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);
Yes, my original intent was to use it in vibe.d projects.
Should I try to adopt it into vibe.d?
NMS
More information about the Digitalmars-d-announce
mailing list