Merge pull request #233 from ErisDS/plugins-2

issue #186 - load plugins (v2)
This commit is contained in:
Hannah Wolfe 2013-07-02 22:49:44 -07:00
commit 3b96c7d591
3 changed files with 45 additions and 27 deletions

View File

@ -39,6 +39,11 @@ config.themeDir = 'themes';
*/
config.activeTheme = 'casper';
config.activePlugins = [
'fancyFirstChar.js'
];
// Default Navigation Items
/**
* @property {Array} nav

View File

@ -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 += '</span>';
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;

View File

@ -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;