Skip to content

v5.0.0

Compare
Choose a tag to compare
@blakek blakek released this 20 Jan 13:36
· 33 commits to master since this release

✨ Additions

Can now render lists of items using section tags {{#example}} and {{/example}}. Empty lists and falsy values aren't rendered:

const template = `
{{#stooges}}
<b>{{name}}</b>
{{/stooges}}
`;

const data = {
  stooges: [
    { name: "Moe" },
    { name: "Larry" },
    { name: "Curly" }
  ]
}

render(template, data);
//» <b>Moe</b>
//» <b>Larry</b>
//» <b>Curly</b>

Added a "Templates" section to the documentation. Before, it was pretty simple because this only replaced one tag: {{example}}. With the addition of the section tag (and potentially more in the future), this needed to be documented.

Added functions renderGlob and renderToFolder for programmatically rendering multiple files to either a string or compiling them to a folder. They were in the last v4 release, but were undocumented. renderGlob takes a glob of files to render and calls a function with the filename and rendered contents. renderToFolder is basically a programmatic version of the CLI that renders files matching the input glob and writes them to a destination folder (returning nothing).

Can now handle the edge-case where an object property has a dot in its name:

import { render } from 'template-file';

const data = { 'with.dot': 'yep' };
render('Does this work? {{with.dot}}', data);

💥 Breaking Changes

  • renderString was renamed render
  • renderTemplateFile was renamed renderFile
  • Object properties with a dot now are resolved.

🐛 Known Issues

The output spacing isn't exactly what I want. I figured it's not a huge deal for now, but here's an example:

<!-- Example Template -->
<ul>
  {{#people}}
  <li>{{name}}</li>
  {{/people}}
</ul>

<!-- Wanted -->
<ul>
  <li>Eric</li>
  <li>Anne</li>
</ul>

<!-- Actual -->
<ul>
    <li>Eric</li>
  <li>Anne</li>
</ul>