mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
issue #186 - load plugins
- Adding activePlugins array to config.js - Adding a loadPlugins function to ghost.js - Tweaking fancyFirstChar.js so that it works again, getting rid of the function wrapper and constructor
This commit is contained in:
parent
59c17468e3
commit
5c15c2d4b0
3 changed files with 45 additions and 27 deletions
|
@ -39,6 +39,11 @@ config.themeDir = 'themes';
|
||||||
*/
|
*/
|
||||||
config.activeTheme = 'casper';
|
config.activeTheme = 'casper';
|
||||||
|
|
||||||
|
|
||||||
|
config.activePlugins = [
|
||||||
|
'fancyFirstChar.js'
|
||||||
|
];
|
||||||
|
|
||||||
// Default Navigation Items
|
// Default Navigation Items
|
||||||
/**
|
/**
|
||||||
* @property {Array} nav
|
* @property {Array} nav
|
||||||
|
|
|
@ -1,27 +1,16 @@
|
||||||
/*globals exports */
|
var fancyFirstChar;
|
||||||
(function () {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var FancyFirstChar;
|
fancyFirstChar = {
|
||||||
|
init: function (ghost) {
|
||||||
FancyFirstChar = function (ghost) {
|
ghost.registerFilter('prePostsRender', function (posts) {
|
||||||
this.ghost = function () {
|
|
||||||
return ghost;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
FancyFirstChar.prototype.init = function () {
|
|
||||||
this.ghost().registerFilter('prePostsRender', function (posts) {
|
|
||||||
var post,
|
var post,
|
||||||
originalContent,
|
originalContent,
|
||||||
newContent,
|
newContent,
|
||||||
firstCharIndex = 0;
|
firstCharIndex = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (post in posts) {
|
for (post in posts) {
|
||||||
if (posts.hasOwnProperty(post)) {
|
if (posts.hasOwnProperty(post)) {
|
||||||
originalContent = posts[post].content;
|
originalContent = posts[post].content_html;
|
||||||
if (originalContent.substr(0, 1) === '<') {
|
if (originalContent.substr(0, 1) === '<') {
|
||||||
firstCharIndex = originalContent.indexOf('>') + 1;
|
firstCharIndex = originalContent.indexOf('>') + 1;
|
||||||
}
|
}
|
||||||
|
@ -32,17 +21,14 @@
|
||||||
newContent += '</span>';
|
newContent += '</span>';
|
||||||
newContent += originalContent.substr(firstCharIndex + 1, originalContent.length - firstCharIndex - 1);
|
newContent += originalContent.substr(firstCharIndex + 1, originalContent.length - firstCharIndex - 1);
|
||||||
|
|
||||||
posts[post].content = newContent;
|
posts[post].content_html = newContent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return posts;
|
return posts;
|
||||||
});
|
});
|
||||||
};
|
},
|
||||||
|
activate: function () {},
|
||||||
|
deactivate: function () {}
|
||||||
|
};
|
||||||
|
|
||||||
FancyFirstChar.prototype.activate = function () {};
|
module.exports = fancyFirstChar;
|
||||||
FancyFirstChar.prototype.deactivate = function () {};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = FancyFirstChar;
|
|
||||||
}());
|
|
|
@ -14,8 +14,10 @@ var config = require('./../config'),
|
||||||
models = require('./shared/models'),
|
models = require('./shared/models'),
|
||||||
|
|
||||||
requireTree = require('./shared/require-tree'),
|
requireTree = require('./shared/require-tree'),
|
||||||
themeDirectories = requireTree(path.resolve(__dirname + '../../content/themes')),
|
themePath = path.resolve(__dirname + '../../content/themes'),
|
||||||
pluginDirectories = requireTree(path.resolve(__dirname + '../../content/plugins')),
|
pluginPath = path.resolve(__dirname + '../../content/plugins'),
|
||||||
|
themeDirectories = requireTree(themePath),
|
||||||
|
pluginDirectories = requireTree(pluginPath),
|
||||||
|
|
||||||
Ghost,
|
Ghost,
|
||||||
instance,
|
instance,
|
||||||
|
@ -113,10 +115,35 @@ Ghost.prototype.init = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
return when.join(instance.dataProvider.init(), instance.getPaths()).then(function () {
|
return when.join(instance.dataProvider.init(), instance.getPaths()).then(function () {
|
||||||
|
return self.loadPlugins();
|
||||||
|
}, errors.logAndThrowError).then(function () {
|
||||||
return self.updateSettingsCache();
|
return self.updateSettingsCache();
|
||||||
}, errors.logAndThrowError);
|
}, 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) {
|
Ghost.prototype.updateSettingsCache = function (settings) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
Loading…
Add table
Reference in a new issue