Added 'log' helper - See #97

This commit is contained in:
Peter Wagenet
2011-10-24 19:41:41 -07:00
parent b36776f4c6
commit 43431d2a78
3 changed files with 24 additions and 2 deletions
+4
View File
@@ -86,6 +86,10 @@ Handlebars.registerHelper('with', function(context, options) {
return options.fn(context);
});
Handlebars.registerHelper('log', function(context) {
Handlebars.log(context);
});
// END(BROWSER)
module.exports = Handlebars;
+2 -1
View File
@@ -104,7 +104,8 @@ Handlebars.JavaScriptCompiler = function() {};
'each': true,
'if': true,
'unless': true,
'with': true
'with': true,
'log': true
};
if (knownHelpers) {
for (var name in knownHelpers) {
+18 -1
View File
@@ -576,7 +576,11 @@ test("Invert blocks work in knownHelpers only mode", function() {
equal(result, "bar", "'bar' should === '" + result);
});
module("built-in helpers");
var teardown;
module("built-in helpers", {
setup: function(){ teardown = null; },
teardown: function(){ if (teardown) { teardown(); } }
});
test("with", function() {
var string = "{{#with person}}{{first}} {{last}}{{/with}}";
@@ -608,6 +612,19 @@ test("each", function() {
"each with array argument ignores the contents when empty");
});
test("log", function() {
var string = "{{log blah}}"
var hash = { blah: "whee" };
var logArg;
var originalLog = Handlebars.log;
Handlebars.log = function(arg){ logArg = arg; }
teardown = function(){ Handlebars.log = originalLog; }
shouldCompileTo(string, hash, "", "log should not display");
equals("whee", logArg, "should call log with 'whee'");
});
test("overriding property lookup", function() {
});