aurelia-node-templating-engine
v0.1.0
Published
A tool to render view/view-models using Aurelia (https://aurelia.io) from node!
Downloads
4
Readme
aurelia-node-templating-engine
Compile Aurelia templates from node!
Why?
I needed to build a templating engine for an emailer service, and why not continue using Aurelia for it??
Installation
npm install aurelia-node-templating-engine
Use
import 'aurelia-polyfills';
import { AureliaNodeTemplatingEngine } from '../src/aurelia-node-templating-engine';
const view = `
<span>\${message}</span>
<ul>
<li repeat.for="item of items">\${item}</li>
</ul>
`;
const contexts = [
{
message: 'hello world!',
items: [
'jim',
'bob',
],
}, {
message: 'hello again world!',
items: [
'sue',
'jim',
],
}, {
message: 'goodbye world!',
items: [
'bob',
'jim',
],
},
];
(async () => {
const engine = new AureliaNodeTemplatingEngine(view);
const timer = 'compile view/view-model';
for (const context of contexts) {
console.time(timer);
const result = await engine.compile(context);
console.log(result);
console.timeEnd(timer);
}
})();
outputs
<div>
<span>hello world!</span>
<ul>
<li>jim</li><li>bob</li><!--anchor-->
</ul>
</div>
first template compile is longest
compile view/view-model: 75.626ms
<div>
<span>hello again world!</span>
<ul>
<li>sue</li><li>jim</li><!--anchor-->
</ul>
</div>
compile view/view-model: 4.532ms
<div>
<span>goodbye world!</span>
<ul>
<li>bob</li><li>jim</li><!--anchor-->
</ul>
</div>
compile view/view-model: 2.923ms