Jump to page: 1 2 3
Thread overview
New Diet template engine almost complete, ready for comments
Jul 25, 2016
Sönke Ludwig
Jul 25, 2016
Stefan Koch
Jul 25, 2016
rikki cattermole
Jul 25, 2016
lqjglkqjsg
Jul 25, 2016
Karabuta
Jul 25, 2016
Sebastiaan Koppe
Jul 26, 2016
Puming
Jul 26, 2016
Rory McGuire
Jul 26, 2016
Sönke Ludwig
Jul 26, 2016
Rory McGuire
Jul 26, 2016
Rory McGuire
Jul 26, 2016
Puming
Jul 28, 2016
Sönke Ludwig
Jul 28, 2016
Chris
Jul 28, 2016
Rory McGuire
Jul 28, 2016
rikki cattermole
Jul 28, 2016
Sönke Ludwig
Jul 28, 2016
WhatMeWorry
Jul 28, 2016
Sönke Ludwig
Jul 29, 2016
Chris
Jul 29, 2016
Sönke Ludwig
July 25, 2016
The Diet template language is aimed at providing a way to define procedurally generated HTML/XML pages (or other output formats), with minimal visual noise. Syntax and feature set are heavily inspired by Jade <http://jade-lang.org/>, but instead of JavaScript, all expressions and statements are D statements, and everything that can be done at compile-time is done at compile-time.

Vibe.d still contains the original implementation, which was written around the limitations of DMD's CTFE engine back years ago, and is basically a monolithic parser+generator with little flexibility and a number of convenience features missing, because of their implementation complexity. The new implementation has been rewritten cleanly, with separate parser, modifier and generator modules, working on a common DOM tree intermediate representation.

The major new features/improvements are:

  - No external dependencies other than Phobos
  - Supports inline and nested tags syntax
  - Supports string interpolations within filter nodes (falls back to
    runtime filters)
  - Supports AngularJS special attribute names
  - Extensible/configurable with traits structures
  - Uses less memory during compilation (this one was a real surprise)
  - (Unit) tested from the start
  - Supports arbitrary uses other than generating HTML, for example we
   use it similar to QML/XAML for our internal UI framework

The API documentation can be shown ba running DUB:
   dub fetch diet-ng --version=1.0.0-alpha.2
   dub run diet-ng -b ddox

You can try the library directly, or together with the latest alpha release of vibe.d (0.7.30-alpha.3). Simply add a dependency to "diet-ng", version "~>1.0.0-alpha.2". Vibe.d will automatically re-route render!(...) calls to diet-ng.

A small example with just the most essential features is shown in the README:
https://code.dlang.org/packages/diet-ng

More complex real-world examples:
https://github.com/rejectedsoftware/vibed.org/tree/master/views
https://github.com/rejectedsoftware/ddox/tree/master/views

Any comments/requests regarding the feature set or API are highly welcome!
July 25, 2016
On Monday, 25 July 2016 at 09:29:38 UTC, Sönke Ludwig wrote:
> The Diet template language is aimed at providing a way to define procedurally generated HTML/XML pages (or other output formats), with minimal visual noise. Syntax and feature set are heavily inspired by Jade <http://jade-lang.org/>, but instead of JavaScript, all expressions and statements are D statements, and everything that can be done at compile-time is done at compile-time.
>
> [...]

This is great news.
diet-ng is so much cleaner!

July 25, 2016
Hmm, I wonder if it could be extended to also do json as well as xml like.
July 25, 2016
On Monday, 25 July 2016 at 09:29:38 UTC, Sönke Ludwig wrote:
> The Diet template language is aimed at providing a way to define procedurally generated HTML/XML pages (or other output formats), with minimal visual noise. Syntax and feature set are heavily inspired by Jade <http://jade-lang.org/>, but instead of JavaScript, all expressions and statements are D statements, and everything that can be done at compile-time is done at compile-time.
> [...]
> Any comments/requests regarding the feature set or API are highly welcome!

I think I'm gonna test it to make my GH blog. It looks perfectly adapted.
July 25, 2016
On Monday, 25 July 2016 at 09:29:38 UTC, Sönke Ludwig wrote:
> The Diet template language is aimed at providing a way to ...

>   - Supports AngularJS special attribute names

Is there a way to get react JS to work with vibe.d in anyway(server-side)?



July 25, 2016
On Monday, 25 July 2016 at 20:42:51 UTC, Karabuta wrote:
> On Monday, 25 July 2016 at 09:29:38 UTC, Sönke Ludwig wrote:
>> The Diet template language is aimed at providing a way to ...
>
>>   - Supports AngularJS special attribute names
>
> Is there a way to get react JS to work with vibe.d in anyway(server-side)?

Without a JS engine that is going to be pretty hard. Or ugly. Basically you would be duplicating a lot of stuff.

I would probably use node.js to do an initial render. And keep all the data/api endpoints in vibe.
July 26, 2016
On Monday, 25 July 2016 at 09:29:38 UTC, Sönke Ludwig wrote:
> The Diet template language is aimed at providing a way to define procedurally generated HTML/XML pages (or other output formats), with minimal visual noise. Syntax and feature set are heavily inspired by Jade <http://jade-lang.org/>, but instead of JavaScript, all expressions and statements are D statements, and everything that can be done at compile-time is done at compile-time.
>
> [...]

A feature I want the most for Diet is the ability to parse Diet templates at RUNTIME instead of compile time with a switch, similar to Regex/CtRegex.

In this way one can do quick turnarounds in dev mode, tweaking little corners of the pages, and then when a page is finished, it can be switched to compile mode for faster render time.

Do you think this is feasible?
July 26, 2016
On Tue, Jul 26, 2016 at 5:22 AM, Puming via Digitalmars-d-announce < digitalmars-d-announce@puremagic.com> wrote:

> On Monday, 25 July 2016 at 09:29:38 UTC, Sönke Ludwig wrote:
>
>> The Diet template language is aimed at providing a way to define procedurally generated HTML/XML pages (or other output formats), with minimal visual noise. Syntax and feature set are heavily inspired by Jade < http://jade-lang.org/>, but instead of JavaScript, all expressions and statements are D statements, and everything that can be done at compile-time is done at compile-time.
>>
>> [...]
>>
>
> A feature I want the most for Diet is the ability to parse Diet templates at RUNTIME instead of compile time with a switch, similar to Regex/CtRegex.
>
> In this way one can do quick turnarounds in dev mode, tweaking little corners of the pages, and then when a page is finished, it can be switched to compile mode for faster render time.
>
> Do you think this is feasible?
>

Hi Puming,

You could use some sort of dialect of JS that is close to D, and then alter
the diet template engine so that is doesn't evaluate the code sections with
some sort of CT switch.
Or you could use my Jaded templates which is basically the same but runs at
compile time or runtime (at runtime you would again have to use a language
with an interpreter.)

I think if you took, vibe.d/diet-ng + arsd/jsvar as your compile time stack, you could find a common denominator so that you could use (node.js + webpack + pug) to do the fast (live) edits of the templates.


July 26, 2016
Am 26.07.2016 um 05:22 schrieb Puming:
> On Monday, 25 July 2016 at 09:29:38 UTC, Sönke Ludwig wrote:
>> The Diet template language is aimed at providing a way to define
>> procedurally generated HTML/XML pages (or other output formats), with
>> minimal visual noise. Syntax and feature set are heavily inspired by
>> Jade <http://jade-lang.org/>, but instead of JavaScript, all
>> expressions and statements are D statements, and everything that can
>> be done at compile-time is done at compile-time.
>>
>> [...]
>
> A feature I want the most for Diet is the ability to parse Diet
> templates at RUNTIME instead of compile time with a switch, similar to
> Regex/CtRegex.
>
> In this way one can do quick turnarounds in dev mode, tweaking little
> corners of the pages, and then when a page is finished, it can be
> switched to compile mode for faster render time.
>
> Do you think this is feasible?

A real runtime solution would require a D runtime interpreter or JIT compiler. There would be an alternative solution based on compiling each template to a shared library and then dynamically recompiling/reloading those as required, but that currently doesn't work due to the alias parameter based interface of render!(...).

However, what should work well is a combination of https://github.com/dlang/dub/pull/446 and https://github.com/rejectedsoftware/vibe.d/pull/1385 - I'll merge the latter one into vibe.d master today. It will require to store session information and similar things in an external store, and on Linux the Gold linker should be used for speed, but then it should be almost as good as a runtime solution.
July 26, 2016
On Tue, Jul 26, 2016 at 7:54 AM, Sönke Ludwig < digitalmars-d-announce@puremagic.com> wrote:

> Am 26.07.2016 um 05:22 schrieb Puming:
>
>> On Monday, 25 July 2016 at 09:29:38 UTC, Sönke Ludwig wrote:
>>
>>> The Diet template language is aimed at providing a way to define procedurally generated HTML/XML pages (or other output formats), with minimal visual noise. Syntax and feature set are heavily inspired by Jade <http://jade-lang.org/>, but instead of JavaScript, all expressions and statements are D statements, and everything that can be done at compile-time is done at compile-time.
>>>
>>> [...]
>>>
>>
>> A feature I want the most for Diet is the ability to parse Diet templates at RUNTIME instead of compile time with a switch, similar to Regex/CtRegex.
>>
>> In this way one can do quick turnarounds in dev mode, tweaking little corners of the pages, and then when a page is finished, it can be switched to compile mode for faster render time.
>>
>> Do you think this is feasible?
>>
>
> A real runtime solution would require a D runtime interpreter or JIT compiler. There would be an alternative solution based on compiling each template to a shared library and then dynamically recompiling/reloading those as required, but that currently doesn't work due to the alias parameter based interface of render!(...).
>
> However, what should work well is a combination of https://github.com/dlang/dub/pull/446 and https://github.com/rejectedsoftware/vibe.d/pull/1385 - I'll merge the latter one into vibe.d master today. It will require to store session information and similar things in an external store, and on Linux the Gold linker should be used for speed, but then it should be almost as good as a runtime solution.
>

!! nice, this is going to make my work life so much easier.

Thanks Sönke!


« First   ‹ Prev
1 2 3