You want to do a quick rendering of your litcoffee masterpiece,
potentially with a custom template and stylesheet.
Common enough scenario.
coffee render.coffee.md render.coffee.md | browser
fs = require 'fs'
coffee = require 'coffee-script'
Yep, we require coffee itself.
Pull in optimist for command-line argument handling.
argv = require('optimist')
.default('template', 'html.cst')
.default('style', 'style.css')
.alias('t', 'template')
.alias('s', 'style')
.argv
OK, let's read and render.
read = (file) -> fs.readFileSync file, 'utf8'
print = console.log
render = (file, data) ->
text = read(file)
.toString()
.replace(/\n/g, '\\n')
.replace(/"/g, '\\"')
template = coffee.eval '(data) -> "' + text + '"'
print template data
for file in argv._ when file.match /\.(litcoffee|markdown|md)/i
data =
md: read file
css: read argv.style
render argv.template, data