mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-13 22:41:32 -05:00
376cf647e5
- adds routes for homepage pagination - adds helper function to compile template file for pagination - adds next and prev to post for next and previous page - adds handlebars template for pagination
47 lines
No EOL
1.4 KiB
JavaScript
47 lines
No EOL
1.4 KiB
JavaScript
var fs = require('fs'),
|
|
path = require('path'),
|
|
_ = require('underscore'),
|
|
handlebars = require('express-hbs').handlebars,
|
|
nodefn = require('when/node/function'),
|
|
|
|
PaginationHelper;
|
|
|
|
PaginationHelper = function (paginationTemplate) {
|
|
// Bind the context for our methods.
|
|
_.bindAll(this, 'compileTemplate', 'renderPagination');
|
|
|
|
if (_.isFunction(paginationTemplate)) {
|
|
this.paginationTemplateFunc = paginationTemplate;
|
|
} else {
|
|
this.paginationTemplatePath = paginationTemplate;
|
|
}
|
|
};
|
|
|
|
PaginationHelper.prototype.compileTemplate = function (templatePath) {
|
|
var self = this;
|
|
|
|
|
|
templatePath = templatePath || this.paginationTemplatePath;
|
|
|
|
return nodefn.call(fs.readFile, templatePath).then(function (paginationContents) {
|
|
// TODO: Can handlebars compile async?
|
|
self.paginationTemplateFunc = handlebars.compile(paginationContents.toString());
|
|
});
|
|
};
|
|
|
|
PaginationHelper.prototype.renderPagination = function (context, options) {
|
|
var output = this.paginationTemplateFunc(context);
|
|
return output;
|
|
};
|
|
|
|
|
|
PaginationHelper.registerWithGhost = function (ghost) {
|
|
var templatePath = path.join(ghost.paths().frontendViews, 'pagination.hbs'),
|
|
paginationHelper = new PaginationHelper(templatePath);
|
|
|
|
return paginationHelper.compileTemplate().then(function () {
|
|
ghost.registerThemeHelper("paginate", paginationHelper.renderPagination);
|
|
});
|
|
};
|
|
|
|
module.exports = PaginationHelper; |