mirror of
https://github.com/Mibew/mibew.git
synced 2025-01-31 13:24:41 +03:00
Fix number arguments in "nl2br" Handlebars.js helper
This commit is contained in:
parent
9805b4bb18
commit
aa12eceeea
@ -109,7 +109,9 @@
|
||||
* This helper replace all new line characters (\n) by 'br' tags
|
||||
*/
|
||||
Handlebars.registerHelper('nl2br', function(text) {
|
||||
return new Handlebars.SafeString(text.replace(/\n/g, "<br/>"));
|
||||
return new Handlebars.SafeString(
|
||||
text.toString().replace(/\n/g, "<br/>")
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -72,6 +72,24 @@ test('apply', function() {
|
||||
}
|
||||
});
|
||||
|
||||
// Test "nl2br" Handlebars helper
|
||||
test('nl2br', function() {
|
||||
var template = '{{nl2br foo}}';
|
||||
var compiledTemplate = Handlebars.compile(template);
|
||||
|
||||
equal(
|
||||
compiledTemplate({foo: 'Hello\ncruel\nworld!\n'}),
|
||||
'Hello<br/>cruel<br/>world!<br/>',
|
||||
'Test simple replacements'
|
||||
);
|
||||
|
||||
equal(
|
||||
compiledTemplate({foo: 456}),
|
||||
'456',
|
||||
'Test number argument'
|
||||
);
|
||||
});
|
||||
|
||||
// Test "ifEven" Handlebars helper
|
||||
test('ifEven', function() {
|
||||
var template = '{{#ifEven foo}}true{{else}}false{{/ifEven}}';
|
||||
|
Loading…
Reference in New Issue
Block a user