pax_global_header00006660000000000000000000000064133355364050014521gustar00rootroot0000000000000052 comment=49714ba8ae0035ee5461eac42ba5f53ff5c0f86a mustache.js-2.3.2/000077500000000000000000000000001333553640500137515ustar00rootroot00000000000000mustache.js-2.3.2/.eslintrc000066400000000000000000000005641333553640500156020ustar00rootroot00000000000000{ "env": { "browser": true, "node": true }, "rules": { "func-names": 2, "no-mixed-spaces-and-tabs": 2, "quotes": [2, "single", "avoid-escape"], "semi": 2, "keyword-spacing": 2, "space-before-function-paren": 2, "curly": 0, "consistent-return": 0, "no-use-before-define": 0, "no-process-exit": 0, "strict": 0 } }mustache.js-2.3.2/.gitignore000066400000000000000000000002321333553640500157360ustar00rootroot00000000000000node_modules jquery.mustache.js mootools.mustache.js dojox yui3 qooxdoo.mustache.js test/render-test-browser.js npm-debug.log test/render-test-browser.jsmustache.js-2.3.2/.gitmodules000066400000000000000000000001221333553640500161210ustar00rootroot00000000000000[submodule "test/spec"] path = test/spec url = https://github.com/mustache/spec mustache.js-2.3.2/.travis.yml000066400000000000000000000012231333553640500160600ustar00rootroot00000000000000language: node_js node_js: - 0.8 - '0.10' - 0.12 - 4 - 6 before_install: - "test $TRAVIS_NODE_VERSION != '0.8' || npm install -g npm@2.x" script: - npm test - "test $TRAVIS_PULL_REQUEST != 'false' || test $TRAVIS_NODE_VERSION != '6' || npm run test-browser" env: global: - secure: L0dg0jr2fwkc2tPwP5svybILPBn2qdLzMrWc5tEXg3MPcy8D59Gvf+ri7INqo+ETPM20o5CsaDCH+LHUNS/V0G4VG1ajvsy7d8uh3hnb/K6VfVui/CjsHIqOcOZrbxVxgyX+iMXEXAj0+Syow9uDQHVhrz1qqad1n79likNCXa4= - secure: J4vbGKivULEHWRWExAWDLkFk9EDU7E6Ny+iRc/oKxXHnBYn9oL2Hfc1J92fOttaFtUzpz7r5FaNa3DGlyAI0wimq5GY8KJQGcquoskerXucd8iJbLCs3nxDeShl4UwHpDIXF8xbH/rUIkrGSKnktf0McMRIyeN95hzug0nxOwAw= mustache.js-2.3.2/.zuul.yml000066400000000000000000000002761333553640500155560ustar00rootroot00000000000000ui: mocha-bdd browsers: - name: chrome version: latest - name: firefox version: latest - name: ie version: 9..latest concurrency: 1 tunnel: type: ngrok bind_tls: false mustache.js-2.3.2/CHANGELOG.md000066400000000000000000000302561333553640500155700ustar00rootroot00000000000000# Change Log All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## [2.3.2] / 17 August 2018 This release is made to revert changes introduced in [2.3.1] that caused unexpected behaviour for several users. ### Minor * [#670]: Rollback template cache causing unexpected behaviour, by [@raymond-lam]. ## [2.3.1] / 7 August 2018 ### Minor * [#643]: `Writer.prototype.parse` to cache by tags in addition to template string, by [@raymond-lam]. * [#664]: Fix `Writer.prototype.parse` cache, by [@seminaoki]. ### Dev * [#666]: Install release tools with npm rather than pre-commit hook & `Rakefile`, by [@phillipj]. * [#667], [#668]: Stabilize browser test suite, by [@phillipj]. ### Docs * [#644]: Document global Mustache.escape overriding capacity, by [@paultopia]. * [#657]: Correct `Mustache.parse()` return type documentation, by [@bbrooks]. ## [2.3.0] / 8 November 2016 ### Minor * [#540]: Add optional `output` argument to mustache CLI, by [@wizawu]. * [#597]: Add compatibility with amdclean, by [@mightyplow]. ### Dev * [#553]: Assert `null` lookup when rendering an unescaped value, by [@dasilvacontin]. * [#580], [#610]: Ignore eslint for greenkeeper updates, by [@phillipj]. * [#560]: Fix CLI tests for Windows, by [@kookookchoozeus]. * Run browser tests w/node v4, by [@phillipj]. ### Docs * [#542]: Add API documentation to README, by [@tomekwi]. * [#546]: Add missing syntax highlighting to README code blocks, by [@pra85]. * [#569]: Update Ctemplate links in README, by [@mortonfox]. * [#592]: Change "loadUser" to "loadUser()" in README, by [@Flaque]. * [#593]: Adding doctype to HTML code example in README, by [@calvinf]. ### Dependencies * eslint -> 2.2.0. Breaking changes fix by [@phillipj]. [#548] * eslint -> 2.5.1. * mocha -> 3.0.2. * zuul -> 3.11.0. ## [2.2.1] / 13 December 2015 ### Fixes * Improve HTML escaping, by [@phillipj]. * Fix inconsistency in defining global mustache object, by [@simast]. * Fix switch-case indent error, by [@norfish]. * Unpin chai and eslint versions, by [@dasilvacontin]. * Update README.md with proper grammar, by [@EvanLovely]. * Update mjackson username in README, by [@mjackson]. * Remove syntax highlighting in README code sample, by [@imagentleman]. * Fix typo in README, by [@Xcrucifier]. * Fix link typo in README, by [@keirog]. ## [2.2.0] / 15 October 2015 ### Added * Add Partials support to CLI, by [@palkan]. ### Changed * Move install instructions to README's top, by [@mateusortiz] * Improved devhook install output, by [@ShashankaNataraj]. * Clarifies and improves language in documentation, by [@jfmercer]. * Linting CLI tool, by [@phillipj]. * npm 2.x and node v4 on Travis, by [@phillipj]. ### Fixes * Fix README spelling error to "aforementioned", by [@djchie]. * Equal error message test in .render() for server and browser, by [@phillipj]. ### Dependencies * chai -> 3.3.0 * eslint -> 1.6.0 ## [2.1.3] / 23 July 2015 ### Added * Throw error when providing .render() with invalid template type, by [@phillipj]. * Documents use of string literals containing double quotes, by [@jfmercer]. ### Changed * Move mustache gif to githubusercontent, by [@Andersos]. ### Fixed * Update UMD Shim to be resilient to HTMLElement global pollution, by [@mikesherov]. ## [2.1.2] / 17 June 2015 ### Added * Mustache global definition ([#466]) by [@yousefcisco]. ## [2.1.1] / 11 June 2015 ### Added * State that we use semver on the change log, by [@dasilvacontin]. * Added version links to change log, by [@dasilvacontin]. ### Fixed * Bugfix for using values from view's context prototype, by [@phillipj]. * Improve test with undefined/null lookup hit using dot notation, by [@dasilvacontin]. * Bugfix for null/undefined lookup hit when using dot notation, by [@phillipj]. * Remove moot `version` property from bower.json, by [@kkirsche]. * bower.json doesn't require a version bump via hook, by [@dasilvacontin]. ## [2.1.0] / 5 June 2015 * Added license attribute to package.json, by [@pgilad]. * Minor changes to make mustache.js compatible with both WSH and ASP, by [@nagaozen]. * Improve CLI view parsing error, by [@phillipj]. * Bugfix for view context cache, by [@phillipj]. ## [2.0.0] / 27 Mar 2015 * Fixed lookup not stopping upon finding `undefined` or `null` values, by [@dasilvacontin]. * Refactored pre-commit hook, by [@dasilvacontin]. ## [1.2.0] / 24 Mar 2015 * Added -v option to CLI, by [@phillipj]. * Bugfix for rendering Number when it serves as the Context, by [@phillipj]. * Specified files in package.json for a cleaner install, by [@phillipj]. ## [1.1.0] / 18 Feb 2015 * Refactor Writer.renderTokens() for better readability, by [@phillipj]. * Cleanup tests section in readme, by [@phillipj]. * Added JSHint to tests/CI, by [@phillipj]. * Added node v0.12 on travis, by [@phillipj]. * Created command line tool, by [@phillipj]. * Added *falsy* to Inverted Sections description in README, by [@kristijanmatic]. ## [1.0.0] / 20 Dec 2014 * Inline tag compilation, by [@mjackson]. * Fixed AMD registration, volo package.json entry, by [@jrburke]. * Added spm support, by [@afc163]. * Only access properties of objects on Context.lookup, by [@cmbuckley]. ## [0.8.2] / 17 Mar 2014 * Supporting Bower through a bower.json file. ## [0.8.1] / 3 Jan 2014 * Fix usage of partial templates. ## [0.8.0] / 2 Dec 2013 * Remove compile* writer functions, use mustache.parse instead. Smaller API. * Throw an error when rendering a template that contains higher-order sections and the original template is not provided. * Remove low-level Context.make function. * Better code readability and inline documentation. * Stop caching templates by name. ## [0.7.3] / 5 Nov 2013 * Don't require the original template to be passed to the rendering function when using compiled templates. This is still required when using higher-order functions in order to be able to extract the portion of the template that was contained by that section. Fixes [#262]. * Performance improvements. ## [0.7.2] / 27 Dec 2012 * Fixed a rendering bug ([#274]) when using nested higher-order sections. * Better error reporting on failed parse. * Converted tests to use mocha instead of vows. ## [0.7.1] / 6 Dec 2012 * Handle empty templates gracefully. Fixes [#265], [#267], and [#270]. * Cache partials by template, not by name. Fixes [#257]. * Added Mustache.compileTokens to compile the output of Mustache.parse. Fixes [#258]. ## [0.7.0] / 10 Sep 2012 * Rename Renderer => Writer. * Allow partials to be loaded dynamically using a callback (thanks [@TiddoLangerak] for the suggestion). * Fixed a bug with higher-order sections that prevented them from being passed the raw text of the section from the original template. * More concise token format. Tokens also include start/end indices in the original template. * High-level API is consistent with the Writer API. * Allow partials to be passed to the pre-compiled function (thanks [@fallenice]). * Don't use eval (thanks [@cweider]). ## [0.6.0] / 31 Aug 2012 * Use JavaScript's definition of falsy when determining whether to render an inverted section or not. Issue [#186]. * Use Mustache.escape to escape values inside {{}}. This function may be reassigned to alter the default escaping behavior. Issue [#244]. * Fixed a bug that clashed with QUnit (thanks [@kannix]). * Added volo support (thanks [@guybedford]). [2.3.2]: https://github.com/janl/mustache.js/compare/v2.3.1...v2.3.2 [2.3.1]: https://github.com/janl/mustache.js/compare/v2.3.0...v2.3.1 [2.3.0]: https://github.com/janl/mustache.js/compare/v2.2.1...v2.3.0 [2.2.1]: https://github.com/janl/mustache.js/compare/v2.2.0...v2.2.1 [2.2.0]: https://github.com/janl/mustache.js/compare/v2.1.3...v2.2.0 [2.1.3]: https://github.com/janl/mustache.js/compare/v2.1.2...v2.1.3 [2.1.2]: https://github.com/janl/mustache.js/compare/v2.1.1...v2.1.2 [2.1.1]: https://github.com/janl/mustache.js/compare/v2.1.0...v2.1.1 [2.1.0]: https://github.com/janl/mustache.js/compare/v2.0.0...v2.1.0 [2.0.0]: https://github.com/janl/mustache.js/compare/v1.2.0...v2.0.0 [1.2.0]: https://github.com/janl/mustache.js/compare/v1.1.0...v1.2.0 [1.1.0]: https://github.com/janl/mustache.js/compare/v1.0.0...v1.1.0 [1.0.0]: https://github.com/janl/mustache.js/compare/0.8.2...v1.0.0 [0.8.2]: https://github.com/janl/mustache.js/compare/0.8.1...0.8.2 [0.8.1]: https://github.com/janl/mustache.js/compare/0.8.0...0.8.1 [0.8.0]: https://github.com/janl/mustache.js/compare/0.7.3...0.8.0 [0.7.3]: https://github.com/janl/mustache.js/compare/0.7.2...0.7.3 [0.7.2]: https://github.com/janl/mustache.js/compare/0.7.1...0.7.2 [0.7.1]: https://github.com/janl/mustache.js/compare/0.7.0...0.7.1 [0.7.0]: https://github.com/janl/mustache.js/compare/0.6.0...0.7.0 [0.6.0]: https://github.com/janl/mustache.js/compare/0.5.2...0.6.0 [#186]: https://github.com/janl/mustache.js/issues/186 [#244]: https://github.com/janl/mustache.js/issues/244 [#257]: https://github.com/janl/mustache.js/issues/257 [#258]: https://github.com/janl/mustache.js/issues/258 [#262]: https://github.com/janl/mustache.js/issues/262 [#265]: https://github.com/janl/mustache.js/issues/265 [#267]: https://github.com/janl/mustache.js/issues/267 [#270]: https://github.com/janl/mustache.js/issues/270 [#274]: https://github.com/janl/mustache.js/issues/274 [#466]: https://github.com/janl/mustache.js/issues/466 [#540]: https://github.com/janl/mustache.js/issues/540 [#542]: https://github.com/janl/mustache.js/issues/542 [#546]: https://github.com/janl/mustache.js/issues/546 [#548]: https://github.com/janl/mustache.js/issues/548 [#553]: https://github.com/janl/mustache.js/issues/553 [#560]: https://github.com/janl/mustache.js/issues/560 [#569]: https://github.com/janl/mustache.js/issues/569 [#580]: https://github.com/janl/mustache.js/issues/580 [#592]: https://github.com/janl/mustache.js/issues/592 [#593]: https://github.com/janl/mustache.js/issues/593 [#597]: https://github.com/janl/mustache.js/issues/597 [#610]: https://github.com/janl/mustache.js/issues/610 [#643]: https://github.com/janl/mustache.js/issues/643 [#644]: https://github.com/janl/mustache.js/issues/644 [#657]: https://github.com/janl/mustache.js/issues/657 [#664]: https://github.com/janl/mustache.js/issues/664 [#666]: https://github.com/janl/mustache.js/issues/666 [#667]: https://github.com/janl/mustache.js/issues/667 [#668]: https://github.com/janl/mustache.js/issues/668 [#670]: https://github.com/janl/mustache.js/issues/670 [@afc163]: https://github.com/afc163 [@Andersos]: https://github.com/Andersos [@bbrooks]: https://github.com/bbrooks [@calvinf]: https://github.com/calvinf [@cmbuckley]: https://github.com/cmbuckley [@cweider]: https://github.com/cweider [@dasilvacontin]: https://github.com/dasilvacontin [@djchie]: https://github.com/djchie [@EvanLovely]: https://github.com/EvanLovely [@fallenice]: https://github.com/fallenice [@Flaque]: https://github.com/Flaque [@guybedford]: https://github.com/guybedford [@imagentleman]: https://github.com/imagentleman [@jfmercer]: https://github.com/jfmercer [@jrburke]: https://github.com/jrburke [@kannix]: https://github.com/kannix [@keirog]: https://github.com/keirog [@kkirsche]: https://github.com/kkirsche [@kookookchoozeus]: https://github.com/kookookchoozeus [@kristijanmatic]: https://github.com/kristijanmatic [@mateusortiz]: https://github.com/mateusortiz [@mightyplow]: https://github.com/mightyplow [@mikesherov]: https://github.com/mikesherov [@mjackson]: https://github.com/mjackson [@mortonfox]: https://github.com/mortonfox [@nagaozen]: https://github.com/nagaozen [@norfish]: https://github.com/norfish [@palkan]: https://github.com/palkan [@paultopia]: https://github.com/paultopia [@pgilad]: https://github.com/pgilad [@phillipj]: https://github.com/phillipj [@pra85]: https://github.com/pra85 [@raymond-lam]: https://github.com/raymond-lam [@seminaoki]: https://github.com/seminaoki [@ShashankaNataraj]: https://github.com/ShashankaNataraj [@simast]: https://github.com/simast [@TiddoLangerak]: https://github.com/TiddoLangerak [@tomekwi]: https://github.com/tomekwi [@wizawu]: https://github.com/wizawu [@Xcrucifier]: https://github.com/Xcrucifier [@yousefcisco]: https://github.com/yousefcisco mustache.js-2.3.2/LICENSE000066400000000000000000000022371333553640500147620ustar00rootroot00000000000000The MIT License Copyright (c) 2009 Chris Wanstrath (Ruby) Copyright (c) 2010-2014 Jan Lehnardt (JavaScript) Copyright (c) 2010-2015 The mustache.js community 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. mustache.js-2.3.2/MIGRATING.md000066400000000000000000000024731333553640500156220ustar00rootroot00000000000000# Migrating Guide ## Moving to mustache.js v2 ### Overview mustache.js v2 introduces a bug fix that breaks compatibility with older versions: fixing null and undefined lookup. When mustache.js tries to render a variable `{{name}}`, it executes a `lookup` function to figure out which value it should render. This function looks up the value for the key `name` in the current context, and if there is no such key in the current context it looks up the parent contexts recursively. Value lookup should stop whenever the key exists in the context. However, due to a bug, this was not happening when the value was `null` or `undefined` even though the key existed in the context. Here's a simple example of the same template rendered with both mustache.js v1 and v2: Template: ```mustache {{#friends}} {{name}}'s twitter is: {{twitter}} {{/friends}} ``` View: ```json { "name": "David", "twitter": "@dasilvacontin", "friends": [ { "name": "Phillip", "twitter": "@phillipjohnsen" }, { "name": "Jan", "twitter": null } ] } ``` Rendered using mustache.js v1: ```text Phillip's twitter is: @phillipjohnsen Jan's twitter is: @dasilvacontin ``` Rendered using mustache.js v2: ```text Phillip's twitter is: @phillipjohnsen Jan's twitter is: ```mustache.js-2.3.2/README.md000066400000000000000000000407311333553640500152350ustar00rootroot00000000000000# mustache.js - Logic-less {{mustache}} templates with JavaScript > What could be more logical awesome than no logic at all? [![Build Status](https://travis-ci.org/janl/mustache.js.svg?branch=master)](https://travis-ci.org/janl/mustache.js) [![Gitter chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/janl/mustache.js) [mustache.js](http://github.com/janl/mustache.js) is an implementation of the [mustache](http://mustache.github.com/) template system in JavaScript. [Mustache](http://mustache.github.com/) is a logic-less template syntax. It can be used for HTML, config files, source code - anything. It works by expanding tags in a template using values provided in a hash or object. We call it "logic-less" because there are no if statements, else clauses, or for loops. Instead there are only tags. Some tags are replaced with a value, some nothing, and others a series of values. For a language-agnostic overview of mustache's template syntax, see the `mustache(5)` [manpage](http://mustache.github.com/mustache.5.html). ## Where to use mustache.js? You can use mustache.js to render mustache templates anywhere you can use JavaScript. This includes web browsers, server-side environments such as [node](http://nodejs.org/), and [CouchDB](http://couchdb.apache.org/) views. mustache.js ships with support for both the [CommonJS](http://www.commonjs.org/) module API and the [Asynchronous Module Definition](https://github.com/amdjs/amdjs-api/wiki/AMD) API, or AMD. And this will be your templates after you use Mustache: !['stache](https://cloud.githubusercontent.com/assets/288977/8779228/a3cf700e-2f02-11e5-869a-300312fb7a00.gif) ## Install You can get Mustache via npm. ```bash $ npm install mustache --save ``` or install with bower: ```bash $ bower install --save mustache ``` ## Command line tool mustache.js is shipped with a node based command line tool. It might be installed as a global tool on your computer to render a mustache template of some kind ```bash $ npm install -g mustache $ mustache dataView.json myTemplate.mustache > output.html ``` also supports stdin. ```bash $ cat dataView.json | mustache - myTemplate.mustache > output.html ``` or as a package.json `devDependency` in a build process maybe? ```bash $ npm install mustache --save-dev ``` ```json { "scripts": { "build": "mustache dataView.json myTemplate.mustache > public/output.html" } } ``` ```bash $ npm run build ``` The command line tool is basically a wrapper around `Mustache.render` so you get all the features. If your templates use partials you should pass paths to partials using `-p` flag: ```bash $ mustache -p path/to/partial1.mustache -p path/to/partial2.mustache dataView.json myTemplate.mustache ``` ## Who uses mustache.js? An updated list of mustache.js users is kept [on the Github wiki](http://wiki.github.com/janl/mustache.js/beard-competition). Add yourself or your company if you use mustache.js! ## Contributing mustache.js is a mature project, but it continues to actively invite maintainers. You can help out a high-profile project that is used in a lot of places on the web. There is [plenty](https://github.com/janl/mustache.js/issues) of [work](https://github.com/janl/mustache.js/pulls) to do. No big commitment required, if all you do is review a single [Pull Request](https://github.com/janl/mustache.js/pulls), you are a maintainer. And a hero. ### Your First Contribution - review a [Pull Request](https://github.com/janl/mustache.js/pulls) - fix an [Issue](https://github.com/janl/mustache.js/issues) - update the [documentation](https://github.com/janl/mustache.js#usage) - make a website - write a tutorial * * * ## Usage Below is a quick example how to use mustache.js: ```js var view = { title: "Joe", calc: function () { return 2 + 4; } }; var output = Mustache.render("{{title}} spends {{calc}}", view); ``` In this example, the `Mustache.render` function takes two parameters: 1) the [mustache](http://mustache.github.com/) template and 2) a `view` object that contains the data and code needed to render the template. ## API Following is an [rtype](https://git.io/rtype) signature of the most commonly used functions. ```js Mustache.render( template : String, view : Object, partials? : Object, ) => String Mustache.parse( template : String, tags = ['{{', '}}'] : Tags, ) => Token[] interface Token [String, String, Number, Number, Token[]?, Number?] interface Tags [String, String] ``` ## Templates A [mustache](http://mustache.github.com/) template is a string that contains any number of mustache tags. Tags are indicated by the double mustaches that surround them. `{{person}}` is a tag, as is `{{#person}}`. In both examples we refer to `person` as the tag's key. There are several types of tags available in mustache.js, described below. There are several techniques that can be used to load templates and hand them to mustache.js, here are two of them: #### Include Templates If you need a template for a dynamic part in a static website, you can consider including the template in the static HTML file to avoid loading templates separately. Here's a small example using `jQuery`: ```html
Loading...
``` ```js function loadUser() { var template = $('#template').html(); Mustache.parse(template); // optional, speeds up future uses var rendered = Mustache.render(template, {name: "Luke"}); $('#target').html(rendered); } ``` #### Load External Templates If your templates reside in individual files, you can load them asynchronously and render them when they arrive. Another example using `jQuery`: ```js function loadUser() { $.get('template.mst', function(template) { var rendered = Mustache.render(template, {name: "Luke"}); $('#target').html(rendered); }); } ``` ### Variables The most basic tag type is a simple variable. A `{{name}}` tag renders the value of the `name` key in the current context. If there is no such key, nothing is rendered. All variables are HTML-escaped by default. If you want to render unescaped HTML, use the triple mustache: `{{{name}}}`. You can also use `&` to unescape a variable. If you'd like to change HTML-escaping behavior globally (for example, to template non-HTML formats), you can override Mustache's escape function. For example, to disable all escaping: `Mustache.escape = function(text) {return text;};`. If you want `{{name}}` _not_ to be interpreted as a mustache tag, but rather to appear exactly as `{{name}}` in the output, you must change and then restore the default delimiter. See the [Custom Delimiters](#custom-delimiters) section for more information. View: ```json { "name": "Chris", "company": "GitHub" } ``` Template: ``` * {{name}} * {{age}} * {{company}} * {{{company}}} * {{&company}} {{=<% %>=}} * {{company}} <%={{ }}=%> ``` Output: ```html * Chris * * <b>GitHub</b> * GitHub * GitHub * {{company}} ``` JavaScript's dot notation may be used to access keys that are properties of objects in a view. View: ```json { "name": { "first": "Michael", "last": "Jackson" }, "age": "RIP" } ``` Template: ```html * {{name.first}} {{name.last}} * {{age}} ``` Output: ```html * Michael Jackson * RIP ``` ### Sections Sections render blocks of text one or more times, depending on the value of the key in the current context. A section begins with a pound and ends with a slash. That is, `{{#person}}` begins a `person` section, while `{{/person}}` ends it. The text between the two tags is referred to as that section's "block". The behavior of the section is determined by the value of the key. #### False Values or Empty Lists If the `person` key does not exist, or exists and has a value of `null`, `undefined`, `false`, `0`, or `NaN`, or is an empty string or an empty list, the block will not be rendered. View: ```json { "person": false } ``` Template: ```html Shown. {{#person}} Never shown! {{/person}} ``` Output: ```html Shown. ``` #### Non-Empty Lists If the `person` key exists and is not `null`, `undefined`, or `false`, and is not an empty list the block will be rendered one or more times. When the value is a list, the block is rendered once for each item in the list. The context of the block is set to the current item in the list for each iteration. In this way we can loop over collections. View: ```json { "stooges": [ { "name": "Moe" }, { "name": "Larry" }, { "name": "Curly" } ] } ``` Template: ```html {{#stooges}} {{name}} {{/stooges}} ``` Output: ```html Moe Larry Curly ``` When looping over an array of strings, a `.` can be used to refer to the current item in the list. View: ```json { "musketeers": ["Athos", "Aramis", "Porthos", "D'Artagnan"] } ``` Template: ```html {{#musketeers}} * {{.}} {{/musketeers}} ``` Output: ```html * Athos * Aramis * Porthos * D'Artagnan ``` If the value of a section variable is a function, it will be called in the context of the current item in the list on each iteration. View: ```js { "beatles": [ { "firstName": "John", "lastName": "Lennon" }, { "firstName": "Paul", "lastName": "McCartney" }, { "firstName": "George", "lastName": "Harrison" }, { "firstName": "Ringo", "lastName": "Starr" } ], "name": function () { return this.firstName + " " + this.lastName; } } ``` Template: ```html {{#beatles}} * {{name}} {{/beatles}} ``` Output: ```html * John Lennon * Paul McCartney * George Harrison * Ringo Starr ``` #### Functions If the value of a section key is a function, it is called with the section's literal block of text, un-rendered, as its first argument. The second argument is a special rendering function that uses the current view as its view argument. It is called in the context of the current view object. View: ```js { "name": "Tater", "bold": function () { return function (text, render) { return "" + render(text) + ""; } } } ``` Template: ```html {{#bold}}Hi {{name}}.{{/bold}} ``` Output: ```html Hi Tater. ``` ### Inverted Sections An inverted section opens with `{{^section}}` instead of `{{#section}}`. The block of an inverted section is rendered only if the value of that section's tag is `null`, `undefined`, `false`, *falsy* or an empty list. View: ```json { "repos": [] } ``` Template: ```html {{#repos}}{{name}}{{/repos}} {{^repos}}No repos :({{/repos}} ``` Output: ```html No repos :( ``` ### Comments Comments begin with a bang and are ignored. The following template: ```html

Today{{! ignore me }}.

``` Will render as follows: ```html

Today.

``` Comments may contain newlines. ### Partials Partials begin with a greater than sign, like {{> box}}. Partials are rendered at runtime (as opposed to compile time), so recursive partials are possible. Just avoid infinite loops. They also inherit the calling context. Whereas in ERB you may have this: ```html+erb <%= partial :next_more, :start => start, :size => size %> ``` Mustache requires only this: ```html {{> next_more}} ``` Why? Because the `next_more.mustache` file will inherit the `size` and `start` variables from the calling context. In this way you may want to think of partials as includes, imports, template expansion, nested templates, or subtemplates, even though those aren't literally the case here. For example, this template and partial: base.mustache:

Names

{{#names}} {{> user}} {{/names}} user.mustache: {{name}} Can be thought of as a single, expanded template: ```html

Names

{{#names}} {{name}} {{/names}} ``` In mustache.js an object of partials may be passed as the third argument to `Mustache.render`. The object should be keyed by the name of the partial, and its value should be the partial text. ```js Mustache.render(template, view, { user: userTemplate }); ``` ### Custom Delimiters Custom delimiters can be used in place of `{{` and `}}` by setting the new values in JavaScript or in templates. #### Setting in JavaScript The `Mustache.tags` property holds an array consisting of the opening and closing tag values. Set custom values by passing a new array of tags to `parse()`, which gets honored over the default values, or by overriding the `tags` property itself: ```js var customTags = [ '<%', '%>' ]; ``` ##### Pass Value into Parse Method ```js Mustache.parse(template, customTags); ``` ##### Override Tags Property ```js Mustache.tags = customTags; // Subsequent parse() and render() calls will use customTags ``` #### Setting in Templates Set Delimiter tags start with an equals sign and change the tag delimiters from `{{` and `}}` to custom strings. Consider the following contrived example: ```html+erb * {{ default_tags }} {{=<% %>=}} * <% erb_style_tags %> <%={{ }}=%> * {{ default_tags_again }} ``` Here we have a list with three items. The first item uses the default tag style, the second uses ERB style as defined by the Set Delimiter tag, and the third returns to the default style after yet another Set Delimiter declaration. According to [ctemplates](https://htmlpreview.github.io/?https://raw.githubusercontent.com/OlafvdSpek/ctemplate/master/doc/howto.html), this "is useful for languages like TeX, where double-braces may occur in the text and are awkward to use for markup." Custom delimiters may not contain whitespace or the equals sign. ## Pre-parsing and Caching Templates By default, when mustache.js first parses a template it keeps the full parsed token tree in a cache. The next time it sees that same template it skips the parsing step and renders the template much more quickly. If you'd like, you can do this ahead of time using `mustache.parse`. ```js Mustache.parse(template); // Then, sometime later. Mustache.render(template, view); ``` ## Plugins for JavaScript Libraries mustache.js may be built specifically for several different client libraries, including the following: - [jQuery](http://jquery.com/) - [MooTools](http://mootools.net/) - [Dojo](http://www.dojotoolkit.org/) - [YUI](http://developer.yahoo.com/yui/) - [qooxdoo](http://qooxdoo.org/) These may be built using [Rake](http://rake.rubyforge.org/) and one of the following commands: ```bash $ rake jquery $ rake mootools $ rake dojo $ rake yui3 $ rake qooxdoo ``` ## Testing In order to run the tests you'll need to install [node](http://nodejs.org/). You also need to install the sub module containing [Mustache specifications](http://github.com/mustache/spec) in the project root. ```bash $ git submodule init $ git submodule update ``` Install dependencies. ```bash $ npm install ``` Then run the tests. ```bash $ npm test ``` The test suite consists of both unit and integration tests. If a template isn't rendering correctly for you, you can make a test for it by doing the following: 1. Create a template file named `mytest.mustache` in the `test/_files` directory. Replace `mytest` with the name of your test. 2. Create a corresponding view file named `mytest.js` in the same directory. This file should contain a JavaScript object literal enclosed in parentheses. See any of the other view files for an example. 3. Create a file with the expected output in `mytest.txt` in the same directory. Then, you can run the test with: ```bash $ TEST=mytest npm run test-render ``` ### Browser tests Browser tests are not included in `npm test` as they run for too long, although they are ran automatically on Travis when merged into master. Run browser tests locally in any browser: ```bash $ npm run test-browser-local ``` then point your browser to `http://localhost:8080/__zuul` ### Troubleshooting #### npm install fails Ensure to have a recent version of npm installed. While developing this project requires npm with support for `^` version ranges. ```bash $ npm install -g npm ``` ## Thanks mustache.js wouldn't kick ass if it weren't for these fine souls: * Chris Wanstrath / defunkt * Alexander Lang / langalex * Sebastian Cohnen / tisba * J Chris Anderson / jchris * Tom Robinson / tlrobinson * Aaron Quint / quirkey * Douglas Crockford * Nikita Vasilyev / NV * Elise Wood / glytch * Damien Mathieu / dmathieu * Jakub Kuźma / qoobaa * Will Leinweber / will * dpree * Jason Smith / jhs * Aaron Gibralter / agibralter * Ross Boucher / boucher * Matt Sanford / mzsanford * Ben Cherry / bcherry * Michael Jackson / mjackson * Phillip Johnsen / phillipj * David da Silva Contín / dasilvacontin mustache.js-2.3.2/Rakefile000066400000000000000000000027661333553640500154310ustar00rootroot00000000000000require 'rake' require 'rake/clean' task :default => :test def minified_file ENV['FILE'] || 'mustache.min.js' end desc "Run all tests" task :test do sh "./node_modules/.bin/mocha test" end desc "Make a compressed build in #{minified_file}" task :minify do sh "./node_modules/.bin/uglifyjs mustache.js > #{minified_file}" end desc "Run JSHint" task :hint do sh "./node_modules/.bin/jshint mustache.js" end # Creates a task that uses the various template wrappers to make a wrapped # output file. There is some extra complexity because Dojo and YUI use # different final locations. def templated_build(name, final_location=nil) short = name.downcase source = File.join("wrappers", short) dependencies = ["mustache.js"] + Dir.glob("#{source}/*.tpl.*") target_js = final_location.nil? ? "#{short}.mustache.js" : "mustache.js" desc "Package for #{name}" task short.to_sym => dependencies do puts "Packaging for #{name}" mkdir_p final_location unless final_location.nil? sources = [ "#{source}/mustache.js.pre", 'mustache.js', "#{source}/mustache.js.post" ] relative_name = "#{final_location || '.'}/#{target_js}" open(relative_name, 'w') do |f| sources.each {|source| f << File.read(source) } end puts "Done, see #{relative_name}" end CLEAN.include(final_location.nil? ? target_js : final_location) end templated_build "jQuery" templated_build "MooTools" templated_build "Dojo", "dojox/string" templated_build "YUI3", "yui3/mustache" templated_build "qooxdoo" mustache.js-2.3.2/bin/000077500000000000000000000000001333553640500145215ustar00rootroot00000000000000mustache.js-2.3.2/bin/mustache000077500000000000000000000061531333553640500162650ustar00rootroot00000000000000#!/usr/bin/env node var fs = require('fs'), path = require('path'); var Mustache = require('..'); var pkg = require('../package'); var partials = {}; var partialsPaths = []; var partialArgIndex = -1; while ((partialArgIndex = process.argv.indexOf('-p')) > -1) { partialsPaths.push(process.argv.splice(partialArgIndex, 2)[1]); } var viewArg = process.argv[2]; var templateArg = process.argv[3]; var outputArg = process.argv[4]; if (hasVersionArg()) { return console.log(pkg.version); } if (!templateArg || !viewArg) { console.error('Syntax: mustache