npm install jextJEXT - Javascript ex DOM templater
======
JEXT is tool for using html templates as JS files with DOM rendered elements and special helper to manipulate real time data updates.
``bash`
npm install jext ---save-dev
`bash`
./bin/jext examples/simple.jext > templates.js
Now merge jext.js lib with generated template
`bash`
cat ./jext.js templates.js > bundle.js
Well you can do same as above with one command:
`bash`
./bin/jext examples/simple.jext -b > bundle.js
Finally require in browser just created the bundle.js file.
You got jext variable defined with template pool manipulation helpers and templates variable with your template.
Now just get rendered DOM and append to any element. The key of template same as file name without extension.
`javascript`
var t = templates.get('simple');
document.body.appendChild(t.dom());
Wanna update some parameters? Easy:
`javascript`
t.update({welcome_text: 'JEXT works!'});
Now you can see rendered test template on your screen.
Install stuff:
`bash`
npm install jext
npm install jext-loader
Somewhere in your code write to render
`javascriptFirst require dependencies
var jext = require('jext');
var simple_tpl = require('examples/simple.jext');
Build your project and enjoy!
Template markup
You can use only simple constructs in your html template.$3
Just use {{ var_name }} in attribute or inside element to make it works.
`html
{{ body }}
`$3
When making iteration inside template JEXT switching context inside iterated object. So only possible to access object variables of current iterated item.`json
{
"rows": [
{"value": 1},
{"value": 2}
]
}
``html
The value is: {{ value }}
`You know what will be as result? :)
$3
Condition switches context as iteration. Its same easy to use.`json
{
"first": false,
"second": {
"value": 2
}
}
``html
First block wont appear here
In context of second condition: {{ value }}
``- template - name of template. If your template name as mytemplate.jext it must be mytemplate (without extension).
- data - optional. Pass data to render your template as object.
- template - name of template.
- instance - generated Node of this template.