0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Cleans up HTML data attributes on body in default.hbs

closes #4485

- removes data attributes used on body in default.hbs
- introduces new way to generate configuration through meta tags
- config initializer consumes configurations from the meta tags using parser
- moves blog_title helper/value to be a property in a configuration api
This commit is contained in:
Nazar Gargol 2014-11-27 21:50:15 +01:00
parent 0fa35b325c
commit b35aecc712
2 changed files with 40 additions and 9 deletions

View file

@ -1,16 +1,11 @@
import getConfig from 'ghost/utils/config-parser';
var ConfigInitializer = {
name: 'config',
initialize: function (container, application) {
var apps = $('body').data('apps'),
tagsUI = $('body').data('tagsui'),
fileStorage = $('body').data('filestorage'),
blogUrl = $('body').data('blogurl'),
blogTitle = $('body').data('blogtitle');
application.register(
'ghost:config', {apps: apps, fileStorage: fileStorage, blogUrl: blogUrl, tagsUI: tagsUI, blogTitle: blogTitle}, {instantiate: false}
);
var config = getConfig();
application.register('ghost:config', config, {instantiate: false});
application.inject('route', 'config', 'ghost:config');
application.inject('controller', 'config', 'ghost:config');

View file

@ -0,0 +1,36 @@
var isNumeric = function (num) {
return !isNaN(num);
},
_mapType = function (val) {
if (val === '') {
return null;
} else if (val === 'true') {
return true;
} else if (val === 'false') {
return false;
} else if (isNumeric(val)) {
return +val;
} else {
return val;
}
},
parseConfiguration = function () {
var metaConfigTags = $('meta[name^="env-"]'),
propertyName,
config = {},
value,
key,
i;
for (i = 0; i < metaConfigTags.length; i += 1) {
key = $(metaConfigTags[i]).prop('name');
value = $(metaConfigTags[i]).prop('content');
propertyName = key.substring(4); // produce config name ignoring the initial 'env-'.
config[propertyName] = _mapType(value); // map string values to types if possible
}
return config;
};
export default parseConfiguration;