mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
Make settings() 'magic'
- access value directly by using ghost.settings('key') - removed use of <key>.value - removed workaround for activeTheme path
This commit is contained in:
parent
117f70dcfd
commit
8f22737f04
@ -93,17 +93,22 @@ Ghost = function () {
|
||||
config: function () { return config[process.env.NODE_ENV]; },
|
||||
|
||||
// there's no management here to be sure this has loaded
|
||||
settings: function () { return instance.settingsCache; },
|
||||
settings: function (key) {
|
||||
if (key) {
|
||||
return instance.settingsCache[key].value;
|
||||
}
|
||||
return instance.settingsCache;
|
||||
},
|
||||
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().url,
|
||||
title: instance.settings().title.value,
|
||||
description: instance.settings().description.value,
|
||||
logo: instance.settings().logo.value,
|
||||
cover: instance.settings().cover.value
|
||||
title: instance.settings('title'),
|
||||
description: instance.settings('description'),
|
||||
logo: instance.settings('logo'),
|
||||
cover: instance.settings('cover')
|
||||
};
|
||||
},
|
||||
statuses: function () { return statuses; },
|
||||
@ -196,16 +201,9 @@ Ghost.prototype.readSettingsResult = function (result) {
|
||||
return when(_.map(result.models, function (member) {
|
||||
if (!settings.hasOwnProperty(member.attributes.key)) {
|
||||
var val = {};
|
||||
if (member.attributes.key === 'activeTheme') {
|
||||
member.attributes.value = member.attributes.value.substring(member.attributes.value.lastIndexOf('/') + 1);
|
||||
val.value = member.attributes.value;
|
||||
val.type = member.attributes.type;
|
||||
settings[member.attributes.key] = val;
|
||||
} else {
|
||||
val.value = member.attributes.value;
|
||||
val.type = member.attributes.type;
|
||||
settings[member.attributes.key] = val;
|
||||
}
|
||||
val.value = member.attributes.value;
|
||||
val.type = member.attributes.type;
|
||||
settings[member.attributes.key] = val;
|
||||
}
|
||||
})).then(function () {
|
||||
return when(instance.paths().availableThemes).then(function (themes) {
|
||||
@ -353,11 +351,11 @@ Ghost.prototype.initTheme = function (app) {
|
||||
// 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.value)) {
|
||||
if (!self.themeDirectories.hasOwnProperty(self.settings('activeTheme'))) {
|
||||
// Throw an error if the theme is not available...
|
||||
// TODO: move this to happen on app start
|
||||
errors.logAndThrowError('The currently active theme ' + self.settings().activeTheme.value + ' is missing.');
|
||||
} else if (self.themeDirectories[self.settings().activeTheme.value].hasOwnProperty('partials')) {
|
||||
errors.logAndThrowError('The currently active theme ' + self.settings('activeTheme') + ' is missing.');
|
||||
} else if (self.themeDirectories[self.settings('activeTheme')].hasOwnProperty('partials')) {
|
||||
// Check that the theme has a partials directory before trying to use it
|
||||
hbsOptions.partialsDir = path.join(self.paths().activeTheme, 'partials');
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ frontendControllers = {
|
||||
'homepage': function (req, res) {
|
||||
// Parse the page number
|
||||
var pageParam = req.params.page !== undefined ? parseInt(req.params.page, 10) : 1,
|
||||
postsPerPage = parseInt(ghost.settings().postsPerPage.value, 10),
|
||||
postsPerPage = parseInt(ghost.settings('postsPerPage'), 10),
|
||||
options = {};
|
||||
|
||||
// No negative pages
|
||||
@ -67,10 +67,10 @@ frontendControllers = {
|
||||
// Initialize RSS
|
||||
var siteUrl = ghost.config().url,
|
||||
feed = new RSS({
|
||||
title: ghost.settings().title.value,
|
||||
description: ghost.settings().description.value,
|
||||
title: ghost.settings('title'),
|
||||
description: ghost.settings('description'),
|
||||
generator: 'Ghost v' + res.locals.version,
|
||||
author: ghost.settings().author.value,
|
||||
author: ghost.settings('author'),
|
||||
feed_url: siteUrl + '/rss/',
|
||||
site_url: siteUrl,
|
||||
ttl: '60'
|
||||
|
@ -234,7 +234,7 @@ coreHelpers = function (ghost) {
|
||||
ghost.registerThemeHelper('e', function (key, defaultString, options) {
|
||||
var output;
|
||||
|
||||
if (ghost.settings().defaultLang.value === 'en' && _.isEmpty(options.hash) && !ghost.settings().forceI18n.value) {
|
||||
if (ghost.settings('defaultLang') === 'en' && _.isEmpty(options.hash) && !ghost.settings('forceI18n')) {
|
||||
output = defaultString;
|
||||
} else {
|
||||
output = ghost.polyglot().t(key, options.hash);
|
||||
|
@ -96,7 +96,7 @@ GhostMailer.prototype.send = function (message) {
|
||||
}
|
||||
|
||||
var from = 'ghost-mailer@' + url.parse(this.ghost.config().url).hostname,
|
||||
to = message.to || this.ghost.settings().email.value,
|
||||
to = message.to || this.ghost.settings('email'),
|
||||
sendMail = nodefn.lift(this.transport.sendMail.bind(this.transport));
|
||||
|
||||
message = _.extend(message, {
|
||||
|
@ -8,7 +8,7 @@ var fs = require('fs'),
|
||||
I18n = function (ghost) {
|
||||
|
||||
// TODO: validate
|
||||
var lang = ghost.settings().defaultLang.value,
|
||||
var lang = ghost.settings('defaultLang'),
|
||||
path = ghost.paths().lang,
|
||||
langFilePath = path + lang + '.json';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user