Allow helperMissing to apply to simple mustaches (paves the way to support things like link_to in a Rails context)
This commit is contained in:
@@ -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>")
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user