jquery/web-learn-jquery-com — pull request #30 by mklabs (2011-11-21 19:10:41+00:00)
Title: Gists fiddles

Hello there,

So here is a pull request asking you to review and merge the work @addyosmani and I have done the last few weeks into trying to find a simple mechanism to handle exercises, relying on gists to both have [fiddles](http://doc.jsfiddle.net/use/gist_read.html) and embed snippets of code.

This is a little node package exposing a basic cli tool to parse/generate/update repository files, intended to be used right after a `nanoc compile`.

I've included in the pull request a readme with more informations on what this "build script" is trying to do.

In a nutshell:

* the script first parse the content of the `content/` folder, looking for any files ending with `exercises.md`.
* In these markdown files, the script parses the content searching for `Use the file` and `Open the file` patterns. They're usually employed to know to which files the exercises are related, to then generate the fiddles folder.
* Once the script has necessary informations, it starts to generate for each exercises found (a `*-exercises.md` page may include a few) the corresponding jsfiddle ready folder. With `fiddle.js` matching the `Use the file ` and `fiddle.html` matching the `Open the file `. `fiddle.css` is always the same (guessed from the relative path found in html). `fiddle.details`.
* if `config.gists` is set to true, the script then uses [ngist](https://github.com/chapel/ngist) to create a new private gist based on `git config --get github.user` and `git config --get github.token` values.
* Third and final step, the script tries to update the pages in `output/` that were generated by a previous `nanoc compile` build, with the according jsfiddle link and the gists created as embed code.

Note that I've also included in this pull request a slight modification of the Rakefile. I've added a new rake task to generate the website with fiddles integration (which is simply running `nanoc compile && cd fiddles && npm install && ./bin/fiddles`).

There is some edge case, and things I'd like to see improved. I'll probably do another pull request to address some of these issues:

* right now, new gists are created on each build generation. This is not ideal. It would be nice to have the script generate new gists only if there is no folder created yet, and if any try to use git commit/push to update the remote gists.
* proxy support: currently the script doesn't support generation done behind a proxy. ngist, AFAIK, is not able to issue https request through proxies, it may be a problem to some. I'm considering the use of [defunkt's gist tool](https://github.com/defunkt/gist), seems like it handles proxies quite nicely.

I wanted to paste here the command line result of running the script, but this pull request description is getting really verbose :) (and it's included in `fiddles/readme.md` anyway).

Cheers,