bevry/docpad-extras — pull request #6 by DjebbZ (2012-06-12 14:57:14+00:00)
Title: `docpad` was undefined, changed params and used new DocPad's helper func...

...tions.

In an first attempt to update the rest plugin to Docpad 6, I noticed that the `serverAfter` event is emitted with the `server` param, whereas the rest plugin receives a `{docpad,server}` param. So using it produces as is produces this error (when issueing `docpad server`) :

``` shell
$ docpad server
info: Welcome to DocPad v6.0.2
info: DocPad listening to http://localhost:9778/ on directory /Users/khalid_jebbari/Documents/Javascript/test-rest-docpad/out
error: Something went wrong with the action
error: An error occured: Cannot read property 'server' of undefined TypeError: Cannot read property 'server' of undefined
at RestPlugin.serverAfter (/Users/khalid_jebbari/Documents/Javascript/test-rest-docpad/node_modules/docpad-plugin-rest/out/rest.plugin.js:22:15)
at /Users/khalid_jebbari/node/lib/node_modules/docpad/out/lib/plugin.js:43:34
at /Users/khalid_jebbari/node/lib/node_modules/docpad/node_modules/bal-util/out/lib/events.js:250:18
at _Class.runTask (/Users/khalid_jebbari/node/lib/node_modules/docpad/node_modules/bal-util/out/lib/flow.js:265:9)
at _Class.nextTask (/Users/khalid_jebbari/node/lib/node_modules/docpad/node_modules/bal-util/out/lib/flow.js:257:14)
at _Class.run (/Users/khalid_jebbari/node/lib/node_modules/docpad/node_modules/bal-util/out/lib/flow.js:278:18)
at _Class.sync (/Users/khalid_jebbari/node/lib/node_modules/docpad/node_modules/bal-util/out/lib/flow.js:301:12)
at DocPad.emitSync (/Users/khalid_jebbari/node/lib/node_modules/docpad/node_modules/bal-util/out/lib/events.js:253:13)
at /Users/khalid_jebbari/node/lib/node_modules/docpad/out/lib/docpad.js:2061:23
at _Class.next (/Users/khalid_jebbari/node/lib/node_modules/docpad/out/lib/docpad.js:2171:24)

```

So I thought of changing the param to `{docpad}` only, requiring a small change in docpad itself (posting it in a few minutes). With these 2 changes, others errors were happening because 'server' isn't a property of docpad. So I update the plugin code to match the new API and use DocPad's helpers, and all errors disappeared when issueing a `docpad server`.

But I couldn't test it to make sure it works properly. For a reason I can't explain, this very small [gist](https://gist.github.com/2917870) with code to test a basic POST request to the server doesn't work, telling me `Cannot find module 'request'`, whereas I do have request installed globally...