Last active
December 26, 2015 01:29
-
-
Save joeriks/7071285 to your computer and use it in GitHub Desktop.
Sample creating HTML in code in Typescript
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
module HTML { | |
export function elem(tag:string, content:string){ | |
return "<" + tag + ">" + content + "</" + tag + ">" | |
} | |
export function div(inner:string[]){ | |
return elem("div",inner.join("")) | |
} | |
export function p(content:string){ | |
return elem("p",content) | |
} | |
} | |
module HTML.views { | |
export var home = | |
div([ | |
p("First para"), | |
p("Second para") | |
]) | |
} | |
document.body.innerHTML=HTML.views.home |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.typescriptlang.org/Playground/#src=module%20HTML%20{%0A%09%0A%09export%20function%20ELEM%28tag%3Astring%2C%20content%3Astring%29{%0A%09%09return%20%22%3C%22%20%2B%20tag%20%2B%20%22%3E%22%20%2B%20content%20%2B%20%22%3C%2F%22%20%2B%20tag%20%2B%20%22%3E%22%0A%09}%0A%09export%20function%20DIV%28inner%3Astring[]%29{%0A%09%09return%20ELEM%28%22div%22%2Cinner.join%28%22%22%29%29%0A%09}%0A%09export%20function%20P%28content%3Astring%29{%0A%09%09return%20ELEM%28%22p%22%2Ccontent%29%0A%09}%0A}%0A%0Amodule%20HTML.views%20{%0A%0A%09export%20var%20home%20%3D%20%0A%09%09DIV%28[%0A%09%09%09P%28%22First%20para%22%29%2C%0A%09%09%09P%28%22Second%20para%22%29%0A%09%09]%29%09%0A}%0A%20%0Adocument.body.innerHTML%3DHTML.views.home