-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Support for @-prefixed keywords in the each block helper #150
Conversation
eachIndex | ||
= !'{' _ '@index' | ||
eachBlockHelperVariable | ||
= !'{' _ variable:(v:'@index' { return 'index'; } / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I screwed up here by prematurely merging in the previous change to add support for @index
; we don't want to handle @key
and @index
as individual special case keywords; rather, we want to support any data keyword that's prefixed with an @
. This way, the helpers have full control over what data vars to add.
So this rule needs to be changed to handle @
followed by any valid identifier, not just @key
and @index
and whatever else might come in the future. Would you mind making this change?
Sounds good. Does using
So it would just be
|
That seems fine to me. |
I'm writing this test case that uses // Support for data keywords that are prefixed with @ in the each
// block helper such as @index, @key, @first, @last
eachBlockHelperVariable
= _ '@' variableName:attributeName
{
var params = {};
var idNode = new AST.IdNode([{part: variableName}]);
var dataNode = new AST.DataNode(idNode);
params = dataNode;
return new AST.MustacheNode([params], null, false);
}
recursivelyParsedMustacheContent
= !'{' text:$[^}]*
{
// Force interpretation as mustache.
// TODO: change to just parse with a specific rule?
text = "=" + text;
return Emblem.parse(text).statements[0];
}
mustacheContent
= eachBlockHelperVariable / recursivelyParsedMustacheContent Is there a better place to define the eachBlockHelperVariable rather than just as some kind of mustacheContent? |
Hmm, honestly, this commit should be reverted: f15ffef There's no reason the parsing of Sorry you've been on this wild goose chase; if you still have energy, and I hope you do, here's what you should do:
The recursiveMustacheParse thing is used in the case that you have something like
It basically restarts the Emblem parser on everything between the curly braces, but you shouldn't have to touch that in any way to get data vars to work. It shouldn't be an insane amount of work, but you're correct that support should also exist for using data keywords as helper args, in addition to making the logic universal beyond just |
Tests all passed now for Handlebars 1.3.0 and 1.2.1. Since Handlebars 1.1.2 doesn't have support for these iteration variables, is there any way we can conditionally skip some of the tests? |
@lai Awesome; yeah, i suppose you can check |
@machty Please review the amended commit. |
Support for @-prefixed keywords in the each block helper
Looks good, thank you! |
Thanks! Can't wait to fully embrace Emblem here :) |
This adds the support for data keywords prefixed by
@
such as@index
,@key
in Handlebars' each block helper. Prior discussion about supporting@index
at #112Note that support for
@first
and@index
in object iteration was added in Handlebars in 1.2.0. handlebars-lang/handlebars.js#661