Repository: janl/mustache.js Branch: master Commit: 972fd2b27a03 Files: 247 Total size: 146.9 KB Directory structure: gitextract_6pju20il/ ├── .eslintrc ├── .esmrc ├── .github/ │ └── workflows/ │ ├── usage.yml │ └── verify.yml ├── .gitignore ├── .gitmodules ├── .travis.yml ├── .zuul.yml ├── CHANGELOG.md ├── LICENSE ├── MIGRATING.md ├── README.md ├── Rakefile ├── bin/ │ └── mustache ├── mustache.js ├── package.json ├── scripts/ │ └── bump-version-in-source ├── spec/ │ └── _files/ │ ├── bom_as_whitespace.js │ ├── bom_as_whitespace.mustache │ └── bom_as_whitespace.txt ├── test/ │ ├── .eslintrc │ ├── _files/ │ │ ├── ampersand_escape.js │ │ ├── ampersand_escape.mustache │ │ ├── ampersand_escape.txt │ │ ├── apostrophe.js │ │ ├── apostrophe.mustache │ │ ├── apostrophe.txt │ │ ├── array_of_strings.js │ │ ├── array_of_strings.mustache │ │ ├── array_of_strings.txt │ │ ├── avoids_obj_prototype_in_view_cache.js │ │ ├── avoids_obj_prototype_in_view_cache.mustache │ │ ├── avoids_obj_prototype_in_view_cache.txt │ │ ├── backslashes.js │ │ ├── backslashes.mustache │ │ ├── backslashes.txt │ │ ├── bug_11_eating_whitespace.js │ │ ├── bug_11_eating_whitespace.mustache │ │ ├── bug_11_eating_whitespace.txt │ │ ├── bug_length_property.js │ │ ├── bug_length_property.mustache │ │ ├── bug_length_property.txt │ │ ├── changing_delimiters.js │ │ ├── changing_delimiters.mustache │ │ ├── changing_delimiters.txt │ │ ├── check_falsy.js │ │ ├── check_falsy.mustache │ │ ├── check_falsy.txt │ │ ├── cli.cjs │ │ ├── cli.js │ │ ├── cli.json │ │ ├── cli.mustache │ │ ├── cli.txt │ │ ├── cli_js_view_with_function.js │ │ ├── cli_js_view_with_function.mustache │ │ ├── cli_js_view_with_function.txt │ │ ├── cli_with_partials.json │ │ ├── cli_with_partials.mustache │ │ ├── cli_with_partials.txt │ │ ├── comments.js │ │ ├── comments.mustache │ │ ├── comments.txt │ │ ├── complex.js │ │ ├── complex.mustache │ │ ├── complex.txt │ │ ├── context_lookup.js │ │ ├── context_lookup.mustache │ │ ├── context_lookup.txt │ │ ├── delimiters.js │ │ ├── delimiters.mustache │ │ ├── delimiters.txt │ │ ├── disappearing_whitespace.js │ │ ├── disappearing_whitespace.mustache │ │ ├── disappearing_whitespace.txt │ │ ├── dot_notation.js │ │ ├── dot_notation.mustache │ │ ├── dot_notation.txt │ │ ├── double_render.js │ │ ├── double_render.mustache │ │ ├── double_render.txt │ │ ├── empty_list.js │ │ ├── empty_list.mustache │ │ ├── empty_list.txt │ │ ├── empty_sections.js │ │ ├── empty_sections.mustache │ │ ├── empty_sections.txt │ │ ├── empty_string.js │ │ ├── empty_string.mustache │ │ ├── empty_string.txt │ │ ├── empty_template.js │ │ ├── empty_template.mustache │ │ ├── empty_template.txt │ │ ├── error_not_found.js │ │ ├── error_not_found.mustache │ │ ├── error_not_found.txt │ │ ├── escaped.js │ │ ├── escaped.mustache │ │ ├── escaped.txt │ │ ├── falsy.js │ │ ├── falsy.mustache │ │ ├── falsy.txt │ │ ├── falsy_array.js │ │ ├── falsy_array.mustache │ │ ├── falsy_array.txt │ │ ├── grandparent_context.js │ │ ├── grandparent_context.mustache │ │ ├── grandparent_context.txt │ │ ├── higher_order_sections.js │ │ ├── higher_order_sections.mustache │ │ ├── higher_order_sections.txt │ │ ├── implicit_iterator.js │ │ ├── implicit_iterator.mustache │ │ ├── implicit_iterator.txt │ │ ├── included_tag.js │ │ ├── included_tag.mustache │ │ ├── included_tag.txt │ │ ├── inverted_section.js │ │ ├── inverted_section.mustache │ │ ├── inverted_section.txt │ │ ├── keys_with_questionmarks.js │ │ ├── keys_with_questionmarks.mustache │ │ ├── keys_with_questionmarks.txt │ │ ├── malicious_template.js │ │ ├── malicious_template.mustache │ │ ├── malicious_template.txt │ │ ├── multiline_comment.js │ │ ├── multiline_comment.mustache │ │ ├── multiline_comment.txt │ │ ├── nested_dot.js │ │ ├── nested_dot.mustache │ │ ├── nested_dot.txt │ │ ├── nested_higher_order_sections.js │ │ ├── nested_higher_order_sections.mustache │ │ ├── nested_higher_order_sections.txt │ │ ├── nested_iterating.js │ │ ├── nested_iterating.mustache │ │ ├── nested_iterating.txt │ │ ├── nesting.js │ │ ├── nesting.mustache │ │ ├── nesting.txt │ │ ├── nesting_same_name.js │ │ ├── nesting_same_name.mustache │ │ ├── nesting_same_name.txt │ │ ├── null_lookup_array.js │ │ ├── null_lookup_array.mustache │ │ ├── null_lookup_array.txt │ │ ├── null_lookup_object.js │ │ ├── null_lookup_object.mustache │ │ ├── null_lookup_object.txt │ │ ├── null_string.js │ │ ├── null_string.mustache │ │ ├── null_string.txt │ │ ├── null_view.js │ │ ├── null_view.mustache │ │ ├── null_view.txt │ │ ├── partial_array.js │ │ ├── partial_array.mustache │ │ ├── partial_array.partial │ │ ├── partial_array.txt │ │ ├── partial_array_of_partials.js │ │ ├── partial_array_of_partials.mustache │ │ ├── partial_array_of_partials.partial │ │ ├── partial_array_of_partials.txt │ │ ├── partial_array_of_partials_implicit.js │ │ ├── partial_array_of_partials_implicit.mustache │ │ ├── partial_array_of_partials_implicit.partial │ │ ├── partial_array_of_partials_implicit.txt │ │ ├── partial_empty.js │ │ ├── partial_empty.mustache │ │ ├── partial_empty.partial │ │ ├── partial_empty.txt │ │ ├── partial_template.js │ │ ├── partial_template.mustache │ │ ├── partial_template.partial │ │ ├── partial_template.txt │ │ ├── partial_view.js │ │ ├── partial_view.mustache │ │ ├── partial_view.partial │ │ ├── partial_view.txt │ │ ├── partial_whitespace.js │ │ ├── partial_whitespace.mustache │ │ ├── partial_whitespace.partial │ │ ├── partial_whitespace.txt │ │ ├── recursion_with_same_names.js │ │ ├── recursion_with_same_names.mustache │ │ ├── recursion_with_same_names.txt │ │ ├── reuse_of_enumerables.js │ │ ├── reuse_of_enumerables.mustache │ │ ├── reuse_of_enumerables.txt │ │ ├── section_as_context.js │ │ ├── section_as_context.mustache │ │ ├── section_as_context.txt │ │ ├── section_functions_in_partials.js │ │ ├── section_functions_in_partials.mustache │ │ ├── section_functions_in_partials.partial │ │ ├── section_functions_in_partials.txt │ │ ├── simple.js │ │ ├── simple.mustache │ │ ├── simple.txt │ │ ├── string_as_context.js │ │ ├── string_as_context.mustache │ │ ├── string_as_context.txt │ │ ├── two_in_a_row.js │ │ ├── two_in_a_row.mustache │ │ ├── two_in_a_row.txt │ │ ├── two_sections.js │ │ ├── two_sections.mustache │ │ ├── two_sections.txt │ │ ├── unescaped.js │ │ ├── unescaped.mustache │ │ ├── unescaped.txt │ │ ├── uses_props_from_view_prototype.js │ │ ├── uses_props_from_view_prototype.mustache │ │ ├── uses_props_from_view_prototype.txt │ │ ├── whitespace.js │ │ ├── whitespace.mustache │ │ ├── whitespace.txt │ │ ├── zero_view.js │ │ ├── zero_view.mustache │ │ └── zero_view.txt │ ├── cli-test.js │ ├── context-test.js │ ├── create-browser-suite.js │ ├── helper.js │ ├── module-systems/ │ │ ├── .eslintrc │ │ ├── _fixtures/ │ │ │ ├── amd.html │ │ │ └── global-scope.html │ │ ├── browser-test.js │ │ ├── commonjs-test.js │ │ ├── deno-test.ts │ │ ├── esm-test-exports.mjs │ │ └── esm-test.mjs │ ├── mustache-spec-test.js │ ├── parse-test.js │ ├── partial-test.js │ ├── render-helper.js │ ├── render-test-browser-tmpl.mustache │ ├── render-test.js │ └── scanner-test.js └── wrappers/ ├── dojo/ │ ├── mustache.js.post │ └── mustache.js.pre ├── jquery/ │ ├── mustache.js.post │ └── mustache.js.pre ├── mootools/ │ ├── mustache.js.post │ └── mustache.js.pre └── qooxdoo/ ├── mustache.js.post └── mustache.js.pre ================================================ FILE CONTENTS ================================================ ================================================ FILE: .eslintrc ================================================ { "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 }, "overrides": [ { "files": ["mustache.js"], "parserOptions": { "sourceType": "module", "ecmaVersion": 2015 } } ] } ================================================ FILE: .esmrc ================================================ { cjs: { // Ensure ESM `export default` ends up as the root, e.g. `module.exports` when // being `require()`d from CJS code. This is not spec compliant, but that does // not matter because only use this `esm` package trickery locally while testing dedefault: true } } ================================================ FILE: .github/workflows/usage.yml ================================================ name: Package usage on: [push, pull_request] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup Node.js uses: actions/setup-node@v1 with: node-version: 14.x - name: npm install and build run: | npm install npm run build - name: Store build-output for later uses: actions/upload-artifact@v2 with: name: build-output path: | mustache.js mustache.mjs package: runs-on: ubuntu-latest needs: build steps: - uses: actions/checkout@v2 - name: Setup Node.js uses: actions/setup-node@v1 with: node-version: 14.x - name: Get build-output from build step uses: actions/download-artifact@v2 with: name: build-output - name: Create package tarball run: | export ARCHIVE_FILENAME=$(npm pack | tail -n 1) mv $ARCHIVE_FILENAME mustache.tgz - name: Store package tarball for later uses: actions/upload-artifact@v2 with: name: package-output path: mustache.tgz common-js-usage: runs-on: ubuntu-latest strategy: matrix: node-version: [10.x, 12.x, 14.x, 15.x] needs: package steps: - uses: actions/checkout@v1 - name: Setup Node.js uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - name: Get package tarball from package step uses: actions/download-artifact@v2 with: name: package-output - name: Package, install and test run: | export UNPACK_DESTINATION=$(mktemp -d) mv mustache.tgz $UNPACK_DESTINATION cp test/module-systems/commonjs-test.js $UNPACK_DESTINATION cd $UNPACK_DESTINATION npm install mustache.tgz node commonjs-test.js esm-usage: runs-on: ubuntu-latest strategy: matrix: node-version: [14.x, 15.x] needs: package steps: - uses: actions/checkout@v1 - name: Setup Node.js uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - name: Get package tarball from package step uses: actions/download-artifact@v2 with: name: package-output - name: Package, install and test run: | export UNPACK_DESTINATION=$(mktemp -d) mv mustache.tgz $UNPACK_DESTINATION cp test/module-systems/esm-test.mjs $UNPACK_DESTINATION cp test/module-systems/esm-test-exports.mjs $UNPACK_DESTINATION cd $UNPACK_DESTINATION npm install mustache.tgz node esm-test.mjs node esm-test-exports.mjs browser-usage: runs-on: ubuntu-latest needs: build steps: - uses: actions/checkout@v1 - name: Setup Node.js uses: actions/setup-node@v1 with: node-version: 12.x - name: Get build-output from build step uses: actions/download-artifact@v2 with: name: build-output - name: Install and test run: | npm ci npx mocha test/module-systems/browser-test.js deno-usage: runs-on: ubuntu-latest needs: build steps: - uses: actions/checkout@v1 - uses: denolib/setup-deno@master with: deno-version: 'v1.0.0' - name: Get build-output from build step uses: actions/download-artifact@v2 with: name: build-output - run: deno --version - run: deno test --allow-net=deno.land test/module-systems/deno-test.ts ================================================ FILE: .github/workflows/verify.yml ================================================ name: Verify changes on: [push, pull_request] jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup Node.js uses: actions/setup-node@v1 with: node-version: 14.x - run: npm install - run: npm run test-lint tests: runs-on: ubuntu-latest strategy: matrix: node-version: [10.x, 12.x, 14.x, 15.x] steps: - uses: actions/checkout@v2 with: submodules: recursive - name: Setup Node.js uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - name: npm install and test run: | npm install npm run test-unit build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup Node.js uses: actions/setup-node@v1 with: node-version: 14.x - name: npm install and build run: | npm install npm run build - name: Store build-output for later uses: actions/upload-artifact@v2 with: name: build-output path: | mustache.js mustache.mjs tests-on-legacy: runs-on: ubuntu-latest strategy: matrix: node-version: [0.10.x, 0.12.x, 4.x, 6.x, 8.x] needs: build steps: - uses: actions/checkout@v2 with: submodules: recursive - name: Setup Node.js uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - name: Get build-output from build step uses: actions/download-artifact@v2 with: name: build-output - name: npm install and test run: | npm install mocha@3 chai@3 npm run test-unit ================================================ FILE: .gitignore ================================================ node_modules jquery.mustache.js mootools.mustache.js dojox yui3 qooxdoo.mustache.js test/render-test-browser.js npm-debug.log .DS_Store test/render-test-browser.js .idea/ mustache.mjs mustache.min.js ================================================ FILE: .gitmodules ================================================ [submodule "test/spec"] path = test/spec url = https://github.com/mustache/spec ================================================ FILE: .travis.yml ================================================ language: node_js node_js: - 8 script: - npm run build - "test $TRAVIS_PULL_REQUEST != 'false' || test $TRAVIS_NODE_VERSION != '8' || npm run test-browser" env: global: - secure: L0dg0jr2fwkc2tPwP5svybILPBn2qdLzMrWc5tEXg3MPcy8D59Gvf+ri7INqo+ETPM20o5CsaDCH+LHUNS/V0G4VG1ajvsy7d8uh3hnb/K6VfVui/CjsHIqOcOZrbxVxgyX+iMXEXAj0+Syow9uDQHVhrz1qqad1n79likNCXa4= - secure: J4vbGKivULEHWRWExAWDLkFk9EDU7E6Ny+iRc/oKxXHnBYn9oL2Hfc1J92fOttaFtUzpz7r5FaNa3DGlyAI0wimq5GY8KJQGcquoskerXucd8iJbLCs3nxDeShl4UwHpDIXF8xbH/rUIkrGSKnktf0McMRIyeN95hzug0nxOwAw= ================================================ FILE: .zuul.yml ================================================ ui: mocha-bdd browsers: - name: chrome version: latest - name: firefox version: latest - name: ie version: 11..latest concurrency: 1 tunnel: type: ngrok bind_tls: false ================================================ FILE: CHANGELOG.md ================================================ # Change Log All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## [4.2.0] / 28 March 2021 ### Added * [#773]: Add package.json `exports` field, by [@manzt]. ## [4.1.0] / 6 December 2020 ### Added * [#764]: `render()` now recognizes a config object argument, by [@pineapplemachine]. ### Fixed * [#764]: Ask custom `escape` functions to escape all types of values (including `number`s), by [@pineapplemachine]. ## [4.0.1] / 15 March 2020 ### Fixed * [#739]: Fix custom delimiters in nested partials, by [@aielo]. ## [4.0.0] / 16 January 2020 Majority of using projects don't have to worry by this being a new major version. **TLDR;** if your project manipulates `Writer.prototype.parse | Writer.cache` directly or uses `.to_html()`, you probably have to change that code. This release allows the internal template cache to be customised, either by disabling it completely or provide a custom strategy deciding how the cache should behave when mustache.js parses templates. ```js const mustache = require('mustache'); // disable caching Mustache.templateCache = undefined; // or use a built-in Map in modern environments Mustache.templateCache = new Map(); ``` Projects that wanted to customise the caching behaviour in earlier versions of mustache.js were forced to override internal method responsible for parsing templates; `Writer.prototype.parse`. In short, that was unfortunate because there is more than caching happening in that method. We've improved that now by introducing a first class API that only affects template caching. The default template cache behaves as before and is still compatible with older JavaScript environments. For those who wants to provide a custom more sopisiticated caching strategy, one can do that with an object that adheres to the following requirements: ```ts { set(cacheKey: string, value: string): void get(cacheKey: string): string | undefined clear(): void } ``` ### Added * [#731]: Allow template caching to be customised, by [@AndrewLeedham]. ### Removed * [#735]: Remove `.to_html()`, by [@phillipj]. ## [3.2.1] / 30 December 2019 ### Fixed * [#733]: Allow the CLI to use JavaScript views when the project has ES6 modules enabled, by [@eobrain]. ## [3.2.0] / 18 December 2019 ### Added * [#728]: Expose ECMAScript Module in addition to UMD (CommonJS, AMD & global scope), by [@phillipj] and [@zekth]. ### Using mustache.js as an ES module To stay backwards compatible with already using projects, the default exposed module format is still UMD. That means projects using mustache.js as an CommonJS, AMD or global scope module, from npm or directly from github.com can keep on doing that for now. For those projects who would rather want to use mustache.js as an ES module, the `mustache/mustache.mjs` file has to be `import`ed directly. Below are some usage scenarios for different runtimes. #### Modern browser with ES module support ```html ``` #### [Node.js](https://nodejs.org) (>= v13.2.0 or using --experimental-modules flag) ```js // index.mjs import mustache from 'mustache/mustache.mjs' console.log(mustache.render('Hello {{name}}!', { name: 'Santa' })) // Hello Santa! ``` ES Module support for Node.js will be improved in the future when [Conditional Exports](https://nodejs.org/api/esm.html#esm_conditional_exports) is enabled by default rather than being behind an experimental flag. More info in [Node.js ECMAScript Modules docs](https://nodejs.org/api/esm.html). #### [Deno](https://deno.land/) ```js // index.ts import mustache from 'https://unpkg.com/mustache@3.2.0/mustache.mjs' console.log(mustache.render('Hello {{name}}!', { name: 'Santa' })) // Hello Santa! ``` ## [3.1.0] / 13 September 2019 ### Added * [#717]: Added support .js files as views in command line tool, by [@JEStaubach]. ### Fixed * [#716]: Bugfix for indentation of inline partials, by [@yotammadem]. ## [3.0.3] / 27 August 2019 ### Added * [#713]: Add test cases for custom functions in partials, by [@wol-soft]. ### Fixed * [#714]: Bugfix for wrong function output in partials with indentation, by [@phillipj]. ## [3.0.2] / 21 August 2019 ### Fixed * [#705]: Fix indentation of partials, by [@kevindew] and [@yotammadem]. ### Dev * [#701]: Fix test failure for Node 10 and above, by [@andersk]. * [#704]: Lint all test files just like the source files, by [@phillipj]. * Start experimenting & comparing GitHub Actions vs Travis CI, by [@phillipj]. ## [3.0.1] / 11 November 2018 * [#679]: Fix partials not rendering tokens when using custom tags, by [@stackchain]. ## [3.0.0] / 16 September 2018 We are very happy to announce a new major version of mustache.js. We want to be very careful not to break projects out in the wild, and adhering to [Semantic Versioning](http://semver.org/) we have therefore cut this new major version. The changes introduced will likely not require any actions for most using projects. The things to look out for that might cause unexpected rendering results are described in the migration guide below. A big shout out and thanks to [@raymond-lam] for this release! Without his contributions with code and issue triaging, this release would never have happened. ### Major * [#618]: Allow rendering properties of primitive types that are not objects, by [@raymond-lam]. * [#643]: `Writer.prototype.parse` to cache by tags in addition to template string, by [@raymond-lam]. * [#664]: Fix `Writer.prototype.parse` cache, by [@seminaoki]. ### Minor * [#673]: Add `tags` parameter to `Mustache.render()`, by [@raymond-lam]. ### Migrating from mustache.js v2.x to v3.x #### Rendering properties of primitive types We have ensured properties of primitive types can be rendered at all times. That means `Array.length`, `String.length` and similar. A corner case where this could cause unexpected output follows: View: ``` { stooges: [ { name: "Moe" }, { name: "Larry" }, { name: "Curly" } ] } ``` Template: ``` {{#stooges}} {{name}}: {{name.length}} characters {{/stooges}} ``` Output with v3.0: ``` Moe: 3 characters Larry: 5 characters Curly: 5 characters ``` Output with v2.x: ``` Moe: characters Larry: characters Curly: characters ``` #### Caching for templates with custom delimiters We have improved the templates cache to ensure custom delimiters are taken into consideration for the cache. This improvement might cause unexpected rendering behaviour for using projects actively using the custom delimiters functionality. Previously it was possible to use `Mustache.parse()` as a means to set global custom delimiters. If custom delimiters were provided as an argument, it would affect all following calls to `Mustache.render()`. Consider the following: ```js const template = "[[item.title]] [[item.value]]"; mustache.parse(template, ["[[", "]]"]); console.log( mustache.render(template, { item: { title: "TEST", value: 1 } }) ); >> TEST 1 ``` The above illustrates the fact that `Mustache.parse()` made mustache.js cache the template without considering the custom delimiters provided. This is no longer true. We no longer encourage using `Mustache.parse()` for this purpose, but have rather added a fourth argument to `Mustache.render()` letting you provide custom delimiters when rendering. If you still need the pre-parse the template and use custom delimiters at the same time, ensure to provide the custom delimiters as argument to `Mustache.render()` as well. ## [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]). [4.2.0]: https://github.com/janl/mustache.js/compare/v4.1.0...v4.2.0 [4.1.0]: https://github.com/janl/mustache.js/compare/v4.0.1...v4.1.0 [4.0.1]: https://github.com/janl/mustache.js/compare/v4.0.0...v4.0.1 [4.0.0]: https://github.com/janl/mustache.js/compare/v3.2.1...v4.0.0 [3.2.1]: https://github.com/janl/mustache.js/compare/v3.2.0...v3.2.1 [3.2.0]: https://github.com/janl/mustache.js/compare/v3.1.0...v3.2.0 [3.1.0]: https://github.com/janl/mustache.js/compare/v3.0.3...v3.1.0 [3.0.3]: https://github.com/janl/mustache.js/compare/v3.0.2...v3.0.3 [3.0.2]: https://github.com/janl/mustache.js/compare/v3.0.1...v3.0.2 [3.0.1]: https://github.com/janl/mustache.js/compare/v3.0.0...v3.0.1 [3.0.0]: https://github.com/janl/mustache.js/compare/v2.3.2...v3.0.0 [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 [#618]: https://github.com/janl/mustache.js/issues/618 [#673]: https://github.com/janl/mustache.js/issues/673 [#679]: https://github.com/janl/mustache.js/issues/679 [#701]: https://github.com/janl/mustache.js/issues/701 [#704]: https://github.com/janl/mustache.js/issues/704 [#705]: https://github.com/janl/mustache.js/issues/705 [#713]: https://github.com/janl/mustache.js/issues/713 [#714]: https://github.com/janl/mustache.js/issues/714 [#716]: https://github.com/janl/mustache.js/issues/716 [#717]: https://github.com/janl/mustache.js/issues/717 [#728]: https://github.com/janl/mustache.js/issues/728 [#733]: https://github.com/janl/mustache.js/issues/733 [#731]: https://github.com/janl/mustache.js/issues/731 [#735]: https://github.com/janl/mustache.js/issues/735 [#739]: https://github.com/janl/mustache.js/issues/739 [#764]: https://github.com/janl/mustache.js/issues/764 [#773]: https://github.com/janl/mustache.js/issues/773 [@afc163]: https://github.com/afc163 [@aielo]: https://github.com/aielo [@andersk]: https://github.com/andersk [@Andersos]: https://github.com/Andersos [@AndrewLeedham]: https://github.com/AndrewLeedham [@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 [@eobrain]: https://github.com/eobrain [@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 [@JEStaubach]: https://github.com/JEStaubach [@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 [@kevindew]: https://github.com/kevindew [@manzt]: https://github.com/manzt [@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 [@pineapplemachine]: https://github.com/pineapplemachine [@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 [@stackchain]: https://github.com/stackchain [@TiddoLangerak]: https://github.com/TiddoLangerak [@tomekwi]: https://github.com/tomekwi [@wizawu]: https://github.com/wizawu [@wol-soft]: https://github.com/wol-soft [@Xcrucifier]: https://github.com/Xcrucifier [@yotammadem]: https://github.com/yotammadem [@yousefcisco]: https://github.com/yousefcisco [@zekth]: https://github.com/zekth ================================================ FILE: LICENSE ================================================ The 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. ================================================ FILE: MIGRATING.md ================================================ # 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: ``` ================================================ FILE: README.md ================================================ # mustache.js - Logic-less {{mustache}} templates with JavaScript > What could be more logical awesome than no logic at all? [](https://travis-ci.org/janl/mustache.js) [mustache.js](http://github.com/janl/mustache.js) is a zero-dependency implementation of the [mustache](http://mustache.github.io/) template system in JavaScript. [Mustache](http://mustache.github.io/) 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.io/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.js](http://nodejs.org/), and [CouchDB](http://couchdb.apache.org/) views. mustache.js ships with support for the [CommonJS](http://www.commonjs.org/) module API, the [Asynchronous Module Definition](https://github.com/amdjs/amdjs-api/wiki/AMD) API (AMD) and [ECMAScript modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules). In addition to being a package to be used programmatically, you can use it as a [command line tool](#command-line-tool). And this will be your templates after you use Mustache:  ## Install You can get Mustache via [npm](http://npmjs.com). ```bash $ npm install mustache --save ``` ## Usage Below is a quick example how to use mustache.js: ```js const Mustache = require('mustache'); const view = { title: "Joe", calc: () => ( 2 + 4 ) }; const output = Mustache.render("{{title}} spends {{calc}}", view); ``` In this example, the `Mustache.render` function takes two parameters: 1) the [mustache](http://mustache.github.io/) template and 2) a `view` object that contains the data and code needed to render the template. ## Templates A [mustache](http://mustache.github.io/) 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: ```js // file: render.js function renderHello() { const template = document.getElementById('template').innerHTML; const rendered = Mustache.render(template, { name: 'Luke' }); document.getElementById('target').innerHTML = rendered; } ``` ```html
'
});
================================================
FILE: test/_files/ampersand_escape.mustache
================================================
{{&message}}
================================================
FILE: test/_files/ampersand_escape.txt
================================================
Some
================================================
FILE: test/_files/apostrophe.js
================================================
({
'apos': "'",
'control': 'X'
});
================================================
FILE: test/_files/apostrophe.mustache
================================================
{{apos}}{{control}}
================================================
FILE: test/_files/apostrophe.txt
================================================
'X
================================================
FILE: test/_files/array_of_strings.js
================================================
({
array_of_strings: ['hello', 'world']
});
================================================
FILE: test/_files/array_of_strings.mustache
================================================
{{#array_of_strings}}{{.}} {{/array_of_strings}}
================================================
FILE: test/_files/array_of_strings.txt
================================================
hello world
================================================
FILE: test/_files/avoids_obj_prototype_in_view_cache.js
================================================
({
valueOf: 'Avoids methods',
watch: 'in Object.prototype'
});
================================================
FILE: test/_files/avoids_obj_prototype_in_view_cache.mustache
================================================
{{valueOf}} {{watch}}
================================================
FILE: test/_files/avoids_obj_prototype_in_view_cache.txt
================================================
Avoids methods in Object.prototype
================================================
FILE: test/_files/backslashes.js
================================================
({
value: '\\abc'
});
================================================
FILE: test/_files/backslashes.mustache
================================================
* {{value}}
* {{{value}}}
* {{&value}}
================================================
FILE: test/_files/backslashes.txt
================================================
* \abc
* \abc
* \abc
================================================
FILE: test/_files/bug_11_eating_whitespace.js
================================================
({
tag: 'yo'
});
================================================
FILE: test/_files/bug_11_eating_whitespace.mustache
================================================
{{tag}} foo
================================================
FILE: test/_files/bug_11_eating_whitespace.txt
================================================
yo foo
================================================
FILE: test/_files/bug_length_property.js
================================================
({
length: 'hello'
});
================================================
FILE: test/_files/bug_length_property.mustache
================================================
{{#length}}The length variable is: {{length}}{{/length}}
================================================
FILE: test/_files/bug_length_property.txt
================================================
The length variable is: hello
================================================
FILE: test/_files/changing_delimiters.js
================================================
({
'foo': 'foooooooooooooo',
'bar': 'bar!'
});
================================================
FILE: test/_files/changing_delimiters.mustache
================================================
{{=<% %>=}}<% foo %> {{foo}} <%{bar}%> {{{bar}}}
================================================
FILE: test/_files/changing_delimiters.txt
================================================
foooooooooooooo {{foo}} bar! {{{bar}}}
================================================
FILE: test/_files/check_falsy.js
================================================
({
number: function (text, render) {
return function (text, render) {
return +render(text);
};
}
});
================================================
FILE: test/_files/check_falsy.mustache
================================================
{{#number}}0{{/number}}
================================================
FILE: test/_files/check_falsy.txt
================================================
0
================================================
FILE: test/_files/cli.cjs
================================================
module.exports = {
name: 'LeBron'
};
================================================
FILE: test/_files/cli.js
================================================
module.exports = {
name: 'LeBron'
};
================================================
FILE: test/_files/cli.json
================================================
{
"name": "LeBron"
}
================================================
FILE: test/_files/cli.mustache
================================================
Howdy {{name}}, CLI rox
================================================
FILE: test/_files/cli.txt
================================================
Howdy LeBron, CLI rox
================================================
FILE: test/_files/cli_js_view_with_function.js
================================================
module.exports = {
'name': 'Tater',
'bold': function () {
return function (text, render) {
return '' + render(text) + '';
};
}
};
================================================
FILE: test/_files/cli_js_view_with_function.mustache
================================================
{{#bold}}Hi {{name}}.{{/bold}}
================================================
FILE: test/_files/cli_js_view_with_function.txt
================================================
Hi Tater.
================================================
FILE: test/_files/cli_with_partials.json
================================================
{ "users": [
{
"name": "LeBron"
},
{
"name": "LeBron 2"
}
],
"comments": [
{
"title": "A Comedy of Errors"
}
]
}
================================================
FILE: test/_files/cli_with_partials.mustache
================================================
{{#users}}
{{>cli}}
{{/users}}
{{#comments}}
{{>comments}}
{{/comments}}
================================================
FILE: test/_files/cli_with_partials.txt
================================================
Howdy LeBron, CLI roxHowdy LeBron 2, CLI rox
A Comedy of Errors
================================================
FILE: test/_files/comments.js
================================================
({
title: function () {
return 'A Comedy of Errors';
}
});
================================================
FILE: test/_files/comments.mustache
================================================
{{title}}{{! just something interesting... or not... }}
================================================
FILE: test/_files/comments.txt
================================================
A Comedy of Errors
================================================
FILE: test/_files/complex.js
================================================
({
header: function () {
return 'Colors';
},
item: [
{name: 'red', current: true, url: '#Red'},
{name: 'green', current: false, url: '#Green'},
{name: 'blue', current: false, url: '#Blue'}
],
link: function () {
return this['current'] !== true;
},
list: function () {
return this.item.length !== 0;
},
empty: function () {
return this.item.length === 0;
}
});
================================================
FILE: test/_files/complex.mustache
================================================
{{header}}
{{#list}}
{{#item}}
{{#current}}
- {{name}}
{{/current}}
{{#link}}
- {{name}}
{{/link}}
{{/item}}
{{/list}}
{{#empty}}
The list is empty.
{{/empty}}
================================================
FILE: test/_files/complex.txt
================================================
Colors
================================================
FILE: test/_files/context_lookup.js
================================================
({
'outer': {
'id': 1,
'second': {
'nothing': 2
}
}
});
================================================
FILE: test/_files/context_lookup.mustache
================================================
{{#outer}}{{#second}}{{id}}{{/second}}{{/outer}}
================================================
FILE: test/_files/context_lookup.txt
================================================
1
================================================
FILE: test/_files/delimiters.js
================================================
({
first: 'It worked the first time.',
second: 'And it worked the second time.',
third: 'Then, surprisingly, it worked the third time.',
fourth: 'Fourth time also fine!.'
});
================================================
FILE: test/_files/delimiters.mustache
================================================
{{=<% %>=}}*
<% first %>
* <% second %>
<%=| |=%>
* | third |
|={{ }}=|
* {{ fourth }}
================================================
FILE: test/_files/delimiters.txt
================================================
*
It worked the first time.
* And it worked the second time.
* Then, surprisingly, it worked the third time.
* Fourth time also fine!.
================================================
FILE: test/_files/disappearing_whitespace.js
================================================
({
bedrooms: true,
total: 1
});
================================================
FILE: test/_files/disappearing_whitespace.mustache
================================================
{{#bedrooms}}{{total}}{{/bedrooms}} BED
================================================
FILE: test/_files/disappearing_whitespace.txt
================================================
1 BED
================================================
FILE: test/_files/dot_notation.js
================================================
({
name: 'A Book',
authors: ['John Power', 'Jamie Walsh'],
price: {
value: 200,
vat: function () {
return this.value * 0.2;
},
currency: {
symbol: '$',
name: 'USD'
}
},
availability: {
status: true,
text: 'In Stock'
},
// And now, some truthy false values
truthy: {
zero: 0,
notTrue: false
},
singletonList: [{singletonItem: 'singleton item'}]
});
================================================
FILE: test/_files/dot_notation.mustache
================================================
{{name}}
Authors:
{{#authors}}- {{.}}
{{/authors}}
Price: {{{price.currency.symbol}}}{{price.value}} {{#price.currency}}{{name}} {{availability.text}}{{/price.currency}}
VAT: {{{price.currency.symbol}}}{{#price}}{{vat}}{{/price}}
Test truthy false values:
Zero: {{truthy.zero}}
False: {{truthy.notTrue}}
length of string should be rendered: {{price.currency.name.length}}
length of string in a list should be rendered: {{#singletonList}}{{singletonItem.length}}{{/singletonList}}
length of an array should be rendered: {{authors.length}}
================================================
FILE: test/_files/dot_notation.txt
================================================
A Book
Authors:
- John Power
- Jamie Walsh
Price: $200 USD In Stock
VAT: $40
Test truthy false values:
Zero: 0
False: false
length of string should be rendered: 3
length of string in a list should be rendered: 14
length of an array should be rendered: 2
================================================
FILE: test/_files/double_render.js
================================================
({
foo: true,
bar: '{{win}}',
win: 'FAIL'
});
================================================
FILE: test/_files/double_render.mustache
================================================
{{#foo}}{{bar}}{{/foo}}
================================================
FILE: test/_files/double_render.txt
================================================
{{win}}
================================================
FILE: test/_files/empty_list.js
================================================
({
jobs: []
});
================================================
FILE: test/_files/empty_list.mustache
================================================
These are the jobs:
{{#jobs}}
{{.}}
{{/jobs}}
================================================
FILE: test/_files/empty_list.txt
================================================
These are the jobs:
================================================
FILE: test/_files/empty_sections.js
================================================
({});
================================================
FILE: test/_files/empty_sections.mustache
================================================
{{#foo}}{{/foo}}foo{{#bar}}{{/bar}}
================================================
FILE: test/_files/empty_sections.txt
================================================
foo
================================================
FILE: test/_files/empty_string.js
================================================
({
description: 'That is all!',
child: {
description: ''
}
});
================================================
FILE: test/_files/empty_string.mustache
================================================
{{description}}{{#child}}{{description}}{{/child}}
================================================
FILE: test/_files/empty_string.txt
================================================
That is all!
================================================
FILE: test/_files/empty_template.js
================================================
({});
================================================
FILE: test/_files/empty_template.mustache
================================================
Test
================================================
FILE: test/_files/empty_template.txt
================================================
Test
================================================
FILE: test/_files/error_not_found.js
================================================
({
bar: 2
});
================================================
FILE: test/_files/error_not_found.mustache
================================================
{{foo}}
================================================
FILE: test/_files/error_not_found.txt
================================================
================================================
FILE: test/_files/escaped.js
================================================
({
title: function () {
return 'Bear > Shark';
},
symbol: null,
entities: "" \"'<>`=/"
});
================================================
FILE: test/_files/escaped.mustache
================================================
{{title}}{{symbol}}
And even {{entities}}, but not {{{entities}}}.
================================================
FILE: test/_files/escaped.txt
================================================
Bear > Shark
And even " "'<>`=/, but not " "'<>`=/.
================================================
FILE: test/_files/falsy.js
================================================
({
'emptyString': '',
'emptyArray': [],
'zero': 0,
'null': null,
'undefined': undefined,
'NaN': 0/0
});
================================================
FILE: test/_files/falsy.mustache
================================================
{{#emptyString}}empty string{{/emptyString}}
{{^emptyString}}inverted empty string{{/emptyString}}
{{#emptyArray}}empty array{{/emptyArray}}
{{^emptyArray}}inverted empty array{{/emptyArray}}
{{#zero}}zero{{/zero}}
{{^zero}}inverted zero{{/zero}}
{{#null}}null{{/null}}
{{^null}}inverted null{{/null}}
{{#undefined}}undefined{{/undefined}}
{{^undefined}}inverted undefined{{/undefined}}
{{#NaN}}NaN{{/NaN}}
{{^NaN}}inverted NaN{{/NaN}}
================================================
FILE: test/_files/falsy.txt
================================================
inverted empty string
inverted empty array
inverted zero
inverted null
inverted undefined
inverted NaN
================================================
FILE: test/_files/falsy_array.js
================================================
({
'list': [
['', 'emptyString'],
[[], 'emptyArray'],
[0, 'zero'],
[null, 'null'],
[undefined, 'undefined'],
[0/0, 'NaN']
]
});
================================================
FILE: test/_files/falsy_array.mustache
================================================
{{#list}}
{{#.}}{{#.}}{{.}}{{/.}}{{^.}}inverted {{/.}}{{/.}}
{{/list}}
================================================
FILE: test/_files/falsy_array.txt
================================================
inverted emptyString
inverted emptyArray
inverted zero
inverted null
inverted undefined
inverted NaN
================================================
FILE: test/_files/grandparent_context.js
================================================
({
grand_parent_id: 'grand_parent1',
parent_contexts: [
{
parent_id: 'parent1',
child_contexts: [
{ child_id: 'parent1-child1' },
{ child_id: 'parent1-child2' }
]
},
{
parent_id: 'parent2',
child_contexts: [
{ child_id: 'parent2-child1' },
{ child_id: 'parent2-child2' }
]
}
]
});
================================================
FILE: test/_files/grandparent_context.mustache
================================================
{{grand_parent_id}}
{{#parent_contexts}}
{{grand_parent_id}}
{{parent_id}}
{{#child_contexts}}
{{grand_parent_id}}
{{parent_id}}
{{child_id}}
{{/child_contexts}}
{{/parent_contexts}}
================================================
FILE: test/_files/grandparent_context.txt
================================================
grand_parent1
grand_parent1
parent1
grand_parent1
parent1
parent1-child1
grand_parent1
parent1
parent1-child2
grand_parent1
parent2
grand_parent1
parent2
parent2-child1
grand_parent1
parent2
parent2-child2
================================================
FILE: test/_files/higher_order_sections.js
================================================
({
name: 'Tater',
helper: 'To tinker?',
bolder: function () {
return function (text, render) {
return text + ' => ' + render(text) + ' ' + this.helper;
};
}
});
================================================
FILE: test/_files/higher_order_sections.mustache
================================================
{{#bolder}}Hi {{name}}.{{/bolder}}
================================================
FILE: test/_files/higher_order_sections.txt
================================================
Hi {{name}}. => Hi Tater. To tinker?
================================================
FILE: test/_files/implicit_iterator.js
================================================
({
data: {
author: {
twitter_id: 819606,
name: 'janl'
}
}
});
================================================
FILE: test/_files/implicit_iterator.mustache
================================================
{{# data.author.twitter_id }}
{{/ data.author.twitter_id }}
{{# data.author.name }}
{{/ data.author.name }}
================================================
FILE: test/_files/implicit_iterator.txt
================================================
================================================
FILE: test/_files/included_tag.js
================================================
({
html: 'I like {{mustache}}'
});
================================================
FILE: test/_files/included_tag.mustache
================================================
You said "{{{html}}}" today
================================================
FILE: test/_files/included_tag.txt
================================================
You said "I like {{mustache}}" today
================================================
FILE: test/_files/inverted_section.js
================================================
({
'repos': []
});
================================================
FILE: test/_files/inverted_section.mustache
================================================
{{#repos}}{{name}}{{/repos}}
{{^repos}}No repos :({{/repos}}
{{^nothin}}Hello!{{/nothin}}
================================================
FILE: test/_files/inverted_section.txt
================================================
No repos :(
Hello!
================================================
FILE: test/_files/keys_with_questionmarks.js
================================================
({
'person?': {
name: 'Jon'
}
});
================================================
FILE: test/_files/keys_with_questionmarks.mustache
================================================
{{#person?}}
Hi {{name}}!
{{/person?}}
================================================
FILE: test/_files/keys_with_questionmarks.txt
================================================
Hi Jon!
================================================
FILE: test/_files/malicious_template.js
================================================
({});
================================================
FILE: test/_files/malicious_template.mustache
================================================
{{"+(function () {throw "evil"})()+"}}
{{{"+(function () {throw "evil"})()+"}}}
{{> "+(function () {throw "evil"})()+"}}
{{# "+(function () {throw "evil"})()+"}}
{{/ "+(function () {throw "evil"})()+"}}
================================================
FILE: test/_files/malicious_template.txt
================================================
================================================
FILE: test/_files/multiline_comment.js
================================================
({});
================================================
FILE: test/_files/multiline_comment.mustache
================================================
{{!
This is a multi-line comment.
}}
Hello world!
================================================
FILE: test/_files/multiline_comment.txt
================================================
Hello world!
================================================
FILE: test/_files/nested_dot.js
================================================
({ name: 'Bruno' });
================================================
FILE: test/_files/nested_dot.mustache
================================================
{{#name}}Hello {{.}}{{/name}}
================================================
FILE: test/_files/nested_dot.txt
================================================
Hello Bruno
================================================
FILE: test/_files/nested_higher_order_sections.js
================================================
({
bold: function () {
return function (text, render) {
return '' + render(text) + '';
};
},
person: { name: 'Jonas' }
});
================================================
FILE: test/_files/nested_higher_order_sections.mustache
================================================
{{#bold}}{{#person}}My name is {{name}}!{{/person}}{{/bold}}
================================================
FILE: test/_files/nested_higher_order_sections.txt
================================================
My name is Jonas!
================================================
FILE: test/_files/nested_iterating.js
================================================
({
inner: [{
foo: 'foo',
inner: [{
bar: 'bar'
}]
}]
});
================================================
FILE: test/_files/nested_iterating.mustache
================================================
{{#inner}}{{foo}}{{#inner}}{{bar}}{{/inner}}{{/inner}}
================================================
FILE: test/_files/nested_iterating.txt
================================================
foobar
================================================
FILE: test/_files/nesting.js
================================================
({
foo: [
{a: {b: 1}},
{a: {b: 2}},
{a: {b: 3}}
]
});
================================================
FILE: test/_files/nesting.mustache
================================================
{{#foo}}
{{#a}}
{{b}}
{{/a}}
{{/foo}}
================================================
FILE: test/_files/nesting.txt
================================================
1
2
3
================================================
FILE: test/_files/nesting_same_name.js
================================================
({
items: [
{
name: 'name',
items: [1, 2, 3, 4]
}
]
});
================================================
FILE: test/_files/nesting_same_name.mustache
================================================
{{#items}}{{name}}{{#items}}{{.}}{{/items}}{{/items}}
================================================
FILE: test/_files/nesting_same_name.txt
================================================
name1234
================================================
FILE: test/_files/null_lookup_array.js
================================================
({
'name': 'David',
'twitter': '@dasilvacontin',
'farray': [
['Flor', '@florrts'],
['Miquel', null],
['Chris', undefined]
]
});
================================================
FILE: test/_files/null_lookup_array.mustache
================================================
{{#farray}}
{{#.}}{{#.}}{{.}} {{/.}}{{^.}}no twitter{{/.}}{{/.}}
{{/farray}}
================================================
FILE: test/_files/null_lookup_array.txt
================================================
Flor @florrts
Miquel no twitter
Chris no twitter
================================================
FILE: test/_files/null_lookup_object.js
================================================
({
'name': 'David',
'twitter': '@dasilvacontin',
'fobject': [
{
'name': 'Flor',
'twitter': '@florrts'
},
{
'name': 'Miquel',
'twitter': null
},
{
'name': 'Chris',
'twitter': undefined
}
],
'favorites': {
'color': 'blue',
'president': 'Bush',
'show': 'Futurama'
},
'mascot': {
'name': 'Squid',
'favorites': {
'color': 'orange',
'president': undefined,
'show': null
}
}
});
================================================
FILE: test/_files/null_lookup_object.mustache
================================================
{{#fobject}}
{{name}}'s twitter: {{#twitter}}{{.}}{{/twitter}}{{^twitter}}unknown{{/twitter}}.
{{/fobject}}
{{#mascot}}
{{name}}'s favorite color: {{#favorites.color}}{{.}}{{/favorites.color}}{{^favorites.color}}no one{{/favorites.color}}.
{{name}}'s favorite president: {{#favorites.president}}{{.}}{{/favorites.president}}{{^favorites.president}}no one{{/favorites.president}}.
{{name}}'s favorite show: {{#favorites.show}}{{.}}{{/favorites.show}}{{^favorites.show}}none{{/favorites.show}}.
{{/mascot}}
================================================
FILE: test/_files/null_lookup_object.txt
================================================
Flor's twitter: @florrts.
Miquel's twitter: unknown.
Chris's twitter: unknown.
Squid's favorite color: orange.
Squid's favorite president: no one.
Squid's favorite show: none.
================================================
FILE: test/_files/null_string.js
================================================
({
name: 'Elise',
glytch: true,
binary: false,
value: null,
undef: undefined,
numeric: function () {
return NaN;
}
});
================================================
FILE: test/_files/null_string.mustache
================================================
Hello {{name}}
glytch {{glytch}}
binary {{binary}}
value {{value}}
undef {{undef}}
numeric {{numeric}}
================================================
FILE: test/_files/null_string.txt
================================================
Hello Elise
glytch true
binary false
value
undef
numeric NaN
================================================
FILE: test/_files/null_view.js
================================================
({
name: 'Joe',
friends: null
});
================================================
FILE: test/_files/null_view.mustache
================================================
{{name}}'s friends: {{#friends}}{{name}}, {{/friends}}
================================================
FILE: test/_files/null_view.txt
================================================
Joe's friends:
================================================
FILE: test/_files/partial_array.js
================================================
({
array: ['1', '2', '3', '4']
});
================================================
FILE: test/_files/partial_array.mustache
================================================
{{>partial}}
================================================
FILE: test/_files/partial_array.partial
================================================
Here's a non-sense array of values
{{#array}}
{{.}}
{{/array}}
================================================
FILE: test/_files/partial_array.txt
================================================
Here's a non-sense array of values
1
2
3
4
================================================
FILE: test/_files/partial_array_of_partials.js
================================================
({
numbers: [
{i: '1'},
{i: '2'},
{i: '3'},
{i: '4'}
]
});
================================================
FILE: test/_files/partial_array_of_partials.mustache
================================================
Here is some stuff!
{{#numbers}}
{{>partial}}
{{/numbers}}
================================================
FILE: test/_files/partial_array_of_partials.partial
================================================
{{i}}
================================================
FILE: test/_files/partial_array_of_partials.txt
================================================
Here is some stuff!
1
2
3
4
================================================
FILE: test/_files/partial_array_of_partials_implicit.js
================================================
({
numbers: ['1', '2', '3', '4']
});
================================================
FILE: test/_files/partial_array_of_partials_implicit.mustache
================================================
Here is some stuff!
{{#numbers}}
{{>partial}}
{{/numbers}}
================================================
FILE: test/_files/partial_array_of_partials_implicit.partial
================================================
{{.}}
================================================
FILE: test/_files/partial_array_of_partials_implicit.txt
================================================
Here is some stuff!
1
2
3
4
================================================
FILE: test/_files/partial_empty.js
================================================
({
foo: 1
});
================================================
FILE: test/_files/partial_empty.mustache
================================================
hey {{foo}}
{{>partial}}
================================================
FILE: test/_files/partial_empty.partial
================================================
================================================
FILE: test/_files/partial_empty.txt
================================================
hey 1
================================================
FILE: test/_files/partial_template.js
================================================
({
title: function () {
return 'Welcome';
},
again: 'Goodbye'
});
================================================
FILE: test/_files/partial_template.mustache
================================================
{{title}}
{{>partial}}
================================================
FILE: test/_files/partial_template.partial
================================================
Again, {{again}}!
================================================
FILE: test/_files/partial_template.txt
================================================
Welcome
Again, Goodbye!
================================================
FILE: test/_files/partial_view.js
================================================
({
greeting: function () {
return 'Welcome';
},
farewell: function () {
return 'Fair enough, right?';
},
name: 'Chris',
value: 10000,
taxed_value: function () {
return this.value - (this.value * 0.4);
},
in_ca: true
});
================================================
FILE: test/_files/partial_view.mustache
================================================
{{greeting}}
{{>partial}}
{{farewell}}
================================================
FILE: test/_files/partial_view.partial
================================================
Hello {{name}}
You have just won ${{value}}!
{{#in_ca}}
Well, ${{ taxed_value }}, after taxes.
{{/in_ca}}
================================================
FILE: test/_files/partial_view.txt
================================================
Welcome
Hello Chris
You have just won $10000!
Well, $6000, after taxes.
Fair enough, right?
================================================
FILE: test/_files/partial_whitespace.js
================================================
({
greeting: function () {
return 'Welcome';
},
farewell: function () {
return 'Fair enough, right?';
},
name: 'Chris',
value: 10000,
taxed_value: function () {
return this.value - (this.value * 0.4);
},
in_ca: true
});
================================================
FILE: test/_files/partial_whitespace.mustache
================================================
{{ greeting }}
{{> partial }}
{{ farewell }}
================================================
FILE: test/_files/partial_whitespace.partial
================================================
Hello {{ name}}
You have just won ${{value }}!
{{# in_ca }}
Well, ${{ taxed_value }}, after taxes.
{{/ in_ca }}
================================================
FILE: test/_files/partial_whitespace.txt
================================================
Welcome
Hello Chris
You have just won $10000!
Well, $6000, after taxes.
Fair enough, right?
================================================
FILE: test/_files/recursion_with_same_names.js
================================================
({
name: 'name',
description: 'desc',
terms: [
{name: 't1', index: 0},
{name: 't2', index: 1}
]
});
================================================
FILE: test/_files/recursion_with_same_names.mustache
================================================
{{ name }}
{{ description }}
{{#terms}}
{{name}}
{{index}}
{{/terms}}
================================================
FILE: test/_files/recursion_with_same_names.txt
================================================
name
desc
t1
0
t2
1
================================================
FILE: test/_files/reuse_of_enumerables.js
================================================
({
terms: [
{name: 't1', index: 0},
{name: 't2', index: 1}
]
});
================================================
FILE: test/_files/reuse_of_enumerables.mustache
================================================
{{#terms}}
{{name}}
{{index}}
{{/terms}}
{{#terms}}
{{name}}
{{index}}
{{/terms}}
================================================
FILE: test/_files/reuse_of_enumerables.txt
================================================
t1
0
t2
1
t1
0
t2
1
================================================
FILE: test/_files/section_as_context.js
================================================
({
a_object: {
title: 'this is an object',
description: 'one of its attributes is a list',
a_list: [
{label: 'listitem1'},
{label: 'listitem2'}
]
}
});
================================================
FILE: test/_files/section_as_context.mustache
================================================
{{#a_object}}
{{title}}
{{description}}
{{#a_list}}
- {{label}}
{{/a_list}}
{{/a_object}}
================================================
FILE: test/_files/section_as_context.txt
================================================
this is an object
one of its attributes is a list
- listitem1
- listitem2
================================================
FILE: test/_files/section_functions_in_partials.js
================================================
({
bold: function (){
return function (text, render) {
return '' + render(text) + '';
};
}
});
================================================
FILE: test/_files/section_functions_in_partials.mustache
================================================
{{> partial}}
some more text
================================================
FILE: test/_files/section_functions_in_partials.partial
================================================
{{#bold}}Hello There{{/bold}}
================================================
FILE: test/_files/section_functions_in_partials.txt
================================================
Hello There
some more text
================================================
FILE: test/_files/simple.js
================================================
({
name: 'Chris',
value: 10000,
taxed_value: function () {
return this.value - (this.value * 0.4);
},
in_ca: true
});
================================================
FILE: test/_files/simple.mustache
================================================
Hello {{name}}
You have just won ${{value}}!
{{#in_ca}}
Well, ${{ taxed_value }}, after taxes.
{{/in_ca}}
================================================
FILE: test/_files/simple.txt
================================================
Hello Chris
You have just won $10000!
Well, $6000, after taxes.
================================================
FILE: test/_files/string_as_context.js
================================================
({
a_string: 'aa',
a_list: ['a','b','c']
});
================================================
FILE: test/_files/string_as_context.mustache
================================================
{{#a_list}}
- {{a_string}}/{{.}}
{{/a_list}}
================================================
FILE: test/_files/string_as_context.txt
================================================
- aa/a
- aa/b
- aa/c
================================================
FILE: test/_files/two_in_a_row.js
================================================
({
name: 'Joe',
greeting: 'Welcome'
});
================================================
FILE: test/_files/two_in_a_row.mustache
================================================
{{greeting}}, {{name}}!
================================================
FILE: test/_files/two_in_a_row.txt
================================================
Welcome, Joe!
================================================
FILE: test/_files/two_sections.js
================================================
({});
================================================
FILE: test/_files/two_sections.mustache
================================================
{{#foo}}
{{/foo}}
{{#bar}}
{{/bar}}
================================================
FILE: test/_files/two_sections.txt
================================================
================================================
FILE: test/_files/unescaped.js
================================================
({
title: function () {
return 'Bear > Shark';
},
symbol: null
});
================================================
FILE: test/_files/unescaped.mustache
================================================
{{{title}}}{{{symbol}}}
================================================
FILE: test/_files/unescaped.txt
================================================
Bear > Shark
================================================
FILE: test/_files/uses_props_from_view_prototype.js
================================================
var Aaa = (function () {
function Aaa (x, y) {
this.x = x;
this._y = y;
}
Object.defineProperty(Aaa.prototype, 'y', {
get: function () {
return this._y;
},
set: function (value) {
this._y = value;
},
enumerable: true,
configurable: true
});
return Aaa;
})();
var Bbb = (function () {
function Bbb () {
}
return Bbb;
})();
var b = new Bbb();
b.item = new Aaa('0', '00');
b.items = [];
b.items.push({ a: new Aaa('1', '2') });
b.items.push({ a: new Aaa('3', '4') });
(b);
================================================
FILE: test/_files/uses_props_from_view_prototype.mustache
================================================
[{{ item.x }};{{ item.y }}]||{{#items}}[{{ a.x }};{{ a.y }} {{#a}}{{y}}{{/a}}]{{/items}}
================================================
FILE: test/_files/uses_props_from_view_prototype.txt
================================================
[0;00]||[1;2 2][3;4 4]
================================================
FILE: test/_files/whitespace.js
================================================
({
tag1: 'Hello',
tag2: 'World'
});
================================================
FILE: test/_files/whitespace.mustache
================================================
{{tag1}}
{{tag2}}.
================================================
FILE: test/_files/whitespace.txt
================================================
Hello
World.
================================================
FILE: test/_files/zero_view.js
================================================
({ nums: [0, 1, 2] });
================================================
FILE: test/_files/zero_view.mustache
================================================
{{#nums}}{{.}},{{/nums}}
================================================
FILE: test/_files/zero_view.txt
================================================
0,1,2,
================================================
FILE: test/cli-test.js
================================================
require('./helper');
var fs = require('fs');
var path = require('path');
var child_process = require('child_process');
var _files = path.join(__dirname, '_files');
var cliTxt = path.resolve(_files, 'cli.txt');
var cliPartialsTxt = path.resolve(_files, 'cli_with_partials.txt');
var moduleVersion = require('../package').version;
function changeForOS (command) {
var requireFlag = !isLegacyNodeVersion ? '--require esm' : '';
command = command.replace('bin/mustache', 'node ' + requireFlag + ' bin/mustache');
if (process.platform === 'win32') {
return command
.replace(/\bcat\b/g, 'type')
.replace(/\//g, '\\');
}
return command;
}
function exec () {
arguments[0] = changeForOS(arguments[0]);
return child_process.exec.apply(child_process, arguments);
}
describe('Mustache CLI', function () {
var expectedOutput;
it('writes syntax hints into stderr when runned with wrong number of arguments', function (done) {
exec('bin/mustache', function (err, stdout, stderr) {
assert.notEqual(stderr.indexOf('Syntax'), -1);
done();
});
});
it('writes hints about JSON parsing errors when given invalid JSON', function (done) {
exec('echo {name:"lebron"} | bin/mustache - test/_files/cli.mustache', function (err, stdout, stderr) {
assert.notEqual(stderr.indexOf('Shooot, could not parse view as JSON'), -1);
done();
});
});
it('writes module version into stdout when runned with --version', function (done){
exec('bin/mustache --version', function (err, stdout, stderr) {
assert.notEqual(stdout.indexOf(moduleVersion), -1);
done();
});
});
it('writes module version into stdout when runned with -v', function (done){
exec('bin/mustache -v', function (err, stdout, stderr) {
assert.notEqual(stdout.indexOf(moduleVersion), -1);
done();
});
});
describe('without partials', function (){
before(function (done) {
fs.readFile(cliTxt, function onFsEnd (err, data) {
if (err) return done(err);
expectedOutput = data.toString();
done();
});
});
it('writes rendered template into stdout when successfull', function (done) {
exec('bin/mustache test/_files/cli.json test/_files/cli.mustache', function (err, stdout, stderr) {
assert.equal(err, null);
assert.equal(stderr, '');
assert.equal(stdout, expectedOutput);
done();
});
});
it('can handle view written in JavaScript with .js suffix', function (done) {
exec('bin/mustache test/_files/cli.js test/_files/cli.mustache', function (err, stdout, stderr) {
assert.equal(err, null);
assert.equal(stderr, '');
assert.equal(stdout, expectedOutput);
done();
});
});
it('can handle view written in JavaScript with .cjs suffix', function (done) {
exec('bin/mustache test/_files/cli.cjs test/_files/cli.mustache', function (err, stdout, stderr) {
assert.equal(err, null);
assert.equal(stderr, '');
assert.equal(stdout, expectedOutput);
done();
});
});
it('writes rendered template into the file specified by the third argument', function (done) {
var outputFile = 'test/_files/cli_output.txt';
exec('bin/mustache test/_files/cli.json test/_files/cli.mustache ' + outputFile, function (err, stdout, stderr) {
assert.equal(err, null);
assert.equal(stderr, '');
assert.equal(stdout, '');
assert.equal(fs.readFileSync(outputFile), expectedOutput);
fs.unlinkSync('test/_files/cli_output.txt');
done();
});
});
it('reads view data from stdin when first argument equals "-"', function (done){
exec('cat test/_files/cli.json | bin/mustache - test/_files/cli.mustache', function (err, stdout, stderr) {
assert.equal(err, null);
assert.equal(stderr, '');
assert.equal(stdout, expectedOutput);
done();
});
});
it('writes it couldnt find template into stderr when second argument doesnt resolve to a file', function (done) {
exec('bin/mustache test/_files/cli.json test/_files/non-existing-template.mustache', function (err, stdout, stderr) {
assert.isOk(/Could not find file: .+non-existing-template\.mustache/.test(stderr));
done();
});
});
it('writes it couldnt find view into stderr when first argument doesnt resolve to a file', function (done) {
exec('bin/mustache test/_files/non-existing-view.json test/_files/cli.mustache', function (err, stdout, stderr) {
assert.isOk(/Could not find file: .+non-existing-view\.json/.test(stderr));
done();
});
});
});
describe('with partials', function (){
before(function (done) {
fs.readFile(cliPartialsTxt, function onFsEnd (err, data) {
if (err) return done(err);
expectedOutput = data.toString();
done();
});
});
it('writes rendered template with partials into stdout', function (done) {
exec('bin/mustache test/_files/cli_with_partials.json test/_files/cli_with_partials.mustache -p test/_files/cli.mustache -p test/_files/comments.mustache', function (err, stdout, stderr) {
assert.equal(err, null);
assert.equal(stderr, '');
assert.equal(stdout, expectedOutput);
done();
});
});
it('writes rendered template with partials when partials args before required args', function (done) {
exec('bin/mustache -p test/_files/cli.mustache -p test/_files/comments.mustache test/_files/cli_with_partials.json test/_files/cli_with_partials.mustache', function (err, stdout, stderr) {
assert.equal(err, null);
assert.equal(stderr, '');
assert.equal(stdout, expectedOutput);
done();
});
});
});
});
================================================
FILE: test/context-test.js
================================================
require('./helper');
var Context = Mustache.Context;
describe('A new Mustache.Context', function () {
var context;
beforeEach(function () {
context = new Context({ name: 'parent', message: 'hi', a: { b: 'b' } });
});
it('is able to lookup properties of its own view', function () {
assert.equal(context.lookup('name'), 'parent');
});
it('is able to lookup nested properties of its own view', function () {
assert.equal(context.lookup('a.b'), 'b');
});
describe('when pushed', function () {
beforeEach(function () {
context = context.push({ name: 'child', c: { d: 'd' } });
});
it('returns the child context', function () {
assert.equal(context.view.name, 'child');
assert.equal(context.parent.view.name, 'parent');
});
it('is able to lookup properties of its own view', function () {
assert.equal(context.lookup('name'), 'child');
});
it("is able to lookup properties of the parent context's view", function () {
assert.equal(context.lookup('message'), 'hi');
});
it('is able to lookup nested properties of its own view', function () {
assert.equal(context.lookup('c.d'), 'd');
});
it('is able to lookup nested properties of its parent view', function () {
assert.equal(context.lookup('a.b'), 'b');
});
});
});
describe('A Mustache.Context', function () {
var context;
describe('with an empty string in the lookup chain', function () {
var view, context;
beforeEach(function () {
view = { a: '' };
view.a.b = 'value';
context = new Context(view);
});
it('is able to lookup a nested property', function () {
assert.equal(context.lookup('a.b'), view.a.b);
});
});
});
================================================
FILE: test/create-browser-suite.js
================================================
require('./helper');
var renderHelper = require('./render-helper');
var fs = require('fs');
var path = require('path');
var _testsTemplate = path.join(__dirname, 'render-test-browser-tmpl.mustache');
var _templateContent = fs.readFileSync(_testsTemplate).toString();
var tests = renderHelper.getTests();
var content = Mustache.render(_templateContent, JSON.stringify(tests));
fs.writeFileSync(path.join(__dirname, 'render-test-browser.js'), content);
================================================
FILE: test/helper.js
================================================
var chai = require('chai');
var isRunningInNode = process !== undefined && process.versions.node !== undefined;
if (isRunningInNode) {
var nodejsMajorVersion = Number(process.versions.node.split('.')[0]);
isLegacyNodeVersion = !(nodejsMajorVersion >= 10);
if (!isLegacyNodeVersion) {
// The `zuul` package we use to run tests in browsers via Saucelabs eagerly loads all
// packages it sees being used via `require()`. Because we don't want the `esm` package
// to be loaded when running browser tests, we refer to `require()` via `module.require()`
// because that avoid the mentioned eager loading
module.require = module.require('esm')(module);
}
}
assert = chai.assert;
chai.should();
Mustache = require('../mustache');
================================================
FILE: test/module-systems/.eslintrc
================================================
{
"extends": "../.eslintrc",
"parserOptions": {
"ecmaVersion": 2017
}
}
================================================
FILE: test/module-systems/_fixtures/amd.html
================================================
Text content to be overwritten
================================================
FILE: test/module-systems/_fixtures/global-scope.html
================================================
Text content to be overwritten
================================================
FILE: test/module-systems/browser-test.js
================================================
const fs = require('fs');
const path = require('path');
const puppeteer = require('puppeteer');
const chai = require('chai');
const mustache = fs.readFileSync(path.join(__dirname, '../../mustache.js'), 'utf8');
describe('Browser usage', () => {
let browser;
let page;
before(async function () {
this.timeout(10 * 1000);
// Awkward .launch() options below are needed to avoid hitting timeouts
// when tests are run in GitHub Actions for some weird reason
// https://github.com/GoogleChrome/puppeteer/issues/4617
browser = await puppeteer.launch({ignoreDefaultArgs: ['--disable-extensions']});
page = await browser.newPage();
page.on('console', msg => console.log('PAGE LOG:', msg.text()));
page.on('pageerror', err => console.error('PAGE ERROR:', err));
});
after(() => browser.close());
it('is exposed on the global scope as window.Mustache', async () => {
await page.goto(`file://${path.join(__dirname, '_fixtures/global-scope.html')}`);
const bodyElement = await page.$('body');
const textContentProperty = await bodyElement.getProperty('textContent');
const value = await textContentProperty.jsonValue();
chai.assert.equal(value.trim(), 'Joe spends 6');
});
it('is exposed as AMD and consumable via RequireJS', async function () {
this.timeout(10 * 1000);
await page.goto(`file://${path.join(__dirname, '_fixtures/amd.html')}`, { waitUntil: 'networkidle0' });
const bodyElement = await page.$('body');
const textContentProperty = await bodyElement.getProperty('textContent');
const value = await textContentProperty.jsonValue();
chai.assert.equal(value, 'Joe spends 6');
});
});
================================================
FILE: test/module-systems/commonjs-test.js
================================================
const assert = require('assert');
const mustache = require('mustache');
const view = {
title: 'Joe',
calc: () => 2 + 4
};
assert.strictEqual(
mustache.render('{{title}} spends {{calc}}', view),
'Joe spends 6'
);
================================================
FILE: test/module-systems/deno-test.ts
================================================
import { assertEquals } from "https://deno.land/std@0.51.0/testing/asserts.ts";
import mustache from "../../mustache.mjs";
const view = {
title: "Joe",
calc: function() {
return 2 + 4;
}
};
Deno.test("can use mustache", () => {
assertEquals(
mustache.render("{{title}} spends {{calc}}", view),
"Joe spends 6"
);
});
================================================
FILE: test/module-systems/esm-test-exports.mjs
================================================
import assert from 'assert';
import mustache from 'mustache';
const view = {
title: 'Joe',
calc: () => 2 + 4
};
assert.strictEqual(
mustache.render('{{title}} spends {{calc}}', view),
'Joe spends 6'
);
================================================
FILE: test/module-systems/esm-test.mjs
================================================
import assert from 'assert';
import mustache from 'mustache/mustache.mjs';
const view = {
title: 'Joe',
calc: () => 2 + 4
};
assert.strictEqual(
mustache.render('{{title}} spends {{calc}}', view),
'Joe spends 6'
);
================================================
FILE: test/mustache-spec-test.js
================================================
require('./helper');
var fs = require('fs');
var path = require('path');
var specsDir = path.join(__dirname, 'spec/specs');
var skipTests = {
comments: [
'Standalone Without Newline'
],
delimiters: [
'Standalone Without Newline'
],
inverted: [
'Standalone Without Newline'
],
partials: [
'Standalone Without Previous Line',
'Standalone Without Newline'
],
sections: [
'Standalone Without Newline'
],
'~lambdas': [
'Interpolation',
'Interpolation - Expansion',
'Interpolation - Alternate Delimiters',
'Interpolation - Multiple Calls',
'Escaping',
'Section - Expansion',
'Section - Alternate Delimiters'
]
};
// You can run the skipped tests by setting the NOSKIP environment variable to
// true (e.g. NOSKIP=true mocha test/mustache-spec-test.js)
var noSkip = process.env.NOSKIP;
// You can put the name of a specific test file to run in the TEST environment
// variable (e.g. TEST=interpolation mocha test/mustache-spec-test.js)
var fileToRun = process.env.TEST;
// Mustache should work on node 0.6 that doesn't have fs.existsSync
function existsDir (path) {
try {
return fs.statSync(path).isDirectory();
} catch (x) {
return false;
}
}
var specFiles;
if (fileToRun) {
specFiles = [fileToRun];
} else if (existsDir(specsDir)) {
specFiles = fs.readdirSync(specsDir).filter(function (file) {
return (/\.json$/).test(file);
}).map(function (file) {
return path.basename(file).replace(/\.json$/, '');
}).sort();
} else {
specFiles = [];
}
function getSpecs (specArea) {
return JSON.parse(fs.readFileSync(path.join(specsDir, specArea + '.' + 'json'), 'utf8'));
}
describe('Mustache spec compliance', function () {
beforeEach(function () {
Mustache.clearCache();
});
specFiles.forEach(function (specArea) {
describe('- ' + specArea + ':', function () {
var specs = getSpecs(specArea);
specs.tests.forEach(function (test) {
var it_ = (!noSkip && skipTests[specArea] && skipTests[specArea].indexOf(test.name) >= 0) ? it.skip : it;
it_(test.name + ' - ' + test.desc, function () {
if (test.data.lambda && test.data.lambda.__tag__ === 'code')
test.data.lambda = eval('(function() { return ' + test.data.lambda.js + '; })');
var output = Mustache.render(test.template, test.data, test.partials);
assert.equal(output, test.expected);
});
});
});
});
});
================================================
FILE: test/parse-test.js
================================================
require('./helper');
// A map of templates to their expected token output. Tokens are in the format:
// [type, value, startIndex, endIndex, subTokens].
var expectations = {
'' : [],
'{{hi}}' : [ [ 'name', 'hi', 0, 6 ] ],
'{{hi.world}}' : [ [ 'name', 'hi.world', 0, 12 ] ],
'{{hi . world}}' : [ [ 'name', 'hi . world', 0, 14 ] ],
'{{ hi}}' : [ [ 'name', 'hi', 0, 7 ] ],
'{{hi }}' : [ [ 'name', 'hi', 0, 7 ] ],
'{{ hi }}' : [ [ 'name', 'hi', 0, 8 ] ],
'{{{hi}}}' : [ [ '&', 'hi', 0, 8 ] ],
'{{!hi}}' : [ [ '!', 'hi', 0, 7 ] ],
'{{! hi}}' : [ [ '!', 'hi', 0, 8 ] ],
'{{! hi }}' : [ [ '!', 'hi', 0, 9 ] ],
'{{ !hi}}' : [ [ '!', 'hi', 0, 8 ] ],
'{{ ! hi}}' : [ [ '!', 'hi', 0, 9 ] ],
'{{ ! hi }}' : [ [ '!', 'hi', 0, 10 ] ],
'a\n b' : [ [ 'text', 'a\n b', 0, 4 ] ],
'a{{hi}}' : [ [ 'text', 'a', 0, 1 ], [ 'name', 'hi', 1, 7 ] ],
'a {{hi}}' : [ [ 'text', 'a ', 0, 2 ], [ 'name', 'hi', 2, 8 ] ],
' a{{hi}}' : [ [ 'text', ' a', 0, 2 ], [ 'name', 'hi', 2, 8 ] ],
' a {{hi}}' : [ [ 'text', ' a ', 0, 3 ], [ 'name', 'hi', 3, 9 ] ],
'a{{hi}}b' : [ [ 'text', 'a', 0, 1 ], [ 'name', 'hi', 1, 7 ], [ 'text', 'b', 7, 8 ] ],
'a{{hi}} b' : [ [ 'text', 'a', 0, 1 ], [ 'name', 'hi', 1, 7 ], [ 'text', ' b', 7, 9 ] ],
'a{{hi}}b ' : [ [ 'text', 'a', 0, 1 ], [ 'name', 'hi', 1, 7 ], [ 'text', 'b ', 7, 9 ] ],
'a\n{{hi}} b \n' : [ [ 'text', 'a\n', 0, 2 ], [ 'name', 'hi', 2, 8 ], [ 'text', ' b \n', 8, 12 ] ],
'a\n {{hi}} \nb' : [ [ 'text', 'a\n ', 0, 3 ], [ 'name', 'hi', 3, 9 ], [ 'text', ' \nb', 9, 12 ] ],
'a\n {{!hi}} \nb' : [ [ 'text', 'a\n', 0, 2 ], [ '!', 'hi', 3, 10 ], [ 'text', 'b', 12, 13 ] ],
'a\n{{#a}}{{/a}}\nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 2, 8, [], 8 ], [ 'text', 'b', 15, 16 ] ],
'a\n {{#a}}{{/a}}\nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 3, 9, [], 9 ], [ 'text', 'b', 16, 17 ] ],
'a\n {{#a}}{{/a}} \nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 3, 9, [], 9 ], [ 'text', 'b', 17, 18 ] ],
'a\n{{#a}}\n{{/a}}\nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 2, 8, [], 9 ], [ 'text', 'b', 16, 17 ] ],
'a\n {{#a}}\n{{/a}}\nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 3, 9, [], 10 ], [ 'text', 'b', 17, 18 ] ],
'a\n {{#a}}\n{{/a}} \nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 3, 9, [], 10 ], [ 'text', 'b', 18, 19 ] ],
'a\n{{#a}}\n{{/a}}\n{{#b}}\n{{/b}}\nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 2, 8, [], 9 ], [ '#', 'b', 16, 22, [], 23 ], [ 'text', 'b', 30, 31 ] ],
'a\n {{#a}}\n{{/a}}\n{{#b}}\n{{/b}}\nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 3, 9, [], 10 ], [ '#', 'b', 17, 23, [], 24 ], [ 'text', 'b', 31, 32 ] ],
'a\n {{#a}}\n{{/a}}\n{{#b}}\n{{/b}} \nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 3, 9, [], 10 ], [ '#', 'b', 17, 23, [], 24 ], [ 'text', 'b', 32, 33 ] ],
'a\n{{#a}}\n{{#b}}\n{{/b}}\n{{/a}}\nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 2, 8, [ [ '#', 'b', 9, 15, [], 16 ] ], 23 ], [ 'text', 'b', 30, 31 ] ],
'a\n {{#a}}\n{{#b}}\n{{/b}}\n{{/a}}\nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 3, 9, [ [ '#', 'b', 10, 16, [], 17 ] ], 24 ], [ 'text', 'b', 31, 32 ] ],
'a\n {{#a}}\n{{#b}}\n{{/b}}\n{{/a}} \nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 3, 9, [ [ '#', 'b', 10, 16, [], 17 ] ], 24 ], [ 'text', 'b', 32, 33 ] ],
'{{>abc}}' : [ [ '>', 'abc', 0, 8, '', 0, false ] ],
'{{> abc }}' : [ [ '>', 'abc', 0, 10, '', 0, false ] ],
'{{ > abc }}' : [ [ '>', 'abc', 0, 11, '', 0, false ] ],
' {{> abc }}\n' : [ [ '>', 'abc', 2, 12, ' ', 0, false ] ],
' {{> abc }} {{> abc }}\n' : [ [ '>', 'abc', 2, 12, ' ', 0, false ], [ '>', 'abc', 13, 23, ' ', 1, false ] ],
'{{ > abc }}' : [ [ '>', 'abc', 0, 11, '', 0, false ] ],
'{{=<% %>=}}' : [ [ '=', '<% %>', 0, 11 ] ],
'{{= <% %> =}}' : [ [ '=', '<% %>', 0, 13 ] ],
'{{=<% %>=}}<%={{ }}=%>' : [ [ '=', '<% %>', 0, 11 ], [ '=', '{{ }}', 11, 22 ] ],
'{{=<% %>=}}<%hi%>' : [ [ '=', '<% %>', 0, 11 ], [ 'name', 'hi', 11, 17 ] ],
'{{#a}}{{/a}}hi{{#b}}{{/b}}\n' : [ [ '#', 'a', 0, 6, [], 6 ], [ 'text', 'hi', 12, 14 ], [ '#', 'b', 14, 20, [], 20 ], [ 'text', '\n', 26, 27 ] ],
'{{a}}\n{{b}}\n\n{{#c}}\n{{/c}}\n' : [ [ 'name', 'a', 0, 5 ], [ 'text', '\n', 5, 6 ], [ 'name', 'b', 6, 11 ], [ 'text', '\n\n', 11, 13 ], [ '#', 'c', 13, 19, [], 20 ] ],
'{{#foo}}\n {{#a}}\n {{b}}\n {{/a}}\n{{/foo}}\n'
: [ [ '#', 'foo', 0, 8, [ [ '#', 'a', 11, 17, [ [ 'text', ' ', 18, 22 ], [ 'name', 'b', 22, 27 ], [ 'text', '\n', 27, 28 ] ], 30 ] ], 37 ] ]
};
var originalTemplateCache;
before(function () {
originalTemplateCache = Mustache.templateCache;
});
beforeEach(function (){
Mustache.clearCache();
Mustache.templateCache = originalTemplateCache;
});
describe('Mustache.parse', function () {
for (var template in expectations) {
(function (template, tokens) {
it('knows how to parse ' + JSON.stringify(template), function () {
assert.deepEqual(Mustache.parse(template), tokens);
});
})(template, expectations[template]);
}
describe('when there is an unclosed tag', function () {
it('throws an error', function () {
assert.throws(function () {
Mustache.parse('My name is {{name');
}, /unclosed tag at 17/i);
});
});
describe('when there is an unclosed section', function () {
it('throws an error', function () {
assert.throws(function () {
Mustache.parse('A list: {{#people}}{{name}}');
}, /unclosed section "people" at 27/i);
});
});
describe('when there is an unopened section', function () {
it('throws an error', function () {
assert.throws(function () {
Mustache.parse('The end of the list! {{/people}}');
}, /unopened section "people" at 21/i);
});
});
describe('when invalid tags are given as an argument', function () {
it('throws an error', function () {
assert.throws(function () {
Mustache.parse('A template <% name %>', [ '<%' ]);
}, /invalid tags/i);
});
});
describe('when the template contains invalid tags', function () {
it('throws an error', function () {
assert.throws(function () {
Mustache.parse('A template {{=<%=}}');
}, /invalid tags/i);
});
});
describe('when parsing a template without tags specified followed by the same template with tags specified', function () {
it('returns different tokens for the latter parse', function () {
var template = '{{foo}}[bar]';
var parsedWithBraces = Mustache.parse(template);
var parsedWithBrackets = Mustache.parse(template, ['[', ']']);
assert.notDeepEqual(parsedWithBrackets, parsedWithBraces);
});
});
describe('when parsing a template with tags specified followed by the same template with different tags specified', function () {
it('returns different tokens for the latter parse', function () {
var template = '(foo)[bar]';
var parsedWithParens = Mustache.parse(template, ['(', ')']);
var parsedWithBrackets = Mustache.parse(template, ['[', ']']);
assert.notDeepEqual(parsedWithBrackets, parsedWithParens);
});
});
describe('when parsing a template after already having parsed that template with a different Mustache.tags', function () {
it('returns different tokens for the latter parse', function () {
var template = '{{foo}}[bar]';
var parsedWithBraces = Mustache.parse(template);
var oldTags = Mustache.tags;
Mustache.tags = ['[', ']'];
var parsedWithBrackets = Mustache.parse(template);
Mustache.tags = oldTags;
assert.notDeepEqual(parsedWithBrackets, parsedWithBraces);
});
});
describe('when parsing a template with the same tags second time, return the cached tokens', function () {
it('returns the same tokens for the latter parse', function () {
var template = '{{foo}}[bar]';
var parsedResult1 = Mustache.parse(template);
var parsedResult2 = Mustache.parse(template);
assert.deepEqual(parsedResult1, parsedResult2);
assert.ok(parsedResult1 === parsedResult2);
});
});
describe('when parsing a template with caching disabled and the same tags second time, do not return the cached tokens', function () {
it('returns different tokens for the latter parse', function () {
Mustache.templateCache = undefined;
var template = '{{foo}}[bar]';
var parsedResult1 = Mustache.parse(template);
var parsedResult2 = Mustache.parse(template);
assert.deepEqual(parsedResult1, parsedResult2);
assert.ok(parsedResult1 !== parsedResult2);
});
});
describe('when parsing a template with custom caching and the same tags second time, do not return the cached tokens', function () {
it('returns the same tokens for the latter parse', function () {
Mustache.templateCache = {
_cache: [],
set: function set (key, value) {
this._cache.push([key, value]);
},
get: function get (key) {
var cacheLength = this._cache.length;
for (var i = 0; i < cacheLength; i++) {
var entry = this._cache[i];
if (entry[0] === key) {
return entry[1];
}
}
return undefined;
},
clear: function clear () {
this._cache = [];
}
};
var template = '{{foo}}[bar]';
var parsedResult1 = Mustache.parse(template);
var parsedResult2 = Mustache.parse(template);
assert.deepEqual(parsedResult1, parsedResult2);
assert.ok(parsedResult1 === parsedResult2);
});
});
});
================================================
FILE: test/partial-test.js
================================================
/* eslint-disable func-names */
require('./helper');
describe('Partials spec', function () {
beforeEach(function () {
Mustache.clearCache();
});
it('The greater-than operator should expand to the named partial.', function () {
var template = '"{{>text}}"';
var data = {};
var partials = {'text':'from partial'};
var expected = '"from partial"';
var renderResult = Mustache.render(template, data, partials);
assert.equal(renderResult, expected);
});
it('The empty string should be used when the named partial is not found.', function () {
var template = '"{{>text}}"';
var data = {};
var partials = {};
var expected = '""';
var renderResult = Mustache.render(template, data, partials);
assert.equal(renderResult, expected);
});
it('The greater-than operator should operate within the current context.', function () {
var template = '"{{>partial}}"';
var data = {'text':'content'};
var partials = {'partial':'*{{text}}*'};
var expected = '"*content*"';
var renderResult = Mustache.render(template, data, partials);
assert.equal(renderResult, expected);
});
it('Inline partials should not be indented', function () {
var template = ' {{> partial}}';
var data = {};
var partials = {'partial':'This is a partial.'};
var expected = ' This is a partial.';
var renderResult = Mustache.render(template, data, partials);
assert.equal(renderResult, expected);
});
it('Inline partials should not be indented (multiline)', function () {
var template = ' {{> partial}}';
var data = {};
var partials = {'partial':'This is a\npartial.'};
var expected = ' This is a\n partial.';
var renderResult = Mustache.render(template, data, partials);
assert.equal(renderResult, expected);
});
it('The greater-than operator should properly recurse.', function () {
var template = '{{>node}}';
var data = {'content':'X','nodes':[{'content':'Y','nodes':[]}]};
var partials = {'node':'{{content}}<{{#nodes}}{{>node}}{{/nodes}}>'};
var expected = 'X>';
var renderResult = Mustache.render(template, data, partials);
assert.equal(renderResult, expected);
});
it('The greater-than operator should not alter surrounding whitespace.', function () {
var template = '| {{>partial}} |';
var data = {};
var partials = {'partial':'\t|\t'};
var expected = '| \t|\t |';
var renderResult = Mustache.render(template, data, partials);
assert.equal(renderResult, expected);
});
it('"\r\n" should be considered a newline for standalone tags.', function () {
var template = '|\r\n{{>partial}}\r\n|';
var data = {};
var partials = {'partial':'>'};
var expected = '|\r\n>|';
var renderResult = Mustache.render(template, data, partials);
assert.equal(renderResult, expected);
});
it('Standalone tags should not require a newline to precede them.', function () {
var template = ' {{>partial}}\n>';
var data = {};
var partials = {'partial':'>\n>'};
var expected = ' >\n >>';
var renderResult = Mustache.render(template, data, partials);
assert.equal(renderResult, expected);
});
it('Superfluous in-tag whitespace should be ignored.', function () {
var template = '|{{> partial }}|';
var data = {'boolean':true};
var partials = {'partial':'[]'};
var expected = '|[]|';
var renderResult = Mustache.render(template, data, partials);
assert.equal(renderResult, expected);
});
it('Each line of the partial should be indented before rendering.', function () {
var template = '\\\n {{>partial}}\n/\n';
var data = {
'content': '<\n->'
};
var partials = {
'partial': '|\n{{{content}}}\n|\n'
};
var expected = '\\\n |\n <\n->\n |\n/\n';
var renderResult = Mustache.render(template, data, partials);
assert.equal(renderResult, expected);
});
it('Standalone tags should not require a newline to follow them.', function () {
var template = '>\n {{>partial}}';
var data = {
};
var partials = {
'partial': '>\n>'
};
var expected = '>\n >\n >';
var renderResult = Mustache.render(template, data, partials);
assert.equal(renderResult, expected);
});
it('Whitespace should be left untouched.', function () {
var template = ' {{data}} {{> partial}}\n';
var data = {
'data': '|'
};
var partials = {
'partial': '>\n>'
};
var expected = ' | >\n>\n';
var renderResult = Mustache.render(template, data, partials);
assert.equal(renderResult, expected);
});
it('Partial without indentation should inherit functions.', function () {
var template = '{{> partial }}';
var data = {
toUpperCase: function () {
return function (label) {
return label.toUpperCase();
};
}
};
var partials = {partial: 'aA-{{ #toUpperCase }}Input{{ /toUpperCase }}-Aa'};
var expected = 'aA-INPUT-Aa';
var renderResult = Mustache.render(template, data, partials);
assert.equal(renderResult, expected);
});
it('Partial with indentation should inherit functions.', function () {
var template = ' {{> partial }}';
var data = {
toUpperCase: function () {
return function (label) {
return label.toUpperCase();
};
}
};
var partials = {partial: 'aA-{{ #toUpperCase }}Input{{ /toUpperCase }}-Aa'};
var expected = ' aA-INPUT-Aa';
var renderResult = Mustache.render(template, data, partials);
assert.equal(renderResult, expected);
});
it('Nested partials should support custom delimiters.', function () {
var tags = ['[[', ']]'];
var template = '[[> level1 ]]';
var partials = {
level1: 'partial 1\n[[> level2]]',
level2: 'partial 2\n[[> level3]]',
level3: 'partial 3\n[[> level4]]',
level4: 'partial 4\n[[> level5]]',
level5: 'partial 5',
};
var expected = 'partial 1\npartial 2\npartial 3\npartial 4\npartial 5';
var renderResult = Mustache.render(template, {}, partials, tags);
assert.equal(renderResult, expected);
});
});
================================================
FILE: test/render-helper.js
================================================
var fs = require('fs');
var path = require('path');
var _files = path.join(__dirname, '_files');
function getContents (testName, ext) {
try {
return fs.readFileSync(path.join(_files, testName + '.' + ext), 'utf8');
} catch (ex) {
return null;
}
}
function getView (testName) {
var view = getContents(testName, 'js');
if (!view) view = getContents(testName, 'cjs');
if (!view) throw new Error('Cannot find view for test "' + testName + '"');
return view;
}
function getPartial (testName) {
try {
return getContents(testName, 'partial');
} catch (error) {
// No big deal. Not all tests need to test partial support.
}
}
// You can put the name of a specific test to run in the TEST environment
// variable (e.g. TEST=backslashes mocha test/render-test.js)
var testToRun = process.env.TEST;
var testNames;
if (testToRun) {
testNames = testToRun.split(',');
} else {
testNames = fs.readdirSync(_files).filter(function (file) {
return (/\.c?js$/).test(file);
}).map(function (file) {
return path.basename(file).replace(/\.c?js$/, '');
});
}
function getTest (testName) {
return {
name: testName,
view: getView(testName),
template: getContents(testName, 'mustache'),
partial: getPartial(testName),
expect: getContents(testName, 'txt')
};
}
exports.getTests = function getTests () {
return testNames.map(getTest);
};
================================================
FILE: test/render-test-browser-tmpl.mustache
================================================
/* eslint-disable */
require('./helper');
describe('Mustache.render', function () {
beforeEach(function () {
Mustache.clearCache();
});
it('requires template to be a string', function () {
assert.throws(function () {
Mustache.render(['dummy template'], ['foo', 'bar']);
}, TypeError, 'Invalid template! Template should be a "string" but ' +
'"array" was given as the first argument ' +
'for mustache#render(template, view, partials)');
});
var i;
var tests = {{{.}}};
for (i = 0; i < tests.length; i++) {
(function indexClosure(test) {
var view = eval(test.view);
it('knows how to render ' + test.name, function () {
var output;
if (test.partial) {
output = Mustache.render(test.template, view, { partial: test.partial });
} else {
output = Mustache.render(test.template, view);
}
assert.equal(output, test.expect);
});
})(tests[i]);
}
});
================================================
FILE: test/render-test.js
================================================
require('./helper');
var renderHelper = require('./render-helper');
var tests = renderHelper.getTests();
describe('Mustache.render', function () {
beforeEach(function () {
Mustache.clearCache();
});
it('requires template to be a string', function () {
assert.throws(function () {
Mustache.render(['dummy template'], ['foo', 'bar']);
}, TypeError, 'Invalid template! Template should be a "string" but ' +
'"array" was given as the first argument ' +
'for mustache#render(template, view, partials)');
});
describe('custom tags', function () {
it('uses tags argument instead of Mustache.tags when given', function () {
var template = '<>bar{{placeholder}}';
Mustache.tags = ['{{', '}}'];
assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['<<', '>>']), 'foobar{{placeholder}}');
});
it('uses config.tags argument instead of Mustache.tags when given', function () {
var template = '<>bar{{placeholder}}';
Mustache.tags = ['{{', '}}'];
assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, { tags: ['<<', '>>']}), 'foobar{{placeholder}}');
});
it('uses tags argument instead of Mustache.tags when given, even when it previously rendered the template using Mustache.tags', function () {
var template = '((placeholder))bar{{placeholder}}';
Mustache.tags = ['{{', '}}'];
Mustache.render(template, { placeholder: 'foo' });
assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['((', '))']), 'foobar{{placeholder}}');
});
it('uses config.tags argument instead of Mustache.tags when given, even when it previously rendered the template using Mustache.tags', function () {
var template = '((placeholder))bar{{placeholder}}';
Mustache.tags = ['{{', '}}'];
Mustache.render(template, { placeholder: 'foo' });
assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, { tags: ['((', '))'] }), 'foobar{{placeholder}}');
});
it('uses tags argument instead of Mustache.tags when given, even when it previously rendered the template using different tags', function () {
var template = '[[placeholder]]bar<>';
Mustache.render(template, { placeholder: 'foo' }, {}, ['<<', '>>']);
assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['[[', ']]']), 'foobar<>');
});
it('uses config.tags argument instead of Mustache.tags when given, even when it previously rendered the template using different tags', function () {
var template = '[[placeholder]]bar<>';
Mustache.render(template, { placeholder: 'foo' }, {}, ['<<', '>>']);
assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, { tags: ['[[', ']]'] }), 'foobar<>');
});
it('does not mutate Mustache.tags when given tags argument', function () {
var correctMustacheTags = ['{{', '}}'];
Mustache.tags = correctMustacheTags;
Mustache.render('((placeholder))', { placeholder: 'foo' }, {}, ['((', '))']);
assert.equal(Mustache.tags, correctMustacheTags);
assert.deepEqual(Mustache.tags, ['{{', '}}']);
});
it('does not mutate Mustache.tags when given config.tags argument', function () {
var correctMustacheTags = ['{{', '}}'];
Mustache.tags = correctMustacheTags;
Mustache.render('((placeholder))', { placeholder: 'foo' }, {}, { tags: ['((', '))'] });
assert.equal(Mustache.tags, correctMustacheTags);
assert.deepEqual(Mustache.tags, ['{{', '}}']);
});
it('uses provided tags when rendering partials', function () {
var output = Mustache.render('<%> partial %>', { name: 'Santa Claus' }, {
partial: '<% name %>'
}, ['<%', '%>']);
assert.equal(output, 'Santa Claus');
});
it('uses provided config.tags when rendering partials', function () {
var output = Mustache.render('<%> partial %>', { name: 'Santa Claus' }, {
partial: '<% name %>'
}, { tags: ['<%', '%>'] });
assert.equal(output, 'Santa Claus');
});
it('uses config.escape argument instead of Mustache.escape when given', function () {
var template = 'Hello, {{placeholder}}';
function escapeBang (text) {
return text + '!';
}
assert.equal(Mustache.render(template, { placeholder: 'world' }, {}, { escape: escapeBang }), 'Hello, world!');
});
it('uses config.escape argument instead of Mustache.escape when given, even when it previously rendered the template using Mustache.escape', function () {
var template = 'Hello, {{placeholder}}';
function escapeQuestion (text) {
return text + '?';
}
Mustache.render(template, { placeholder: 'world' });
assert.equal(Mustache.render(template, { placeholder: 'world' }, {}, { escape: escapeQuestion }), 'Hello, world?');
});
it('uses config.escape argument instead of Mustache.escape when given, even when it previously rendered the template using a different escape function', function () {
var template = 'Hello, {{placeholder}}';
function escapeQuestion (text) {
return text + '?';
}
function escapeBang (text) {
return text + '!';
}
Mustache.render(template, { placeholder: 'foo' }, {}, { escape: escapeQuestion });
assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, { escape: escapeBang }), 'Hello, foo!');
});
it('does not mutate Mustache.escape when given config.escape argument', function () {
var correctMustacheEscape = Mustache.escape;
function escapeNone (text) {
return text;
}
Mustache.render('((placeholder))', { placeholder: 'foo' }, {}, { escape: escapeNone });
assert.equal(Mustache.escape, correctMustacheEscape);
assert.equal(Mustache.escape('>&'), '>&');
});
it('uses provided config.escape when rendering partials', function () {
function escapeDoubleAmpersand (text) {
return text.replace('&', '&&');
}
var output = Mustache.render('{{> partial }}', { name: 'Ampersand &' }, {
partial: '{{ name }}'
}, { escape: escapeDoubleAmpersand });
assert.equal(output, 'Ampersand &&');
});
it('uses config.tags and config.escape arguments instead of Mustache.tags and Mustache.escape when given', function () {
var template = 'Hello, {{placeholder}} [[placeholder]]';
function escapeTwoBangs (text) {
return text + '!!';
}
var config = {
tags: ['[[', ']]'],
escape: escapeTwoBangs,
};
assert.equal(Mustache.render(template, { placeholder: 'world' }, {}, config), 'Hello, {{placeholder}} world!!');
});
it('uses provided config.tags and config.escape when rendering partials', function () {
function escapeDoubleAmpersand (text) {
return text.replace('&', '&&');
}
var config = {
tags: ['[[', ']]'],
escape: escapeDoubleAmpersand
};
var output = Mustache.render('[[> partial ]]', { name: 'Ampersand &' }, {
partial: '[[ name ]]'
}, config);
assert.equal(output, 'Ampersand &&');
});
it('uses provided config.tags and config.escape when rendering sections', function () {
var template = (
'<[[&value-raw]]: ' +
'[[#test-1]][[value-1]][[/test-1]]' +
'[[^test-2]][[value-2]][[/test-2]], ' +
'[[#test-lambda]][[value-lambda]][[/test-lambda]]' +
'>'
);
function escapeQuotes (text) {
return '"' + text + '"';
}
var config = {
tags: ['[[', ']]'],
escape: escapeQuotes
};
var viewTestTrue = {
'value-raw': 'foo',
'test-1': true,
'value-1': 'abc',
'test-2': true,
'value-2': '123',
'test-lambda': function () {
return function (text, render) { return 'lambda: ' + render(text); };
},
'value-lambda': 'bar'
};
var viewTestFalse = {
'value-raw': 'foo',
'test-1': false,
'value-1': 'abc',
'test-2': false,
'value-2': '123',
'test-lambda': function () {
return function (text, render) { return 'lambda: ' + render(text); };
},
'value-lambda': 'bar'
};
var outputTrue = Mustache.render(template, viewTestTrue, {}, config);
var outputFalse = Mustache.render(template, viewTestFalse, {}, config);
assert.equal(outputTrue, '');
assert.equal(outputFalse, '');
});
});
tests.forEach(function (test) {
var view = eval(test.view);
it('knows how to render ' + test.name, function () {
var output;
if (test.partial) {
output = Mustache.render(test.template, view, { partial: test.partial });
} else {
output = Mustache.render(test.template, view);
}
output.should.equal(test.expect);
});
});
});
================================================
FILE: test/scanner-test.js
================================================
require('./helper');
var Scanner = Mustache.Scanner;
describe('A new Mustache.Scanner', function () {
describe('for an empty string', function () {
it('is at the end', function () {
var scanner = new Scanner('');
assert(scanner.eos());
});
});
describe('for a non-empty string', function () {
var scanner;
beforeEach(function () {
scanner = new Scanner('a b c');
});
describe('scan', function () {
describe('when the RegExp matches the entire string', function () {
it('returns the entire string', function () {
var match = scanner.scan(/a b c/);
assert.equal(match, scanner.string);
assert(scanner.eos());
});
});
describe('when the RegExp matches at index 0', function () {
it('returns the portion of the string that matched', function () {
var match = scanner.scan(/a/);
assert.equal(match, 'a');
assert.equal(scanner.pos, 1);
});
});
describe('when the RegExp matches at some index other than 0', function () {
it('returns the empty string', function () {
var match = scanner.scan(/b/);
assert.equal(match, '');
assert.equal(scanner.pos, 0);
});
});
describe('when the RegExp does not match', function () {
it('returns the empty string', function () {
var match = scanner.scan(/z/);
assert.equal(match, '');
assert.equal(scanner.pos, 0);
});
});
}); // scan
describe('scanUntil', function () {
describe('when the RegExp matches at index 0', function () {
it('returns the empty string', function () {
var match = scanner.scanUntil(/a/);
assert.equal(match, '');
assert.equal(scanner.pos, 0);
});
});
describe('when the RegExp matches at some index other than 0', function () {
it('returns the string up to that index', function () {
var match = scanner.scanUntil(/b/);
assert.equal(match, 'a ');
assert.equal(scanner.pos, 2);
});
});
describe('when the RegExp does not match', function () {
it('returns the entire string', function () {
var match = scanner.scanUntil(/z/);
assert.equal(match, scanner.string);
assert(scanner.eos());
});
});
}); // scanUntil
}); // for a non-empty string
});
================================================
FILE: wrappers/dojo/mustache.js.post
================================================
dojox.mustache = dojo.hitch(Mustache, "render");
})();
================================================
FILE: wrappers/dojo/mustache.js.pre
================================================
/*
Shameless port of a shameless port
@defunkt => @janl => @aq => @voodootikigod
See http://github.com/defunkt/mustache for more info.
*/
dojo.provide("dojox.mustache._base");
(function(){
================================================
FILE: wrappers/jquery/mustache.js.post
================================================
$.mustache = function (template, view, partials) {
return Mustache.render(template, view, partials);
};
$.fn.mustache = function (view, partials) {
return $(this).map(function (i, elm) {
var template = $.trim($(elm).html());
var output = $.mustache(template, view, partials);
return $(output).get();
});
};
})(jQuery);
================================================
FILE: wrappers/jquery/mustache.js.pre
================================================
/*
Shameless port of a shameless port
@defunkt => @janl => @aq
See http://github.com/defunkt/mustache for more info.
*/
;(function($) {
================================================
FILE: wrappers/mootools/mustache.js.post
================================================
Object.implement('mustache', function(view, partials){
return Mustache.render(view, this, partials);
});
})();
================================================
FILE: wrappers/mootools/mustache.js.pre
================================================
(function(){
================================================
FILE: wrappers/qooxdoo/mustache.js.post
================================================
/**
* Above is the original mustache code.
*/
// EXPOSE qooxdoo variant
qx.bom.Template.version = this.Mustache.version;
qx.bom.Template.render = this.Mustache.render;
}).call({});
================================================
FILE: wrappers/qooxdoo/mustache.js.pre
================================================
/* ************************************************************************
qooxdoo - the new era of web development
http://qooxdoo.org
Copyright:
2004-2012 1&1 Internet AG, Germany, http://www.1und1.de
License:
LGPL: http://www.gnu.org/licenses/lgpl.html
EPL: http://www.eclipse.org/org/documents/epl-v10.php
See the LICENSE file in the project's top-level directory for details.
Authors:
* Martin Wittemann (martinwittemann)
======================================================================
This class contains code based on the following work:
* Mustache.js version 0.8.0
Code:
https://github.com/janl/mustache.js
Copyright:
(c) 2009 Chris Wanstrath (Ruby)
(c) 2010 Jan Lehnardt (JavaScript)
License:
MIT: http://www.opensource.org/licenses/mit-license.php
----------------------------------------------------------------------
Copyright (c) 2009 Chris Wanstrath (Ruby)
Copyright (c) 2010 Jan Lehnardt (JavaScript)
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.
************************************************************************ */
/**
* The is a template class which can be used for HTML templating. In fact,
* this is a wrapper for mustache.js which is a "framework-agnostic way to
* render logic-free views".
*
* Here is a basic example how to use it:
* Template:
*
* var template = "Hi, my name is {{name}}!";
* var view = {name: "qooxdoo"};
* qx.bom.Template.render(template, view);
* // return "Hi, my name is qooxdoo!"
*
*
* For further details, please visit the mustache.js documentation here:
* https://github.com/janl/mustache.js/blob/master/README.md
*
* @ignore(module)
*/
qx.Bootstrap.define("qx.bom.Template", {
statics : {
/** Contains the mustache.js version. */
version: null,
/**
* Original and only template method of mustache.js. For further
* documentation, please visit https://github.com/janl/mustache.js
*
* @signature function(template, view, partials)
* @param template {String} The String containing the template.
* @param view {Object} The object holding the data to render.
* @param partials {Object} Object holding parts of a template.
* @return {String} The parsed template.
*/
render: null,
/**
* Combines {@link #render} and {@link #get}. Input is equal to {@link #render}
* and output is equal to {@link #get}. The advantage over {@link #get}
* is that you don't need a HTML template but can use a template
* string and still get a DOM element. Keep in mind that templates
* can only have one root element.
*
* @param template {String} The String containing the template.
* @param view {Object} The object holding the data to render.
* @param partials {Object} Object holding parts of a template.
* @return {Element} A DOM element holding the parsed template data.
*/
renderToNode : function(template, view, partials) {
var renderedTmpl = this.render(template, view, partials);
return this._createNodeFromTemplate(renderedTmpl);
},
/**
* Helper method which provides you with a direct access to templates
* stored as HTML in the DOM. The DOM node with the given ID will be used
* as a template, parsed and a new DOM node will be returned containing the
* parsed data. Keep in mind to have only one root DOM element in the the
* template.
* Additionally, you should not put the template into a regular, hidden
* DOM element because the template may not be valid HTML due to the containing
* mustache tags. We suggest to put it into a script tag with the type
* text/template.
*
* @param id {String} The id of the HTML template in the DOM.
* @param view {Object} The object holding the data to render.
* @param partials {Object} Object holding parts of a template.
* @return {Element} A DOM element holding the parsed template data.
*/
get : function(id, view, partials) {
// get the content stored in the DOM
var template = document.getElementById(id);
return this.renderToNode(template.innerHTML, view, partials);
},
/**
* Accepts a parsed template and returns a (potentially nested) node.
*
* @param template {String} The String containing the template.
* @return {Element} A DOM element holding the parsed template data.
*/
_createNodeFromTemplate : function(template) {
// template is text only (no html elems) so use text node
if (template.search(/<|>/) === -1) {
return document.createTextNode(template);
}
// template has html elems so convert string into DOM nodes
var helper = qx.dom.Element.create("div");
helper.innerHTML = template;
return helper.children[0];
}
}
});
(function() {
// prevent using CommonJS exports object,
// by shadowing global exports object
var exports;
// prevent using AMD compatible loader,
// by shadowing global define function
var define;
/**
* Below is the original mustache.js code. Snapshot date is mentioned in
* the head of this file.
* @ignore(exports)
* @ignore(define.*)
* @ignore(module.*)
* @lint ignoreNoLoopBlock()
*/