From 429116e4492c6e39be1162434e155e8e62df3648 Mon Sep 17 00:00:00 2001 From: Keith Cirkel Date: Sun, 12 Apr 2015 22:57:41 +0100 Subject: [PATCH] Ensure _loaderHelpers registers actual filenames Slicing a path by the last 3 characters works for two character extensions, e.g. `'.js'` or `'.cs'` but not for longer extensions (`'.es6'`, `'.javascript'`, `'.coffeescript'` for example). Using `Path.extname` will extract the proper extension from a path, which can then be used to determine the length of the extension proper, and thereby allowing helpers with longer extension names. --- lib/manager.js | 2 +- test/templates/valid/helpers/long.javascript | 4 ++++ test/templates/valid/testHelpers.html | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 test/templates/valid/helpers/long.javascript diff --git a/lib/manager.js b/lib/manager.js index 857854f..b0f43cd 100755 --- a/lib/manager.js +++ b/lib/manager.js @@ -251,7 +251,7 @@ internals.Manager.prototype._loadHelpers = function (engine) { var helper = require(file); if (typeof helper === 'function') { var offset = path.slice(-1) === Path.sep ? 0 : 1; - var name = file.slice(path.length + offset, -3); + var name = file.slice(path.length + offset, -Path.extname(file).length); engine.module.registerHelper(name, helper); } } diff --git a/test/templates/valid/helpers/long.javascript b/test/templates/valid/helpers/long.javascript new file mode 100644 index 0000000..40ecae0 --- /dev/null +++ b/test/templates/valid/helpers/long.javascript @@ -0,0 +1,4 @@ +exports = module.exports = function (context) { + + return context; +}; diff --git a/test/templates/valid/testHelpers.html b/test/templates/valid/testHelpers.html index 916780b..c9a59bc 100755 --- a/test/templates/valid/testHelpers.html +++ b/test/templates/valid/testHelpers.html @@ -1 +1 @@ -

This is all {{uppercase this.something}} and this is how we like it!

\ No newline at end of file +

This is all {{uppercase this.something}} and this is {{long "how"}} we like it!

\ No newline at end of file