I wonder if there are anything like a Javascript template system that wraps HTML, so that we don’t have to deal with HTML directly (yeah, i know it’s a bad idea, but just out of curiosity).
So instead of writing HTML:
<body>
<div id="title">Great work!</div>
<span>My name is Peter</span>
</body>
We write in Json:
body: [
{div: [
{id: "title"},
{body: "Great work!"}
]
{span: [
{body: "My name is Peter"}
]
]
I know it looks kinda weird, but I really love the thing that everything is an object 🙂
Is there a such implementation for any language? (Im using Ruby myself).
EDIT: Found something interesting:
Look at their examples! Brilliant!
I’ve just wrote a little example of the parser, similar to mentioned by you, using plain old JavaScript. My code is a bit dirty (as mentioned by Casey Hope, you shouldn’t extend
Object.prototype) , perhaps, but it works and very easy to understand, I hope.The function itself:
How to use: