On Wed, 11 Sep 2013 12:34:37 GMT, Ľudovít Lučenič wrote:

Dňa 11.9.2013 12:07 Sönke Ludwig wrote / napísal(a):> On Wed, 11 Sep 2013 08:44:46 GMT, Ľudovít Lučenič wrote:

Hello,

I have a question regarding dynamic generation of a diet template to be used for generating the very response the request for which implied the dynamic generation of a template itself. I mean no file write/read step during the response process.
It's enough for me, if you redirect me to some portion of documentation, if this is already possible.
If it is not, I would like to discuss the topic.
Thank you very much in advance.

Ludovit

Since the templates are compiled to D code while the project is built, there is no way to actually generate them at run time (and due to the possibility to embed D code there is also no way to make this work without a JIT compiler of some kind).

However, there are numerous possibilities to control program flow and thus compose different building blocks. Most importantly, arbitrary D control statements can be used and mixed with HTML nodes (see http://vibed.org/templates/diet#procedural-content and http://vibed.org/templates/diet#functions).

Additionally, blocks/extensions and includes can be used to help composition of different templates. Unfortunately, this part of the documentation still needs to be written, but they are more or less equivalent to what Jade offers: https://github.com/visionmedia/jade/blob/master/jade-language.md#template-inheritance and https://github.com/visionmedia/jade/blob/master/jade-language.md#includes

A relatively simple example that uses these features is vibelog: https://github.com/rejectedsoftware/vibelog/blob/master/views/vibelog.postlist.dt

Hallo Sönke,

thank you for the hints. I'll take a closer look at it.

Basically I am interested in making web based editor, that could edit its own sources. I have seen this presentation from Vladimir at DConf 2013 where he pointed out there is some way in making this feasible. I mean, having a compiler in operation at the web back-end.

However, I may help with your docs when I found something useful in the codes in the end :-)

Regards,

Ludovit

I think I have to watch the video again there... but I mean considering that using shared libraries has become a lot better in the current git version of DMD, it could indeed work to dynamically compile a template as a shared library and dynamically load that in the running application. It would involve writing a file on disk, though, and would require stepping into slightly adventurous terrain (the very early shared library support that AFAIK only works on Linux so far).

But hopefully using dynamic control flow inside of a static template will be enough here. Helping with documentation is of course highly welcome - after all this surely is the worst part of any project ;) (damn, I need to force myself to do more documentation work ;))