Created
January 24, 2010 04:11
-
-
Save brapse/285001 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var html = function(t_func){ | |
var t = {}; | |
var tag_function = function(tag){ | |
return function(attrs, contents){ | |
var tag_attributes = []; | |
if(typeof(attrs) == 'object'){ | |
for(var prop in attrs){ | |
if (attrs.hasOwnProperty(prop)){ | |
tag_attributes.push(prop + '="' + attrs[prop] + '"'); | |
} | |
} | |
} | |
return '<' + tag + ' ' + tag_attributes.join(' ') + '>' + content + '</' +tag + '>' | |
} | |
}; | |
var body = t_func.toString().replace(/\n/g, "").match(/{(.*)}/)[1]; | |
var supported_tags = ['div', 'p', 'span', 'a', 'ul', 'li', 'table', 'tr', 'td']; | |
var wrapper = new Function('div', 'p', 'span', 'a', 'ul', 'li', 'table', 'tr', 'td', body); | |
var tag_functions = supported.tags.map(function(tag){ | |
return tag_function(tag); | |
}); | |
var stack = wrapper.apply(null, tag_functions); | |
var render = function(node){ | |
} | |
return render.call(stack); | |
}; |
This file contains hidden or 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
var example4 = html(function(){ | |
return [ul, | |
[li, "ichi"], | |
[li, "ni"], | |
[li, "san"], | |
]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment