Merge with upstream/master

This commit is contained in:
kpdecker
2012-08-21 12:49:40 -05:00
5 changed files with 61 additions and 3 deletions
+22 -2
View File
@@ -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('');
+7 -1
View File
@@ -240,7 +240,13 @@ Handlebars.JavaScriptCompiler = function() {};
ID: function(id) {
this.addDepth(id.depth);
this.opcode('getContext', id.depth);
this.opcode('lookupOnContext', id.parts[0]);
var name = id.parts[0];
if (!name) {
this.opcode('pushContext');
} else {
this.opcode('lookupOnContext', id.parts[0]);
}
for(var i=1, l=id.parts.length; i<l; i++) {
this.opcode('lookup', id.parts[i]);
+4
View File
@@ -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
+27
View File
@@ -187,6 +187,20 @@ test("this keyword in paths", function() {
shouldCompileTo(string, hash, "helloHelloHELLO", "This keyword evaluates in more complex paths");
});
test("this keyword in helpers", function() {
var helpers = {foo: function(value, options) {
return 'bar ' + value;
}};
var string = "{{#goodbyes}}{{foo this}}{{/goodbyes}}";
var hash = {goodbyes: ["goodbye", "Goodbye", "GOODBYE"]};
shouldCompileTo(string, [hash, helpers], "bar goodbyebar Goodbyebar GOODBYE",
"This keyword in paths evaluates to current context");
string = "{{#hellos}}{{foo this/text}}{{/hellos}}";
hash = {hellos: [{text: "hello"}, {text: "Hello"}, {text: "HELLO"}]};
shouldCompileTo(string, [hash, helpers], "bar hellobar Hellobar HELLO", "This keyword evaluates in more complex paths");
});
suite("inverted sections");
test("inverted sections with unset value", function() {
@@ -1002,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) {
+1
View File
@@ -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'; }