Add {{elseif}} sugar syntax #50

Closed
wants to merge 7,343 commits into
from

Conversation

Projects
None yet
@nathantreid

Implements #39.

{{#if counterIsAt 2}}
    test
{{elseif counterIsAt 3}}
    test3
{{elseif counterIsAt 4}}
    test4
{{else}}
    test5
{{/if}}

Working example here: https://github.com/nathantreid/blaze-test-issue-39

benjamn and others added some commits Dec 18, 2015

alexandesigner and others added some commits Sep 5, 2016

Merge pull request #85 from alexandesigner/master
Updates of documentation improvements
Update of readme (packages)
- Blaze;
- Templating;
- Spacebars;
- Spacebars Compiler;
@mitar

This comment has been minimized.

Show comment
Hide comment
@mitar

mitar Sep 8, 2016

Collaborator

@alexandesigner: This broke deployment. You removed this dependency.

Collaborator

mitar commented on site/package.json in d36d0a6 Sep 8, 2016

@alexandesigner: This broke deployment. You removed this dependency.

This comment has been minimized.

Show comment
Hide comment
@alexandesigner

alexandesigner Sep 9, 2016

Collaborator

Our.. Haha, sorry for the oversight.

Collaborator

alexandesigner replied Sep 9, 2016

Our.. Haha, sorry for the oversight.

@mitar

This comment has been minimized.

Show comment
Hide comment
@mitar

mitar Sep 8, 2016

Collaborator

@nathantreid: This is great work. Can you please resolve merge conflicts? And add also all changes to documentation (spacebars API, mention this also somewhere in guide, blaze itself, and so on)?

We have now documentation in this repository, so you can just update this pull request.

Collaborator

mitar commented Sep 8, 2016

@nathantreid: This is great work. Can you please resolve merge conflicts? And add also all changes to documentation (spacebars API, mention this also somewhere in guide, blaze itself, and so on)?

We have now documentation in this repository, so you can just update this pull request.

@mitar

This comment has been minimized.

Show comment
Hide comment
@mitar

mitar Sep 9, 2016

Collaborator

BTW, Handlebars seems to have else if.

See also example in documentation. It seems the syntax is:

{{else if isInactive}}

And also:

{{else unless isInactive}}

Or in general it seems it can be {{else <any block helper>}}.

It is not necessary to use the same helper in subsequent calls, the unless helper could be used in the else portion as with any other helper. When the helper values are different, the closing mustache should match the opening helper name.

While I dislike this syntax, I see benefit of having it match Handlebars, and benefit of supporting any block helper. Implementation might be a bit trickier to implement, but this sugar is easy to do:

{{#if foo}}

{{else something bar}}

{{/if}}

Becomes:

{{#if foo}}

{{else}}
  {{#something bar}}

  {{/something}}
{{/if}}

@nathantreid, could you implement it this way?

Collaborator

mitar commented Sep 9, 2016

BTW, Handlebars seems to have else if.

See also example in documentation. It seems the syntax is:

{{else if isInactive}}

And also:

{{else unless isInactive}}

Or in general it seems it can be {{else <any block helper>}}.

It is not necessary to use the same helper in subsequent calls, the unless helper could be used in the else portion as with any other helper. When the helper values are different, the closing mustache should match the opening helper name.

While I dislike this syntax, I see benefit of having it match Handlebars, and benefit of supporting any block helper. Implementation might be a bit trickier to implement, but this sugar is easy to do:

{{#if foo}}

{{else something bar}}

{{/if}}

Becomes:

{{#if foo}}

{{else}}
  {{#something bar}}

  {{/something}}
{{/if}}

@nathantreid, could you implement it this way?

@stubailo

This comment has been minimized.

Show comment
Hide comment
@stubailo

stubailo Sep 9, 2016

Contributor

Yikes.... that seems kind of odd. Are we sure we want to think about handlebars at all? Honestly Handlebars doesn't seem that well designed to start with.

Contributor

stubailo commented Sep 9, 2016

Yikes.... that seems kind of odd. Are we sure we want to think about handlebars at all? Honestly Handlebars doesn't seem that well designed to start with.

@mitar

This comment has been minimized.

Show comment
Hide comment
@mitar

mitar Sep 9, 2016

Collaborator

For this particular feature I think I would. I would change what this means inside a template, but for syntax I would try to stick with Handlebars.

Collaborator

mitar commented Sep 9, 2016

For this particular feature I think I would. I would change what this means inside a template, but for syntax I would try to stick with Handlebars.

@mitar

This comment has been minimized.

Show comment
Hide comment
@mitar

mitar Sep 9, 2016

Collaborator

Also, this syntax seems to map nicely to the sugar we are trying to make.

Collaborator

mitar commented Sep 9, 2016

Also, this syntax seems to map nicely to the sugar we are trying to make.

@nathantreid

This comment has been minimized.

Show comment
Hide comment
@nathantreid

nathantreid Sep 9, 2016

I also think that the {{else if}} syntax looks odd, perhaps we could put that up for a vote?
I personally don't have any desire to match Handlebars going forward, unless of course it's because the syntax actually makes a lot of sense on its own.

nathantreid commented Sep 9, 2016

I also think that the {{else if}} syntax looks odd, perhaps we could put that up for a vote?
I personally don't have any desire to match Handlebars going forward, unless of course it's because the syntax actually makes a lot of sense on its own.

@mitar

This comment has been minimized.

Show comment
Hide comment
@mitar

mitar Sep 9, 2016

Collaborator

It is not just a syntax here, but also a feature. So that you can use any block helper in this way. elseif does not support that. I think that a feature of else <blockname> is a good one. I use quite some custom block helpers (Blaze Components add extra power to them).

Collaborator

mitar commented Sep 9, 2016

It is not just a syntax here, but also a feature. So that you can use any block helper in this way. elseif does not support that. I think that a feature of else <blockname> is a good one. I use quite some custom block helpers (Blaze Components add extra power to them).

@bengott

This comment has been minimized.

Show comment
Hide comment
@bengott

bengott Sep 14, 2016

Contributor

'Edit on GitHub' links are broken

I'm not very familiar with Hexo config files, but it looks like github_repo and content_root are used to generate the orange 'Edit on GitHub' link buttons. After looking at the history, it appears that these two lines have changed a few times in the process of moving things around.

I had a PR in the works, but given my lack of experience with Hexo, I figured it would be best to comment here first. I'm assuming that changing content_root: 'site' to content_root: 'site/source'will fix the links. Am I correct? @mitar @alexandesigner

Contributor

bengott commented on 6af0a1b Sep 14, 2016

'Edit on GitHub' links are broken

I'm not very familiar with Hexo config files, but it looks like github_repo and content_root are used to generate the orange 'Edit on GitHub' link buttons. After looking at the history, it appears that these two lines have changed a few times in the process of moving things around.

I had a PR in the works, but given my lack of experience with Hexo, I figured it would be best to comment here first. I'm assuming that changing content_root: 'site' to content_root: 'site/source'will fix the links. Am I correct? @mitar @alexandesigner

This comment has been minimized.

Show comment
Hide comment
@mitar

mitar Sep 14, 2016

Collaborator

Yea, I am not sure what was the change here, @stubailo?

Collaborator

mitar replied Sep 14, 2016

Yea, I am not sure what was the change here, @stubailo?

This comment has been minimized.

Show comment
Hide comment
@stubailo

stubailo Sep 14, 2016

Contributor

ohh, yeah perhaps that is better. It didn't work before I made this change either though. I thought this would be it but it wasn't.

Contributor

stubailo replied Sep 14, 2016

ohh, yeah perhaps that is better. It didn't work before I made this change either though. I thought this would be it but it wasn't.

This comment has been minimized.

Show comment
Hide comment
@mitar

mitar Sep 14, 2016

Collaborator

:-)

@bengott: Thanks for looking into this. I suggest you simply do your changes locally and then run Hexo locally and see what is the result and if links work. You can see how to do that in README in site directory.

Collaborator

mitar replied Sep 14, 2016

:-)

@bengott: Thanks for looking into this. I suggest you simply do your changes locally and then run Hexo locally and see what is the result and if links work. You can see how to do that in README in site directory.

This comment has been minimized.

Show comment
Hide comment
@bengott

bengott Sep 14, 2016

Contributor

So running Hexo locally was easier than I thought... :) My suggested changes fixed the links as expected. Submitted PR #99, and @mitar already merged it.

Contributor

bengott replied Sep 14, 2016

So running Hexo locally was easier than I thought... :) My suggested changes fixed the links as expected. Submitted PR #99, and @mitar already merged it.

@mitar mitar modified the milestone: v2.2 Sep 14, 2016

@mitar

This comment has been minimized.

Show comment
Hide comment
@mitar

mitar Sep 26, 2016

Collaborator

@nathantreid, I really love your work here and I think many people would like to see this in. But I also really like that the Handlebars syntax work with arbitrary block helpers. I think that block helpers are really powerful feature of Blaze and with allowing such chaining of them it would be really powerful. Currently block helpers were a bit strange to use because what if you had only two cases, but now you can potentially get multiple cases supported, not just true/false.

Could you please update the pull request to support arbitrary block helpers?

Collaborator

mitar commented Sep 26, 2016

@nathantreid, I really love your work here and I think many people would like to see this in. But I also really like that the Handlebars syntax work with arbitrary block helpers. I think that block helpers are really powerful feature of Blaze and with allowing such chaining of them it would be really powerful. Currently block helpers were a bit strange to use because what if you had only two cases, but now you can potentially get multiple cases supported, not just true/false.

Could you please update the pull request to support arbitrary block helpers?

@mitar

This comment has been minimized.

Show comment
Hide comment
@mitar

mitar Sep 26, 2016

Collaborator

So something like this could then work:

{{#tab title="Foo"}}

{{else tab title="Bar"}}

{{else tab title="Baz"}}

{{/tab}}

And have a block helper which renders dynamically tabs, opens/closes them, etc.

Collaborator

mitar commented Sep 26, 2016

So something like this could then work:

{{#tab title="Foo"}}

{{else tab title="Bar"}}

{{else tab title="Baz"}}

{{/tab}}

And have a block helper which renders dynamically tabs, opens/closes them, etc.

@nathantreid

This comment has been minimized.

Show comment
Hide comment
@nathantreid

nathantreid Sep 27, 2016

I'd be happy too, but I'm swamped right now IRL. If someone else wants to have a go at it, be my guest. Otherwise, I'll try to get to it as soon as I can.

I'd be happy too, but I'm swamped right now IRL. If someone else wants to have a go at it, be my guest. Otherwise, I'll try to get to it as soon as I can.

@mitar

This comment has been minimized.

Show comment
Hide comment
@mitar

mitar Sep 27, 2016

Collaborator

No worries. I just wanted to make sure we have a path forward.

Collaborator

mitar commented Sep 27, 2016

No worries. I just wanted to make sure we have a path forward.

@mitar

This comment has been minimized.

Show comment
Hide comment
@mitar

mitar Nov 15, 2016

Collaborator

Any progress here? Anyone else wants to tackle this?

Collaborator

mitar commented Nov 15, 2016

Any progress here? Anyone else wants to tackle this?

@kulttuuri

This comment has been minimized.

Show comment
Hide comment
@kulttuuri

kulttuuri Dec 4, 2016

This would be fantastic feature to have. @nathantreid still busy with things IRL? :)

This would be fantastic feature to have. @nathantreid still busy with things IRL? :)

@mitar

This comment has been minimized.

Show comment
Hide comment
@mitar

mitar Dec 30, 2016

Collaborator

I cleaned master branch to remove all Meteor history (#112). This means the pull request should be also updated to new history to not base it on old commits. Sorry for this extra work.

Collaborator

mitar commented Dec 30, 2016

I cleaned master branch to remove all Meteor history (#112). This means the pull request should be also updated to new history to not base it on old commits. Sorry for this extra work.

@mitar

This comment has been minimized.

Show comment
Hide comment
@mitar

mitar Jan 1, 2017

Collaborator

With 2fa3cab I implemented the Handlebars syntax for chaining block tags. I am closing this pull request in favor of that.

Collaborator

mitar commented Jan 1, 2017

With 2fa3cab I implemented the Handlebars syntax for chaining block tags. I am closing this pull request in favor of that.

@mitar mitar closed this Jan 1, 2017

@mitar

This comment has been minimized.

Show comment
Hide comment
@mitar

mitar Jan 12, 2017

Collaborator

Released as 2.3.0. You have to update templating package.

Collaborator

mitar commented Jan 12, 2017

Released as 2.3.0. You have to update templating package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment