@@ -10,13 +10,25 @@ JavaScriptCompiler.prototype = {
|
||||
// PUBLIC API: You can override these methods in a subclass to provide
|
||||
// alternative compiled forms for name lookup and buffering semantics
|
||||
nameLookup: function(parent, name /* , type*/) {
|
||||
var wrap,
|
||||
ret;
|
||||
if (parent.indexOf('depth') === 0) {
|
||||
wrap = true;
|
||||
}
|
||||
|
||||
if (/^[0-9]+$/.test(name)) {
|
||||
return parent + "[" + name + "]";
|
||||
ret = parent + "[" + name + "]";
|
||||
} else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
|
||||
return parent + "." + name;
|
||||
ret = parent + "." + name;
|
||||
}
|
||||
else {
|
||||
return parent + "['" + name + "']";
|
||||
ret = parent + "['" + name + "']";
|
||||
}
|
||||
|
||||
if (wrap) {
|
||||
return '(' + parent + ' && ' + ret + ')';
|
||||
} else {
|
||||
return ret;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -22,6 +22,12 @@ describe("basic context", function() {
|
||||
"It works if all the required keys are provided");
|
||||
});
|
||||
|
||||
it("compiling with an undefined context", function() {
|
||||
shouldCompileTo("Goodbye\n{{cruel}}\n{{world.bar}}!", undefined, "Goodbye\n\n!");
|
||||
|
||||
shouldCompileTo("{{#unless foo}}Goodbye{{../test}}{{test2}}{{/unless}}", undefined, "Goodbye");
|
||||
});
|
||||
|
||||
it("comments", function() {
|
||||
shouldCompileTo("{{! Goodbye}}Goodbye\n{{cruel}}\n{{world}}!",
|
||||
{cruel: "cruel", world: "world"}, "Goodbye\ncruel\nworld!",
|
||||
|
||||
@@ -16,6 +16,13 @@ describe('partials', function() {
|
||||
"Partials can be passed a context");
|
||||
});
|
||||
|
||||
it("partials with undefined context", function() {
|
||||
var string = "Dudes: {{>dude dudes}}";
|
||||
var partial = "{{foo}} Empty";
|
||||
var hash = {};
|
||||
shouldCompileToWithPartials(string, [hash, {}, {dude: partial}], true, "Dudes: Empty");
|
||||
});
|
||||
|
||||
it("partial in a partial", function() {
|
||||
var string = "Dudes: {{#dudes}}{{>dude}}{{/dudes}}";
|
||||
var dude = "{{name}} {{> url}} ";
|
||||
|
||||
Reference in New Issue
Block a user