Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Plugins #10

Merged
merged 2 commits into from almost 2 years ago

2 participants

Will Laurance Guy Halford-Thompson
Will Laurance

No description provided.

Guy Halford-Thompson

These are both set to [{}] on the Glog initialisation (line 24/25), so I don't think we need them here as well

Owner
Guy Halford-Thompson
Owner
guyht commented June 11, 2012

Thanks for this. One small comment on the 2nd commit where we have set the hooks=[{}] twice. Could you please make that small change and then I will merge.

Awesome work!

Guy Halford-Thompson guyht referenced this pull request June 11, 2012
Closed

Plugins #9

Guy Halford-Thompson guyht merged commit 98a9701 into from June 11, 2012
Guy Halford-Thompson guyht closed this June 11, 2012
Will Laurance wlaurance referenced this pull request from a commit in wlaurance/Glog June 12, 2012
Will Laurance Use new glog object for each test.
Closes #10
15a0f0d
Will Laurance wlaurance referenced this pull request June 12, 2012
Closed

Plugins #13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Jun 09, 2012
Will Laurance Done called multiple times 5bb912e
Jun 11, 2012
Will Laurance Plugin test passing green 9c35a46
This page is out of date. Refresh to see the latest.
39  lib/glog.js
@@ -21,7 +21,8 @@ function Glog() {
21 21
      * Object variable to track pages
22 22
      */
23 23
     this.pages = {};
24  
-    this.articlePlugins = [{}];
  24
+    this.articlePrePlugins = [{}];
  25
+    this.articlePostPlugins = [{}];
25 26
 };
26 27
 
27 28
 /*
@@ -89,14 +90,19 @@ Glog.prototype.load_configs = function(cb) {
89 90
 Glog.prototype.load_plugins = function(options, cb) {
90 91
     var fn = this, i;
91 92
 
  93
+    this.articlePrePlugins = [{}];
  94
+    this.articlePostPlugins = [{}];
92 95
 
93 96
     var GlogPlugin = {
94  
-       registerArticleHook : function(hook) {
95  
-           fn.articlePlugins.push(hook);
  97
+       registerPreArticleHook : function(hook) {
  98
+           fn.articlePrePlugins.push(hook);
  99
+       },
  100
+
  101
+       registerPostArticleHook : function(hook){
  102
+         fn.articlePostPlugins.push(hook);
96 103
        }
97 104
     };
98  
-
99  
-    for(i=0;i<options.plugins.length;i++) {
  105
+    for(var i=0;i<options.plugins.length;i++) {
100 106
         try {
101 107
             var p = require('../plugins/' + options.plugins[i]);
102 108
             p.load(GlogPlugin);
@@ -185,19 +191,16 @@ Glog.prototype.load_articles = function(options, cb) {
185 191
                     'body'     : body,
186 192
                     'url'      : [year, month, (header.url || header.title.replace(/\s/g, '-'))].join('/')
187 193
                 });
188  
-
189  
-                // If that was the last article then trigger the callback
190  
-                if(files.length === articles.length) {
191  
-                    // Apply plugins
192  
-                    fn.articlePlugins[0] = function(wcb) {
193  
-                        wcb(null, articles);
194  
-                    };
195  
-                    fn.articlePlugins[fn.articlePlugins.length] = function(res) {
196  
-                        console.log('CALLING');
197  
-                        cb(res.reverse());
198  
-                    };
199  
-
200  
-                    async.waterfall(fn.articlePlugins);
  194
+                if (files.length === articles.length && fn.articlePostPlugins.length > 1){
  195
+                  fn.articlePostPlugins[0] = function(wcb){
  196
+                    wcb(null, articles);
  197
+                  };
  198
+                  fn.articlePostPlugins[fn.articlePostPlugins.length] = function(result){
  199
+                    cb(result.reverse());
  200
+                  };
  201
+                  async.waterfall(fn.articlePostPlugins);
  202
+                } else if (files.length === articles.length && fn.articlePostPlugins.length === 1) {
  203
+                  cb(articles.reverse());
201 204
                 }
202 205
 
203 206
             });
2  plugins/example.js
@@ -8,7 +8,7 @@
8 8
  */
9 9
 
10 10
 module.exports.load = function(glog) {
11  
-    glog.registerArticleHook(function(articles, cb) {
  11
+    glog.registerPostArticleHook(function(articles, cb) {
12 12
         for(var i=0;i<articles.length;i++) {
13 13
             articles[i].title = 'Title changed by plugin';
14 14
         }
14  test/glog_tests.js
@@ -55,7 +55,6 @@ describe('Glog', function() {
55 55
     it('should render the articles', function(done) {
56 56
         glog.load_configs(function(options) {
57 57
             glog.load_articles(options, function(articles) {
58  
-
59 58
                 glog.render_blog(options, articles, function() {
60 59
                     assert.ok(glog.pages['/']);
61 60
                     done();
@@ -66,16 +65,19 @@ describe('Glog', function() {
66 65
 
67 66
     it('should handle plugins', function(done) {
68 67
         glog.load_configs(function(options) {
69  
-            options.plugins = ['example'];
70  
-            glog.load_articles(options, function(articles) {
71  
-                glog.render_blog(options, articles, function() {
72  
-                    assert.equal(articles[0].title, 'Title changed by plugin');
73  
-                    done();
  68
+            options.plugins.push("example");
  69
+            glog.load_plugins(options, function(){
  70
+                glog.load_articles(options, function(articles) {
  71
+                    glog.render_blog(options, articles, function() {
  72
+                        assert.equal(articles[0].title, 'Title changed by plugin');
  73
+                        done();
  74
+                    });
74 75
                 });
75 76
             });
76 77
         });
77 78
     });
78 79
 
  80
+
79 81
 });
80 82
 
81 83
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.