What is it?
mustache.is is a logic-less templating engine for JavaScript which is an implementation of the mustache templating engine syntax originally written in Ruby (these days a whole family of mustache syntax interpreters are available). There are a couple of good articles out there explaining the benefits and powers of Mustache, so if you are unfamiliar, you should look at those first. The implementation of mustache.js presented here is a fork of the “official” JavaScript version of Mustache project. This version has three primary benefits over the mainline implementation:
- Spec Complaint: Even after the rewrite for version 0.5.0, the mainline version of mustache.js is not complaint to the official specification for Mustache interpreters. Spec compliance is important because the spec serves as excellent documentation to developers over what the acceptable syntax for the templates are. In addition, the specification clearly outlines how the context stack should operate, thereby clearing up a major grey area of Mustache implementations. Compliant parsers do not succumb to strange bugs like this one.
- QUnit Tests: The unit tests for the mainline implementation of Mustache.js are written in a way to be testable across a wide variety of environments (Rhino, V8, node.js, etc.) which the unfortunate outcome that they are more than difficult to run in the most common environment: the browser. This fork rewrites all of the tests as QUnit tests which can quickly be run in the browser. Furthermore, all of the specification tests are included and “green” as well.
- More expressive comments: This implementation allows developers to comment out code by wrapping existing Mustache code in comments. This is a fairly major addition to both the spec and the mainline interpreter.
Downloads
- mustache.min.js (minimized, suitable for Production) (8 KB).
- mustache.js (uncompressed, suitable for Development) (20 KB).
- Public source repository available on GitHub
Licensing
Mustache.js (all versions) is available under an MIT license.