Skip to content

Instantly share code, notes, and snippets.

@ggoodman
Created January 11, 2012 05:15
Show Gist options
  • Save ggoodman/1593167 to your computer and use it in GitHub Desktop.
Save ggoodman/1593167 to your computer and use it in GitHub Desktop.
compile = (fn) ->
fnText = fn.toString()
fnArgs = fnText.substring(fnText.indexOf("(") + 1, fnText.indexOf(")")).replace(/^\s+|\s+$/g, "").split(",")
fnBody = fnText.substring(fnText.indexOf("{") + 1, fnText.lastIndexOf("}"))
code = "with(context) { with (window.drykup()) {"
for arg, i in fnArgs
unless arg.replace(/^\s+|\s+$/g, "") is ""
code += "var #{arg} = arguments[#{i}];\n"
code += fnBody
code += "}}"
alert code.replace(/return/g, "")
(context = {}) ->
eval code.replace(/return/g, "")
tpl = compile ->
div class: name, ->
a name
span "ba"
alert tpl(name: "ggoodman")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment