digitalmars.D.learn - Vibe.d diet templates
- JG (7/7) Jun 17 2021 Suppose I have an array of attributes and values v is there any
- WebFreak001 (19/26) Jun 17 2021 I think there is nothing for this built-in in diet, so you have
- JG (3/34) Jun 17 2021 Thanks, this works. I would have thought this would be a common
- WebFreak001 (3/7) Jun 17 2021 Opened an issue here:
- JG (2/10) Jun 17 2021 Thanks for opening that issue.
- Steven Schveighoffer (8/10) Jun 17 2021 I haven't found a need for it, as I'm usually only dynamically
- kdevel (9/14) Jun 17 2021 BTW: Is it possible to replace the diet generator in vibe.d with
- Steven Schveighoffer (16/32) Jun 17 2021 Of course. Vibe's diet support is wholly based on the diet-ng project,
Suppose I have an array of attributes and values v is there any way to apply these attributes to a tag? So that something like becomes <tag attribute0=value0 ....> where v[0][0]="attribute0" and v[0][1]="value0"?
Jun 17 2021
On Thursday, 17 June 2021 at 08:23:54 UTC, JG wrote:Suppose I have an array of attributes and values v is there any way to apply these attributes to a tag? So that something like becomes <tag attribute0=value0 ....> where v[0][0]="attribute0" and v[0][1]="value0"?I think there is nothing for this built-in in diet, so you have to manually emit raw HTML: ```diet - import std.xml : encode; - auto start = appender!string; - start ~= "<tag"; - foreach (pair; v) - start ~= " "; - start ~= pair[0].encode; - start ~= "=\""; - start ~= pair[1].encode; - start ~= '"'; - start ~= ">"; |!= start // content here |!= "</tag>" ``` Maybe some attribute splat operator would be nice for this.
Jun 17 2021
On Thursday, 17 June 2021 at 09:16:56 UTC, WebFreak001 wrote:On Thursday, 17 June 2021 at 08:23:54 UTC, JG wrote:Thanks, this works. I would have thought this would be a common enough use case to have support in diet. Anyone else wanted this?Suppose I have an array of attributes and values v is there any way to apply these attributes to a tag? So that something like becomes <tag attribute0=value0 ....> where v[0][0]="attribute0" and v[0][1]="value0"?I think there is nothing for this built-in in diet, so you have to manually emit raw HTML: ```diet - import std.xml : encode; - auto start = appender!string; - start ~= "<tag"; - foreach (pair; v) - start ~= " "; - start ~= pair[0].encode; - start ~= "=\""; - start ~= pair[1].encode; - start ~= '"'; - start ~= ">"; |!= start // content here |!= "</tag>" ``` Maybe some attribute splat operator would be nice for this.
Jun 17 2021
On Thursday, 17 June 2021 at 16:26:57 UTC, JG wrote:[...] Thanks, this works. I would have thought this would be a common enough use case to have support in diet. Anyone else wanted this?Opened an issue here: https://github.com/rejectedsoftware/diet-ng/issues/91
Jun 17 2021
On Thursday, 17 June 2021 at 18:54:41 UTC, WebFreak001 wrote:On Thursday, 17 June 2021 at 16:26:57 UTC, JG wrote:Thanks for opening that issue.[...] Thanks, this works. I would have thought this would be a common enough use case to have support in diet. Anyone else wanted this?Opened an issue here: https://github.com/rejectedsoftware/diet-ng/issues/91
Jun 17 2021
On 6/17/21 12:26 PM, JG wrote:Thanks, this works. I would have thought this would be a common enough use case to have support in diet. Anyone else wanted this?I haven't found a need for it, as I'm usually only dynamically configuring attribute values, not attribute names. But my web-fu is pretty weak. However, what I *have* wanted is to have attribute values support `Nullable!T` such that they are only included if the item is non-null. See [here](https://github.com/rejectedsoftware/diet-ng/issues/28). -Steve
Jun 17 2021
On Thursday, 17 June 2021 at 19:14:28 UTC, Steven Schveighoffer wrote:On 6/17/21 12:26 PM, JG wrote: However, what I *have* wanted is to have attribute values support `Nullable!T` such that they are only included if the item is non-null. See [here](https://github.com/rejectedsoftware/diet-ng/issues/28).BTW: Is it possible to replace the diet generator in vibe.d with a template engine like moustache [1] which is agnostic wrt the code it produces? In the past 25 or so years I frequently encountered designed HTML pages where only some data had to be inserted here or there. If I got the vibe.d model right one would have to reimplement these HTML pages in the diet language first. [1] https://github.com/repeatedly/mustache-d
Jun 17 2021
On 6/17/21 4:22 PM, kdevel wrote:On Thursday, 17 June 2021 at 19:14:28 UTC, Steven Schveighoffer wrote:Of course. Vibe's diet support is wholly based on the diet-ng project, and you don't have to use it. It's just there out of the box. when you do: ```d res.render!("sometemplate.dt", all, my, args); ``` It's just a UFCS call. You could replace this with: res.renderMustache(...) Where you have to write the adapter. It's possible to get a char output range out of HTTPServerResponse, which you then can write to and it's just sent back to the client. This seems like it would do the trick, you just have to pass the output range in as the sink: https://mustache-d.dpldocs.info/mustache.MustacheEngine.render.2.html -SteveOn 6/17/21 12:26 PM, JG wrote: However, what I *have* wanted is to have attribute values support `Nullable!T` such that they are only included if the item is non-null. See [here](https://github.com/rejectedsoftware/diet-ng/issues/28).BTW: Is it possible to replace the diet generator in vibe.d with a template engine like moustache [1] which is agnostic wrt the code it produces? In the past 25 or so years I frequently encountered designed HTML pages where only some data had to be inserted here or there. If I got the vibe.d model right one would have to reimplement these HTML pages in the diet language first. [1] https://github.com/repeatedly/mustache-d
Jun 17 2021