Merge branch 'master' into grunt-build

This commit is contained in:
kpdecker
2013-08-24 12:13:09 -05:00
5 changed files with 24 additions and 16 deletions
+3 -4
View File
@@ -98,10 +98,9 @@ Handlebars.registerHelper('blockHelperMissing', function(context, options) {
Handlebars.K = function() {};
Handlebars.createFrame = Object.create || function(object) {
Handlebars.K.prototype = object;
var obj = new Handlebars.K();
Handlebars.K.prototype = null;
Handlebars.createFrame = function(object) {
var obj = {};
Handlebars.Utils.extend(obj, object);
return obj;
};
+3 -4
View File
@@ -98,10 +98,9 @@ Handlebars.registerHelper('blockHelperMissing', function(context, options) {
Handlebars.K = function() {};
Handlebars.createFrame = Object.create || function(object) {
Handlebars.K.prototype = object;
var obj = new Handlebars.K();
Handlebars.K.prototype = null;
Handlebars.createFrame = function(object) {
var obj = {};
Handlebars.Utils.extend(obj, object);
return obj;
};
+3 -4
View File
@@ -73,10 +73,9 @@ Handlebars.registerHelper('blockHelperMissing', function(context, options) {
Handlebars.K = function() {};
Handlebars.createFrame = Object.create || function(object) {
Handlebars.K.prototype = object;
var obj = new Handlebars.K();
Handlebars.K.prototype = null;
Handlebars.createFrame = function(object) {
var obj = {};
Handlebars.Utils.extend(obj, object);
return obj;
};
+10
View File
@@ -84,6 +84,16 @@ describe('builtin helpers', function() {
equal(result, "0. goodbye! 1. Goodbye! 2. GOODBYE! cruel world!", "The @index variable is used");
});
it("each with nested @index", function() {
var string = "{{#each goodbyes}}{{@index}}. {{text}}! {{#each ../goodbyes}}{{@index}} {{/each}}After {{@index}} {{/each}}{{@index}}cruel {{world}}!";
var hash = {goodbyes: [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}], world: "world"};
var template = CompilerContext.compile(string);
var result = template(hash);
equal(result, "0. goodbye! 0 1 2 After 0 1. Goodbye! 0 1 2 After 1 2. GOODBYE! 0 1 2 After 2 cruel world!", "The @index variable is used");
});
it("each with function argument", function() {
var string = "{{#each goodbyes}}{{text}}! {{/each}}cruel {{world}}!";
var hash = {goodbyes: function () { return [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}];}, world: "world"};
+5 -4
View File
@@ -112,18 +112,19 @@ describe('data', function() {
});
it("data is inherited downstream", function() {
var template = CompilerContext.compile("{{#let foo=bar.baz}}{{@foo}}{{/let}}", { data: true });
var template = CompilerContext.compile("{{#let foo=1 bar=2}}{{#let foo=bar.baz}}{{@bar}}{{@foo}}{{/let}}{{@foo}}{{/let}}", { data: true });
var helpers = {
let: function(options) {
var frame = Handlebars.createFrame(options.data);
for (var prop in options.hash) {
options.data[prop] = options.hash[prop];
frame[prop] = options.hash[prop];
}
return options.fn(this);
return options.fn(this, {data: frame});
}
};
var result = template({ bar: { baz: "hello world" } }, { helpers: helpers, data: {} });
equals("hello world", result, "data variables are inherited downstream");
equals("2hello world1", result, "data variables are inherited downstream");
});
it("passing in data to a compiled function that expects data - works with helpers in partials", function() {