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

Add {@any} helper. #107

Merged
merged 1 commit into from Dec 22, 2014
Merged

Conversation

sethkinast
Copy link
Contributor

  • Must be contained in a {@select} block
  • Renders its body if any truth test inside the {@select} block evaluates to true
  • Can be included multiple times inside a {@select} block.

As part of this change, {@select} no longer clobbers the current context, so keys that begin with a dot work inside a {@select}. This closes #9, closes #42, closes #50, and closes #79.

@sethkinast
Copy link
Contributor Author

Enables syntax such as:

{! foo is 1 or 2 or 3 !}
{@select key=foo}
  {@eq value="1"/}
  {@eq value="2"/}
  {@eq value="3"/}
  {@any}Foo is 1, 2, or 3{/any}
  {@default}Foo is not 1, 2, or 3{/default}
{/select}

{! Output something specific as well !}
{@select key=foo}
  {@any}Congratulations! You got: {/any}
  {@eq value="1"}First Place{/eq}
  {@eq value="2"}Second Place{/eq}
  {@eq value="3"}Third Place{/eq}
  {@default}Better luck next time!{/default}
{/select}

{! If any truth test passes, all {@any} blocks will be evaluated !}
{@select key=foo}
  {@any}<span class="place">{/any}
  {@eq value=1}First Place{/eq}
  {@eq value=2}Second Place{/eq}
  {@eq value=3}Third Place{/eq}
  {@any}</span>{/any}
{/select}

@sethkinast
Copy link
Contributor Author

I purposely made the deferral generation generic in case we want to add the equivalent none. default mimics switch in that once it's hit, evaluation of further truth tests stops. I feel like it would have been more useful if you could have multiple default blocks that didn't stop truth testing, so that the default didn't have to be the last content in the block.

@prashn64
Copy link
Contributor

lgtm, let's get one more set of eyes on it.

@sethkinast
Copy link
Contributor Author

More than one more set I think, this is a fairly large grammar addition.

@rragan
Copy link
Contributor

rragan commented Dec 13, 2014

Has lots of value and slots in cleanly. Do you need a test with an any helper within another any helper within a select. That should just get diagnosed I think.

@sethkinast
Copy link
Contributor Author

That's a really good call-- that actually crashes the template.

@sethkinast
Copy link
Contributor Author

@rragan, are you OK with this syntax? I don't want you to feel like you're being run over-- your PR is the direct driver for this one. The team here was just worried about coming up with something that felt Dust-like.

- Must be contained in a {@select} block
- Renders its body if any truth test inside the {@select} block evaluates to true
- Can be included multiple times inside a {@select} block.

As part of this change, {@select} no longer clobbers the current context, so keys that begin with a dot work inside a {@select}. This closes LinkedInAttic#9, closes LinkedInAttic#42, closes LinkedInAttic#50, and closes LinkedInAttic#79.
@rragan
Copy link
Contributor

rragan commented Dec 15, 2014

The syntax works for me. It is a bit odd using a "select/case" mechanism for achieving a multi-output OR mechanism -- the name becomes a misnomer for someone looking at how to achieve OR behavior. Docs can help --, e.g. Need to do a an OR, see Select

@sethkinast
Copy link
Contributor Author

@jimmyhchan whaddya think

prashn64 added a commit that referenced this pull request Dec 22, 2014
Add {@any} helper for use within an {@select} body.
@prashn64 prashn64 merged commit eb10839 into LinkedInAttic:master Dec 22, 2014
@rragan
Copy link
Contributor

rragan commented Dec 23, 2014

When the "dust settles" on this round of changes and you are good to publish new dust and helpers, let me know and I can update the wiki.

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