In the real world, I recommend NEVER building an app with a tool like this for two main reasons: 1.
- Generating markup programmatically completely violates the separation of concerns principle.
- It's hostile toward project members who do not have Javascript in their skillset.
A small library to generate markup.
Generating markup can get ugly, the mix of html and javascript can get very confusing very quickly. This little library helps you create readable code. It also has no dependencies on the DOM so you can use it on your node.js server.
var template = require('to-ml')().template
template(function() {
return div('hey!',
span('this is',
b('easy')
)
})
<div>hey!<span>this is<b>easy</b></span></div>
If a string value matches the pattern used to create IDs
and classes
, they
will be automatically generated.
a('#home.primary.link', 'home', { href: '/' })
<a id="home" class="primary link" href="/">home</a>
The pattern to determine if a string value passed to a tag function is special looks like this...
'[#id][.class1[.class2[...]]]'
Just add an object to the arguments, doesnt mater what order it's provided in.
textarea('hey!', { 'data-id': 'greeting' })
<textarea data-id="greeting">hey!</textarea>
header(
br,
h1('Hello, World!')
hr,
br
),
<header><br><h1>Hello, World!</h1><hr><br></header>