Merge pull request #1092 from halfdan/uc-helper

Added new helper to escape URIs called 'encode'
This commit is contained in:
Hannah Wolfe 2013-10-16 02:23:13 -07:00
commit 7419e05b3a
2 changed files with 30 additions and 1 deletions

View File

@ -47,6 +47,19 @@ coreHelpers = function (ghost) {
return date;
});
//
// ### URI Encoding helper
//
// *Usage example:*
// `{{encode uri}}`
//
// Returns URI encoded string
//
ghost.registerThemeHelper('encode', function (context, str) {
var uri = context || str;
return new hbs.handlebars.SafeString(encodeURIComponent(uri));
});
// ### Page URL Helper
//
// *Usage example:*

View File

@ -86,6 +86,22 @@ describe('Core Helpers', function () {
});
describe('encode Helper', function () {
it('has loaded encode helper', function() {
should.exist(handlebars.helpers.encode);
});
it('can escape URI', function() {
var uri = "$pecial!Charact3r(De[iver]y)Foo #Bar",
expected = "%24pecial!Charact3r(De%5Biver%5Dy)Foo%20%23Bar",
escaped = handlebars.helpers.encode(uri);
should.exist(escaped);
String(escaped).should.equal(expected);
});
});
describe('Excerpt Helper', function () {
it('has loaded excerpt helper', function () {
@ -367,4 +383,4 @@ describe('Core Helpers', function () {
}).then(null, done);
});
});
});
});