Backed out function helpers.
This commit is contained in:
@@ -72,8 +72,7 @@ Handlebars.registerHelper('blockHelperMissing', function(context, fn, inverse) {
|
|||||||
return fn(context);
|
return fn(context);
|
||||||
});
|
});
|
||||||
|
|
||||||
Handlebars.registerHelper('each', function(ctx, fn, inverse) {
|
Handlebars.registerHelper('each', function(context, fn, inverse) {
|
||||||
var context = typeof ctx == "function" ? ctx.call(this) : ctx;
|
|
||||||
var ret = "";
|
var ret = "";
|
||||||
|
|
||||||
if(context && context.length > 0) {
|
if(context && context.length > 0) {
|
||||||
@@ -99,8 +98,7 @@ Handlebars.registerHelper('unless', function(context, fn, inverse) {
|
|||||||
Handlebars.helpers['if'].call(this, context, inverse, fn);
|
Handlebars.helpers['if'].call(this, context, inverse, fn);
|
||||||
});
|
});
|
||||||
|
|
||||||
Handlebars.registerHelper('with', function(ctx, fn) {
|
Handlebars.registerHelper('with', function(context, fn) {
|
||||||
var context = typeof ctx == "function" ? ctx.call(this) : ctx;
|
|
||||||
return fn(context);
|
return fn(context);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+4
-34
@@ -494,20 +494,12 @@ test("if a context is not found, helperMissing is used", function() {
|
|||||||
|
|
||||||
module("built-in helpers");
|
module("built-in helpers");
|
||||||
|
|
||||||
test("with non-function argument", function() {
|
test("with", function() {
|
||||||
var string = "{{#with person}}{{first}} {{last}}{{/with}}";
|
var string = "{{#with person}}{{first}} {{last}}{{/with}}";
|
||||||
|
|
||||||
shouldCompileTo(string, {person: {first: "Alan", last: "Johnson"}}, "Alan Johnson");
|
shouldCompileTo(string, {person: {first: "Alan", last: "Johnson"}}, "Alan Johnson");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("with function argument", function() {
|
test("if", function() {
|
||||||
var string = "{{#with person}}{{first}} {{last}}{{/with}}";
|
|
||||||
|
|
||||||
shouldCompileTo(string, {person: function() {return {first: this.firsName, last: this.lastName};},
|
|
||||||
firsName: "Alan", lastName: "Johnson"}, "Alan Johnson");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("if with non-function argument", function() {
|
|
||||||
var string = "{{#if goodbye}}GOODBYE {{/if}}cruel {{world}}!";
|
var string = "{{#if goodbye}}GOODBYE {{/if}}cruel {{world}}!";
|
||||||
shouldCompileTo(string, {goodbye: true, world: "world"}, "GOODBYE cruel world!",
|
shouldCompileTo(string, {goodbye: true, world: "world"}, "GOODBYE cruel world!",
|
||||||
"if with boolean argument shows the contents when true");
|
"if with boolean argument shows the contents when true");
|
||||||
@@ -519,33 +511,11 @@ test("if with non-function argument", function() {
|
|||||||
"if with undefined does not show the contents");
|
"if with undefined does not show the contents");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("if with function argument", function() {
|
test("each", function() {
|
||||||
var string = "{{#if goodbye}}GOODBYE {{/if}}cruel {{world}}!";
|
|
||||||
shouldCompileTo(string, {goodbye: function() {return true}, world: "world"}, "GOODBYE cruel world!",
|
|
||||||
"if with function shows the contents when function returns true");
|
|
||||||
shouldCompileTo(string, {goodbye: function() {return this.world}, world: "world"}, "GOODBYE cruel world!",
|
|
||||||
"if with function shows the contents when function returns string");
|
|
||||||
shouldCompileTo(string, {goodbye: function() {return false}, world: "world"}, "cruel world!",
|
|
||||||
"if with function does not show the contents when returns false");
|
|
||||||
shouldCompileTo(string, {goodbye: function() {return this.foo}, world: "world"}, "cruel world!",
|
|
||||||
"if with function does not show the contents when returns undefined");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("each with non-function argument", function() {
|
|
||||||
var string = "{{#each goodbyes}}{{text}}! {{/each}}cruel {{world}}!"
|
var string = "{{#each goodbyes}}{{text}}! {{/each}}cruel {{world}}!"
|
||||||
var hash = {goodbyes: [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}], world: "world"};
|
var hash = {goodbyes: [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}], world: "world"};
|
||||||
shouldCompileTo(string, hash, "goodbye! Goodbye! GOODBYE! cruel world!",
|
shouldCompileTo(string, hash, "goodbye! Goodbye! GOODBYE! cruel world!",
|
||||||
"each with array argument iterates over the contents when not empty");
|
"each with array argument iterates over the contents when not empty");
|
||||||
shouldCompileTo(string, {goodbyes: [], world: "world"}, "cruel world!",
|
shouldCompileTo(string, {goodbyes: [], world: "world"}, "cruel world!",
|
||||||
"each with array argument ignores the contents when empty");
|
"each with array argument ignores the contents when empty");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("each with function argument", function() {
|
|
||||||
var string = "{{#each goodbyes}}{{text}}! {{/each}}cruel {{world}}!"
|
|
||||||
var hash = {goodbyes: function() {return this.texts;},
|
|
||||||
texts: [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}], world: "world"};
|
|
||||||
shouldCompileTo(string, hash, "goodbye! Goodbye! GOODBYE! cruel world!",
|
|
||||||
"each with function argument returning array iterates over the contents when not empty");
|
|
||||||
shouldCompileTo(string, {goodbyes: [], world: "world"}, "cruel world!",
|
|
||||||
"each with function argument returning array ignores the contents when empty");
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user