0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

Remove filters from theme helpers (no async)

closes #5850

- filters were added so that apps could change the output of the helpers, but as async helpers are a hack, this led to issues
- apps aren't currently a working part of Ghost, so for now, lets remove the filters
- we'll add these back when we have a better implementation of async helpers & this style of app is back on the cards
This commit is contained in:
Hannah Wolfe 2015-12-08 14:35:04 +00:00
parent 2b926f55a1
commit 88065f58a0
8 changed files with 225 additions and 275 deletions

View file

@ -8,7 +8,6 @@
var hbs = require('express-hbs'), var hbs = require('express-hbs'),
_ = require('lodash'), _ = require('lodash'),
filters = require('../filters'),
// @TODO Fix this // @TODO Fix this
template = require('../controllers/frontend/templates'), template = require('../controllers/frontend/templates'),
body_class; body_class;
@ -65,10 +64,8 @@ body_class = function (options) {
} }
} }
return filters.doFilter('body_class', classes).then(function (classes) { classes = _.reduce(classes, function (memo, item) { return memo + ' ' + item; }, '');
var classString = _.reduce(classes, function (memo, item) { return memo + ' ' + item; }, ''); return new hbs.handlebars.SafeString(classes.trim());
return new hbs.handlebars.SafeString(classString.trim());
});
}; };
module.exports = body_class; module.exports = body_class;

View file

@ -8,7 +8,6 @@
var _ = require('lodash'), var _ = require('lodash'),
config = require('../config'), config = require('../config'),
filters = require('../filters'),
meta_description; meta_description;
meta_description = function (options) { meta_description = function (options) {
@ -31,10 +30,7 @@ meta_description = function (options) {
description = this.post.meta_description; description = this.post.meta_description;
} }
return filters.doFilter('meta_description', description).then(function (description) { return (description || '').trim();
description = description || '';
return description.trim();
});
}; };
module.exports = meta_description; module.exports = meta_description;

View file

@ -8,7 +8,6 @@
var _ = require('lodash'), var _ = require('lodash'),
config = require('../config'), config = require('../config'),
filters = require('../filters'),
meta_title; meta_title;
meta_title = function (options) { meta_title = function (options) {
@ -37,10 +36,7 @@ meta_title = function (options) {
title = blog.title + pageString; title = blog.title + pageString;
} }
return filters.doFilter('meta_title', title).then(function (title) { return (title || '').trim();
title = title || '';
return title.trim();
});
}; };
module.exports = meta_title; module.exports = meta_title;

View file

@ -8,7 +8,6 @@
var hbs = require('express-hbs'), var hbs = require('express-hbs'),
_ = require('lodash'), _ = require('lodash'),
filters = require('../filters'),
post_class; post_class;
post_class = function (options) { post_class = function (options) {
@ -30,10 +29,8 @@ post_class = function (options) {
classes.push('page'); classes.push('page');
} }
return filters.doFilter('post_class', classes).then(function (classes) { classes = _.reduce(classes, function (memo, item) { return memo + ' ' + item; }, '');
var classString = _.reduce(classes, function (memo, item) { return memo + ' ' + item; }, ''); return new hbs.handlebars.SafeString(classes.trim());
return new hbs.handlebars.SafeString(classString.trim());
});
}; };
module.exports = post_class; module.exports = post_class;

View file

@ -45,16 +45,13 @@ describe('{{body_class}} helper', function () {
should.exist(handlebars.helpers.body_class); should.exist(handlebars.helpers.body_class);
}); });
it('can render class string', function (done) { it('can render class string', function () {
options.data.root.context = ['home']; options.data.root.context = ['home'];
helpers.body_class.call({}, options).then(function (rendered) { var rendered = helpers.body_class.call({}, options);
should.exist(rendered); should.exist(rendered);
rendered.string.should.equal('home-template'); rendered.string.should.equal('home-template');
done();
}).catch(done);
}); });
describe('can render class string for context', function () { describe('can render class string for context', function () {
@ -66,81 +63,103 @@ describe('{{body_class}} helper', function () {
); );
} }
it('Standard home page', function (done) { it('Standard home page', function () {
callBodyClassWithContext(['home', 'index'], {relativeUrl: '/'}).then(function (rendered) { var rendered = callBodyClassWithContext(
['home', 'index'],
{relativeUrl: '/'}
);
rendered.string.should.equal('home-template'); rendered.string.should.equal('home-template');
done();
}).catch(done);
}); });
it('a post', function (done) { it('a post', function () {
callBodyClassWithContext(['post'], {relativeUrl: '/a-post-title', post: {}}).then(function (rendered) { var rendered = callBodyClassWithContext(
['post'],
{relativeUrl: '/a-post-title', post: {}}
);
rendered.string.should.equal('post-template'); rendered.string.should.equal('post-template');
done();
}).catch(done);
}); });
it('paginated index', function (done) { it('paginated index', function () {
callBodyClassWithContext(['index', 'paged'], {relativeUrl: '/page/4'}).then(function (rendered) { var rendered = callBodyClassWithContext(
['index', 'paged'],
{relativeUrl: '/page/4'}
);
rendered.string.should.equal('paged archive-template'); rendered.string.should.equal('paged archive-template');
done();
}).catch(done);
}); });
it('tag page', function (done) { it('tag page', function () {
callBodyClassWithContext(['tag'], {relativeUrl: '/tag/foo', tag: {slug: 'foo'}}).then(function (rendered) { var rendered = callBodyClassWithContext(
['tag'],
{relativeUrl: '/tag/foo', tag: {slug: 'foo'}}
);
rendered.string.should.equal('tag-template tag-foo'); rendered.string.should.equal('tag-template tag-foo');
done();
}).catch(done);
}); });
it('paginated tag page', function (done) { it('paginated tag page', function () {
callBodyClassWithContext(['tag', 'paged'], {relativeUrl: '/tag/foo/page/2', tag: {slug: 'foo'}}).then(function (rendered) { var rendered = callBodyClassWithContext(
['tag', 'paged'],
{relativeUrl: '/tag/foo/page/2', tag: {slug: 'foo'}}
);
rendered.string.should.equal('tag-template tag-foo paged archive-template'); rendered.string.should.equal('tag-template tag-foo paged archive-template');
done();
}).catch(done);
}); });
it('author page', function (done) { it('author page', function () {
callBodyClassWithContext(['author'], {relativeUrl: '/author/bar', author: {slug: 'bar'}}).then(function (rendered) { var rendered = callBodyClassWithContext(
['author'],
{relativeUrl: '/author/bar', author: {slug: 'bar'}}
);
rendered.string.should.equal('author-template author-bar'); rendered.string.should.equal('author-template author-bar');
done();
}).catch(done);
}); });
it('paginated author page', function (done) { it('paginated author page', function () {
callBodyClassWithContext(['author', 'paged'], {relativeUrl: '/author/bar/page/2', author: {slug: 'bar'}}).then(function (rendered) { var rendered = callBodyClassWithContext(
['author', 'paged'],
{relativeUrl: '/author/bar/page/2', author: {slug: 'bar'}}
);
rendered.string.should.equal('author-template author-bar paged archive-template'); rendered.string.should.equal('author-template author-bar paged archive-template');
done();
}).catch(done);
}); });
it('private route for password protection', function (done) { it('private route for password protection', function () {
callBodyClassWithContext(['private'], {relativeUrl: '/private/'}).then(function (rendered) { var rendered = callBodyClassWithContext(
['private'],
{relativeUrl: '/private/'}
);
rendered.string.should.equal('private-template'); rendered.string.should.equal('private-template');
done();
}).catch(done);
}); });
it('post with tags', function (done) { it('post with tags', function () {
callBodyClassWithContext(['post'], {relativeUrl: '/my-awesome-post/', post: {tags: [{slug: 'foo'}, {slug: 'bar'}]}}).then(function (rendered) { var rendered = callBodyClassWithContext(
['post'],
{relativeUrl: '/my-awesome-post/', post: {tags: [{slug: 'foo'}, {slug: 'bar'}]}}
);
rendered.string.should.equal('post-template tag-foo tag-bar'); rendered.string.should.equal('post-template tag-foo tag-bar');
done();
}).catch(done);
}); });
it('a static page', function (done) { it('a static page', function () {
callBodyClassWithContext(['page'], {relativeUrl: '/about', post: {page: true}}).then(function (rendered) { var rendered = callBodyClassWithContext(
['page'],
{relativeUrl: '/about', post: {page: true}}
);
rendered.string.should.equal('post-template page-template page'); rendered.string.should.equal('post-template page-template page');
done();
}).catch(done);
}); });
it('a static page with custom template', function (done) { it('a static page with custom template', function () {
callBodyClassWithContext(['page'], {relativeUrl: '/about', post: {page: true, slug: 'about'}}).then(function (rendered) { var rendered = callBodyClassWithContext(
['page'],
{relativeUrl: '/about', post: {page: true, slug: 'about'}}
);
rendered.string.should.equal('post-template page-template page page-about page-template-about'); rendered.string.should.equal('post-template page-template page page-about page-template-about');
done();
}).catch(done);
}); });
}); });
}); });

View file

@ -26,135 +26,113 @@ describe('{{meta_description}} helper', function () {
should.exist(handlebars.helpers.meta_description); should.exist(handlebars.helpers.meta_description);
}); });
it('returns correct blog description', function (done) { it('returns correct blog description', function () {
helpers.meta_description.call( var rendered = helpers.meta_description.call(
{}, {},
{data: {root: {context: ['home', 'index']}}} {data: {root: {context: ['home', 'index']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('Just a blogging platform.'); String(rendered).should.equal('Just a blogging platform.');
done();
}).catch(done);
}); });
it('returns empty description on paginated page', function (done) { it('returns empty description on paginated page', function () {
helpers.meta_description.call( var rendered = helpers.meta_description.call(
{}, {},
{data: {root: {context: ['index', 'paged']}}} {data: {root: {context: ['index', 'paged']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal(''); String(rendered).should.equal('');
done();
}).catch(done);
}); });
it('returns empty description for a tag page', function (done) { it('returns empty description for a tag page', function () {
helpers.meta_description.call( var rendered = helpers.meta_description.call(
{tag: {name: 'Rasper Red'}}, {tag: {name: 'Rasper Red'}},
{data: {root: {context: ['tag']}}} {data: {root: {context: ['tag']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal(''); String(rendered).should.equal('');
done();
}).catch(done);
}); });
it('returns empty description for a paginated tag page', function (done) { it('returns empty description for a paginated tag page', function () {
helpers.meta_description.call( var rendered = helpers.meta_description.call(
{tag: {name: 'Rasper Red'}}, {tag: {name: 'Rasper Red'}},
{data: {root: {context: ['tag', 'paged']}}} {data: {root: {context: ['tag', 'paged']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal(''); String(rendered).should.equal('');
done();
}).catch(done);
}); });
it('returns tag meta_description if present for a tag page', function (done) { it('returns tag meta_description if present for a tag page', function () {
helpers.meta_description.call( var rendered = helpers.meta_description.call(
{tag: {name: 'Rasper Red', meta_description: 'Rasper is the Cool Red Casper'}}, {tag: {name: 'Rasper Red', meta_description: 'Rasper is the Cool Red Casper'}},
{data: {root: {context: ['tag']}}} {data: {root: {context: ['tag']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('Rasper is the Cool Red Casper'); String(rendered).should.equal('Rasper is the Cool Red Casper');
done();
}).catch(done);
}); });
it('returns empty description on paginated tag page that has meta data', function (done) { it('returns empty description on paginated tag page that has meta data', function () {
helpers.meta_description.call( var rendered = helpers.meta_description.call(
{tag: {name: 'Rasper Red', meta_description: 'Rasper is the Cool Red Casper'}}, {tag: {name: 'Rasper Red', meta_description: 'Rasper is the Cool Red Casper'}},
{data: {root: {context: ['tag', 'paged']}}} {data: {root: {context: ['tag', 'paged']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal(''); String(rendered).should.equal('');
done();
}).catch(done);
}); });
it('returns correct description for an author page', function (done) { it('returns correct description for an author page', function () {
helpers.meta_description.call( var rendered = helpers.meta_description.call(
{author: {bio: 'I am a Duck.'}}, {author: {bio: 'I am a Duck.'}},
{data: {root: {context: ['author']}}} {data: {root: {context: ['author']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('I am a Duck.'); String(rendered).should.equal('I am a Duck.');
done();
}).catch(done);
}); });
it('returns empty description for a paginated author page', function (done) { it('returns empty description for a paginated author page', function () {
helpers.meta_description.call( var rendered = helpers.meta_description.call(
{author: {name: 'Donald Duck'}}, {author: {name: 'Donald Duck'}},
{data: {root: {context: ['author', 'paged']}}} {data: {root: {context: ['author', 'paged']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal(''); String(rendered).should.equal('');
done();
}).catch(done);
}); });
it('returns empty description when meta_description is not set', function (done) { it('returns empty description when meta_description is not set', function () {
helpers.meta_description.call( var rendered = helpers.meta_description.call(
{post: {title: 'Post Title', html: 'Very nice post indeed.'}}, {post: {title: 'Post Title', html: 'Very nice post indeed.'}},
{data: {root: {context: ['post']}}} {data: {root: {context: ['post']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal(''); String(rendered).should.equal('');
done();
}).catch(done);
}); });
it('returns meta_description on post with meta_description set', function (done) { it('returns meta_description on post with meta_description set', function () {
helpers.meta_description.call( var rendered = helpers.meta_description.call(
{post: {title: 'Post Title', meta_description: 'Nice post about stuff.'}}, {post: {title: 'Post Title', meta_description: 'Nice post about stuff.'}},
{data: {root: {context: ['post']}}} {data: {root: {context: ['post']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('Nice post about stuff.'); String(rendered).should.equal('Nice post about stuff.');
done();
}).catch(done);
}); });
it('returns meta_description on post when used within {{#foreach posts}}', function (done) { it('returns meta_description on post when used within {{#foreach posts}}', function () {
helpers.meta_description.call( var rendered = helpers.meta_description.call(
{meta_description: 'Nice post about stuff.'}, {meta_description: 'Nice post about stuff.'},
{data: {root: {context: ['home']}}} {data: {root: {context: ['home']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('Nice post about stuff.'); String(rendered).should.equal('Nice post about stuff.');
done();
}).catch(done);
}); });
}); });

View file

@ -26,160 +26,134 @@ describe('{{meta_title}} helper', function () {
should.exist(handlebars.helpers.meta_title); should.exist(handlebars.helpers.meta_title);
}); });
it('returns correct title for homepage', function (done) { it('returns correct title for homepage', function () {
helpers.meta_title.call( var rendered = helpers.meta_title.call(
{}, {},
{data: {root: {context: ['home']}}} {data: {root: {context: ['home']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('Ghost'); String(rendered).should.equal('Ghost');
done();
}).catch(done);
}); });
it('returns correct title for paginated page', function (done) { it('returns correct title for paginated page', function () {
helpers.meta_title.call( var rendered = helpers.meta_title.call(
{}, {},
{data: {root: {context: [], pagination: {total: 2, page: 2}}}} {data: {root: {context: [], pagination: {total: 2, page: 2}}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('Ghost - Page 2'); String(rendered).should.equal('Ghost - Page 2');
done();
}).catch(done);
}); });
it('returns correct title for a post', function (done) { it('returns correct title for a post', function () {
helpers.meta_title.call( var rendered = helpers.meta_title.call(
{post: {title: 'Post Title'}}, {post: {title: 'Post Title'}},
{data: {root: {context: ['post']}}} {data: {root: {context: ['post']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('Post Title'); String(rendered).should.equal('Post Title');
done();
}).catch(done);
}); });
it('returns correct title for a post with meta_title set', function (done) { it('returns correct title for a post with meta_title set', function () {
helpers.meta_title.call( var rendered = helpers.meta_title.call(
{post: {title: 'Post Title', meta_title: 'Awesome Post'}}, {post: {title: 'Post Title', meta_title: 'Awesome Post'}},
{data: {root: {context: ['post']}}} {data: {root: {context: ['post']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('Awesome Post'); String(rendered).should.equal('Awesome Post');
done();
}).catch(done);
}); });
it('returns correct title for a page with meta_title set', function (done) { it('returns correct title for a page with meta_title set', function () {
helpers.meta_title.call( var rendered = helpers.meta_title.call(
{post: {title: 'About Page', meta_title: 'All about my awesomeness', page: true}}, {post: {title: 'About Page', meta_title: 'All about my awesomeness', page: true}},
{data: {root: {context: ['page']}}} {data: {root: {context: ['page']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('All about my awesomeness'); String(rendered).should.equal('All about my awesomeness');
done();
}).catch(done);
}); });
it('returns correct title for a tag page', function (done) { it('returns correct title for a tag page', function () {
var tag = {relativeUrl: '/tag/rasper-red', tag: {name: 'Rasper Red'}}; var tag = {relativeUrl: '/tag/rasper-red', tag: {name: 'Rasper Red'}},
helpers.meta_title.call( rendered = helpers.meta_title.call(
tag, tag,
{data: {root: {context: ['tag']}}} {data: {root: {context: ['tag']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('Rasper Red - Ghost'); String(rendered).should.equal('Rasper Red - Ghost');
done();
}).catch(done);
}); });
it('returns correct title for a paginated tag page', function (done) { it('returns correct title for a paginated tag page', function () {
helpers.meta_title.call( var rendered = helpers.meta_title.call(
{tag: {name: 'Rasper Red'}}, {tag: {name: 'Rasper Red'}},
{data: {root: {context: ['tag', 'paged'], pagination: {total: 2, page: 2}}}} {data: {root: {context: ['tag', 'paged'], pagination: {total: 2, page: 2}}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('Rasper Red - Page 2 - Ghost'); String(rendered).should.equal('Rasper Red - Page 2 - Ghost');
done();
}).catch(done);
}); });
it('uses tag meta_title to override default response on tag page', function (done) { it('uses tag meta_title to override default response on tag page', function () {
helpers.meta_title.call( var rendered = helpers.meta_title.call(
{tag: {name: 'Rasper Red', meta_title: 'Sasper Red'}}, {tag: {name: 'Rasper Red', meta_title: 'Sasper Red'}},
{data: {root: {context: ['tag']}}} {data: {root: {context: ['tag']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('Sasper Red'); String(rendered).should.equal('Sasper Red');
done();
}).catch(done);
}); });
it('uses tag meta_title to override default response on paginated tag page', function (done) { it('uses tag meta_title to override default response on paginated tag page', function () {
helpers.meta_title.call( var rendered = helpers.meta_title.call(
{tag: {name: 'Rasper Red', meta_title: 'Sasper Red'}}, {tag: {name: 'Rasper Red', meta_title: 'Sasper Red'}},
{data: {root: {context: ['tag']}}} {data: {root: {context: ['tag']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('Sasper Red'); String(rendered).should.equal('Sasper Red');
done();
}).catch(done);
}); });
it('returns correct title for an author page', function (done) { it('returns correct title for an author page', function () {
helpers.meta_title.call( var rendered = helpers.meta_title.call(
{author: {name: 'Donald Duck'}}, {author: {name: 'Donald Duck'}},
{data: {root: {context: ['author']}}} {data: {root: {context: ['author']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('Donald Duck - Ghost'); String(rendered).should.equal('Donald Duck - Ghost');
done();
}).catch(done);
}); });
it('returns correct title for a paginated author page', function (done) { it('returns correct title for a paginated author page', function () {
helpers.meta_title.call( var rendered = helpers.meta_title.call(
{author: {name: 'Donald Duck'}}, {author: {name: 'Donald Duck'}},
{data: {root: {context: ['author', 'paged'], pagination: {total: 2, page: 2}}}} {data: {root: {context: ['author', 'paged'], pagination: {total: 2, page: 2}}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('Donald Duck - Page 2 - Ghost'); String(rendered).should.equal('Donald Duck - Page 2 - Ghost');
done();
}).catch(done);
}); });
it('returns correctly escaped title of a post', function (done) { it('returns correctly escaped title of a post', function () {
helpers.meta_title.call( var rendered = helpers.meta_title.call(
{post: {title: 'Post Title "</>'}}, {post: {title: 'Post Title "</>'}},
{data: {root: {context: ['post']}}} {data: {root: {context: ['post']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('Post Title "</>'); String(rendered).should.equal('Post Title "</>');
done();
}).catch(done);
}); });
it('returns meta_title on post when used within {{#foreach posts}}', function (done) { it('returns meta_title on post when used within {{#foreach posts}}', function () {
helpers.meta_title.call( var rendered = helpers.meta_title.call(
{meta_title: 'Awesome Post'}, {meta_title: 'Awesome Post'},
{data: {root: {context: ['home']}}} {data: {root: {context: ['home']}}}
).then(function (rendered) { );
should.exist(rendered); should.exist(rendered);
String(rendered).should.equal('Awesome Post'); String(rendered).should.equal('Awesome Post');
done();
}).catch(done);
}); });
}); });

View file

@ -17,33 +17,26 @@ describe('{{post_class}} helper', function () {
should.exist(handlebars.helpers.post_class); should.exist(handlebars.helpers.post_class);
}); });
it('can render class string', function (done) { it('can render class string', function () {
helpers.post_class.call({}).then(function (rendered) { var rendered = helpers.post_class.call({});
should.exist(rendered); should.exist(rendered);
rendered.string.should.equal('post'); rendered.string.should.equal('post');
done();
}).catch(done);
}); });
it('can render featured class', function (done) { it('can render featured class', function () {
var post = {featured: true}; var post = {featured: true},
rendered = helpers.post_class.call(post);
helpers.post_class.call(post).then(function (rendered) {
should.exist(rendered); should.exist(rendered);
rendered.string.should.equal('post featured'); rendered.string.should.equal('post featured');
done();
}).catch(done);
}); });
it('can render page class', function (done) { it('can render page class', function () {
var post = {page: true}; var post = {page: true},
rendered = helpers.post_class.call(post);
helpers.post_class.call(post).then(function (rendered) {
should.exist(rendered); should.exist(rendered);
rendered.string.should.equal('post page'); rendered.string.should.equal('post page');
done();
}).catch(done);
}); });
}); });