vibe.d: is it possible to use bare HTML with the functionalty of DIET templates ?

Steven Schveighoffer schveiguy at gmail.com
Wed Sep 1 11:34:52 UTC 2021


On 8/31/21 8:40 PM, someone wrote:
> On Tuesday, 31 August 2021 at 14:06:32 UTC, Steven Schveighoffer wrote:
> 
>> The generation of code to output the page depends on the diet file 
>> format (i.e. code islands are designated by the leading `-`).
> 
>> However, vibe-d does not require using the diet template system.
> 
> Does that means I can still get the code islands resolved on a, say, 
> plain-XHTML file ?
> 
> Or does that means that I should output HTML/XHTML from my own functions 
> instead ?

Vibe just provides an output range for use in diet. You can use 
anything, including just writing the data yourself, or using an 
alternative template system.

>> Given how templating systems work (and how D allows strings to be used 
>> as code using mixins), it's likely pretty trivial to write a simple 
>> templating system to do this. All you need is an escape protocol that 
>> is unlikely to appear in HTML, and you can probably get away with a 10 
>> line function that doesn't need to actually parse the HTML.
> 
> Probably. Bit I am not a huge fan of modifying libraries for minor 
> functionality fixes (unless is really really necessary). For whatever 
> reasons I already have custom nginx builds etc etc so I do not want to 
> keep tracking and fixing more software -in the end is a pain-in-the-ass.

You aren't modifying anything. Vibe-d provides default access to 
diet-ng, but you have no obligation to use it. Just use the output range 
(`HTTPServerResponse.bodyWriter`) and hook up your preferred templating 
system.

I think you are misunderstanding the architecture of vibe. There is no 
need to replace anything inside vibe to use a different templating 
system, it does not depend on diet at all, just provides default access.

The views directory isn't exactly special either (though there may be 
code in dub that deals with looking at modification times), nor is the 
extension `.dt`.

Most of the diet compiler is dealing with transforming the pug format 
into HTML, and proper string interpolation. The code island stuff is 
quite trivial (just copied as-is).

Oh, and I realized I forgot about string interpolation. You definitely 
want a way to change D expressions into string output. You can still do 
this with code-islands, but a good template system would handle the 
boilerplate for you.

Which leads me to -- diet really should be split into 2 parts, one that 
handles the pug parsing and compiling, and one that handles proper 
string interpolation. Then you could leverage that second part.

-Steve


More information about the Digitalmars-d-learn mailing list