Skip to content

Commit

Permalink
Recognize bar='baz' hash argument
Browse files Browse the repository at this point in the history
  • Loading branch information
leshill committed Aug 15, 2012
1 parent 2b3e777 commit 9ce3032
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spec/parser_spec.rb
Expand Up @@ -172,6 +172,10 @@ def path(*parts)
mustache id("foo"), [], hash(["bar", "ID:baz"], ["bat", "\"bam\""])
end

ast_for("{{foo bat='bam'}}").should == root do
mustache id("foo"), [], hash(["bat", "\"bam\""])
end

ast_for("{{foo omg bar=baz bat=\"bam\"}}").should == root do
mustache id("foo"), [id("omg")], hash(["bar", id("baz")], ["bat", string("bam")])
end
Expand Down
13 changes: 13 additions & 0 deletions spec/qunit_spec.js
Expand Up @@ -995,6 +995,19 @@ test("block helpers can take an optional hash", function() {
equals(result, "GOODBYE CRUEL world 12 TIMES", "Hash parameters output");
});

test("block helpers can take an optional hash with single quoted stings", function() {
var template = CompilerContext.compile("{{#goodbye cruel='CRUEL' times=12}}world{{/goodbye}}");

var helpers = {
goodbye: function(options) {
return "GOODBYE " + options.hash.cruel + " " + options.fn(this) + " " + options.hash.times + " TIMES";
}
};

var result = template({}, {helpers: helpers});
equals(result, "GOODBYE CRUEL world 12 TIMES", "Hash parameters output");
});

test("block helpers can take an optional hash with booleans", function() {
var helpers = {
goodbye: function(options) {
Expand Down
1 change: 1 addition & 0 deletions src/handlebars.l
Expand Up @@ -31,6 +31,7 @@
<mu>"}}}" { this.popState(); return 'CLOSE'; }
<mu>"}}" { this.popState(); return 'CLOSE'; }
<mu>'"'("\\"["]|[^"])*'"' { yytext = yytext.substr(1,yyleng-2).replace(/\\"/g,'"'); return 'STRING'; }
<mu>"'"("\\"[']|[^'])*"'" { yytext = yytext.substr(1,yyleng-2).replace(/\\"/g,'"'); return 'STRING'; }
<mu>"@"[a-zA-Z]+ { yytext = yytext.substr(1); return 'DATA'; }
<mu>"true"/[}\s] { return 'BOOLEAN'; }
<mu>"false"/[}\s] { return 'BOOLEAN'; }
Expand Down

0 comments on commit 9ce3032

Please sign in to comment.