Skip to content

Commit

Permalink
Merge pull request #1630 from hswolff/remove-ghost-singleton
Browse files Browse the repository at this point in the history
Remove ghost.js
  • Loading branch information
ErisDS committed Dec 8, 2013
2 parents fe8e24d + c8c02a6 commit 119af63
Show file tree
Hide file tree
Showing 15 changed files with 233 additions and 297 deletions.
132 changes: 0 additions & 132 deletions core/ghost.js

This file was deleted.

6 changes: 6 additions & 0 deletions core/server/config/index.js
@@ -1,6 +1,11 @@
// General entry point for all configuration data
//
// This file itself is a wrapper for the root level config.js file.
// All other files that need to reference config.js should use this file.

var loader = require('./loader'),
paths = require('./paths'),
theme = require('./theme'),
ghostConfig;

// Returns NODE_ENV config object
Expand All @@ -24,5 +29,6 @@ function loadConfig() {

config.load = loadConfig;
config.paths = paths;
config.theme = theme;

module.exports = config;
6 changes: 6 additions & 0 deletions core/server/config/loader.js
@@ -1,3 +1,9 @@
// This file manages the root level config.js.
// It will create config.js from config.exampe.js
// if it doesn't exist and then always attempt to load
// config.js into memory, error and quitting if config.js
// has an improper format.

var fs = require('fs'),
url = require('url'),
when = require('when'),
Expand Down
3 changes: 2 additions & 1 deletion core/server/config/paths.js
@@ -1,4 +1,5 @@

// Contains all path information to be used throughout
// the codebase.

var path = require('path'),
when = require('when'),
Expand Down
42 changes: 42 additions & 0 deletions core/server/config/theme.js
@@ -0,0 +1,42 @@
// Holds all theme configuration information
// that as mostly used by templates and handlebar helpers.

var when = require('when'),

// Variables
theme,
themeConfig = {},
update;


function theme() {
return themeConfig;
}

// We must pass the api and config object
// into this method due to circular dependencies.
// If we were to require the api module here
// there would be a race condition where the ./models/base
// tries to access the config() object before it is created.
// And we can't require('./index') from here because it is circular.
function update(api, config) {
return when.all([
api.settings.read('title'),
api.settings.read('description'),
api.settings.read('logo'),
api.settings.read('cover')
]).then(function (globals) {

themeConfig.path = config.paths().path;

themeConfig.url = config().url;
themeConfig.title = globals[0].value;
themeConfig.description = globals[1].value;
themeConfig.logo = globals[2] ? globals[2].value : '';
themeConfig.cover = globals[3] ? globals[3].value : '';
return;
});
}

module.exports = theme;
module.exports.update = update;
21 changes: 9 additions & 12 deletions core/server/helpers/index.js
Expand Up @@ -94,7 +94,7 @@ coreHelpers.url = function (options) {
slug: function () { return self.slug; },
id: function () { return self.id; }
},
blog = coreHelpers.ghost.blogGlobals(),
blog = coreHelpers.config.theme(),
isAbsolute = options && options.hash.absolute;
return api.settings.read('permalinks').then(function (permalinks) {
if (isAbsolute) {
Expand Down Expand Up @@ -125,7 +125,7 @@ coreHelpers.url = function (options) {
// flag outputs the asset path for the Ghost admin
coreHelpers.asset = function (context, options) {
var output = '',
subDir = coreHelpers.ghost.blogGlobals().path,
subDir = coreHelpers.config.theme().path,
isAdmin = options && options.hash && options.hash.ghost;

if (subDir === '/') {
Expand Down Expand Up @@ -264,7 +264,7 @@ coreHelpers.fileStorage = function (context, options) {

coreHelpers.ghostScriptTags = function () {
var scriptFiles = [],
blog = coreHelpers.ghost.blogGlobals();
blog = coreHelpers.config.theme();

if (isProduction) {
scriptFiles.push("ghost.min.js");
Expand Down Expand Up @@ -347,7 +347,7 @@ coreHelpers.post_class = function (options) {

coreHelpers.ghost_head = function (options) {
/*jslint unparam:true*/
var blog = coreHelpers.ghost.blogGlobals(),
var blog = coreHelpers.config.theme(),
root = blog.path === '/' ? '' : blog.path,
head = [],
majorMinor = /^(\d+\.)?(\d+)/,
Expand All @@ -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/' + '">');
if (this.ghostRoot) {
head.push('<link rel="canonical" href="' + coreHelpers.ghost.blogGlobals().url + this.ghostRoot + '" />');
head.push('<link rel="canonical" href="' + coreHelpers.config.theme().url + this.ghostRoot + '" />');
}

return filters.doFilter('ghost_head', head).then(function (head) {
Expand All @@ -371,7 +371,7 @@ coreHelpers.ghost_head = function (options) {
coreHelpers.ghost_foot = function (options) {
/*jslint unparam:true*/
var foot = [];
foot.push('<script src="' + coreHelpers.ghost.blogGlobals().url + '/shared/vendor/jquery/jquery.js"></script>');
foot.push('<script src="' + coreHelpers.config.theme().url + '/shared/vendor/jquery/jquery.js"></script>');

return filters.doFilter('ghost_foot', foot).then(function (foot) {
var footString = _.reduce(foot, function (memo, item) { return memo + ' ' + item; }, '');
Expand All @@ -385,7 +385,7 @@ coreHelpers.meta_title = function (options) {
blog;
if (_.isString(this.ghostRoot)) {
if (!this.ghostRoot || this.ghostRoot === '/' || this.ghostRoot === '' || this.ghostRoot.match(/\/page/)) {
blog = coreHelpers.ghost.blogGlobals();
blog = coreHelpers.config.theme();
title = blog.title;
} else {
title = this.post.title;
Expand All @@ -405,7 +405,7 @@ coreHelpers.meta_description = function (options) {

if (_.isString(this.ghostRoot)) {
if (!this.ghostRoot || this.ghostRoot === '/' || this.ghostRoot === '' || this.ghostRoot.match(/\/page/)) {
blog = coreHelpers.ghost.blogGlobals();
blog = coreHelpers.config.theme();
description = blog.description;
} else {
description = '';
Expand Down Expand Up @@ -592,12 +592,9 @@ function registerAsyncThemeHelper(name, fn) {
});
}

registerHelpers = function (ghost, config) {
registerHelpers = function (config) {
var paginationHelper;

// Expose this so our helpers can use it in their code.
coreHelpers.ghost = ghost;

// And expose config
coreHelpers.config = config;

Expand Down

0 comments on commit 119af63

Please sign in to comment.