idomizer
idomizer
is an HTML template compiler providing an incremental-dom render factory.
idomizer
can be used at compile time (front end projects) or runtime time(back end projects).
Versions and compatibilities:
- idomizer <= 0.5 -> incremental-dom 0.4 and below.
- idomizer >= 0.6 -> incremental-dom 0.5 and above.
- idomizer >= 1.0.0 -> incremental-dom 0.6 and above.
Installation
$ npm install idomizer
Babel
A babel's plugin is available to compile an idomizer template into an incremental-dom render factory.
See the babel's plugins page to get more information about plugins in babel.
plugins: 'idomizer/lib/plugins/babel-idomizer.js'
Presently the plugin only support ES6 Template literals tagged with idomizer.
For instance,
const template = idomizer`<h1 class="{{data.h1Class}}">Hello</h1>`;
will be compiled into:
var { var _elementOpen = _ielementOpen _elementClose = _ielementClose _elementVoid = _ielementVoid _text = _itext _skip = _iskip; return { var helpers = _h || {} data = _data_ || {}; ; ; ; };};
Be aware the template can not contain expressions like ${anExpression}
.
Webpack
A webpack's loader is available to compile an idomizer file into an incremental-dom render factory.
See module.rules to get more information about loaders in webpack.
module.loaders: [
{test: /\.idomizer$/, loader: 'idomizer/lib/plugins/idomizer-loader'}
];
Browserify
A browserify's transform module is available to compile an idomizer file into an incremental-dom render factory.
See transforms to get more information about the transform system in browserify.
browserify -t idomizer/lib/plugins/idomizerify main.js > bundle.js
const browserify = ;const idomizerify = ;const bundle = ;bundle;
API
idomizer.compile
transforms an HTML template into a factory method.
// idomizer.compile('<h1 class="main">Hello</h1>') will return: { var _elementOpen = _ielementOpen _elementClose = _ielementClose _elementVoid = _ielementVoid _text = _itext _skip = _iskip; return { var helpers = _h || {} data = _data_ || {}; ; ; ; };}
The factory method requires the incremental-dom library and an optional map of helpers. The factory returns the incremental-dom's render method.
Syntax
Static attributes
From
idomizerIncrementalDOM;
To
{ var _elementOpen = _ielementOpen _elementClose = _ielementClose _elementVoid = _ielementVoid _text = _itext _skip = _iskip; return { var helpers = _h || {} data = _data_ || {}; ; ; ; };}
Dynamic attributes
From
idomizerIncrementalDOM
To
{ var _elementOpen = _ielementOpen _elementClose = _ielementClose _elementVoid = _ielementVoid _text = _itext _skip = _iskip; return { var helpers = _h || {} data = _data_ || {}; ; ; ; };}
Self closing elements
From
idomizerIncrementalDOM
To
{ var _elementOpen = _ielementOpen _elementClose = _ielementClose _elementVoid = _ielementVoid _text = _itext _skip = _iskip; return { var helpers = _h || {} data = _data_ || {}; ; };}
Dynamic text nodes
From
idomizerIncrementalDOM// oridomizerIncrementalDOM
To
{ var _elementOpen = _ielementOpen _elementClose = _ielementClose _elementVoid = _ielementVoid _text = _itext _skip = _iskip; return { var helpers = _h || {} data = _data_ || {}; ; ; ; };}
Condition with the tags if, else-if and else
From
idomizerIncrementalDOM;
To
{ var _elementOpen = _ielementOpen _elementClose = _ielementClose _elementVoid = _ielementVoid _text = _itext _skip = _iskip; return { var helpers = _h || {} data = _data_ || {}; if datayes ; else if datayes !== false ; else ; };}
Iteration with the tag each
From
idomizerIncrementalDOM;
To
{ var _elementOpen = _ielementOpen _elementClose = _ielementClose _elementVoid = _ielementVoid _text = _itext _skip = _iskip; return { var helpers = _h || {} data = _data_ || {}; dataitems || ; };}
Iteration with inline javascript
From
idomizerIncrementalDOM;
To
{ var _elementOpen = _ielementOpen _elementClose = _ielementClose _elementVoid = _ielementVoid _text = _itext _skip = _iskip; return { var helpers = _h || {} data = _data_ || {}; dataitems; };}
Custom tags
From
idomizerIncrementalDOM;
To
{ var _elementOpen = _ielementOpen _elementClose = _ielementClose _elementVoid = _ielementVoid _text = _itext _skip = _iskip; return { var helpers = _h || {} data = _data_ || {}; ; ; ; ; ; ; ; };}
Custom helpers
From
const subRender = IncrementalDOM;idomizerIncrementalDOM subRender;
To
{ var _elementOpen = _ielementOpen _elementClose = _ielementClose _elementVoid = _ielementVoid _text = _itext _skip = _iskip; return { var helpers = _h || {} data = _data_ || {}; ; ; ; helpers; ; ; ; };}
Custom elements
For incremental-dom, custom elements are regular HTML elements.
So, if a custom element generates a sub-tree (i.e. a light DOM) outside of a ShadowDOM node,
it will be overridden during the execution of the function patch()
.
To control this default behavior, incremental-dom provides the function skip()
saying:
don't touch the inner light DOM of the just opened node!
By default idomizier detects the custom elements and force the call of the function skip()
to protect their light DOM nodes.
Custom elements are detected according to the following rules:
- from the name, because of the
-
character - from the attribute
ìs
Obviously, this behavior can be deactivated:
- globally (for a whole HTML template)const render =
- locally (an HTML element), ``const render =