Skip to content

Latest commit

 

History

History
26 lines (17 loc) · 877 Bytes

interactive.coffee.md

File metadata and controls

26 lines (17 loc) · 877 Bytes

Interactive Runtime for Docs

require "./lib/hamlet"

{Observable, Compiler} = Hamlet

# {applyStylesheet, CSON} = require "./lib/util"
# applyStylesheet require "./style/demo"

# TODO: Textarea for template, text area for data, live interactive demo
# Changing data reloads the new data into the same template
# Changing template reloads the same data into the new template

Interactive.register "demo", ({source, runtimeElement}) ->
  code =
    "var template, model;" +
    CoffeeScript.compile(source, bare: true)

  code += "\nreturn [template, model];"

  [template, model] = Function("Observable", code)(Observable)

  view = Function("return " + Compiler.compile(template, compiler: CoffeeScript, runtime: "Hamlet", exports: false))()

  runtimeElement.empty().append view(model)