pencil-mustache

1.1.0 • Public • Published

pencil-mustache

Simple mustache-style string interpolation.

pencil-mustache is an ultra-minimal mustache-style interpolation micro library. It only implements simple interpolation of double and triple-mustache placeholder expressions (the former being escaped). No pre-compiling. No caching. No partials. No helpers.

npm Version Build Status Test Coverage Dependency Status

Installation

Install using npm:

$ npm install pencil-mustache

Usage

Given the following HTML string:

<section>
  <h1>{{headline}}</h1>
  {{{description}}}
</section>

and this context:

{
    headline: 'Fish & Chips',
    description: '<span>A house specialty!</span>'
}

results in:

<section>
  <h1>Fish &amp; Chips</h1>
  <span>A house specialty!</span>
</section>

All together:

var mustache = require('pencil-mustache'),
    html = require('./section.html'),
    context = {
        headline: 'Fish & Chips',
        description: '<span>A house specialty!</span>'
    },
    template = mustache(html);
 
document.querySelector('.my-target').innerHtml = template(context);

Changelog

1.1.0

  • Changed: replace undefined and null with empty string

1.0.0

  • Initial release

License

MIT

Package Sidebar

Install

npm i pencil-mustache

Weekly Downloads

127

Version

1.1.0

License

MIT

Last publish

Collaborators

  • jimf