mirror of https://github.com/TryGhost/Ghost.git
Global settings for themes
issue #389 - Upgrade express-hbs to get template options access - Grab config & settings with a hacky new method in ghost & pass to template options - Settings are no longer passed to res.locals
This commit is contained in:
parent
40c3b7fe31
commit
be62a550f9
|
@ -97,6 +97,18 @@ Ghost = function () {
|
||||||
// there's no management here to be sure this has loaded
|
// there's no management here to be sure this has loaded
|
||||||
settings: function () { return instance.settingsCache; },
|
settings: function () { return instance.settingsCache; },
|
||||||
dataProvider: models,
|
dataProvider: models,
|
||||||
|
blogGlobals: function () {
|
||||||
|
/* this is a bit of a hack until we have a better way to combine settings and config
|
||||||
|
* this data is what becomes globally available to themes */
|
||||||
|
return {
|
||||||
|
url: instance.config().env[process.env.NODE_ENV].url,
|
||||||
|
title: instance.settings().title,
|
||||||
|
description: instance.settings().description,
|
||||||
|
logo: instance.settings().logo,
|
||||||
|
/* urg.. need to fix paths */
|
||||||
|
themedir: path.join('/content/themes', instance.paths().activeTheme, instance.settingsCache.activeTheme)
|
||||||
|
};
|
||||||
|
},
|
||||||
statuses: function () { return statuses; },
|
statuses: function () { return statuses; },
|
||||||
polyglot: function () { return polyglot; },
|
polyglot: function () { return polyglot; },
|
||||||
getPaths: function () {
|
getPaths: function () {
|
||||||
|
@ -296,27 +308,29 @@ Ghost.prototype.initPlugins = function (pluginsToLoad) {
|
||||||
|
|
||||||
// Initialise Theme or admin
|
// Initialise Theme or admin
|
||||||
Ghost.prototype.initTheme = function (app) {
|
Ghost.prototype.initTheme = function (app) {
|
||||||
var self = this;
|
var self = this,
|
||||||
|
hbsOptions;
|
||||||
return function initTheme(req, res, next) {
|
return function initTheme(req, res, next) {
|
||||||
app.set('view engine', 'hbs');
|
app.set('view engine', 'hbs');
|
||||||
// return the correct mime type for woff files
|
// return the correct mime type for woff files
|
||||||
express['static'].mime.define({'application/font-woff': ['woff']});
|
express['static'].mime.define({'application/font-woff': ['woff']});
|
||||||
|
|
||||||
if (!res.isAdmin) {
|
if (!res.isAdmin) {
|
||||||
|
|
||||||
|
// self.globals is a hack til we have a better way of getting combined settings & config
|
||||||
|
hbsOptions = {templateOptions: {data: {blog: self.blogGlobals()}}};
|
||||||
|
|
||||||
if (!self.themeDirectories.hasOwnProperty(self.settings().activeTheme)) {
|
if (!self.themeDirectories.hasOwnProperty(self.settings().activeTheme)) {
|
||||||
// Throw an error if the theme is not available...
|
// Throw an error if the theme is not available...
|
||||||
// TODO: move this to happen on app start
|
// TODO: move this to happen on app start
|
||||||
errors.logAndThrowError('The currently active theme ' + self.settings().activeTheme + ' is missing.');
|
errors.logAndThrowError('The currently active theme ' + self.settings().activeTheme + ' is missing.');
|
||||||
} else if (self.themeDirectories[self.settings().activeTheme].hasOwnProperty('partials')) {
|
} else if (self.themeDirectories[self.settings().activeTheme].hasOwnProperty('partials')) {
|
||||||
// Check that the theme has a partials directory before trying to use it
|
// Check that the theme has a partials directory before trying to use it
|
||||||
app.engine('hbs', hbs.express3(
|
hbsOptions.partialsDir = path.join(self.paths().activeTheme, 'partials');
|
||||||
{partialsDir: path.join(self.paths().activeTheme, 'partials')}
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
// No partial dir, so no need to configure it
|
|
||||||
app.engine('hbs', hbs.express3());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.engine('hbs', hbs.express3(hbsOptions));
|
||||||
|
|
||||||
app.set('views', self.paths().activeTheme);
|
app.set('views', self.paths().activeTheme);
|
||||||
} else {
|
} else {
|
||||||
app.engine('hbs', hbs.express3({partialsDir: self.paths().adminViews + 'partials'}));
|
app.engine('hbs', hbs.express3({partialsDir: self.paths().adminViews + 'partials'}));
|
||||||
|
|
6
index.js
6
index.js
|
@ -108,10 +108,8 @@ function ghostLocals(req, res, next) {
|
||||||
if (!res.isAdmin) {
|
if (!res.isAdmin) {
|
||||||
// filter the navigation items
|
// filter the navigation items
|
||||||
ghost.doFilter('ghostNavItems', {path: req.path, navItems: []}, function (navData) {
|
ghost.doFilter('ghostNavItems', {path: req.path, navItems: []}, function (navData) {
|
||||||
// pass the theme navigation items and settings
|
// pass the theme navigation items, settings get configured as globals
|
||||||
_.extend(res.locals, navData, {
|
_.extend(res.locals, navData);
|
||||||
settings: ghost.settings()
|
|
||||||
});
|
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
"engineStrict": true,
|
"engineStrict": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "3.3.4",
|
"express": "3.3.4",
|
||||||
"express-hbs": "0.2.0",
|
"express-hbs": "0.2.1",
|
||||||
"node-polyglot": "0.2.1",
|
"node-polyglot": "0.2.1",
|
||||||
"moment": "2.1.0",
|
"moment": "2.1.0",
|
||||||
"underscore": "1.5.1",
|
"underscore": "1.5.1",
|
||||||
|
|
Loading…
Reference in New Issue