codom

Mini functional templating

npm install codom
1 downloads in the last week
2 downloads in the last month

Codom - mini functional templating

Codom is a mini functional templating engine. There are only 3 functions. You probably won't use 2 of them.

Getting started

var stuff = co.node('div#content',
              co.node('a#google.linkclass', { href: 'http://google.com' },
                "google!"));

stuff is a string:

<div id="content">
  <a class="linkclass" id="google" href="http://google.com">google!</a>
</div>

Abstractions

Easily build abstractions!

function row(columnRenderers, data) {
  var n = 0;
  return co.node('tr', columnRenderers.map(function(fn){
    return co.node('td#column' + (++n), fn(data));
  }).join(""));
}

function table(meta) {
  var rows = meta.rowData.map(function(rowData){
    return row(meta.renderers, rowData);
  }).join("");
  return co.node("table#myTable", rows);
}
npm loves you