Skip to content

Commit 3426969

Browse files
committed
Merge pull request handlebars-lang#291 from leshill/quotes
Recognize bar='baz' hash argument
2 parents 2b3e777 + 9ce3032 commit 3426969

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

spec/parser_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ def path(*parts)
172172
mustache id("foo"), [], hash(["bar", "ID:baz"], ["bat", "\"bam\""])
173173
end
174174

175+
ast_for("{{foo bat='bam'}}").should == root do
176+
mustache id("foo"), [], hash(["bat", "\"bam\""])
177+
end
178+
175179
ast_for("{{foo omg bar=baz bat=\"bam\"}}").should == root do
176180
mustache id("foo"), [id("omg")], hash(["bar", id("baz")], ["bat", string("bam")])
177181
end

spec/qunit_spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,19 @@ test("block helpers can take an optional hash", function() {
995995
equals(result, "GOODBYE CRUEL world 12 TIMES", "Hash parameters output");
996996
});
997997

998+
test("block helpers can take an optional hash with single quoted stings", function() {
999+
var template = CompilerContext.compile("{{#goodbye cruel='CRUEL' times=12}}world{{/goodbye}}");
1000+
1001+
var helpers = {
1002+
goodbye: function(options) {
1003+
return "GOODBYE " + options.hash.cruel + " " + options.fn(this) + " " + options.hash.times + " TIMES";
1004+
}
1005+
};
1006+
1007+
var result = template({}, {helpers: helpers});
1008+
equals(result, "GOODBYE CRUEL world 12 TIMES", "Hash parameters output");
1009+
});
1010+
9981011
test("block helpers can take an optional hash with booleans", function() {
9991012
var helpers = {
10001013
goodbye: function(options) {

src/handlebars.l

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<mu>"}}}" { this.popState(); return 'CLOSE'; }
3232
<mu>"}}" { this.popState(); return 'CLOSE'; }
3333
<mu>'"'("\\"["]|[^"])*'"' { yytext = yytext.substr(1,yyleng-2).replace(/\\"/g,'"'); return 'STRING'; }
34+
<mu>"'"("\\"[']|[^'])*"'" { yytext = yytext.substr(1,yyleng-2).replace(/\\"/g,'"'); return 'STRING'; }
3435
<mu>"@"[a-zA-Z]+ { yytext = yytext.substr(1); return 'DATA'; }
3536
<mu>"true"/[}\s] { return 'BOOLEAN'; }
3637
<mu>"false"/[}\s] { return 'BOOLEAN'; }

0 commit comments

Comments
 (0)