mustache / spec

The Mustache spec.
MIT License
364 stars 71 forks source link

Feature/conditional block #22

Closed wesen closed 7 years ago

wesen commented 13 years ago

I'm writing a compiler, and for efficiency purposes (and also template "clarity", in that i can see when a conditional is meant rather than iteration/lambda/new context/conditional), I decided to add a {{?test}} construct that can be used for conditionals. Also allows a kind of shortcut syntax {{?test}}then{{^test}}else{{/test}}.

let me know what you think.

zeelot commented 13 years ago

+1, having to make a new method for checking whether something is empty before iterating over it is quite annoying. (I hope this is what I think it is O_o)

wesen commented 13 years ago

the way i implemented it is actually not for iteration. For iteration, usually, this should work, depending on the truthiness semantics of your implementation language

{{#product}}
Name: {{name}}
{{/product}}
{{^product}}
No products.
{{/product}}

Where is clear that you want to iterate over products. I use the above for things like:

{{?isLoggedIn}}Hello {{user}}.{{^isLoggedIn}}Login{{/isLoggedIn}}
spullara commented 12 years ago

I've implemented the ? tag but didn't do the else. Looks like a reasonable idea to me.

Baggz commented 12 years ago

+1

ghost commented 7 years ago

It appears that d5c6d4e does not belong into this pull request.

ghost commented 7 years ago

What was the reason for closing this?

wesen commented 7 years ago

Just closing after 5 years to clean up my open pull request view :)

On Aug 22, 2017, at 1:55 PM, Dennis Schridde notifications@github.com wrote:

What was the reason for closing this?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/mustache/spec/pull/22#issuecomment-324003823, or mute the thread https://github.com/notifications/unsubscribe-auth/AAH1uYpMQ5448W36uVDOk3kJr0m4en1Pks5sasGwgaJpZM4LwmW5.

ghost commented 7 years ago

Shall I submit the patch in a new pull request?

wesen commented 7 years ago

Sure, go ahead. I’m happy to reopen the pull-requests too if that is easier?

ghost commented 7 years ago

That would probably be easier, yes. Are you still maintaining the specification and do you plan to make changes like these?

wesen commented 7 years ago

Oh I’m not the maintainer of mustache, and in fact I haven’t done any web development in the last 5 years. I don’t see myself working on this any time in the future either.

On Aug 23, 2017, at 1:57 PM, Dennis Schridde notifications@github.com wrote:

That would probably be easier, yes. Are you still maintaining the specification and do you plan to make changes like these?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/mustache/spec/pull/22#issuecomment-324306566, or mute the thread https://github.com/notifications/unsubscribe-auth/AAH1uSQ7otAOh-hSe4Iw0OZcKdKNahnoks5sbBOegaJpZM4LwmW5.