A Twitch.tv viewer reward and games system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

32 lines
13 KiB

{
"name": "mustache",
"version": "0.7.2",
"description": "Logic-less {{mustache}} templates with JavaScript",
"author": {
"name": "mustache.js Authors",
"email": "http://github.com/janl/mustache.js"
},
"keywords": [
"mustache",
"template",
"templates",
"ejs"
],
"main": "./mustache.js",
"devDependencies": {
"mocha": "1.5.0"
},
"volo": {
"url": "https://raw.github.com/janl/mustache.js/0.7.2/mustache.js"
},
"scripts": {
"test": "mocha test"
},
"readme": "# mustache.js - Logic-less {{mustache}} templates with JavaScript\n\n> What could be more logical awesome than no logic at all?\n\n[mustache.js](http://github.com/janl/mustache.js) is an implementation of the [mustache](http://mustache.github.com/) template system in JavaScript.\n\n[Mustache](http://mustache.github.com/) is a logic-less template syntax. It can be used for HTML, config files, source code - anything. It works by expanding tags in a template using values provided in a hash or object.\n\nWe 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.\n\nFor a language-agnostic overview of mustache's template syntax, see the `mustache(5)` [manpage](http://mustache.github.com/mustache.5.html).\n\n## Where to use mustache.js?\n\nYou can use mustache.js to render mustache templates anywhere you can use JavaScript. This includes web browsers, server-side environments such as [node](http://nodejs.org/), and [CouchDB](http://couchdb.apache.org/) views.\n\nmustache.js ships with support for both the [CommonJS](http://www.commonjs.org/) module API and the [Asynchronous Module Definition](https://github.com/amdjs/amdjs-api/wiki/AMD) API, or AMD.\n\n## Who uses mustache.js?\n\nAn updated list of mustache.js users is kept [on the Github wiki](http://wiki.github.com/janl/mustache.js/beard-competition). Add yourself or your company if you use mustache.js!\n\n## Usage\n\nBelow is quick example how to use mustache.js:\n\n var view = {\n title: \"Joe\",\n calc: function () {\n return 2 + 4;\n }\n };\n\n var output = Mustache.render(\"{{title}} spends {{calc}}\", view);\n\nIn this example, the `Mustache.render` function takes two parameters: 1) the [mustache](http://mustache.github.com/) template and 2) a `view` object that contains the data and code needed to render the template.\n\n## Templates\n\nA [mustache](http://mustache.github.com/) template is a string that contains any number of mustache tags. Tags are indicated by the double mustaches that surround them. `{{person}}` is a tag, as is `{{#person}}`. In both examples we refer to `person` as the tag's key.\n\nThere are several types of tags available in mustache.js.\n\n### Variables\n\nThe most basic tag type is a simple variable. A `{{name}}` tag renders the value of the `name` key in the current context. If there is no such key, nothing is rendered.\n\nAll variables are HTML-escaped by default. If you want to render unescaped HTML, use the triple mustache: `{{{name}}}`. You can also use `&` to unescape a variable.\n\nView:\n\n {\n \"name\": \"Chris\",\n \"company\": \"<b>GitHub</b>\"\n }\n\nTemplate:\n\n * {{name}}\n * {{age}}\n * {{company}}\n * {{{company}}}\n * {{&company}}\n\nOutput:\n\n * Chris\n *\n * &lt;b&gt;GitHub&lt;/b&gt;\n * <b>GitHub</b>\n * <b>GitHub</b>\n\nJavaScript's dot notation may be used to access keys that are properties of objects in a view.\n\nView:\n\n {\n \"name\": {\n \"first\": \"Michael\",\n \"last\": \"Jackson\"\n },\n \"age\": \"RIP\"\n }\n\nTemplate:\n\n * {{name.first}} {{name.last}}\n * {{age}}\n\nOutput:\n\n * Michael Jackson\n * RIP\n\n### Sections\n\nSections render blocks of text one or more times, depending on the value of the key in the current context.\n\nA section begins with a pound and ends with a slash. That is, `{{#person}}` begins a `person` section, while `{{/person}}` ends it. The text between the two tags is referred to as that section's \"block\".\n\nThe behavior of the section is determined by the value of the key.\n\n#### False Values or Empty Lists\n\nIf the `person` key does not exist, or exists and has a value of `null`, `undefined`, or `false`, or is an empty list, the block will not be rendered.\n\nView:\n\n {\n \"person\": false\n }\n\nTemplate:\n\n Shown.\n {{#person}}\n Never shown!\n {{/person}}\n\nOutput:\n\n Shown.\n\n#### Non-Empty Lists\n\nIf the `person` key exists and is not `null`, `undefined`, or `false`, and is not an empty list the block will be rendered one or more times.\n\nWhen the value is a list, the block is rendered once for each item in the list. The context of the block is set to the current item in the list for each iteration. In this way we can loop over collections.\n\nView:\n\n {\n \"stooges\": [\n { \"name\": \"Moe\" },\n { \"name\": \"Larry\" },\n { \"name\": \"Curly\" }\n ]\n }\n\nTemplate:\n\n {{#stooges}}\n <b>{{name}}</b>\n {{/stooges}}\n\nOutput:\n\n <b>Moe</b>\n <b>Larry</b>\n <b>Curly</b>\n\nWhen looping over an array of strings, a `.` can be used to refer to the current item in the list.\n\nView:\n\n {\n \"musketeers\": [\"Athos\", \"Aramis\", \"Porthos\", \"D'Artagnan\"]\n }\n\nTemplate:\n\n {{#musketeers}}\n * {{.}}\n {{/musketeers}}\n\nOutput:\n\n * Athos\n * Aramis\n * Porthos\n * D'Artagnan\n\nIf the value of a section variable is a function, it will be called in the context of the current item in the list on each iteration.\n\nView:\n\n {\n \"beatles\": [\n { \"firstName\": \"John\", \"lastName\": \"Lennon\" },\n { \"firstName\": \"Paul\", \"lastName\": \"McCartney\" },\n { \"firstName\": \"George\", \"lastName\": \"Harrison\" },\n { \"firstName\": \"Ringo\", \"lastName\": \"Starr\" }\n ],\n \"name\": function () {\n return this.firstName + \" \" + this.lastName;\n }\n }\n\nTemplate:\n\n {{#beatles}}\n * {{name}}\n {{/beatles}}\n\nOutput:\n\n * John Lennon\n * Paul McCartney\n * George Harrison\n * Ringo Starr\n\n#### Functions\n\nIf the value of a section key is a function, it is called with the section's literal block of text, un-rendered, as its first argument. The second argument is a special rendering function that uses the current view as its view argument. It is called in the context of the current view object.\n\nView:\n\n {\n \"name\": \"Tater\",\n \"bold\": function () {\n return function (text, render) {\n return \"<b>\" + render(text) + \"</b>\";\n }\n }\n }\n\nTemplate:\n\n {{#bold}}Hi {{name}}.{{/bold}}\n\nOutput:\n\n <b>Hi Tater.</b>\n\n### Inverted Sections\n\nAn inverted section opens with `{{^section}}` instead of `{{#section}}`. The block of an inverted section is rendered only if the value of that section's tag is `null`, `undefined`, `false`, or an empty list.\n\nView:\n\n {\n \"repos\": []\n }\n\nTemplate:\n\n {{#repos}}<b>{{name}}</b>{{/repos}}\n {{^repos}}No repos :({{/repos}}\n\nOutput:\n\n No repos :(\n\n### Comments\n\nComments begin with a bang and are ignored. The following template:\n\n <h1>Today{{! ignore me }}.</h1>\n\nWill render as follows:\n\n <h1>Today.</h1>\n\nComments may contain newlines.\n\n### Partials\n\nPartials begin with a greater than sign, like {{> box}}.\n\nPartials are rendered at runtime (as opposed to compile time), so recursive partials are possible. Just avoid infinite loops.\n\nThey also inherit the calling context. Whereas in ERB you may have this:\n\n <%= partial :next_more, :start => start, :size => size %>\n\nMustache requires only this:\n\n {{> next_more}}\n\nWhy? Because the `next_more.mustache` file will inherit the `size` and `start` variables from the calling context. In this way you may want to think of partials as includes, or template expansion, even though it's not literally true.\n\nFor example, this template and partial:\n\n base.mustache:\n <h2>Names</h2>\n {{#names}}\n {{> user}}\n {{/names}}\n\n user.mustache:\n <strong>{{name}}</strong>\n\nCan be thought of as a single, expanded template:\n\n <h2>Names</h2>\n {{#names}}\n <strong>{{name}}</strong>\n {{/names}}\n\nIn mustache.js an object of partials may be passed as the third argument to `Mustache.render`. The object should be keyed by the name of the partial, and its value should be the partial text.\n\n### Set Delimiter\n\nSet Delimiter tags start with an equals sign and change the tag delimiters from `{{` and `}}` to custom strings.\n\nConsider the following contrived example:\n\n * {{ default_tags }}\n {{=<% %>=}}\n * <% erb_style_tags %>\n <%={{ }}=%>\n * {{ default_tags_again }}\n\nHere we have a list with three items. The first item uses the default tag style, the second uses ERB style as defined by the Set Delimiter tag, and the third returns to the default style after yet another Set Delimiter declaration.\n\nAccording to [ctemplates](http://google-ctemplate.googlecode.com/svn/trunk/doc/howto.html), this \"is useful for languages like TeX, where double-braces may occur in the text and are awkward to use for markup.\"\n\nCustom delimiters may not contain whitespace or the equals sign.\n\n### Compiled Templates\n\nMustache templates can be compiled into JavaScript functions using `Mustache.compile` for improved rendering performance.\n\nIf you have template views that are rendered multiple times, compiling your template into a JavaScript function will minimise the amount of work required for each re-render.\n\nPre-compiled templates can also be generated server-side, for delivery to the browser as ready to use JavaScript functions, further reducing the amount of client side processing required for initialising templates.\n\n**Mustache.compile**\n\nUse `Mustache.compile` to compile standard Mustache string templates into reusable Mustache template functions.\n\n var compiledTemplate = Mustache.compile(stringTemplate);\n\nThe function returned from `Mustache.compile` can then be called directly, passing in the template data as an argument (with an object of partials as an optional second parameter), to generate the final output.\n\n var templateOutput = compiledTemplate(templateData);\n\n**Mustache.compilePartial**\n\nTemplate partials can also be compiled using the `Mustache.compilePartial` function. The first parameter of this function, is the name of the partial as it appears within parent templates.\n\n Mustache.compilePartial('partial-name', stringTemplate);\n\nCompiled partials are then available to both `Mustache.render` and `Mustache.compile`.\n\n## Plugins for JavaScript Libraries\n\nmustache.js may be built specifically for several different client libraries, including the following:\n\n - [jQuery](http://jquery.com/)\n - [MooTools](http://mootools.net/)\n - [Dojo](http://www.dojotoolkit.org/)\n - [YUI](http://developer.yahoo.com/yui/)\n - [qooxdoo](http://qooxdoo.org/)\n\nThese may be built using [Rake](http://rake.rubyforge.org/) and one of the following commands:\n\n $ rake jquery\n $ rake mootools\n $ rake dojo\n $ rake yui\n $ rake qooxdoo\n\n## Testing\n\nThe mustache.js test suite uses the [vows](http://vowsjs.org/) testing framework. In order to run the tests you'll need to install [node](http://nodejs.org/). Once that's done you can install vows using [npm](http://npmjs.org/).\n\n $ npm install -g vows\n\nThen run the tests.\n\n $ vows --spec\n\nThe test suite consists of both unit and integration tests. If a template isn't rendering correctly for you, you can make a test for it by doing the following:\n\n 1. Create a template file named `mytest.mustache` in the `test/_files`\n directory. Replace `mytest` with the name of your test.\n 2. Create a corresponding view file named `mytest.js` in the same directory.\n This file should contain a JavaScript object literal enclosed in\n parentheses. See any of the other view files for an example.\n 3. Create a file with the expected output in `mytest.txt` in the same\n directory.\n\nThen, you can run the test with:\n\n $ TEST=mytest vows test/render_test.js\n\n## Thanks\n\nmustache.js wouldn't kick ass if it weren't for these fine souls:\n\n * Chris Wanstrath / defunkt\n * Alexander Lang / langalex\n * Sebastian Cohnen / tisba\n * J Chris Anderson / jchris\n * Tom Robinson / tlrobinson\n * Aaron Quint / quirkey\n * Douglas Crockford\n * Nikita Vasilyev / NV\n * Elise Wood / glytch\n * Damien Mathieu / dmathieu\n * Jakub Kuźma / qoobaa\n * Will Leinweber / will\n * dpree\n * Jason Smith / jhs\n * Aaron Gibralter / agibralter\n * Ross Boucher / boucher\n * Matt Sanford / mzsanford\n * Ben Cherry / bcherry\n * Michael Jackson / mjijackson\n",
"readmeFilename": "README.md",
"_id": "mustache@0.7.2",
"dist": {
"shasum": "788c1e1f8af9c3c992ad5f6103aa3df7a029dfb7"
},
"_from": "mustache"
}