mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03:00
Merge pull request #1092 from halfdan/uc-helper
Added new helper to escape URIs called 'encode'
This commit is contained in:
commit
7419e05b3a
@ -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:*
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user