mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
dbd22d7447
closes #9200 - Registered new server helper `{{reading_time}}`. - Added new global util `word-count` based on the util in Ghost admin, which returns the number of words in an HTML string. - Based on the word count of the post html, the helper calculated the estimated reading time: - 275 words per minute - additional 12 seconds when post has feature image - Renders a string like 'x min red', unless reading time is less than a minute. In this case, the rendered string is '< 1 min read'.
38 lines
1.6 KiB
JavaScript
38 lines
1.6 KiB
JavaScript
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
|
var should = require('should'), // jshint ignore:line
|
|
_ = require('lodash'),
|
|
hbs = require.main.require('core/server/themes/engine'),
|
|
|
|
// Stuff we are testing
|
|
helpers = require.main.require('core/server/helpers');
|
|
|
|
describe('Helpers', function () {
|
|
var hbsHelpers = ['each', 'if', 'unless', 'with', 'helperMissing', 'blockHelperMissing', 'log', 'lookup'],
|
|
ghostHelpers = [
|
|
'asset', 'author', 'body_class', 'content', 'date', 'encode', 'excerpt', 'facebook_url', 'foreach', 'get',
|
|
'ghost_foot', 'ghost_head', 'has', 'img_url', 'is', 'meta_description', 'meta_title', 'navigation',
|
|
'next_post', 'page_url', 'pagination', 'plural', 'post_class', 'prev_post', 'reading_time', 'tags', 'title', 'twitter_url',
|
|
'url'
|
|
],
|
|
expectedHelpers = _.concat(hbsHelpers, ghostHelpers);
|
|
|
|
describe('Load Core Helpers', function () {
|
|
before(function () {
|
|
helpers.loadCoreHelpers();
|
|
});
|
|
|
|
// This will work when we finish refactoring
|
|
it('should have exactly the right helpers', function () {
|
|
var foundHelpers, missingHelpers, unexpectedHelpers;
|
|
|
|
foundHelpers = _.keys(hbs.handlebars.helpers);
|
|
|
|
missingHelpers = _.difference(expectedHelpers, foundHelpers);
|
|
unexpectedHelpers = _.difference(foundHelpers, expectedHelpers);
|
|
|
|
missingHelpers.should.be.an.Array().with.lengthOf(0);
|
|
unexpectedHelpers.should.be.an.Array().with.lengthOf(0);
|
|
});
|
|
});
|
|
});
|