Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular/Mustache-like templates for vibe.d? #1134

Open
IgorStepanov opened this issue Jun 12, 2015 · 2 comments
Open

Angular/Mustache-like templates for vibe.d? #1134

IgorStepanov opened this issue Jun 12, 2015 · 2 comments

Comments

@IgorStepanov
Copy link
Contributor

Hello. As I see, vibe.d has only one template tool: diet.
Without going into the debate about diet advantages/disadvantages, we have to admit that it looks strange for a beginner, and not always attractive for the experienced user.
I suggest to add alternative template tool, similar to mustache templates. In this case, templates in vibe.d seem comfortable for the majority of web programmers.
Now about implementation: I have one implementation of templates. Initially, it didn't make for vibe.d, however I ready to adapt it to the requirements of vibe.d
What it can:

{{#import common/common.dsp}} <!-- Import macroses for another file. -->

<!-- Insert `test_1` value from the model, which passed to template processor. -->
simple text{{test_1}}text 

<!-- Different expressions are allowed (in this case, built-in function 'fxx.bar' is called).
You able to register your built-in values for the temlplate processor.
-->
{{fxx.bar()}} 
{{fxx.bar("}}")}}

<!-- If-then-else statement. All variables is taken from `Model` -->
{{#if foo != boo}}
Yes
{{#else}}
No
{{/#if}}

<!-- Foreach construction. key and foo values inside foreach hides a global key and foo values -->
{{#foreach key, foo; array}}
    {{key}} => {{foo.val}}
{{/#foreach}}
{{foo}}

<!-- My templates allow to be extended with the user constructions. They should be declared in D. swich-case is the one of them. -->
{{#switch 1 + 1}}
{{#case 1}}
One
{{/#case}}
{{#case 2}}
Two
{{/#case}}
{{#default}}
Unknown
{{/#default}}
{{/#switch}}

<!-- Macros (subtemplate), which takes two arguments. -->
{{@mySub a, b}}
    {{#if a}}
             <p>{{b}}</p>
             {{&mySub a - 1, b}} <!--recursion is allowed-->
        {{/#if}}
{{/@mySub}}


{{&mySub 3, "BOOM"}} <!-- Writes "BOOM" three times -->
{{&myCommonSub "foo"}} <!-- Call a subtemplate from imported file. -->

{{{<html>}}} <!-- Encode html, writes "&lt;html&gt;" -->
@s-ludwig
Copy link
Member

There is already a Mustache template implementation (mustache-d), as well as some similar libraries: temple, embd

All of them can work with vibe.d, and I think one of them (I think "temple") has some additional convenience functions for seamless integration into vibe.d apps.

The plan for vibe.d is to eventually split up the library into separate DUB packages, so any new templating solution should already be implemented as a separate package, too. Your implementation looks to have some advanced syntax features - I think some more than mustache-d -, so maybe it makes sense to simply try to extend mustache-d?

@Geod24
Copy link
Contributor

Geod24 commented Jun 12, 2015

The plan for vibe.d is to eventually split up the library into separate DUB packages, so any new templating solution should already be implemented as a separate package, too.

On that topic, do you plan to create a Vibe.d organization, or similar, where project that officially integrate with Vibe.d (and are well tested) are put ? I can foresee some compatibility issues with the moving targets that D and Vibe.d are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants