From 95caad6b593679276be7ebab958a1f6773863273 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Fri, 12 Sep 2014 11:12:34 +0000 Subject: [PATCH] Use "replace" helper instead of "nl2br" in HBS.js templates --- .../js/source/default/handlebars_helpers.js | 11 ----------- .../client_side/chat/message.handlebars | 2 +- .../client_side/message.handlebars | 2 +- .../client_side/default/message.handlebars | 2 +- .../test_cases/handlebars_helpers_tests.js | 18 ------------------ 5 files changed, 3 insertions(+), 32 deletions(-) diff --git a/src/mibew/js/source/default/handlebars_helpers.js b/src/mibew/js/source/default/handlebars_helpers.js index 045e9ee6..40d2a42e 100644 --- a/src/mibew/js/source/default/handlebars_helpers.js +++ b/src/mibew/js/source/default/handlebars_helpers.js @@ -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, "
") - ); - }); - /** * Register 'l10n' Handlebars helper * diff --git a/src/mibew/styles/dialogs/default/templates_src/client_side/chat/message.handlebars b/src/mibew/styles/dialogs/default/templates_src/client_side/chat/message.handlebars index 8016359f..1f3dca36 100644 --- a/src/mibew/styles/dialogs/default/templates_src/client_side/chat/message.handlebars +++ b/src/mibew/styles/dialogs/default/templates_src/client_side/chat/message.handlebars @@ -1,3 +1,3 @@ {{formatTime created}} {{#if name}}{{name}}: {{/if}} -{{nl2br (urlReplace message)}}
\ No newline at end of file +{{#replace "\n" "
"}}{{urlReplace message}}{{/replace}}

\ No newline at end of file diff --git a/src/mibew/styles/dialogs/default/templates_src/client_side/message.handlebars b/src/mibew/styles/dialogs/default/templates_src/client_side/message.handlebars index 5cdf0714..8a68527b 100644 --- a/src/mibew/styles/dialogs/default/templates_src/client_side/message.handlebars +++ b/src/mibew/styles/dialogs/default/templates_src/client_side/message.handlebars @@ -1,3 +1,3 @@ {{formatTime created}} {{#if name}}{{name}}: {{/if}} -{{nl2br (urlReplace message)}}
\ No newline at end of file +{{#replace "\n" "
"}}{{urlReplace message}}{{/replace}}

\ No newline at end of file diff --git a/src/mibew/styles/pages/default/templates_src/client_side/default/message.handlebars b/src/mibew/styles/pages/default/templates_src/client_side/default/message.handlebars index 5cdf0714..8a68527b 100644 --- a/src/mibew/styles/pages/default/templates_src/client_side/default/message.handlebars +++ b/src/mibew/styles/pages/default/templates_src/client_side/default/message.handlebars @@ -1,3 +1,3 @@ {{formatTime created}} {{#if name}}{{name}}: {{/if}} -{{nl2br (urlReplace message)}}
\ No newline at end of file +{{#replace "\n" "
"}}{{urlReplace message}}{{/replace}}

\ No newline at end of file diff --git a/src/tests/client_side/qunit/test_cases/handlebars_helpers_tests.js b/src/tests/client_side/qunit/test_cases/handlebars_helpers_tests.js index 0fcd040e..3542d1f3 100644 --- a/src/tests/client_side/qunit/test_cases/handlebars_helpers_tests.js +++ b/src/tests/client_side/qunit/test_cases/handlebars_helpers_tests.js @@ -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
cruel
world!
', - '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}}';