Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Mini mustache compiling to stand-alone functions
JavaScript
Tree: 6da2888a55

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bin
test
.gitignore
.npmignore
History.md
Makefile
Readme.md
component.json
index.js
package.json

Readme.md

minstache

Mini mustache template engine.

Installation

$ npm install minstache
$ component install visionmedia/minstache

minstache(1)

The minstache(1) executable can compile a file to a valid stand-alone commonjs module for you, there's no need to have minstache as a dependency:

hello.mustache:

Hello {{name}}!

convert it:

$ minstache < hello.mustache > hello.js

hello.js:

module.exports = function(obj) {
  function escape(html) {
    return String(html)
      .replace(/&/g, '&amp;')
      .replace(/"/g, '&quot;')
      .replace(/</g, '&lt;')
      .replace(/>/g, '&gt;');
  };
  return "Hello " + escape(obj.name) + "!"
};

API

minstache(string, [obj])

Compile and render the given mustache string with optional context obj.

minstache.compile(string)

Compile the mustache string to a stand-alone Function accepting a context obj.

Divergence

Minstache also allows { as an alias of {{ to reduce the noise.

Partials are not supported, this lib is meant to be a small template engine solution for stand-alone component templates. If your template takes "partials" then pass other rendered strings to it. If you need a full-blown mustache solution Hogan.js is still great.

The {#foo} / {^foo} syntax behave as conditionals only, iteration implies you're doing too much. If you have a list of users, have a "user" view and a "user-list" view. Maybe we'll add this in the future but for now {#foo}{/foo} compiles to a ternary.

Todo

  • lambdas

License

(The MIT License)

Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.