diff options
author | wycats <wycats@gmail.com> | 2010-12-11 18:43:58 -0800 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-12-11 18:43:58 -0800 |
commit | 9fcd85bbac33c643efa02c3a144c0a50e25d13cc (patch) | |
tree | 04706f8f3fba30cf016dfdf99d6fdd8c01d76829 /spec/qunit_spec.js | |
parent | 62cea5b05e4b4f60b6d27b5b0e1f1724c104702a (diff) | |
download | handlebars.js-9fcd85bbac33c643efa02c3a144c0a50e25d13cc.zip handlebars.js-9fcd85bbac33c643efa02c3a144c0a50e25d13cc.tar.gz handlebars.js-9fcd85bbac33c643efa02c3a144c0a50e25d13cc.tar.bz2 |
Allow helperMissing to apply to simple mustaches (paves the way to support things like link_to in a Rails context)
Diffstat (limited to 'spec/qunit_spec.js')
-rw-r--r-- | spec/qunit_spec.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/spec/qunit_spec.js b/spec/qunit_spec.js index dee8891..5ccc457 100644 --- a/spec/qunit_spec.js +++ b/spec/qunit_spec.js @@ -1,5 +1,11 @@ module("basic context"); +Handlebars.registerHelper('helperMissing', function(helper, context) { + if(helper === "link_to") { + return new Handlebars.SafeString("<a>" + context + "</a>"); + } +}); + var shouldCompileTo = function(string, hash, expected, message) { var template = Handlebars.compile(string); if(Object.prototype.toString.call(hash) === "[object Array]") { @@ -459,3 +465,11 @@ test("constructing a safestring from a string and checking its type", function() equal(safe, "testing 1, 2, 3", "SafeString is equivalent to its underlying string"); }); +module("helperMissing"); + +test("if a context is not found, helperMissing is used", function() { + var string = "{{hello}} {{link_to world}}" + var context = { hello: "Hello", world: "world" }; + + shouldCompileTo(string, context, "Hello <a>world</a>") +}) |