Commit 82f6a647feb654251000155428951b3692c870e3
1 parent
3ffa38aa
Exists in
master
and in
7 other branches
Inclusao da biblioteca Mustache
Showing
197 changed files
with
2605 additions
and
0 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 197 files displayed.
admin/admin.db
No preview for this file type
... | ... | @@ -0,0 +1,60 @@ |
1 | += 0.8.2 / 17 Mar 2014 | |
2 | + | |
3 | + * Supporting Bower through a bower.json file. | |
4 | + | |
5 | += 0.8.1 / 3 Jan 2014 | |
6 | + | |
7 | + * Fix usage of partial templates. | |
8 | + | |
9 | += 0.8.0 / 2 Dec 2013 | |
10 | + | |
11 | + * Remove compile* writer functions, use mustache.parse instead. Smaller API. | |
12 | + * Throw an error when rendering a template that contains higher-order sections and | |
13 | + the original template is not provided. | |
14 | + * Remove low-level Context.make function. | |
15 | + * Better code readability and inline documentation. | |
16 | + * Stop caching templates by name. | |
17 | + | |
18 | += 0.7.3 / 5 Nov 2013 | |
19 | + | |
20 | + * Don't require the original template to be passed to the rendering function | |
21 | + when using compiled templates. This is still required when using higher-order | |
22 | + functions in order to be able to extract the portion of the template | |
23 | + that was contained by that section. Fixes #262. | |
24 | + * Performance improvements. | |
25 | + | |
26 | += 0.7.2 / 27 Dec 2012 | |
27 | + | |
28 | + * Fixed a rendering bug (#274) when using nested higher-order sections. | |
29 | + * Better error reporting on failed parse. | |
30 | + * Converted tests to use mocha instead of vows. | |
31 | + | |
32 | += 0.7.1 / 6 Dec 2012 | |
33 | + | |
34 | + * Handle empty templates gracefully. Fixes #265, #267, and #270. | |
35 | + * Cache partials by template, not by name. Fixes #257. | |
36 | + * Added Mustache.compileTokens to compile the output of Mustache.parse. Fixes | |
37 | + #258. | |
38 | + | |
39 | += 0.7.0 / 10 Sep 2012 | |
40 | + | |
41 | + * Rename Renderer => Writer. | |
42 | + * Allow partials to be loaded dynamically using a callback (thanks | |
43 | + @TiddoLangerak for the suggestion). | |
44 | + * Fixed a bug with higher-order sections that prevented them from being | |
45 | + passed the raw text of the section from the original template. | |
46 | + * More concise token format. Tokens also include start/end indices in the | |
47 | + original template. | |
48 | + * High-level API is consistent with the Writer API. | |
49 | + * Allow partials to be passed to the pre-compiled function (thanks | |
50 | + @fallenice). | |
51 | + * Don't use eval (thanks @cweider). | |
52 | + | |
53 | += 0.6.0 / 31 Aug 2012 | |
54 | + | |
55 | + * Use JavaScript's definition of falsy when determining whether to render an | |
56 | + inverted section or not. Issue #186. | |
57 | + * Use Mustache.escape to escape values inside {{}}. This function may be | |
58 | + reassigned to alter the default escaping behavior. Issue #244. | |
59 | + * Fixed a bug that clashed with QUnit (thanks @kannix). | |
60 | + * Added volo support (thanks @guybedford). | ... | ... |
... | ... | @@ -0,0 +1,10 @@ |
1 | +The MIT License | |
2 | + | |
3 | +Copyright (c) 2009 Chris Wanstrath (Ruby) | |
4 | +Copyright (c) 2010-2014 Jan Lehnardt (JavaScript) | |
5 | + | |
6 | +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: | |
7 | + | |
8 | +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
9 | + | |
10 | +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. | ... | ... |
... | ... | @@ -0,0 +1,495 @@ |
1 | +# mustache.js - Logic-less {{mustache}} templates with JavaScript | |
2 | + | |
3 | +> What could be more logical awesome than no logic at all? | |
4 | + | |
5 | +[mustache.js](http://github.com/janl/mustache.js) is an implementation of the [mustache](http://mustache.github.com/) template system in JavaScript. | |
6 | + | |
7 | +[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. | |
8 | + | |
9 | +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. | |
10 | + | |
11 | +For a language-agnostic overview of mustache's template syntax, see the `mustache(5)` [manpage](http://mustache.github.com/mustache.5.html). | |
12 | + | |
13 | +## Where to use mustache.js? | |
14 | + | |
15 | +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. | |
16 | + | |
17 | +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. | |
18 | + | |
19 | +## Who uses mustache.js? | |
20 | + | |
21 | +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! | |
22 | + | |
23 | +## Usage | |
24 | + | |
25 | +Below is quick example how to use mustache.js: | |
26 | + | |
27 | +```js | |
28 | +var view = { | |
29 | + title: "Joe", | |
30 | + calc: function () { | |
31 | + return 2 + 4; | |
32 | + } | |
33 | +}; | |
34 | + | |
35 | +var output = Mustache.render("{{title}} spends {{calc}}", view); | |
36 | +``` | |
37 | + | |
38 | +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. | |
39 | + | |
40 | +## Templates | |
41 | + | |
42 | +A [mustache](http://mustache.github.com/) template is a string that contains any number of mustache tags. Tags are indicated by the double mustaches that surround them. `{{person}}` is a tag, as is `{{#person}}`. In both examples we refer to `person` as the tag's key. There are several types of tags available in mustache.js, described below. | |
43 | + | |
44 | +There are several techniques that can be used to load templates and hand them to mustache.js, here are two of them: | |
45 | + | |
46 | +#### Include Templates | |
47 | + | |
48 | +If you need a template for a dynamic part in a static website, you can consider including the template in the static HTML file to avoid loading templates separately. Here's a small example using `jQuery`: | |
49 | + | |
50 | +```html | |
51 | +<html> | |
52 | +<body onload="loadUser"> | |
53 | +<div id="target">Loading...</div> | |
54 | +<script id="template" type="x-tmpl-mustache"> | |
55 | +Hello {{ name }}! | |
56 | +</script> | |
57 | +</body> | |
58 | +</html> | |
59 | +``` | |
60 | + | |
61 | +```js | |
62 | +function loadUser() { | |
63 | + var template = $('#template').html(); | |
64 | + Mustache.parse(template); // optional, speeds up future uses | |
65 | + var rendered = Mustache.render(template, {name: "Luke"}); | |
66 | + $('#target').html(rendered); | |
67 | +} | |
68 | +``` | |
69 | + | |
70 | +#### Load External Templates | |
71 | + | |
72 | +If your templates reside in individual files, you can load them asynchronously and render them when they arrive. Another example using `jQuery`: | |
73 | + | |
74 | +```js | |
75 | +function loadUser() { | |
76 | + $.get('template.mst', function(template) { | |
77 | + var rendered = Mustache.render(template, {name: "Luke"}); | |
78 | + $('#target').html(rendered); | |
79 | + }); | |
80 | +} | |
81 | +``` | |
82 | + | |
83 | +### Variables | |
84 | + | |
85 | +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. | |
86 | + | |
87 | +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. | |
88 | + | |
89 | +View: | |
90 | + | |
91 | +```json | |
92 | +{ | |
93 | + "name": "Chris", | |
94 | + "company": "<b>GitHub</b>" | |
95 | +} | |
96 | +``` | |
97 | + | |
98 | +Template: | |
99 | + | |
100 | +```html | |
101 | +* {{name}} | |
102 | +* {{age}} | |
103 | +* {{company}} | |
104 | +* {{{company}}} | |
105 | +* {{&company}} | |
106 | +``` | |
107 | + | |
108 | +Output: | |
109 | + | |
110 | +```html | |
111 | +* Chris | |
112 | +* | |
113 | +* <b>GitHub</b> | |
114 | +* <b>GitHub</b> | |
115 | +* <b>GitHub</b> | |
116 | +``` | |
117 | + | |
118 | +JavaScript's dot notation may be used to access keys that are properties of objects in a view. | |
119 | + | |
120 | +View: | |
121 | + | |
122 | +```json | |
123 | +{ | |
124 | + "name": { | |
125 | + "first": "Michael", | |
126 | + "last": "Jackson" | |
127 | + }, | |
128 | + "age": "RIP" | |
129 | +} | |
130 | +``` | |
131 | + | |
132 | +Template: | |
133 | + | |
134 | +```html | |
135 | +* {{name.first}} {{name.last}} | |
136 | +* {{age}} | |
137 | +``` | |
138 | + | |
139 | +Output: | |
140 | + | |
141 | +```html | |
142 | +* Michael Jackson | |
143 | +* RIP | |
144 | +``` | |
145 | + | |
146 | +### Sections | |
147 | + | |
148 | +Sections render blocks of text one or more times, depending on the value of the key in the current context. | |
149 | + | |
150 | +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". | |
151 | + | |
152 | +The behavior of the section is determined by the value of the key. | |
153 | + | |
154 | +#### False Values or Empty Lists | |
155 | + | |
156 | +If the `person` key does not exist, or exists and has a value of `null`, `undefined`, `false`, `0`, or `NaN`, or is an empty string or an empty list, the block will not be rendered. | |
157 | + | |
158 | +View: | |
159 | + | |
160 | +```json | |
161 | +{ | |
162 | + "person": false | |
163 | +} | |
164 | +``` | |
165 | + | |
166 | +Template: | |
167 | + | |
168 | +```html | |
169 | +Shown. | |
170 | +{{#person}} | |
171 | +Never shown! | |
172 | +{{/person}} | |
173 | +``` | |
174 | + | |
175 | +Output: | |
176 | + | |
177 | +```html | |
178 | +Shown. | |
179 | +``` | |
180 | + | |
181 | +#### Non-Empty Lists | |
182 | + | |
183 | +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. | |
184 | + | |
185 | +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 | + | |
187 | +View: | |
188 | + | |
189 | +```json | |
190 | +{ | |
191 | + "stooges": [ | |
192 | + { "name": "Moe" }, | |
193 | + { "name": "Larry" }, | |
194 | + { "name": "Curly" } | |
195 | + ] | |
196 | +} | |
197 | +``` | |
198 | + | |
199 | +Template: | |
200 | + | |
201 | +```html | |
202 | +{{#stooges}} | |
203 | +<b>{{name}}</b> | |
204 | +{{/stooges}} | |
205 | +``` | |
206 | + | |
207 | +Output: | |
208 | + | |
209 | +```html | |
210 | +<b>Moe</b> | |
211 | +<b>Larry</b> | |
212 | +<b>Curly</b> | |
213 | +``` | |
214 | + | |
215 | +When looping over an array of strings, a `.` can be used to refer to the current item in the list. | |
216 | + | |
217 | +View: | |
218 | + | |
219 | +```json | |
220 | +{ | |
221 | + "musketeers": ["Athos", "Aramis", "Porthos", "D'Artagnan"] | |
222 | +} | |
223 | +``` | |
224 | + | |
225 | +Template: | |
226 | + | |
227 | +```html | |
228 | +{{#musketeers}} | |
229 | +* {{.}} | |
230 | +{{/musketeers}} | |
231 | +``` | |
232 | + | |
233 | +Output: | |
234 | + | |
235 | +```html | |
236 | +* Athos | |
237 | +* Aramis | |
238 | +* Porthos | |
239 | +* D'Artagnan | |
240 | +``` | |
241 | + | |
242 | +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. | |
243 | + | |
244 | +View: | |
245 | + | |
246 | +```js | |
247 | +{ | |
248 | + "beatles": [ | |
249 | + { "firstName": "John", "lastName": "Lennon" }, | |
250 | + { "firstName": "Paul", "lastName": "McCartney" }, | |
251 | + { "firstName": "George", "lastName": "Harrison" }, | |
252 | + { "firstName": "Ringo", "lastName": "Starr" } | |
253 | + ], | |
254 | + "name": function () { | |
255 | + return this.firstName + " " + this.lastName; | |
256 | + } | |
257 | +} | |
258 | +``` | |
259 | + | |
260 | +Template: | |
261 | + | |
262 | +```html | |
263 | +{{#beatles}} | |
264 | +* {{name}} | |
265 | +{{/beatles}} | |
266 | +``` | |
267 | + | |
268 | +Output: | |
269 | + | |
270 | +```html | |
271 | +* John Lennon | |
272 | +* Paul McCartney | |
273 | +* George Harrison | |
274 | +* Ringo Starr | |
275 | +``` | |
276 | + | |
277 | +#### Functions | |
278 | + | |
279 | +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. | |
280 | + | |
281 | +View: | |
282 | + | |
283 | +```js | |
284 | +{ | |
285 | + "name": "Tater", | |
286 | + "bold": function () { | |
287 | + return function (text, render) { | |
288 | + return "<b>" + render(text) + "</b>"; | |
289 | + } | |
290 | + } | |
291 | +} | |
292 | +``` | |
293 | + | |
294 | +Template: | |
295 | + | |
296 | +```html | |
297 | +{{#bold}}Hi {{name}}.{{/bold}} | |
298 | +``` | |
299 | + | |
300 | +Output: | |
301 | + | |
302 | +```html | |
303 | +<b>Hi Tater.</b> | |
304 | +``` | |
305 | + | |
306 | +### Inverted Sections | |
307 | + | |
308 | +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. | |
309 | + | |
310 | +View: | |
311 | + | |
312 | +```json | |
313 | +{ | |
314 | + "repos": [] | |
315 | +} | |
316 | +``` | |
317 | + | |
318 | +Template: | |
319 | + | |
320 | +```html | |
321 | +{{#repos}}<b>{{name}}</b>{{/repos}} | |
322 | +{{^repos}}No repos :({{/repos}} | |
323 | +``` | |
324 | + | |
325 | +Output: | |
326 | + | |
327 | +```html | |
328 | +No repos :( | |
329 | +``` | |
330 | + | |
331 | +### Comments | |
332 | + | |
333 | +Comments begin with a bang and are ignored. The following template: | |
334 | + | |
335 | +```html | |
336 | +<h1>Today{{! ignore me }}.</h1> | |
337 | +``` | |
338 | + | |
339 | +Will render as follows: | |
340 | + | |
341 | +```html | |
342 | +<h1>Today.</h1> | |
343 | +``` | |
344 | + | |
345 | +Comments may contain newlines. | |
346 | + | |
347 | +### Partials | |
348 | + | |
349 | +Partials begin with a greater than sign, like {{> box}}. | |
350 | + | |
351 | +Partials are rendered at runtime (as opposed to compile time), so recursive partials are possible. Just avoid infinite loops. | |
352 | + | |
353 | +They also inherit the calling context. Whereas in ERB you may have this: | |
354 | + | |
355 | +```html+erb | |
356 | +<%= partial :next_more, :start => start, :size => size %> | |
357 | +``` | |
358 | + | |
359 | +Mustache requires only this: | |
360 | + | |
361 | +```html | |
362 | +{{> next_more}} | |
363 | +``` | |
364 | + | |
365 | +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. | |
366 | + | |
367 | +For example, this template and partial: | |
368 | + | |
369 | + base.mustache: | |
370 | + <h2>Names</h2> | |
371 | + {{#names}} | |
372 | + {{> user}} | |
373 | + {{/names}} | |
374 | + | |
375 | + user.mustache: | |
376 | + <strong>{{name}}</strong> | |
377 | + | |
378 | +Can be thought of as a single, expanded template: | |
379 | + | |
380 | +```html | |
381 | +<h2>Names</h2> | |
382 | +{{#names}} | |
383 | + <strong>{{name}}</strong> | |
384 | +{{/names}} | |
385 | +``` | |
386 | + | |
387 | +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. | |
388 | + | |
389 | +```js | |
390 | +Mustache.render(template, view, { | |
391 | + user: userTemplate | |
392 | +}); | |
393 | +``` | |
394 | + | |
395 | +### Set Delimiter | |
396 | + | |
397 | +Set Delimiter tags start with an equals sign and change the tag delimiters from `{{` and `}}` to custom strings. | |
398 | + | |
399 | +Consider the following contrived example: | |
400 | + | |
401 | +``` | |
402 | +* {{ default_tags }} | |
403 | +{{=<% %>=}} | |
404 | +* <% erb_style_tags %> | |
405 | +<%={{ }}=%> | |
406 | +* {{ default_tags_again }} | |
407 | +``` | |
408 | + | |
409 | +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. | |
410 | + | |
411 | +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." | |
412 | + | |
413 | +Custom delimiters may not contain whitespace or the equals sign. | |
414 | + | |
415 | +## Pre-parsing and Caching Templates | |
416 | + | |
417 | +By default, when mustache.js first parses a template it keeps the full parsed token tree in a cache. The next time it sees that same template it skips the parsing step and renders the template much more quickly. If you'd like, you can do this ahead of time using `mustache.parse`. | |
418 | + | |
419 | +```js | |
420 | +Mustache.parse(template); | |
421 | + | |
422 | +// Then, sometime later. | |
423 | +Mustache.render(template, view); | |
424 | +``` | |
425 | + | |
426 | +## Plugins for JavaScript Libraries | |
427 | + | |
428 | +mustache.js may be built specifically for several different client libraries, including the following: | |
429 | + | |
430 | + - [jQuery](http://jquery.com/) | |
431 | + - [MooTools](http://mootools.net/) | |
432 | + - [Dojo](http://www.dojotoolkit.org/) | |
433 | + - [YUI](http://developer.yahoo.com/yui/) | |
434 | + - [qooxdoo](http://qooxdoo.org/) | |
435 | + | |
436 | +These may be built using [Rake](http://rake.rubyforge.org/) and one of the following commands: | |
437 | + | |
438 | + $ rake jquery | |
439 | + $ rake mootools | |
440 | + $ rake dojo | |
441 | + $ rake yui3 | |
442 | + $ rake qooxdoo | |
443 | + | |
444 | +## Testing | |
445 | + | |
446 | +The mustache.js test suite uses the [mocha](http://visionmedia.github.com/mocha/) testing framework. In order to run the tests you'll need to install [node](http://nodejs.org/). Once that's done you can install mocha using [npm](http://npmjs.org/). | |
447 | + | |
448 | + $ npm install -g mocha | |
449 | + | |
450 | +You also need to install the sub module containing [Mustache specifications](http://github.com/mustache/spec) in the project root. | |
451 | + | |
452 | + $ git submodule init | |
453 | + $ git submodule update | |
454 | + | |
455 | +Then run the tests. | |
456 | + | |
457 | + $ mocha test | |
458 | + | |
459 | +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: | |
460 | + | |
461 | + 1. Create a template file named `mytest.mustache` in the `test/_files` | |
462 | + directory. Replace `mytest` with the name of your test. | |
463 | + 2. Create a corresponding view file named `mytest.js` in the same directory. | |
464 | + This file should contain a JavaScript object literal enclosed in | |
465 | + parentheses. See any of the other view files for an example. | |
466 | + 3. Create a file with the expected output in `mytest.txt` in the same | |
467 | + directory. | |
468 | + | |
469 | +Then, you can run the test with: | |
470 | + | |
471 | + $ TEST=mytest mocha test/render-test.js | |
472 | + | |
473 | +## Thanks | |
474 | + | |
475 | +mustache.js wouldn't kick ass if it weren't for these fine souls: | |
476 | + | |
477 | + * Chris Wanstrath / defunkt | |
478 | + * Alexander Lang / langalex | |
479 | + * Sebastian Cohnen / tisba | |
480 | + * J Chris Anderson / jchris | |
481 | + * Tom Robinson / tlrobinson | |
482 | + * Aaron Quint / quirkey | |
483 | + * Douglas Crockford | |
484 | + * Nikita Vasilyev / NV | |
485 | + * Elise Wood / glytch | |
486 | + * Damien Mathieu / dmathieu | |
487 | + * Jakub Kuźma / qoobaa | |
488 | + * Will Leinweber / will | |
489 | + * dpree | |
490 | + * Jason Smith / jhs | |
491 | + * Aaron Gibralter / agibralter | |
492 | + * Ross Boucher / boucher | |
493 | + * Matt Sanford / mzsanford | |
494 | + * Ben Cherry / bcherry | |
495 | + * Michael Jackson / mjijackson | ... | ... |
... | ... | @@ -0,0 +1,69 @@ |
1 | +require 'rake' | |
2 | +require 'rake/clean' | |
3 | + | |
4 | +task :default => :test | |
5 | + | |
6 | +def minified_file | |
7 | + ENV['FILE'] || 'mustache.min.js' | |
8 | +end | |
9 | + | |
10 | +task :install_mocha do | |
11 | + sh "npm install -g mocha" if `which mocha`.empty? | |
12 | +end | |
13 | + | |
14 | +task :install_uglify do | |
15 | + sh "npm install -g uglify-js" if `which uglifyjs`.empty? | |
16 | +end | |
17 | + | |
18 | +task :install_jshint do | |
19 | + sh "npm install -g jshint" if `which jshint`.empty? | |
20 | +end | |
21 | + | |
22 | +desc "Run all tests" | |
23 | +task :test => :install_mocha do | |
24 | + sh "mocha test" | |
25 | +end | |
26 | + | |
27 | +desc "Make a compressed build in #{minified_file}" | |
28 | +task :minify => :install_uglify do | |
29 | + sh "uglifyjs mustache.js > #{minified_file}" | |
30 | +end | |
31 | + | |
32 | +desc "Run JSHint" | |
33 | +task :hint => :install_jshint do | |
34 | + sh "jshint mustache.js" | |
35 | +end | |
36 | + | |
37 | +# Creates a task that uses the various template wrappers to make a wrapped | |
38 | +# output file. There is some extra complexity because Dojo and YUI use | |
39 | +# different final locations. | |
40 | +def templated_build(name, final_location=nil) | |
41 | + short = name.downcase | |
42 | + source = File.join("wrappers", short) | |
43 | + dependencies = ["mustache.js"] + Dir.glob("#{source}/*.tpl.*") | |
44 | + target_js = final_location.nil? ? "#{short}.mustache.js" : "mustache.js" | |
45 | + | |
46 | + desc "Package for #{name}" | |
47 | + task short.to_sym => dependencies do | |
48 | + puts "Packaging for #{name}" | |
49 | + | |
50 | + mkdir_p final_location unless final_location.nil? | |
51 | + | |
52 | + sources = [ "#{source}/mustache.js.pre", 'mustache.js', "#{source}/mustache.js.post" ] | |
53 | + relative_name = "#{final_location || '.'}/#{target_js}" | |
54 | + | |
55 | + open(relative_name, 'w') do |f| | |
56 | + sources.each {|source| f << File.read(source) } | |
57 | + end | |
58 | + | |
59 | + puts "Done, see #{relative_name}" | |
60 | + end | |
61 | + | |
62 | + CLEAN.include(final_location.nil? ? target_js : final_location) | |
63 | +end | |
64 | + | |
65 | +templated_build "jQuery" | |
66 | +templated_build "MooTools" | |
67 | +templated_build "Dojo", "dojox/string" | |
68 | +templated_build "YUI3", "yui3/mustache" | |
69 | +templated_build "qooxdoo" | ... | ... |
... | ... | @@ -0,0 +1,21 @@ |
1 | +{ | |
2 | + "name": "mustache.js", | |
3 | + "main": "mustache.js", | |
4 | + "version": "0.8.2", | |
5 | + "homepage": "https://github.com/janl/mustache.js", | |
6 | + "authors": [ | |
7 | + "mustache.js Authors <http://github.com/janl/mustache.js>" | |
8 | + ], | |
9 | + "description": "Logic-less {{mustache}} templates with JavaScript", | |
10 | + "keywords": ["mustache", "template", "templates", "ejs"], | |
11 | + "moduleType": [ | |
12 | + "amd", | |
13 | + "globals", | |
14 | + "node" | |
15 | + ], | |
16 | + "license": "MIT", | |
17 | + "ignore": [ | |
18 | + "**/.*", | |
19 | + "test" | |
20 | + ] | |
21 | +} | ... | ... |
... | ... | @@ -0,0 +1,578 @@ |
1 | +/*! | |
2 | + * mustache.js - Logic-less {{mustache}} templates with JavaScript | |
3 | + * http://github.com/janl/mustache.js | |
4 | + */ | |
5 | + | |
6 | +/*global define: false*/ | |
7 | + | |
8 | +(function (global, factory) { | |
9 | + if (typeof exports === "object" && exports) { | |
10 | + factory(exports); // CommonJS | |
11 | + } else if (typeof define === "function" && define.amd) { | |
12 | + define(['exports'], factory); // AMD | |
13 | + } else { | |
14 | + factory(global.Mustache = {}); // <script> | |
15 | + } | |
16 | +}(this, function (mustache) { | |
17 | + | |
18 | + var Object_toString = Object.prototype.toString; | |
19 | + var isArray = Array.isArray || function (object) { | |
20 | + return Object_toString.call(object) === '[object Array]'; | |
21 | + }; | |
22 | + | |
23 | + function isFunction(object) { | |
24 | + return typeof object === 'function'; | |
25 | + } | |
26 | + | |
27 | + function escapeRegExp(string) { | |
28 | + return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&"); | |
29 | + } | |
30 | + | |
31 | + // Workaround for https://issues.apache.org/jira/browse/COUCHDB-577 | |
32 | + // See https://github.com/janl/mustache.js/issues/189 | |
33 | + var RegExp_test = RegExp.prototype.test; | |
34 | + function testRegExp(re, string) { | |
35 | + return RegExp_test.call(re, string); | |
36 | + } | |
37 | + | |
38 | + var nonSpaceRe = /\S/; | |
39 | + function isWhitespace(string) { | |
40 | + return !testRegExp(nonSpaceRe, string); | |
41 | + } | |
42 | + | |
43 | + var entityMap = { | |
44 | + "&": "&", | |
45 | + "<": "<", | |
46 | + ">": ">", | |
47 | + '"': '"', | |
48 | + "'": ''', | |
49 | + "/": '/' | |
50 | + }; | |
51 | + | |
52 | + function escapeHtml(string) { | |
53 | + return String(string).replace(/[&<>"'\/]/g, function (s) { | |
54 | + return entityMap[s]; | |
55 | + }); | |
56 | + } | |
57 | + | |
58 | + var whiteRe = /\s*/; | |
59 | + var spaceRe = /\s+/; | |
60 | + var equalsRe = /\s*=/; | |
61 | + var curlyRe = /\s*\}/; | |
62 | + var tagRe = /#|\^|\/|>|\{|&|=|!/; | |
63 | + | |
64 | + /** | |
65 | + * Breaks up the given `template` string into a tree of tokens. If the `tags` | |
66 | + * argument is given here it must be an array with two string values: the | |
67 | + * opening and closing tags used in the template (e.g. [ "<%", "%>" ]). Of | |
68 | + * course, the default is to use mustaches (i.e. mustache.tags). | |
69 | + * | |
70 | + * A token is an array with at least 4 elements. The first element is the | |
71 | + * mustache symbol that was used inside the tag, e.g. "#" or "&". If the tag | |
72 | + * did not contain a symbol (i.e. {{myValue}}) this element is "name". For | |
73 | + * all text that appears outside a symbol this element is "text". | |
74 | + * | |
75 | + * The second element of a token is its "value". For mustache tags this is | |
76 | + * whatever else was inside the tag besides the opening symbol. For text tokens | |
77 | + * this is the text itself. | |
78 | + * | |
79 | + * The third and fourth elements of the token are the start and end indices, | |
80 | + * respectively, of the token in the original template. | |
81 | + * | |
82 | + * Tokens that are the root node of a subtree contain two more elements: 1) an | |
83 | + * array of tokens in the subtree and 2) the index in the original template at | |
84 | + * which the closing tag for that section begins. | |
85 | + */ | |
86 | + function parseTemplate(template, tags) { | |
87 | + if (!template) | |
88 | + return []; | |
89 | + | |
90 | + var sections = []; // Stack to hold section tokens | |
91 | + var tokens = []; // Buffer to hold the tokens | |
92 | + var spaces = []; // Indices of whitespace tokens on the current line | |
93 | + var hasTag = false; // Is there a {{tag}} on the current line? | |
94 | + var nonSpace = false; // Is there a non-space char on the current line? | |
95 | + | |
96 | + // Strips all whitespace tokens array for the current line | |
97 | + // if there was a {{#tag}} on it and otherwise only space. | |
98 | + function stripSpace() { | |
99 | + if (hasTag && !nonSpace) { | |
100 | + while (spaces.length) | |
101 | + delete tokens[spaces.pop()]; | |
102 | + } else { | |
103 | + spaces = []; | |
104 | + } | |
105 | + | |
106 | + hasTag = false; | |
107 | + nonSpace = false; | |
108 | + } | |
109 | + | |
110 | + var openingTagRe, closingTagRe, closingCurlyRe; | |
111 | + function compileTags(tags) { | |
112 | + if (typeof tags === 'string') | |
113 | + tags = tags.split(spaceRe, 2); | |
114 | + | |
115 | + if (!isArray(tags) || tags.length !== 2) | |
116 | + throw new Error('Invalid tags: ' + tags); | |
117 | + | |
118 | + openingTagRe = new RegExp(escapeRegExp(tags[0]) + '\\s*'); | |
119 | + closingTagRe = new RegExp('\\s*' + escapeRegExp(tags[1])); | |
120 | + closingCurlyRe = new RegExp('\\s*' + escapeRegExp('}' + tags[1])); | |
121 | + } | |
122 | + | |
123 | + compileTags(tags || mustache.tags); | |
124 | + | |
125 | + var scanner = new Scanner(template); | |
126 | + | |
127 | + var start, type, value, chr, token, openSection; | |
128 | + while (!scanner.eos()) { | |
129 | + start = scanner.pos; | |
130 | + | |
131 | + // Match any text between tags. | |
132 | + value = scanner.scanUntil(openingTagRe); | |
133 | + | |
134 | + if (value) { | |
135 | + for (var i = 0, valueLength = value.length; i < valueLength; ++i) { | |
136 | + chr = value.charAt(i); | |
137 | + | |
138 | + if (isWhitespace(chr)) { | |
139 | + spaces.push(tokens.length); | |
140 | + } else { | |
141 | + nonSpace = true; | |
142 | + } | |
143 | + | |
144 | + tokens.push([ 'text', chr, start, start + 1 ]); | |
145 | + start += 1; | |
146 | + | |
147 | + // Check for whitespace on the current line. | |
148 | + if (chr === '\n') | |
149 | + stripSpace(); | |
150 | + } | |
151 | + } | |
152 | + | |
153 | + // Match the opening tag. | |
154 | + if (!scanner.scan(openingTagRe)) | |
155 | + break; | |
156 | + | |
157 | + hasTag = true; | |
158 | + | |
159 | + // Get the tag type. | |
160 | + type = scanner.scan(tagRe) || 'name'; | |
161 | + scanner.scan(whiteRe); | |
162 | + | |
163 | + // Get the tag value. | |
164 | + if (type === '=') { | |
165 | + value = scanner.scanUntil(equalsRe); | |
166 | + scanner.scan(equalsRe); | |
167 | + scanner.scanUntil(closingTagRe); | |
168 | + } else if (type === '{') { | |
169 | + value = scanner.scanUntil(closingCurlyRe); | |
170 | + scanner.scan(curlyRe); | |
171 | + scanner.scanUntil(closingTagRe); | |
172 | + type = '&'; | |
173 | + } else { | |
174 | + value = scanner.scanUntil(closingTagRe); | |
175 | + } | |
176 | + | |
177 | + // Match the closing tag. | |
178 | + if (!scanner.scan(closingTagRe)) | |
179 | + throw new Error('Unclosed tag at ' + scanner.pos); | |
180 | + | |
181 | + token = [ type, value, start, scanner.pos ]; | |
182 | + tokens.push(token); | |
183 | + | |
184 | + if (type === '#' || type === '^') { | |
185 | + sections.push(token); | |
186 | + } else if (type === '/') { | |
187 | + // Check section nesting. | |
188 | + openSection = sections.pop(); | |
189 | + | |
190 | + if (!openSection) | |
191 | + throw new Error('Unopened section "' + value + '" at ' + start); | |
192 | + | |
193 | + if (openSection[1] !== value) | |
194 | + throw new Error('Unclosed section "' + openSection[1] + '" at ' + start); | |
195 | + } else if (type === 'name' || type === '{' || type === '&') { | |
196 | + nonSpace = true; | |
197 | + } else if (type === '=') { | |
198 | + // Set the tags for the next time around. | |
199 | + compileTags(value); | |
200 | + } | |
201 | + } | |
202 | + | |
203 | + // Make sure there are no open sections when we're done. | |
204 | + openSection = sections.pop(); | |
205 | + | |
206 | + if (openSection) | |
207 | + throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos); | |
208 | + | |
209 | + return nestTokens(squashTokens(tokens)); | |
210 | + } | |
211 | + | |
212 | + /** | |
213 | + * Combines the values of consecutive text tokens in the given `tokens` array | |
214 | + * to a single token. | |
215 | + */ | |
216 | + function squashTokens(tokens) { | |
217 | + var squashedTokens = []; | |
218 | + | |
219 | + var token, lastToken; | |
220 | + for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) { | |
221 | + token = tokens[i]; | |
222 | + | |
223 | + if (token) { | |
224 | + if (token[0] === 'text' && lastToken && lastToken[0] === 'text') { | |
225 | + lastToken[1] += token[1]; | |
226 | + lastToken[3] = token[3]; | |
227 | + } else { | |
228 | + squashedTokens.push(token); | |
229 | + lastToken = token; | |
230 | + } | |
231 | + } | |
232 | + } | |
233 | + | |
234 | + return squashedTokens; | |
235 | + } | |
236 | + | |
237 | + /** | |
238 | + * Forms the given array of `tokens` into a nested tree structure where | |
239 | + * tokens that represent a section have two additional items: 1) an array of | |
240 | + * all tokens that appear in that section and 2) the index in the original | |
241 | + * template that represents the end of that section. | |
242 | + */ | |
243 | + function nestTokens(tokens) { | |
244 | + var nestedTokens = []; | |
245 | + var collector = nestedTokens; | |
246 | + var sections = []; | |
247 | + | |
248 | + var token, section; | |
249 | + for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) { | |
250 | + token = tokens[i]; | |
251 | + | |
252 | + switch (token[0]) { | |
253 | + case '#': | |
254 | + case '^': | |
255 | + collector.push(token); | |
256 | + sections.push(token); | |
257 | + collector = token[4] = []; | |
258 | + break; | |
259 | + case '/': | |
260 | + section = sections.pop(); | |
261 | + section[5] = token[2]; | |
262 | + collector = sections.length > 0 ? sections[sections.length - 1][4] : nestedTokens; | |
263 | + break; | |
264 | + default: | |
265 | + collector.push(token); | |
266 | + } | |
267 | + } | |
268 | + | |
269 | + return nestedTokens; | |
270 | + } | |
271 | + | |
272 | + /** | |
273 | + * A simple string scanner that is used by the template parser to find | |
274 | + * tokens in template strings. | |
275 | + */ | |
276 | + function Scanner(string) { | |
277 | + this.string = string; | |
278 | + this.tail = string; | |
279 | + this.pos = 0; | |
280 | + } | |
281 | + | |
282 | + /** | |
283 | + * Returns `true` if the tail is empty (end of string). | |
284 | + */ | |
285 | + Scanner.prototype.eos = function () { | |
286 | + return this.tail === ""; | |
287 | + }; | |
288 | + | |
289 | + /** | |
290 | + * Tries to match the given regular expression at the current position. | |
291 | + * Returns the matched text if it can match, the empty string otherwise. | |
292 | + */ | |
293 | + Scanner.prototype.scan = function (re) { | |
294 | + var match = this.tail.match(re); | |
295 | + | |
296 | + if (!match || match.index !== 0) | |
297 | + return ''; | |
298 | + | |
299 | + var string = match[0]; | |
300 | + | |
301 | + this.tail = this.tail.substring(string.length); | |
302 | + this.pos += string.length; | |
303 | + | |
304 | + return string; | |
305 | + }; | |
306 | + | |
307 | + /** | |
308 | + * Skips all text until the given regular expression can be matched. Returns | |
309 | + * the skipped string, which is the entire tail if no match can be made. | |
310 | + */ | |
311 | + Scanner.prototype.scanUntil = function (re) { | |
312 | + var index = this.tail.search(re), match; | |
313 | + | |
314 | + switch (index) { | |
315 | + case -1: | |
316 | + match = this.tail; | |
317 | + this.tail = ""; | |
318 | + break; | |
319 | + case 0: | |
320 | + match = ""; | |
321 | + break; | |
322 | + default: | |
323 | + match = this.tail.substring(0, index); | |
324 | + this.tail = this.tail.substring(index); | |
325 | + } | |
326 | + | |
327 | + this.pos += match.length; | |
328 | + | |
329 | + return match; | |
330 | + }; | |
331 | + | |
332 | + /** | |
333 | + * Represents a rendering context by wrapping a view object and | |
334 | + * maintaining a reference to the parent context. | |
335 | + */ | |
336 | + function Context(view, parentContext) { | |
337 | + this.view = view == null ? {} : view; | |
338 | + this.cache = { '.': this.view }; | |
339 | + this.parent = parentContext; | |
340 | + } | |
341 | + | |
342 | + /** | |
343 | + * Creates a new context using the given view with this context | |
344 | + * as the parent. | |
345 | + */ | |
346 | + Context.prototype.push = function (view) { | |
347 | + return new Context(view, this); | |
348 | + }; | |
349 | + | |
350 | + /** | |
351 | + * Returns the value of the given name in this context, traversing | |
352 | + * up the context hierarchy if the value is absent in this context's view. | |
353 | + */ | |
354 | + Context.prototype.lookup = function (name) { | |
355 | + var cache = this.cache; | |
356 | + | |
357 | + var value; | |
358 | + if (name in cache) { | |
359 | + value = cache[name]; | |
360 | + } else { | |
361 | + var context = this, names, index; | |
362 | + | |
363 | + while (context) { | |
364 | + if (name.indexOf('.') > 0) { | |
365 | + value = context.view; | |
366 | + names = name.split('.'); | |
367 | + index = 0; | |
368 | + | |
369 | + while (value != null && index < names.length) | |
370 | + value = value[names[index++]]; | |
371 | + } else { | |
372 | + value = context.view[name]; | |
373 | + } | |
374 | + | |
375 | + if (value != null) | |
376 | + break; | |
377 | + | |
378 | + context = context.parent; | |
379 | + } | |
380 | + | |
381 | + cache[name] = value; | |
382 | + } | |
383 | + | |
384 | + if (isFunction(value)) | |
385 | + value = value.call(this.view); | |
386 | + | |
387 | + return value; | |
388 | + }; | |
389 | + | |
390 | + /** | |
391 | + * A Writer knows how to take a stream of tokens and render them to a | |
392 | + * string, given a context. It also maintains a cache of templates to | |
393 | + * avoid the need to parse the same template twice. | |
394 | + */ | |
395 | + function Writer() { | |
396 | + this.cache = {}; | |
397 | + } | |
398 | + | |
399 | + /** | |
400 | + * Clears all cached templates in this writer. | |
401 | + */ | |
402 | + Writer.prototype.clearCache = function () { | |
403 | + this.cache = {}; | |
404 | + }; | |
405 | + | |
406 | + /** | |
407 | + * Parses and caches the given `template` and returns the array of tokens | |
408 | + * that is generated from the parse. | |
409 | + */ | |
410 | + Writer.prototype.parse = function (template, tags) { | |
411 | + var cache = this.cache; | |
412 | + var tokens = cache[template]; | |
413 | + | |
414 | + if (tokens == null) | |
415 | + tokens = cache[template] = parseTemplate(template, tags); | |
416 | + | |
417 | + return tokens; | |
418 | + }; | |
419 | + | |
420 | + /** | |
421 | + * High-level method that is used to render the given `template` with | |
422 | + * the given `view`. | |
423 | + * | |
424 | + * The optional `partials` argument may be an object that contains the | |
425 | + * names and templates of partials that are used in the template. It may | |
426 | + * also be a function that is used to load partial templates on the fly | |
427 | + * that takes a single argument: the name of the partial. | |
428 | + */ | |
429 | + Writer.prototype.render = function (template, view, partials) { | |
430 | + var tokens = this.parse(template); | |
431 | + var context = (view instanceof Context) ? view : new Context(view); | |
432 | + return this.renderTokens(tokens, context, partials, template); | |
433 | + }; | |
434 | + | |
435 | + /** | |
436 | + * Low-level method that renders the given array of `tokens` using | |
437 | + * the given `context` and `partials`. | |
438 | + * | |
439 | + * Note: The `originalTemplate` is only ever used to extract the portion | |
440 | + * of the original template that was contained in a higher-order section. | |
441 | + * If the template doesn't use higher-order sections, this argument may | |
442 | + * be omitted. | |
443 | + */ | |
444 | + Writer.prototype.renderTokens = function (tokens, context, partials, originalTemplate) { | |
445 | + var buffer = ''; | |
446 | + | |
447 | + // This function is used to render an arbitrary template | |
448 | + // in the current context by higher-order sections. | |
449 | + var self = this; | |
450 | + function subRender(template) { | |
451 | + return self.render(template, context, partials); | |
452 | + } | |
453 | + | |
454 | + var token, value; | |
455 | + for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) { | |
456 | + token = tokens[i]; | |
457 | + | |
458 | + switch (token[0]) { | |
459 | + case '#': | |
460 | + value = context.lookup(token[1]); | |
461 | + | |
462 | + if (!value) | |
463 | + continue; | |
464 | + | |
465 | + if (isArray(value)) { | |
466 | + for (var j = 0, valueLength = value.length; j < valueLength; ++j) { | |
467 | + buffer += this.renderTokens(token[4], context.push(value[j]), partials, originalTemplate); | |
468 | + } | |
469 | + } else if (typeof value === 'object' || typeof value === 'string') { | |
470 | + buffer += this.renderTokens(token[4], context.push(value), partials, originalTemplate); | |
471 | + } else if (isFunction(value)) { | |
472 | + if (typeof originalTemplate !== 'string') | |
473 | + throw new Error('Cannot use higher-order sections without the original template'); | |
474 | + | |
475 | + // Extract the portion of the original template that the section contains. | |
476 | + value = value.call(context.view, originalTemplate.slice(token[3], token[5]), subRender); | |
477 | + | |
478 | + if (value != null) | |
479 | + buffer += value; | |
480 | + } else { | |
481 | + buffer += this.renderTokens(token[4], context, partials, originalTemplate); | |
482 | + } | |
483 | + | |
484 | + break; | |
485 | + case '^': | |
486 | + value = context.lookup(token[1]); | |
487 | + | |
488 | + // Use JavaScript's definition of falsy. Include empty arrays. | |
489 | + // See https://github.com/janl/mustache.js/issues/186 | |
490 | + if (!value || (isArray(value) && value.length === 0)) | |
491 | + buffer += this.renderTokens(token[4], context, partials, originalTemplate); | |
492 | + | |
493 | + break; | |
494 | + case '>': | |
495 | + if (!partials) | |
496 | + continue; | |
497 | + | |
498 | + value = isFunction(partials) ? partials(token[1]) : partials[token[1]]; | |
499 | + | |
500 | + if (value != null) | |
501 | + buffer += this.renderTokens(this.parse(value), context, partials, value); | |
502 | + | |
503 | + break; | |
504 | + case '&': | |
505 | + value = context.lookup(token[1]); | |
506 | + | |
507 | + if (value != null) | |
508 | + buffer += value; | |
509 | + | |
510 | + break; | |
511 | + case 'name': | |
512 | + value = context.lookup(token[1]); | |
513 | + | |
514 | + if (value != null) | |
515 | + buffer += mustache.escape(value); | |
516 | + | |
517 | + break; | |
518 | + case 'text': | |
519 | + buffer += token[1]; | |
520 | + break; | |
521 | + } | |
522 | + } | |
523 | + | |
524 | + return buffer; | |
525 | + }; | |
526 | + | |
527 | + mustache.name = "mustache.js"; | |
528 | + mustache.version = "0.8.1"; | |
529 | + mustache.tags = [ "{{", "}}" ]; | |
530 | + | |
531 | + // All high-level mustache.* functions use this writer. | |
532 | + var defaultWriter = new Writer(); | |
533 | + | |
534 | + /** | |
535 | + * Clears all cached templates in the default writer. | |
536 | + */ | |
537 | + mustache.clearCache = function () { | |
538 | + return defaultWriter.clearCache(); | |
539 | + }; | |
540 | + | |
541 | + /** | |
542 | + * Parses and caches the given template in the default writer and returns the | |
543 | + * array of tokens it contains. Doing this ahead of time avoids the need to | |
544 | + * parse templates on the fly as they are rendered. | |
545 | + */ | |
546 | + mustache.parse = function (template, tags) { | |
547 | + return defaultWriter.parse(template, tags); | |
548 | + }; | |
549 | + | |
550 | + /** | |
551 | + * Renders the `template` with the given `view` and `partials` using the | |
552 | + * default writer. | |
553 | + */ | |
554 | + mustache.render = function (template, view, partials) { | |
555 | + return defaultWriter.render(template, view, partials); | |
556 | + }; | |
557 | + | |
558 | + // This is here for backwards compatibility with 0.4.x. | |
559 | + mustache.to_html = function (template, view, partials, send) { | |
560 | + var result = mustache.render(template, view, partials); | |
561 | + | |
562 | + if (isFunction(send)) { | |
563 | + send(result); | |
564 | + } else { | |
565 | + return result; | |
566 | + } | |
567 | + }; | |
568 | + | |
569 | + // Export the escaping function so that the user may override it. | |
570 | + // See https://github.com/janl/mustache.js/issues/244 | |
571 | + mustache.escape = escapeHtml; | |
572 | + | |
573 | + // Export these mainly for testing, but also for advanced usage. | |
574 | + mustache.Scanner = Scanner; | |
575 | + mustache.Context = Context; | |
576 | + mustache.Writer = Writer; | |
577 | + | |
578 | +})); | ... | ... |
... | ... | @@ -0,0 +1,14 @@ |
1 | +<?xml version="1.0"?> | |
2 | +<package > | |
3 | + <metadata> | |
4 | + <id>mustache.js</id> | |
5 | + <version>0.8.2</version> | |
6 | + <authors>mustache.js Authors</authors> | |
7 | + <licenseUrl>https://github.com/janl/mustache.js/blob/master/LICENSE</licenseUrl> | |
8 | + <projectUrl>http://mustache.github.com/</projectUrl> | |
9 | + <requireLicenseAcceptance>false</requireLicenseAcceptance> | |
10 | + <description>Logic-less templates in JavaScript.</description> | |
11 | + <releaseNotes></releaseNotes> | |
12 | + <tags>mustache template templates javascript</tags> | |
13 | + </metadata> | |
14 | +</package> | |
0 | 15 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,21 @@ |
1 | +{ | |
2 | + "name": "mustache", | |
3 | + "version": "0.8.2", | |
4 | + "description": "Logic-less {{mustache}} templates with JavaScript", | |
5 | + "author": "mustache.js Authors <http://github.com/janl/mustache.js>", | |
6 | + "repository": { | |
7 | + "type": "git", | |
8 | + "url": "https://github.com/janl/mustache.js.git" | |
9 | + }, | |
10 | + "keywords": ["mustache", "template", "templates", "ejs"], | |
11 | + "main": "./mustache.js", | |
12 | + "devDependencies": { | |
13 | + "mocha": "1.5.0" | |
14 | + }, | |
15 | + "volo": { | |
16 | + "url": "https://raw.github.com/janl/mustache.js/{version}/mustache.js" | |
17 | + }, | |
18 | + "scripts": { | |
19 | + "test": "mocha test" | |
20 | + } | |
21 | +} | ... | ... |
pacotes/mustache.js-master/test/_files/ampersand_escape.js
0 → 100644
pacotes/mustache.js-master/test/_files/ampersand_escape.mustache
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +{{&message}} | ... | ... |
pacotes/mustache.js-master/test/_files/ampersand_escape.txt
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +Some <code> | ... | ... |
pacotes/mustache.js-master/test/_files/apostrophe.mustache
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +{{apos}}{{control}} | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +'X | ... | ... |
pacotes/mustache.js-master/test/_files/array_of_strings.js
0 → 100644
pacotes/mustache.js-master/test/_files/array_of_strings.mustache
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +{{#array_of_strings}}{{.}} {{/array_of_strings}} | ... | ... |
pacotes/mustache.js-master/test/_files/array_of_strings.txt
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +hello world | ... | ... |
pacotes/mustache.js-master/test/_files/backslashes.mustache
0 → 100644
pacotes/mustache.js-master/test/_files/bug_11_eating_whitespace.js
0 → 100644
pacotes/mustache.js-master/test/_files/bug_11_eating_whitespace.mustache
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +{{tag}} foo | ... | ... |
pacotes/mustache.js-master/test/_files/bug_11_eating_whitespace.txt
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +yo foo | ... | ... |
pacotes/mustache.js-master/test/_files/changing_delimiters.js
0 → 100644
pacotes/mustache.js-master/test/_files/changing_delimiters.mustache
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +{{=<% %>=}}<% foo %> {{foo}} <%{bar}%> {{{bar}}} | ... | ... |
pacotes/mustache.js-master/test/_files/changing_delimiters.txt
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +foooooooooooooo {{foo}} <b>bar!</b> {{{bar}}} | ... | ... |
pacotes/mustache.js-master/test/_files/check_falsy.mustache
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +<p>{{#number}}0{{/number}}</p> | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +<p>0</p> | ... | ... |
pacotes/mustache.js-master/test/_files/comments.mustache
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +<h1>{{title}}{{! just something interesting... or not... }}</h1> | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +<h1>A Comedy of Errors</h1> | ... | ... |
... | ... | @@ -0,0 +1,19 @@ |
1 | +({ | |
2 | + header: function () { | |
3 | + return "Colors"; | |
4 | + }, | |
5 | + item: [ | |
6 | + {name: "red", current: true, url: "#Red"}, | |
7 | + {name: "green", current: false, url: "#Green"}, | |
8 | + {name: "blue", current: false, url: "#Blue"} | |
9 | + ], | |
10 | + link: function () { | |
11 | + return this["current"] !== true; | |
12 | + }, | |
13 | + list: function () { | |
14 | + return this.item.length !== 0; | |
15 | + }, | |
16 | + empty: function () { | |
17 | + return this.item.length === 0; | |
18 | + } | |
19 | +}) | ... | ... |
... | ... | @@ -0,0 +1,16 @@ |
1 | +<h1>{{header}}</h1> | |
2 | +{{#list}} | |
3 | + <ul> | |
4 | + {{#item}} | |
5 | + {{#current}} | |
6 | + <li><strong>{{name}}</strong></li> | |
7 | + {{/current}} | |
8 | + {{#link}} | |
9 | + <li><a href="{{url}}">{{name}}</a></li> | |
10 | + {{/link}} | |
11 | + {{/item}} | |
12 | + </ul> | |
13 | +{{/list}} | |
14 | +{{#empty}} | |
15 | + <p>The list is empty.</p> | |
16 | +{{/empty}} | ... | ... |
pacotes/mustache.js-master/test/_files/context_lookup.js
0 → 100644
pacotes/mustache.js-master/test/_files/context_lookup.mustache
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +{{#outer}}{{#second}}{{id}}{{/second}}{{/outer}} | ... | ... |
pacotes/mustache.js-master/test/_files/context_lookup.txt
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +1 | ... | ... |
pacotes/mustache.js-master/test/_files/delimiters.mustache
0 → 100644
pacotes/mustache.js-master/test/_files/disappearing_whitespace.js
0 → 100644
pacotes/mustache.js-master/test/_files/disappearing_whitespace.mustache
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +{{#bedrooms}}{{total}}{{/bedrooms}} BED | ... | ... |
pacotes/mustache.js-master/test/_files/disappearing_whitespace.txt
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +1 BED | ... | ... |
... | ... | @@ -0,0 +1,23 @@ |
1 | +({ | |
2 | + name: "A Book", | |
3 | + authors: ["John Power", "Jamie Walsh"], | |
4 | + price: { | |
5 | + value: 200, | |
6 | + vat: function () { | |
7 | + return this.value * 0.2; | |
8 | + }, | |
9 | + currency: { | |
10 | + symbol: '$', | |
11 | + name: 'USD' | |
12 | + } | |
13 | + }, | |
14 | + availability: { | |
15 | + status: true, | |
16 | + text: "In Stock" | |
17 | + }, | |
18 | + // And now, some truthy false values | |
19 | + truthy: { | |
20 | + zero: 0, | |
21 | + notTrue: false | |
22 | + } | |
23 | +}) | ... | ... |
pacotes/mustache.js-master/test/_files/dot_notation.mustache
0 → 100644
... | ... | @@ -0,0 +1,9 @@ |
1 | +<!-- exciting part --> | |
2 | +<h1>{{name}}</h1> | |
3 | +<p>Authors: <ul>{{#authors}}<li>{{.}}</li>{{/authors}}</ul></p> | |
4 | +<p>Price: {{{price.currency.symbol}}}{{price.value}} {{#price.currency}}{{name}} <b>{{availability.text}}</b>{{/price.currency}}</p> | |
5 | +<p>VAT: {{{price.currency.symbol}}}{{#price}}{{vat}}{{/price}}</p> | |
6 | +<!-- boring part --> | |
7 | +<h2>Test truthy false values:</h2> | |
8 | +<p>Zero: {{truthy.zero}}</p> | |
9 | +<p>False: {{truthy.notTrue}}</p> | ... | ... |
... | ... | @@ -0,0 +1,9 @@ |
1 | +<!-- exciting part --> | |
2 | +<h1>A Book</h1> | |
3 | +<p>Authors: <ul><li>John Power</li><li>Jamie Walsh</li></ul></p> | |
4 | +<p>Price: $200 USD <b>In Stock</b></p> | |
5 | +<p>VAT: $40</p> | |
6 | +<!-- boring part --> | |
7 | +<h2>Test truthy false values:</h2> | |
8 | +<p>Zero: 0</p> | |
9 | +<p>False: false</p> | ... | ... |
pacotes/mustache.js-master/test/_files/double_render.mustache
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +{{#foo}}{{bar}}{{/foo}} | ... | ... |
pacotes/mustache.js-master/test/_files/double_render.txt
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +{{win}} | ... | ... |
pacotes/mustache.js-master/test/_files/empty_list.mustache
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +These are the jobs: | ... | ... |
pacotes/mustache.js-master/test/_files/empty_sections.js
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +({}) | ... | ... |
pacotes/mustache.js-master/test/_files/empty_sections.mustache
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +{{#foo}}{{/foo}}foo{{#bar}}{{/bar}} | ... | ... |
pacotes/mustache.js-master/test/_files/empty_sections.txt
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +foo | ... | ... |
pacotes/mustache.js-master/test/_files/empty_string.mustache
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +{{description}}{{#child}}{{description}}{{/child}} | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +That is all! | ... | ... |
pacotes/mustache.js-master/test/_files/empty_template.js
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +({}) | ... | ... |
pacotes/mustache.js-master/test/_files/empty_template.mustache
0 → 100644
pacotes/mustache.js-master/test/_files/empty_template.txt
0 → 100644
pacotes/mustache.js-master/test/_files/error_not_found.js
0 → 100644
pacotes/mustache.js-master/test/_files/error_not_found.mustache
0 → 100644
pacotes/mustache.js-master/test/_files/error_not_found.txt
0 → 100644
... | ... | @@ -0,0 +1,12 @@ |
1 | +{{#emptyString}}empty string{{/emptyString}} | |
2 | +{{^emptyString}}inverted empty string{{/emptyString}} | |
3 | +{{#emptyArray}}empty array{{/emptyArray}} | |
4 | +{{^emptyArray}}inverted empty array{{/emptyArray}} | |
5 | +{{#zero}}zero{{/zero}} | |
6 | +{{^zero}}inverted zero{{/zero}} | |
7 | +{{#null}}null{{/null}} | |
8 | +{{^null}}inverted null{{/null}} | |
9 | +{{#undefined}}undefined{{/undefined}} | |
10 | +{{^undefined}}inverted undefined{{/undefined}} | |
11 | +{{#NaN}}NaN{{/NaN}} | |
12 | +{{^NaN}}inverted NaN{{/NaN}} | ... | ... |
pacotes/mustache.js-master/test/_files/grandparent_context.js
0 → 100644
... | ... | @@ -0,0 +1,19 @@ |
1 | +({ | |
2 | + grand_parent_id: 'grand_parent1', | |
3 | + parent_contexts: [ | |
4 | + { | |
5 | + parent_id: 'parent1', | |
6 | + child_contexts: [ | |
7 | + { child_id: 'parent1-child1' }, | |
8 | + { child_id: 'parent1-child2' } | |
9 | + ] | |
10 | + }, | |
11 | + { | |
12 | + parent_id: 'parent2', | |
13 | + child_contexts: [ | |
14 | + { child_id: 'parent2-child1' }, | |
15 | + { child_id: 'parent2-child2' } | |
16 | + ] | |
17 | + } | |
18 | + ] | |
19 | +}) | ... | ... |
pacotes/mustache.js-master/test/_files/grandparent_context.mustache
0 → 100644
pacotes/mustache.js-master/test/_files/grandparent_context.txt
0 → 100644
pacotes/mustache.js-master/test/_files/higher_order_sections.js
0 → 100644
pacotes/mustache.js-master/test/_files/higher_order_sections.mustache
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +{{#bolder}}Hi {{name}}.{{/bolder}} | ... | ... |
pacotes/mustache.js-master/test/_files/higher_order_sections.txt
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +Hi {{name}}. => <b>Hi Tater.</b> To tinker? | ... | ... |
pacotes/mustache.js-master/test/_files/included_tag.mustache
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +You said "{{{html}}}" today | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +You said "I like {{mustache}}" today | ... | ... |
pacotes/mustache.js-master/test/_files/inverted_section.js
0 → 100644
pacotes/mustache.js-master/test/_files/inverted_section.mustache
0 → 100644
pacotes/mustache.js-master/test/_files/inverted_section.txt
0 → 100644
pacotes/mustache.js-master/test/_files/keys_with_questionmarks.js
0 → 100644
pacotes/mustache.js-master/test/_files/keys_with_questionmarks.mustache
0 → 100644
pacotes/mustache.js-master/test/_files/keys_with_questionmarks.txt
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | + Hi Jon! | ... | ... |
pacotes/mustache.js-master/test/_files/malicious_template.js
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +({}) | ... | ... |
pacotes/mustache.js-master/test/_files/malicious_template.mustache
0 → 100644
pacotes/mustache.js-master/test/_files/malicious_template.txt
0 → 100644
pacotes/mustache.js-master/test/_files/multiline_comment.js
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +({}) | ... | ... |
pacotes/mustache.js-master/test/_files/multiline_comment.mustache
0 → 100644
pacotes/mustache.js-master/test/_files/multiline_comment.txt
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +Hello world! | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +({ name: 'Bruno' }) | ... | ... |
pacotes/mustache.js-master/test/_files/nested_dot.mustache
0 → 100644