Skip to content
This repository has been archived by the owner on Dec 10, 2022. It is now read-only.

Latest commit

 

History

History
93 lines (74 loc) · 1.79 KB

README.md

File metadata and controls

93 lines (74 loc) · 1.79 KB

aurelia-node-templating-engine

npm

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