From cc2adbaaa27600e5f57088ef2b9c09f595405f9b Mon Sep 17 00:00:00 2001 From: Sebastian Hoitz Date: Thu, 27 Feb 2014 14:39:35 +0100 Subject: [PATCH 1/2] Parse strings when arguments are passed to the translate method --- lib/parser.js | 2 +- test/fixtures/arguments.hbs | 3 +++ test/parser_test.js | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/arguments.hbs diff --git a/lib/parser.js b/lib/parser.js index 7aceef2..e1c3cb9 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -14,7 +14,7 @@ function Parser(keywords) { this.keywords = keywords; - this.pattern = new RegExp('\\{\\{(?:' + keywords.join('|') + ') "((?:\\\\.|[^"\\\\])*)"(?: "((?:\\\\.|[^"\\\\])*)" \\w+)? ?\\}\\}', 'gm'); + this.pattern = new RegExp('\\{\\{(?:' + keywords.join('|') + ') "((?:\\\\.|[^"\\\\])*)"(?: "((?:\\\\.|[^"\\\\])*)" \\w+)?(?: [\\w|\\.]+)? ?\\}\\}', 'gm'); } /** diff --git a/test/fixtures/arguments.hbs b/test/fixtures/arguments.hbs new file mode 100644 index 0000000..9fb1e4f --- /dev/null +++ b/test/fixtures/arguments.hbs @@ -0,0 +1,3 @@ +

{{title}}

+

{{_ "Hello %s" name}}

+ diff --git a/test/parser_test.js b/test/parser_test.js index 482c7bc..c9762d6 100644 --- a/test/parser_test.js +++ b/test/parser_test.js @@ -27,5 +27,17 @@ exports.parser = { test.equal(Object.keys(result).length, 1, 'Invalid amount of strings returned'); test.done(); + }, + 'arguments': function (test) { + test.expect(1); + + var templatePath = __dirname + '/fixtures/arguments.hbs', + template = fs.readFileSync(templatePath, 'utf8'), + result = parser.parse(template); + + test.equal(Object.keys(result).length, 1, 'Invalid amount of strings returned'); + + test.done(); + } }; From f37311f626377a5260c80b3cd7e5f1376ef2420c Mon Sep 17 00:00:00 2001 From: Sebastian Hoitz Date: Thu, 27 Feb 2014 14:45:35 +0100 Subject: [PATCH 2/2] Allow more than one argument --- lib/parser.js | 2 +- test/fixtures/arguments.hbs | 1 + test/parser_test.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index e1c3cb9..4da2b32 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -14,7 +14,7 @@ function Parser(keywords) { this.keywords = keywords; - this.pattern = new RegExp('\\{\\{(?:' + keywords.join('|') + ') "((?:\\\\.|[^"\\\\])*)"(?: "((?:\\\\.|[^"\\\\])*)" \\w+)?(?: [\\w|\\.]+)? ?\\}\\}', 'gm'); + this.pattern = new RegExp('\\{\\{(?:' + keywords.join('|') + ') "((?:\\\\.|[^"\\\\])*)"(?: "((?:\\\\.|[^"\\\\])*)" \\w+)?(?: [\\w|\\.]+)*? ?\\}\\}', 'gm'); } /** diff --git a/test/fixtures/arguments.hbs b/test/fixtures/arguments.hbs index 9fb1e4f..dd73bc8 100644 --- a/test/fixtures/arguments.hbs +++ b/test/fixtures/arguments.hbs @@ -1,3 +1,4 @@

{{title}}

{{_ "Hello %s" name}}

+

{{_ "Hello %s. It is %s" name weekday}}

diff --git a/test/parser_test.js b/test/parser_test.js index c9762d6..27c7e6b 100644 --- a/test/parser_test.js +++ b/test/parser_test.js @@ -35,7 +35,7 @@ exports.parser = { template = fs.readFileSync(templatePath, 'utf8'), result = parser.parse(template); - test.equal(Object.keys(result).length, 1, 'Invalid amount of strings returned'); + test.equal(Object.keys(result).length, 2, 'Invalid amount of strings returned'); test.done();