Comparing version 0.5.2 to 0.6.0
@@ -11,3 +11,3 @@ /*! | ||
(function (exports) { | ||
if (typeof module !== "undefined") { | ||
if (typeof module !== "undefined" && typeof module.exports !== "undefined") { | ||
module.exports = exports; // CommonJS | ||
@@ -23,3 +23,3 @@ } else if (typeof define === "function") { | ||
exports.name = "mustache.js"; | ||
exports.version = "0.5.2"; | ||
exports.version = "0.6.0"; | ||
exports.tags = ["{{", "}}"]; | ||
@@ -69,3 +69,3 @@ | ||
// OSWASP Guidelines: escape all non alphanumeric characters in ASCII space. | ||
// OSWASP Guidelines: Escape all non alphanumeric characters in ASCII space. | ||
var jsCharsRe = /[\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\xFF\u2028\u2029]/gm; | ||
@@ -100,8 +100,5 @@ | ||
// Export these utility functions. | ||
exports.isWhitespace = isWhitespace; | ||
exports.isArray = isArray; | ||
exports.quote = quote; | ||
exports.escapeRe = escapeRe; | ||
exports.escapeHtml = escapeHtml; | ||
// Export the escaping function so that the user may override it. | ||
// See https://github.com/janl/mustache.js/issues/244 | ||
exports.escape = escapeHtml; | ||
@@ -296,6 +293,5 @@ function Scanner(string) { | ||
// From the spec: inverted sections may render text once based on the | ||
// inverse value of the key. That is, they will be rendered if the key | ||
// doesn't exist, is false, or is an empty list. | ||
if (value == null || value === false || (isArray(value) && value.length === 0)) { | ||
// Use JavaScript's definition of falsy. Include empty arrays. | ||
// See https://github.com/janl/mustache.js/issues/186 | ||
if (!value || (isArray(value) && value.length === 0)) { | ||
return callback(context, this); | ||
@@ -327,3 +323,3 @@ } | ||
if (escape) { | ||
return escapeHtml(string); | ||
return exports.escape(string); | ||
} | ||
@@ -385,10 +381,10 @@ | ||
function escapeTags(tags) { | ||
if (tags.length === 2) { | ||
return [ | ||
new RegExp(escapeRe(tags[0]) + "\\s*"), | ||
new RegExp("\\s*" + escapeRe(tags[1])) | ||
]; | ||
if (tags.length !== 2) { | ||
throw new Error("Invalid tags: " + tags.join(" ")); | ||
} | ||
throw new Error("Invalid tags: " + tags.join(" ")); | ||
return [ | ||
new RegExp(escapeRe(tags[0]) + "\\s*"), | ||
new RegExp("\\s*" + escapeRe(tags[1])) | ||
]; | ||
} | ||
@@ -395,0 +391,0 @@ |
{ | ||
"name": "mustache", | ||
"version": "0.5.2", | ||
"version": "0.6.0", | ||
"description": "Logic-less {{mustache}} templates with JavaScript", | ||
@@ -9,5 +9,7 @@ "author": "mustache.js Authors <http://github.com/janl/mustache.js>", | ||
"devDependencies": { | ||
"vows": "0.6.x", | ||
"uglify-js": "1.3.0" | ||
"vows": "0.6.x" | ||
}, | ||
"volo": { | ||
"url": "https://raw.github.com/janl/mustache.js/0.6.0/mustache.js" | ||
}, | ||
"scripts": { | ||
@@ -14,0 +16,0 @@ "test": "vows --spec" |
111
README.md
@@ -5,29 +5,19 @@ # mustache.js - Logic-less {{mustache}} templates with JavaScript | ||
[mustache.js](http://github.com/janl/mustache.js) is an implementation of the | ||
[mustache](http://mustache.github.com/) template system in JavaScript. | ||
[mustache.js](http://github.com/janl/mustache.js) is an implementation of the [mustache](http://mustache.github.com/) template system in JavaScript. | ||
[Mustache](http://mustache.github.com/) is a logic-less template syntax. It can | ||
be used for HTML, config files, source code - anything. It works by expanding | ||
tags in a template using values provided in a hash or object. | ||
[Mustache](http://mustache.github.com/) is a logic-less template syntax. It can be used for HTML, config files, source code - anything. It works by expanding tags in a template using values provided in a hash or object. | ||
We call it "logic-less" because there are no if statements, else clauses, or for | ||
loops. Instead there are only tags. Some tags are replaced with a value, some | ||
nothing, and others a series of values. | ||
We call it "logic-less" because there are no if statements, else clauses, or for loops. Instead there are only tags. Some tags are replaced with a value, some nothing, and others a series of values. | ||
For a language-agnostic overview of mustache's template syntax, see the | ||
`mustache(5)` [manpage](http://mustache.github.com/mustache.5.html). | ||
For a language-agnostic overview of mustache's template syntax, see the `mustache(5)` [manpage](http://mustache.github.com/mustache.5.html). | ||
## Where to use mustache.js? | ||
You can use mustache.js to render mustache templates anywhere you can use | ||
JavaScript. This includes web browsers, server-side environments such as [node](http://nodejs.org/), and [CouchDB](http://couchdb.apache.org/) | ||
views. | ||
You can use mustache.js to render mustache templates anywhere you can use JavaScript. This includes web browsers, server-side environments such as [node](http://nodejs.org/), and [CouchDB](http://couchdb.apache.org/) views. | ||
mustache.js ships with support for both the [CommonJS](http://www.commonjs.org/) | ||
module API and the [Asynchronous Module Definition](https://github.com/amdjs/amdjs-api/wiki/AMD) API, or AMD. | ||
mustache.js ships with support for both the [CommonJS](http://www.commonjs.org/) module API and the [Asynchronous Module Definition](https://github.com/amdjs/amdjs-api/wiki/AMD) API, or AMD. | ||
## Who uses mustache.js? | ||
An updated list of mustache.js users is kept [on the Github wiki](http://wiki.github.com/janl/mustache.js/beard-competition). | ||
Add yourself or your company if you use mustache.js! | ||
An updated list of mustache.js users is kept [on the Github wiki](http://wiki.github.com/janl/mustache.js/beard-competition). Add yourself or your company if you use mustache.js! | ||
@@ -47,12 +37,7 @@ ## Usage | ||
In this example, the `Mustache.render` function takes two parameters: 1) the | ||
[mustache](http://mustache.github.com/) template and 2) a `view` object that | ||
contains the data and code needed to render the template. | ||
In this example, the `Mustache.render` function takes two parameters: 1) the [mustache](http://mustache.github.com/) template and 2) a `view` object that contains the data and code needed to render the template. | ||
## Templates | ||
A [mustache](http://mustache.github.com/) template is a string that contains | ||
any number of mustache tags. Tags are indicated by the double mustaches that | ||
surround them. `{{person}}` is a tag, as is `{{#person}}`. In both examples we | ||
refer to `person` as the tag's key. | ||
A [mustache](http://mustache.github.com/) template is a string that contains any number of mustache tags. Tags are indicated by the double mustaches that surround them. `{{person}}` is a tag, as is `{{#person}}`. In both examples we refer to `person` as the tag's key. | ||
@@ -63,9 +48,5 @@ There are several types of tags available in mustache.js. | ||
The most basic tag type is a simple variable. A `{{name}}` tag renders the value | ||
of the `name` key in the current context. If there is no such key, nothing is | ||
rendered. | ||
The most basic tag type is a simple variable. A `{{name}}` tag renders the value of the `name` key in the current context. If there is no such key, nothing is rendered. | ||
All variables are HTML-escaped by default. If you want to render unescaped HTML, | ||
use the triple mustache: `{{{name}}}`. You can also use `&` to unescape a | ||
variable. | ||
All variables are HTML-escaped by default. If you want to render unescaped HTML, use the triple mustache: `{{{name}}}`. You can also use `&` to unescape a variable. | ||
@@ -95,4 +76,3 @@ View: | ||
JavaScript's dot notation may be used to access keys that are properties of | ||
objects in a view. | ||
JavaScript's dot notation may be used to access keys that are properties of objects in a view. | ||
@@ -121,8 +101,5 @@ View: | ||
Sections render blocks of text one or more times, depending on the value of the | ||
key in the current context. | ||
Sections render blocks of text one or more times, depending on the value of the key in the current context. | ||
A section begins with a pound and ends with a slash. That is, `{{#person}}` | ||
begins a `person` section, while `{{/person}}` ends it. The text between the two | ||
tags is referred to as that section's "block". | ||
A section begins with a pound and ends with a slash. That is, `{{#person}}` begins a `person` section, while `{{/person}}` ends it. The text between the two tags is referred to as that section's "block". | ||
@@ -133,4 +110,3 @@ The behavior of the section is determined by the value of the key. | ||
If the `person` key exists and has a value of `null`, `undefined`, or `false`, | ||
or is an empty list, the block will not be rendered. | ||
If the `person` key exists and has a value of `null`, `undefined`, or `false`, or is an empty list, the block will not be rendered. | ||
@@ -156,8 +132,5 @@ View: | ||
If the `person` key exists and is not `null`, `undefined`, or `false`, and is | ||
not an empty list the block will be rendered one or more times. | ||
If the `person` key exists and is not `null`, `undefined`, or `false`, and is not an empty list the block will be rendered one or more times. | ||
When the value is a list, the block is rendered once for each item in the list. | ||
The context of the block is set to the current item in the list for each | ||
iteration. In this way we can loop over collections. | ||
When the value is a list, the block is rendered once for each item in the list. The context of the block is set to the current item in the list for each iteration. In this way we can loop over collections. | ||
@@ -186,4 +159,3 @@ View: | ||
When looping over an array of strings, a `.` can be used to refer to the current | ||
item in the list. | ||
When looping over an array of strings, a `.` can be used to refer to the current item in the list. | ||
@@ -209,4 +181,3 @@ View: | ||
If the value of a section variable is a function, it will be called in the | ||
context of the current item in the list on each iteration. | ||
If the value of a section variable is a function, it will be called in the context of the current item in the list on each iteration. | ||
@@ -242,6 +213,3 @@ View: | ||
If the value of a section key is a function, it is called with the section's | ||
literal block of text, un-rendered, as its first argument. The second argument | ||
is a special rendering function that uses the current view as its view argument. | ||
It is called in the context of the current view object. | ||
If the value of a section key is a function, it is called with the section's literal block of text, un-rendered, as its first argument. The second argument is a special rendering function that uses the current view as its view argument. It is called in the context of the current view object. | ||
@@ -269,5 +237,3 @@ View: | ||
An inverted section opens with `{{^section}}` instead of `{{#section}}`. The | ||
block of an inverted section is rendered only if the value of that section's tag | ||
is `null`, `undefined`, `false`, or an empty list. | ||
An inverted section opens with `{{^section}}` instead of `{{#section}}`. The block of an inverted section is rendered only if the value of that section's tag is `null`, `undefined`, `false`, or an empty list. | ||
@@ -305,4 +271,3 @@ View: | ||
Partials are rendered at runtime (as opposed to compile time), so recursive | ||
partials are possible. Just avoid infinite loops. | ||
Partials are rendered at runtime (as opposed to compile time), so recursive partials are possible. Just avoid infinite loops. | ||
@@ -317,5 +282,3 @@ They also inherit the calling context. Whereas in ERB you may have this: | ||
Why? Because the `next_more.mustache` file will inherit the `size` and `start` | ||
variables from the calling context. In this way you may want to think of | ||
partials as includes, or template expansion, even though it's not literally true. | ||
Why? Because the `next_more.mustache` file will inherit the `size` and `start` variables from the calling context. In this way you may want to think of partials as includes, or template expansion, even though it's not literally true. | ||
@@ -340,10 +303,7 @@ For example, this template and partial: | ||
In mustache.js an object of partials may be passed as the third argument to | ||
`Mustache.render`. The object should be keyed by the name of the partial, and | ||
its value should be the partial text. | ||
In mustache.js an object of partials may be passed as the third argument to `Mustache.render`. The object should be keyed by the name of the partial, and its value should be the partial text. | ||
### Set Delimiter | ||
Set Delimiter tags start with an equals sign and change the tag delimiters from | ||
`{{` and `}}` to custom strings. | ||
Set Delimiter tags start with an equals sign and change the tag delimiters from `{{` and `}}` to custom strings. | ||
@@ -358,9 +318,5 @@ Consider the following contrived example: | ||
Here we have a list with three items. The first item uses the default tag style, | ||
the second uses ERB style as defined by the Set Delimiter tag, and the third | ||
returns to the default style after yet another Set Delimiter declaration. | ||
Here we have a list with three items. The first item uses the default tag style, the second uses ERB style as defined by the Set Delimiter tag, and the third returns to the default style after yet another Set Delimiter declaration. | ||
According to [ctemplates](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." | ||
According 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." | ||
@@ -371,4 +327,3 @@ Custom delimiters may not contain whitespace or the equals sign. | ||
mustache.js may be built specifically for several different client libraries, | ||
including the following: | ||
mustache.js may be built specifically for several different client libraries, including the following: | ||
@@ -381,4 +336,3 @@ - [jQuery](http://jquery.com/) | ||
These may be built using [Rake](http://rake.rubyforge.org/) and one of the | ||
following commands: | ||
These may be built using [Rake](http://rake.rubyforge.org/) and one of the following commands: | ||
@@ -393,5 +347,3 @@ $ rake jquery | ||
The 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/). | ||
The 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/). | ||
@@ -404,4 +356,3 @@ $ npm install -g vows | ||
The test suite consists of both unit and integration tests. If a template isn't | ||
rendering correctly for you, you can make a test for it by doing the following: | ||
The test suite consists of both unit and integration tests. If a template isn't rendering correctly for you, you can make a test for it by doing the following: | ||
@@ -408,0 +359,0 @@ 1. Create a template file named `mytest.mustache` in the `test/_files` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60824
1
170
1059
375