guyht / Glog

NodeJS and Git backed blogging engine
MIT License
52 stars 10 forks source link

Plugins #7

Closed wlaurance closed 11 years ago

wlaurance commented 12 years ago

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.

guyht commented 12 years ago

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:

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.

wlaurance commented 12 years ago

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.

guyht commented 12 years ago

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

guyht commented 12 years ago

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.

wlaurance commented 12 years ago

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

wlaurance commented 12 years ago

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

guyht commented 12 years ago

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.

wlaurance commented 12 years ago

Sounds good

guyht commented 12 years ago

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: https://github.com/guyht/Glog/issues/7#issuecomment-6123751

wlaurance commented 12 years ago
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.

guyht commented 12 years ago

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.

guyht commented 12 years ago

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.

guyht commented 12 years ago

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.

wlaurance commented 12 years ago

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