0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Update config.theme() after every settings edit

fixes #1645

- removes server.get('ghost root') as it is only an alias
to config.paths().path, and adds unnecessary indirection
- removes config.theme().path as its just an alias to
config.paths().path, updated all relevant references
- update config.theme.update to only require the api/settings object,
and no longer need the config object
- modify api/settings.edit to call config.theme.update so that
the themeObject is ready for next rendering of template
This commit is contained in:
Harry Wolff 2013-12-09 23:41:58 -05:00
parent 589b4a8cea
commit 058b82bba1
6 changed files with 33 additions and 33 deletions

View file

@ -154,7 +154,10 @@ settings = {
result.models = result; result.models = result;
return when(readSettingsResult(result)).then(function (settings) { return when(readSettingsResult(result)).then(function (settings) {
updateSettingsCache(settings); updateSettingsCache(settings);
return settingsObject(settingsFilter(settingsCache, type)); }).then(function () {
return config.theme.update(settings).then(function () {
return settingsObject(settingsFilter(settingsCache, type));
});
}); });
}).otherwise(function (error) { }).otherwise(function (error) {
return dataProvider.Settings.read(key.key).then(function (result) { return dataProvider.Settings.read(key.key).then(function (result) {
@ -175,8 +178,11 @@ settings = {
setting.set('value', value); setting.set('value', value);
return dataProvider.Settings.edit(setting).then(function (result) { return dataProvider.Settings.edit(setting).then(function (result) {
settingsCache[_.first(result).attributes.key].value = _.first(result).attributes.value; settingsCache[_.first(result).attributes.key].value = _.first(result).attributes.value;
return settingsObject(settingsCache); }).then(function () {
}, errors.logAndThrowError); return config.theme.update(settings).then(function () {
return settingsObject(settingsCache);
});
}).otherwise(errors.logAndThrowError);
}); });
} }
}; };

View file

@ -13,23 +13,19 @@ function theme() {
return themeConfig; return themeConfig;
} }
// We must pass the api and config object // We must pass the api.settings object
// into this method due to circular dependencies. // into this method due to circular dependencies.
// If we were to require the api module here // If we were to require the api module here
// there would be a race condition where the ./models/base // there would be a race condition where the ./models/base
// tries to access the config() object before it is created. // tries to access the config() object before it is created.
// And we can't require('./index') from here because it is circular. function update(settings) {
function update(api, config) {
return when.all([ return when.all([
api.settings.read('title'), settings.read('title'),
api.settings.read('description'), settings.read('description'),
api.settings.read('logo'), settings.read('logo'),
api.settings.read('cover') settings.read('cover')
]).then(function (globals) { ]).then(function (globals) {
themeConfig.path = config.paths().path;
themeConfig.url = config().url;
themeConfig.title = globals[0].value; themeConfig.title = globals[0].value;
themeConfig.description = globals[1].value; themeConfig.description = globals[1].value;
themeConfig.logo = globals[2] ? globals[2].value : ''; themeConfig.logo = globals[2] ? globals[2].value : '';

View file

@ -94,14 +94,14 @@ coreHelpers.url = function (options) {
slug: function () { return self.slug; }, slug: function () { return self.slug; },
id: function () { return self.id; } id: function () { return self.id; }
}, },
blog = coreHelpers.config.theme(), path = coreHelpers.config.paths().path,
isAbsolute = options && options.hash.absolute; isAbsolute = options && options.hash.absolute;
return api.settings.read('permalinks').then(function (permalinks) { return api.settings.read('permalinks').then(function (permalinks) {
if (isAbsolute) { if (isAbsolute) {
output += blog.url; output += coreHelpers.config().url;
} }
if (blog.path && blog.path !== '/') { if (path && path !== '/') {
output += blog.path; output += path;
} }
if (models.isPost(self)) { if (models.isPost(self)) {
output += permalinks.value; output += permalinks.value;
@ -125,7 +125,7 @@ coreHelpers.url = function (options) {
// flag outputs the asset path for the Ghost admin // flag outputs the asset path for the Ghost admin
coreHelpers.asset = function (context, options) { coreHelpers.asset = function (context, options) {
var output = '', var output = '',
subDir = coreHelpers.config.theme().path, subDir = coreHelpers.config.paths().path,
isAdmin = options && options.hash && options.hash.ghost; isAdmin = options && options.hash && options.hash.ghost;
if (subDir === '/') { if (subDir === '/') {
@ -264,7 +264,7 @@ coreHelpers.fileStorage = function (context, options) {
coreHelpers.ghostScriptTags = function () { coreHelpers.ghostScriptTags = function () {
var scriptFiles = [], var scriptFiles = [],
blog = coreHelpers.config.theme(); webroot = coreHelpers.config.paths().webroot;
if (isProduction) { if (isProduction) {
scriptFiles.push("ghost.min.js"); scriptFiles.push("ghost.min.js");
@ -280,7 +280,7 @@ coreHelpers.ghostScriptTags = function () {
scriptFiles = _.map(scriptFiles, function (fileName) { scriptFiles = _.map(scriptFiles, function (fileName) {
return scriptTemplate({ return scriptTemplate({
source: (blog.path === '/' ? '' : blog.path) + '/built/scripts/' + fileName, source: webroot + '/built/scripts/' + fileName,
version: version version: version
}); });
}); });
@ -348,7 +348,7 @@ coreHelpers.post_class = function (options) {
coreHelpers.ghost_head = function (options) { coreHelpers.ghost_head = function (options) {
/*jslint unparam:true*/ /*jslint unparam:true*/
var blog = coreHelpers.config.theme(), var blog = coreHelpers.config.theme(),
root = blog.path === '/' ? '' : blog.path, root = coreHelpers.config.paths().webroot,
head = [], head = [],
majorMinor = /^(\d+\.)?(\d+)/, majorMinor = /^(\d+\.)?(\d+)/,
trimmedVersion = this.version; trimmedVersion = this.version;
@ -359,7 +359,7 @@ coreHelpers.ghost_head = function (options) {
head.push('<link rel="alternate" type="application/rss+xml" title="' + _.escape(blog.title) + '" href="' + root + '/rss/' + '">'); head.push('<link rel="alternate" type="application/rss+xml" title="' + _.escape(blog.title) + '" href="' + root + '/rss/' + '">');
if (this.ghostRoot) { if (this.ghostRoot) {
head.push('<link rel="canonical" href="' + coreHelpers.config.theme().url + this.ghostRoot + '" />'); head.push('<link rel="canonical" href="' + coreHelpers.config().url + this.ghostRoot + '" />');
} }
return filters.doFilter('ghost_head', head).then(function (head) { return filters.doFilter('ghost_head', head).then(function (head) {
@ -371,7 +371,7 @@ coreHelpers.ghost_head = function (options) {
coreHelpers.ghost_foot = function (options) { coreHelpers.ghost_foot = function (options) {
/*jslint unparam:true*/ /*jslint unparam:true*/
var foot = []; var foot = [];
foot.push('<script src="' + coreHelpers.config.theme().url + '/shared/vendor/jquery/jquery.js"></script>'); foot.push('<script src="' + coreHelpers.config().url + '/shared/vendor/jquery/jquery.js"></script>');
return filters.doFilter('ghost_foot', foot).then(function (foot) { return filters.doFilter('ghost_foot', foot).then(function (foot) {
var footString = _.reduce(foot, function (memo, item) { return memo + ' ' + item; }, ''); var footString = _.reduce(foot, function (memo, item) { return memo + ' ' + item; }, '');

View file

@ -94,9 +94,9 @@ function setup(server) {
// Initialize the settings cache // Initialize the settings cache
return api.init(); return api.init();
}).then(function () { }).then(function () {
// We must pass the api and config object // We must pass the api.settings object
// into this method due to circular dependencies. // into this method due to circular dependencies.
return config.theme.update(api, config); return config.theme.update(api.settings);
}).then(function () { }).then(function () {
return when.join( return when.join(
// Check for or initialise a dbHash. // Check for or initialise a dbHash.
@ -118,9 +118,6 @@ function setup(server) {
// set the view engine // set the view engine
server.set('view engine', 'hbs'); server.set('view engine', 'hbs');
// set the configured URL
server.set('ghost root', config.theme().path);
// return the correct mime type for woff filess // return the correct mime type for woff filess
express['static'].mime.define({'application/font-woff': ['woff']}); express['static'].mime.define({'application/font-woff': ['woff']});

View file

@ -30,7 +30,7 @@ function ghostLocals(req, res, next) {
res.locals.version = packageInfo.version; res.locals.version = packageInfo.version;
res.locals.path = req.path; res.locals.path = req.path;
// Strip off the subdir part of the path // Strip off the subdir part of the path
res.locals.ghostRoot = req.path.replace(config.theme().path.replace(/\/$/, ''), ''); res.locals.ghostRoot = req.path.replace(config.paths().webroot, '');
if (res.isAdmin) { if (res.isAdmin) {
res.locals.csrfToken = req.csrfToken(); res.locals.csrfToken = req.csrfToken();
@ -117,10 +117,10 @@ function activateTheme(activeTheme) {
// This is used to ensure the right content is served, and is not for security purposes // This is used to ensure the right content is served, and is not for security purposes
function manageAdminAndTheme(req, res, next) { function manageAdminAndTheme(req, res, next) {
// TODO improve this regex // TODO improve this regex
if (config.theme().path === '/') { if (config.paths().path === '/') {
res.isAdmin = /(^\/ghost\/)/.test(req.url); res.isAdmin = /(^\/ghost\/)/.test(req.url);
} else { } else {
res.isAdmin = new RegExp("^\\" + config.theme().path + "\\/ghost\\/").test(req.url); res.isAdmin = new RegExp("^\\" + config.paths().path + "\\/ghost\\/").test(req.url);
} }
if (res.isAdmin) { if (res.isAdmin) {
@ -149,7 +149,7 @@ function manageAdminAndTheme(req, res, next) {
// Redirect to signup if no users are currently created // Redirect to signup if no users are currently created
function redirectToSignup(req, res, next) { function redirectToSignup(req, res, next) {
var root = expressServer.get('ghost root').replace(/\/$/, ''); var root = config.paths().webroot;
/*jslint unparam:true*/ /*jslint unparam:true*/
api.users.browse().then(function (users) { api.users.browse().then(function (users) {
if (users.length === 0) { if (users.length === 0) {

View file

@ -1,10 +1,11 @@
var admin = require('../controllers/admin'), var admin = require('../controllers/admin'),
api = require('../api'), api = require('../api'),
config = require('../config'),
middleware = require('../middleware').middleware, middleware = require('../middleware').middleware,
url = require('url'); url = require('url');
module.exports = function (server) { module.exports = function (server) {
var root = server.get('ghost root').replace(/\/$/, ''); var root = config.paths().webroot;
// ### Admin routes // ### Admin routes
/* TODO: put these somewhere in admin */ /* TODO: put these somewhere in admin */
server.get('/logout/', function redirect(req, res) { server.get('/logout/', function redirect(req, res) {