diff options
-rwxr-xr-x | bin/handlebars | 24 | ||||
-rw-r--r-- | spec/parser_spec.rb | 4 | ||||
-rw-r--r-- | spec/qunit_spec.js | 13 | ||||
-rw-r--r-- | src/handlebars.l | 1 |
4 files changed, 40 insertions, 2 deletions
diff --git a/bin/handlebars b/bin/handlebars index 2c03b0b..7a2fc1c 100755 --- a/bin/handlebars +++ b/bin/handlebars @@ -7,6 +7,17 @@ var optimist = require('optimist') 'description': 'Output File', 'alias': 'output' }, + 'a': { + 'type': 'boolean', + 'description': 'Exports amd style (require.js)', + 'alias': 'amd' + }, + 'h': { + 'type': 'string', + 'description': 'Path to handlebar.js (only valid for amd-style)', + 'alias': 'handlebarPath', + 'default': '' + }, 'k': { 'type': 'string', 'description': 'Known helpers', @@ -78,7 +89,12 @@ if (argv.known) { var output = []; if (!argv.simple) { - output.push('(function() {\n var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\n'); + if (argv.amd) { + output.push('define([\'' + argv.handlebarPath + 'handlebars\'], function(Handlebars) {\n'); + } else { + output.push('(function() {\n'); + } + output.push(' var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\n'); } function processTemplate(template, root) { var path = template, @@ -121,7 +137,11 @@ argv._.forEach(function(template) { // Output the content if (!argv.simple) { - output.push('})();'); + if (argv.amd) { + output.push('});'); + } else { + output.push('})();'); + } } output = output.join(''); diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb index 3fe9029..2b234d3 100644 --- a/spec/parser_spec.rb +++ b/spec/parser_spec.rb @@ -172,6 +172,10 @@ describe "Parser" do 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 diff --git a/spec/qunit_spec.js b/spec/qunit_spec.js index 482d4d7..cbbc138 100644 --- a/spec/qunit_spec.js +++ b/spec/qunit_spec.js @@ -1016,6 +1016,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) { diff --git a/src/handlebars.l b/src/handlebars.l index f81fcdb..2e0c4f7 100644 --- a/src/handlebars.l +++ b/src/handlebars.l @@ -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'; } |