Merge pull request #1218 from halfdan/1212-themable-error-pages

Allow themes to provide custom error template.
This commit is contained in:
Hannah Wolfe 2013-10-23 08:00:56 -07:00
commit 40ba763f0f
2 changed files with 14 additions and 6 deletions

View File

@ -198,6 +198,9 @@ function activateTheme() {
if (stackLocation) {
server.stack[stackLocation].handle = whenEnabled(server.get('activeTheme'), middleware.staticTheme(ghost));
}
// Update user error template
errors.updateActiveTheme(ghost.settings('activeTheme'));
}
// ### ManageAdminAndTheme Middleware

View File

@ -6,17 +6,22 @@ var _ = require('underscore'),
errors,
// Paths for views
appRoot = path.resolve(__dirname, '../'),
themePath = path.resolve(appRoot + '/content/themes'),
adminTemplatePath = path.resolve(appRoot + '/server/views/'),
defaultErrorTemplatePath = path.resolve(adminTemplatePath + '/user-error.hbs'),
userErrorTemplatePath = path.resolve(themePath + '/error.hbs'),
appRoot = path.resolve(__dirname, '..', '..'),
themePath = path.resolve(appRoot, 'content', 'themes'),
adminTemplatePath = path.resolve(appRoot, 'core', 'server', 'views'),
defaultErrorTemplatePath = path.resolve(adminTemplatePath, 'user-error.hbs'),
userErrorTemplatePath = path.resolve(themePath, 'error.hbs'),
userErrorTemplateExists;
/**
* Basic error handling helpers
*/
errors = {
updateActiveTheme: function (activeTheme) {
userErrorTemplatePath = path.resolve(themePath, activeTheme, 'error.hbs');
userErrorTemplateExists = undefined;
},
throwError: function (err) {
if (!err) {
err = new Error("An error occurred");
@ -104,7 +109,7 @@ errors = {
renderErrorPage: function (code, err, req, res, next) {
function parseStack(stack) {
if (typeof stack !== 'string') {
if (_.isString(stack)) {
return stack;
}