Permalink
Browse files

Plugin test passing green

  • Loading branch information...
1 parent 5bb912e commit 9c35a465ea67994ec241fdec1cd7406a2ff865da @wlaurance wlaurance committed Jun 12, 2012
Showing with 30 additions and 29 deletions.
  1. +20 −20 lib/glog.js
  2. +1 −1 plugins/example.js
  3. +1 −2 test/glog_config.json
  4. +8 −6 test/glog_tests.js
View
@@ -21,7 +21,8 @@ function Glog() {
* Object variable to track pages
*/
this.pages = {};
- this.articlePlugins = [{}];
+ this.articlePrePlugins = [{}];
+ this.articlePostPlugins = [{}];
};
/*
@@ -89,18 +90,22 @@ Glog.prototype.load_configs = function(cb) {
Glog.prototype.load_plugins = function(options, cb) {
var fn = this, i;
+ this.articlePrePlugins = [{}];
+ this.articlePostPlugins = [{}];
var GlogPlugin = {
- registerArticleHook : function(hook) {
- fn.articlePlugins.push(hook);
+ registerPreArticleHook : function(hook) {
+ fn.articlePrePlugins.push(hook);
+ },
+
+ registerPostArticleHook : function(hook){
+ fn.articlePostPlugins.push(hook);
}
};
-
- for(i=0;i<options.plugins.length;i++) {
+ for(var i=0;i<options.plugins.length;i++) {
try {
var p = require('../plugins/' + options.plugins[i]);
p.load(GlogPlugin);
- console.log(JSON.stringify(p));
} catch(e) {
console.log('Error loading plugins');
console.log(e);
@@ -186,20 +191,15 @@ Glog.prototype.load_articles = function(options, cb) {
'body' : body,
'url' : [year, month, (header.url || header.title.replace(/\s/g, '-'))].join('/')
});
-
- // If that was the last article then trigger the callback
- if(files.length === articles.length && fn.articlePlugins.length > 0) {
- // Apply plugins
- fn.articlePlugins[0] = function(wcb) {
- wcb(null, articles);
- };
- fn.articlePlugins[fn.articlePlugins.length] = function(res) {
- console.log('CALLING ' + JSON.stringify(res));
- cb(res.reverse());
- };
-
- async.waterfall(fn.articlePlugins);
- } else {
+ if (files.length === articles.length && fn.articlePostPlugins.length > 1){
+ fn.articlePostPlugins[0] = function(wcb){
+ wcb(null, articles);
+ };
+ fn.articlePostPlugins[fn.articlePostPlugins.length] = function(result){
+ cb(result.reverse());
+ };
+ async.waterfall(fn.articlePostPlugins);
+ } else if (files.length === articles.length && fn.articlePostPlugins.length === 1) {
cb(articles.reverse());
}
View
@@ -8,7 +8,7 @@
*/
module.exports.load = function(glog) {
- glog.registerArticleHook(function(articles, cb) {
+ glog.registerPostArticleHook(function(articles, cb) {
for(var i=0;i<articles.length;i++) {
articles[i].title = 'Title changed by plugin';
}
View
@@ -2,6 +2,5 @@
"blog_repository" : "https://github.com/guyht/Guido.git",
"author" : "Glog",
"blog_title" : "The Glog Blog",
- "port" : 8080,
- "plugins": ["example"]
+ "port" : 8080
}
View
@@ -55,7 +55,6 @@ describe('Glog', function() {
it('should render the articles', function(done) {
glog.load_configs(function(options) {
glog.load_articles(options, function(articles) {
-
glog.render_blog(options, articles, function() {
assert.ok(glog.pages['/']);
done();
@@ -66,16 +65,19 @@ describe('Glog', function() {
it('should handle plugins', function(done) {
glog.load_configs(function(options) {
- options.plugins = ['example'];
- glog.load_articles(options, function(articles) {
- glog.render_blog(options, articles, function() {
- assert.equal(articles[0].title, 'Title changed by plugin');
- done();
+ options.plugins.push("example");
+ glog.load_plugins(options, function(){
+ glog.load_articles(options, function(articles) {
+ glog.render_blog(options, articles, function() {
+ assert.equal(articles[0].title, 'Title changed by plugin');
+ done();
+ });
});
});
});
});
+
});

0 comments on commit 9c35a46

Please sign in to comment.