Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Plugins #7

Closed
wlaurance opened this Issue Jun 3, 2012 · 14 comments

Comments

Projects
None yet
2 participants
Contributor

wlaurance commented Jun 3, 2012

So I really like the simplicity of Glog, but there are a few extra features I would like to have for my own blog. One that I am considering is adding support for ditaa which turns ASCII art into graphical diagrams. So my question to you is what would be the best practice to write plugins against Glog? In other words, keep Glog as simple as possible but allow modules to be added.

Owner

guyht commented Jun 3, 2012

At the moment Glog doest have a plugin system per say.

A plugin system is something I would like to implement at some point and I can see 2 ways of doing it:

  • A pre/post hook type plugin system where plugins register hooks with Glog to be executed pre/post events
  • Plugins are build into Glog (e.g. disqus and Google Analytics at the moment) and can be turned on/off in the config file.

Ideally, I would like to go down the route of the first option. The way I see it working is by adding a 'plugins' array to the config.json. Glog would read the array, and 'require' the plugin files, passing a Glog object as an argument.

The plugin can then register its pre/post hooks with the Glog object. The hooks will simply be functions that are passed an 'article' object, and return the same object having make some modifications.

This is 100% open to discussion, let me know what you think.

Contributor

wlaurance commented Jun 3, 2012

I definitely like the first idea as well. This seems like the best approach. I will start working on my ditaa plugin and assume that it will receive a Glog object and an article for the hooks. You probably have the best insight on how to set the system up in lib/glog.js, but I can take a stab at this part.

Owner

guyht commented Jun 4, 2012

Cool. Will be working on this today so should have a plugin system in place by tomorrow.

guyht pushed a commit that referenced this issue Jun 4, 2012

Owner

guyht commented Jun 4, 2012

I have added a first draft of the plugin implementation. Its on branch b1.2.0 and will eventually be merged to master to mark the 1.2.0 version release.

The tests are currently failing (haven't had time to look at why yet) but the plugin implementation seems to work ok. Let me know what you think.

Contributor

wlaurance commented Jun 4, 2012

Looks great! The example plugin runs and I smoke tested my own plugin and everything seems great.

Contributor

wlaurance commented Jun 4, 2012

Would it be possible to have a plugins applied before markdown is applied? Its not a huge deal.

@guyht guyht closed this Jun 5, 2012

@guyht guyht reopened this Jun 5, 2012

Owner

guyht commented Jun 5, 2012

Sorry, wrong button. Going to work on this today if I have time. registerArticleHook will take an additional first parameter which can be either pre or post do determine if the plugin gets invoked before or after markdown (and any other processing) is applied.

Contributor

wlaurance commented Jun 5, 2012

Sounds good

Owner

guyht commented Jun 5, 2012

Doesn't look like I am going to have time to do this today. Feel free to
take over the development, otherwise I will try to get it done over the
next couple of days.

G

On 5 June 2012 05:29, Will Laurance <
reply@reply.github.com

wrote:

Sounds good


Reply to this email directly or view it on GitHub:
#7 (comment)

Contributor

wlaurance commented Jun 6, 2012

3) should handle plugins

✖ 3 of 6 tests failed:

  1. Glog should load articles from the cloned repository:
    TypeError: Object function () {} has no method 'reverse'
    at /home/will/workspace/Glog/lib/glog.js:197:32
    at /home/will/workspace/Glog/node_modules/async/lib/async.js:517:34
    at Array. (/home/will/workspace/Glog/node_modules/async/lib/async.js:441:34)
    at EventEmitter._tickCallback (node.js:190:38)

  2. Glog should render the articles:
    TypeError: Object function () {} has no method 'reverse'
    at /home/will/workspace/Glog/lib/glog.js:197:32
    at /home/will/workspace/Glog/node_modules/async/lib/async.js:517:34
    at Array. (/home/will/workspace/Glog/node_modules/async/lib/async.js:441:34)
    at EventEmitter._tickCallback (node.js:190:38)

  3. Glog should handle plugins:
    TypeError: Object function () {} has no method 'reverse'
    at /home/will/workspace/Glog/lib/glog.js:197:32
    at /home/will/workspace/Glog/node_modules/async/lib/async.js:517:34
    at Array. (/home/will/workspace/Glog/node_modules/async/lib/async.js:441:34)
    at EventEmitter._tickCallback (node.js:190:38)

Looks to me like async waterfall isn't passing back the list of articles.

Owner

guyht commented Jun 6, 2012

Hmm, not sure whats causing that. For some reason the articles array is not making it to the last function in the waterfall, but instead is being replaced by a function.

The async lib comes from here: https://github.com/caolan/async I have used it before and its pretty reliable so I don't think its a bug in the waterfall function. Whats more likely is that the callback is being called incorrectly at some point.

Each function in the waterfall receives 2 arguments, the articles object and a callback function, the callback function should be invoked in the form:
cb(null, articles);
where null refers to no errors having occurred, and articles is the modified articles object. Somewhere along the line, it looks like a function is being passed in place of the 'articles' array.

Also, test 3 (Glog should handle plugins) might be a bit buggy as I don't think I fully tested it.

Owner

guyht commented Jun 12, 2012

Now we have a decent working version with post hooks with all tests working I am going to test the b1.2.0 branch on my live blog and assuming its all still working I will merge it back to master and do an official 1.2.0 release.

The next step is the implementation of the pre-hook but I am happy for that to be in the 1.2.1 release.

Owner

guyht commented Jun 13, 2012

This has now been merged to master, and Glog is officially at version 1.3.0.

I am going to keep this issue open as we still need to implement post hooks. @wlaurance thanks for all the work you have put into this so far.

Contributor

wlaurance commented Jun 13, 2012

No problem, it has been fun. Now I need to come up with new plugin ideas.

@wlaurance wlaurance closed this Oct 26, 2012

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