Created
October 23, 2013 17:15
-
-
Save also/7122751 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exposed_scope = {} | |
top_scope = null | |
push_scope = -> | |
top_scope = exposed_scope.__proto__ = Object.create exposed_scope.__proto__ | |
pop_scope = -> | |
top_scope = exposed_scope.__proto__ = exposed_scope.__proto__.__proto__ | |
with_scope = (fn) -> | |
push_scope() | |
try | |
fn() | |
finally | |
pop_scope() | |
window.importing = (vars, fn) -> | |
console.log 'importing', vars | |
with_scope -> | |
top_scope[k] = v for k, v of vars | |
fn() | |
window.run_dsl = (fn) -> | |
with_scope -> | |
`with (exposed_scope) {` | |
eval("(#{fn.toString()})")() | |
`}` | |
#################################### | |
tag_names = 'div p strong em'.split ' ' | |
create_tag = (t) -> | |
console.log t | |
tag = document.createElement t | |
tag.innerText = t | |
tag | |
nested_tag = (parent, name) -> | |
tag = create_tag name | |
parent.add_child tag | |
window.tags = {} | |
create_nesting_tags = (parent) -> | |
nested_tags = {} | |
for t in tag_names | |
do (t) -> | |
nested_tags[t] = (fn) -> | |
tag = create_tag t | |
parent.appendChild tag | |
if fn? | |
importing create_nesting_tags(tag), fn | |
console.log 'adding', tag, 'to', parent | |
tag | |
nested_tags | |
for t in tag_names | |
do (t) -> | |
tags[t] = (fn) -> | |
tag = create_tag t | |
if fn? | |
importing create_nesting_tags(tag), fn | |
tag | |
#################################### | |
output = (o) -> run_context.output o | |
run_dsl -> | |
importing tags, -> | |
output div -> | |
p -> | |
em() | |
strong() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment