satyr/ckup — pull request #2 by jdknezek (2012-01-27 18:37:04+00:00)
Title: added @compile

I added a `compile` function that compiles a Coco template string into a function to be called with a `context`:

$ coco -es
t = '''
<~! ul
for v, i of @
li "#i: #v"
'''

f = require \ckup .compile t

console.log f <[a b c]>

0: a
1: b
2: c

`ckup` is included with `with`, and if `context` isn't specified then it defaults to `ckup`, so these should all be equivalent:

console.log ckup.render 'doctype \\html'
#
console.log ckup.render '@doctype \\html'
#

console.log ckup.compile('doctype \\html')!
#
console.log ckup.compile('@doctype \\html')!
#
console.log ckup.compile('doctype \\html') \context
#

The only incompatibility should be if you combine `@` and `context`:

console.log ckup.compile('@doctype \\html') \context
# TypeError: Object context has no method 'doctype'