creationix / wheat

Wheat is a blog engine for coders written in node.JS
Other
1.36k stars 134 forks source link

Added support for git file versions in snippets #27

Open loarabia opened 13 years ago

loarabia commented 13 years ago

CONTEXT Wheat currently supports snippets that are demarcated by a newline < > newline.

Inside of the snippet's brackets, you can specify the relative path from one of Wheat's markdown articles to a code snippet. In addition to that, wheat can handle those snippets in different ways.

A snippet ending in a , for example foo/bar.baz. Will be executed and the result shown beneath the snippet in final rendering.

A snippet ending in a #label will look inside the snippet file for a comment and display from that #forward.

For instance, foo/bar.baz#doAwesomeStuff will look for:

//doAwesomeStuff doSomethingAwesome();

//doSomethingLessAwesome doLesserThings();

and diaplay just the doSomethingAwesome.

CHANGE MOTIVIATION This change proposes the addition of an additional syntax, :SHA which will get a specific version of a file in Wheat's git repository.

One would want this when building out a demo application step by step. If you make a project directory under articles and commit to it piece by piece, it is very natural as a developer.

On the other hand, right now when using Wheat, a developer often makes multiple copies of the same file for instance app.js, app2.js, app-final.js to use as snippets during different stages of the article. If you're not careful, this can get confusing (speaking from experience here using Wheat) especially if you go to update an article you wrote a while back.

CHANGE USAGE With this change, you can use the below as the content of a snippet:

foo/bar.baz:aaaaabbbbbcccccdddddeeeeefffff1111100040 and foo/bar.baz:ffffffffffffffffffffffffffffffffff00040

and get different versions of the same file from git.

When using this feature, you must specify the full 40 character git SHA and it does not work with # (although it does work with *) -- the theory being do the smallest change possible.