Use "replace" helper instead of "nl2br" in HBS.js templates

This commit is contained in:
Dmitriy Simushev 2014-09-12 11:12:34 +00:00
parent ae9de7aa92
commit 95caad6b59
5 changed files with 3 additions and 32 deletions

View File

@ -52,17 +52,6 @@
);
});
/**
* Register 'nl2br' Handlebars helper.
*
* This helper replace all new line characters (\n) by 'br' tags
*/
Handlebars.registerHelper('nl2br', function(text) {
return new Handlebars.SafeString(
text.toString().replace(/\n/g, "<br/>")
);
});
/**
* Register 'l10n' Handlebars helper
*

View File

@ -1,3 +1,3 @@
<span>{{formatTime created}}</span>
{{#if name}}<span class='n{{kindName}}'>{{name}}</span>: {{/if}}
<span class='m{{kindName}}'>{{nl2br (urlReplace message)}}</span><br/>
<span class='m{{kindName}}'>{{#replace "\n" "<br/>"}}{{urlReplace message}}{{/replace}}</span><br/>

View File

@ -1,3 +1,3 @@
<span>{{formatTime created}}</span>
{{#if name}}<span class='n{{kindName}}'>{{name}}</span>: {{/if}}
<span class='m{{kindName}}'>{{nl2br (urlReplace message)}}</span><br/>
<span class='m{{kindName}}'>{{#replace "\n" "<br/>"}}{{urlReplace message}}{{/replace}}</span><br/>

View File

@ -1,3 +1,3 @@
<span>{{formatTime created}}</span>
{{#if name}}<span class='n{{kindName}}'>{{name}}</span>: {{/if}}
<span class='m{{kindName}}'>{{nl2br (urlReplace message)}}</span><br/>
<span class='m{{kindName}}'>{{#replace "\n" "<br/>"}}{{urlReplace message}}{{/replace}}</span><br/>

View File

@ -37,24 +37,6 @@ test('urlReplace', 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}}';