0.0.3 • Published 2 years ago

mailout v0.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Features

  • Angular-like syntaxt
  • CSS-inlining
  • Output minification
  • Shared layout file support
  • JS-templates evaluation

Example usage

Sample code

const renderer = require('./renderer');

const template = `
<style>
  .red { color: red; }
  a { text-decoration: none; }
  div:first-child { font-weight: bold; }
</style>
<div class="red" [innerHTML]="html"></div>
<div *if="state.visible">Will be visible</div>
<div *if="!state.visible">Will not be visible</div>
<a [href]="url"></a>
<div *for="let u of users">{{u.id}} - {{u.name.toUpperCase()}}</div>
`;

const context = {
    html: 'outer<p>inner</p>',
    url: 'https://example.com',
    state: {
        visible: true
    },
    users: [
        { id: 1, name: 'John' },
        { id: 2, name: 'Bill' }
    ]
};

console.log(await renderer.renderTemplate(template, context));

Sample output

<div class="red" style="color:red;font-weight:700">outer<p>inner</p></div>
<div>Will be visible</div>
<a style="text-decoration:none" href="https://example.com"></a>
<div>1 - JOHN</div>
<div>2 - BILL</div>