diff --git a/config.js b/config.js index bde0e1806c..345a161c28 100644 --- a/config.js +++ b/config.js @@ -39,6 +39,11 @@ config.themeDir = 'themes'; */ config.activeTheme = 'casper'; + +config.activePlugins = [ + 'fancyFirstChar.js' +]; + // Default Navigation Items /** * @property {Array} nav diff --git a/content/plugins/fancyFirstChar.js b/content/plugins/fancyFirstChar.js index df7aa8acb5..157fc71054 100644 --- a/content/plugins/fancyFirstChar.js +++ b/content/plugins/fancyFirstChar.js @@ -1,27 +1,16 @@ -/*globals exports */ -(function () { - "use strict"; +var fancyFirstChar; - var FancyFirstChar; - - FancyFirstChar = function (ghost) { - this.ghost = function () { - return ghost; - }; - }; - - FancyFirstChar.prototype.init = function () { - this.ghost().registerFilter('prePostsRender', function (posts) { +fancyFirstChar = { + init: function (ghost) { + ghost.registerFilter('prePostsRender', function (posts) { var post, originalContent, newContent, firstCharIndex = 0; - - for (post in posts) { if (posts.hasOwnProperty(post)) { - originalContent = posts[post].content; + originalContent = posts[post].content_html; if (originalContent.substr(0, 1) === '<') { firstCharIndex = originalContent.indexOf('>') + 1; } @@ -32,17 +21,14 @@ newContent += ''; newContent += originalContent.substr(firstCharIndex + 1, originalContent.length - firstCharIndex - 1); - posts[post].content = newContent; + posts[post].content_html = newContent; } } return posts; }); - }; + }, + activate: function () {}, + deactivate: function () {} +}; - FancyFirstChar.prototype.activate = function () {}; - FancyFirstChar.prototype.deactivate = function () {}; - - - - module.exports = FancyFirstChar; -}()); +module.exports = fancyFirstChar; \ No newline at end of file diff --git a/core/ghost.js b/core/ghost.js index 3d1c4f2139..9be4d0b467 100644 --- a/core/ghost.js +++ b/core/ghost.js @@ -14,8 +14,10 @@ var config = require('./../config'), models = require('./shared/models'), requireTree = require('./shared/require-tree'), - themeDirectories = requireTree(path.resolve(__dirname + '../../content/themes')), - pluginDirectories = requireTree(path.resolve(__dirname + '../../content/plugins')), + themePath = path.resolve(__dirname + '../../content/themes'), + pluginPath = path.resolve(__dirname + '../../content/plugins'), + themeDirectories = requireTree(themePath), + pluginDirectories = requireTree(pluginPath), Ghost, instance, @@ -113,10 +115,35 @@ Ghost.prototype.init = function () { var self = this; return when.join(instance.dataProvider.init(), instance.getPaths()).then(function () { + return self.loadPlugins(); + }, errors.logAndThrowError).then(function () { return self.updateSettingsCache(); }, errors.logAndThrowError); }; +Ghost.prototype.loadPlugins = function () { + var self = this, + pluginPaths = _.values(self.paths().availablePlugins), + pluginPromises = []; + + _.each(self.config().activePlugins, function (plugin) { + var match = _.find(pluginPaths, function (path) { + return new RegExp(plugin + '$').test(path); + }); + + if (match) { + pluginPromises.push(require(path.join(pluginPath, plugin))); + } + }); + + return when.all(pluginPromises).then(function (plugins) { + _.each(plugins, function (plugin) { + if (_.isFunction(plugin.init)) { + plugin.init(self); + } + }); + }, errors.logAndThrowError); +}; Ghost.prototype.updateSettingsCache = function (settings) { var self = this;