mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 19:52:01 +03:00
243b387063
refs #8126, #8221, #8223 ✨ New 'Proxy' for all helper requires - this is not currently enforced, but could be, much like apps - the proxy object is HUGE - changed date to use SafeString, this should have been there anyway - use the proxy for all helpers, including those in apps 😁 ✨ 🎨 Single instance of hbs for theme + for errors - we now have theme/engine instead of requiring express-hbs everywhere - only error-handler still also requires express-hbs, this is so that we can render errors without extra crud - TODO: remove the asset helper after #8126 IF it is not needed, or else remove the TODO 🎨 Cleanup visibility utils 🎨 Clean up the proxy a little bit 🚨 Unskip test as it now works! 🎨 Minor amends as per comments
45 lines
1.6 KiB
JavaScript
45 lines
1.6 KiB
JavaScript
// ### Pagination Helper
|
|
// `{{pagination}}`
|
|
// Outputs previous and next buttons, along with info about the current page
|
|
|
|
var proxy = require('./proxy'),
|
|
_ = require('lodash'),
|
|
errors = proxy.errors,
|
|
i18n = proxy.i18n,
|
|
templates = proxy.templates,
|
|
pagination;
|
|
|
|
pagination = function (options) {
|
|
/*jshint unused:false*/
|
|
if (!_.isObject(this.pagination) || _.isFunction(this.pagination)) {
|
|
throw new errors.IncorrectUsageError({
|
|
message: i18n.t('warnings.helpers.pagination.invalidData')
|
|
});
|
|
}
|
|
|
|
if (_.isUndefined(this.pagination.page) || _.isUndefined(this.pagination.pages) ||
|
|
_.isUndefined(this.pagination.total) || _.isUndefined(this.pagination.limit)) {
|
|
throw new errors.IncorrectUsageError({
|
|
message: i18n.t('warnings.helpers.pagination.valuesMustBeDefined')
|
|
});
|
|
}
|
|
|
|
if ((!_.isNull(this.pagination.next) && !_.isNumber(this.pagination.next)) ||
|
|
(!_.isNull(this.pagination.prev) && !_.isNumber(this.pagination.prev))) {
|
|
throw new errors.IncorrectUsageError({
|
|
message: i18n.t('warnings.helpers.pagination.nextPrevValuesMustBeNumeric')
|
|
});
|
|
}
|
|
|
|
if (!_.isNumber(this.pagination.page) || !_.isNumber(this.pagination.pages) ||
|
|
!_.isNumber(this.pagination.total) || !_.isNumber(this.pagination.limit)) {
|
|
throw new errors.IncorrectUsageError({message: i18n.t('warnings.helpers.pagination.valuesMustBeNumeric')});
|
|
}
|
|
|
|
var data = _.merge({}, this.pagination);
|
|
|
|
return templates.execute('pagination', data, options);
|
|
};
|
|
|
|
module.exports = pagination;
|