Преглед изворни кода

Merge remote-tracking branch 'janl/master'

tags/0.7.3
wittemann пре 13 година
родитељ
комит
4c3caf8f49
100 измењених фајлова са 757 додато и 1004 уклоњено
  1. +1
    -0
      .gitignore
  2. +5
    -0
      .jshintrc
  3. +4
    -5
      .travis.yml
  4. +27
    -0
      CHANGES
  5. +5
    -18
      LICENSE
  6. +100
    -144
      README.md
  7. +27
    -18
      Rakefile
  8. +0
    -62
      TESTING.md
  9. +496
    -410
      mustache.js
  10. +1
    -1
      mustache.js.nuspec
  11. +11
    -2
      package.json
  12. +0
    -3
      spec/_files/ampersand_escape.js
  13. +0
    -1
      spec/_files/apostrophe.js
  14. +0
    -1
      spec/_files/array_of_strings.js
  15. +0
    -3
      spec/_files/backslashes.js
  16. +0
    -3
      spec/_files/bug_11_eating_whitespace.js
  17. +0
    -4
      spec/_files/changing_delimiters.js
  18. +0
    -5
      spec/_files/comments.js
  19. +0
    -4
      spec/_files/disappearing_whitespace.js
  20. +0
    -3
      spec/_files/empty_list.js
  21. +0
    -1
      spec/_files/empty_sections.js
  22. +0
    -1
      spec/_files/empty_template.js
  23. +0
    -1
      spec/_files/error_not_found.js
  24. +0
    -6
      spec/_files/escaped.js
  25. +0
    -2
      spec/_files/escaped.mustache
  26. +0
    -2
      spec/_files/escaped.txt
  27. +0
    -9
      spec/_files/higher_order_sections.js
  28. +0
    -1
      spec/_files/higher_order_sections.txt
  29. +0
    -3
      spec/_files/inverted_section.js
  30. +0
    -1
      spec/_files/multiline_comment.js
  31. +0
    -3
      spec/_files/partial_array_of_partials.js
  32. +0
    -3
      spec/_files/partial_array_of_partials_implicit.js
  33. +0
    -3
      spec/_files/partial_empty.js
  34. +0
    -11
      spec/_files/partial_recursion.js
  35. +0
    -4
      spec/_files/partial_recursion.mustache
  36. +0
    -4
      spec/_files/partial_recursion.partial
  37. +0
    -3
      spec/_files/partial_recursion.txt
  38. +0
    -6
      spec/_files/partial_template.js
  39. +0
    -4
      spec/_files/string_as_context.js
  40. +0
    -1
      spec/_files/two_sections.js
  41. +0
    -5
      spec/_files/unescaped.js
  42. +0
    -218
      spec/mustache_spec.rb
  43. +3
    -0
      test/_files/ampersand_escape.js
  44. +0
    -0
      test/_files/ampersand_escape.mustache
  45. +0
    -0
      test/_files/ampersand_escape.txt
  46. +4
    -0
      test/_files/apostrophe.js
  47. +0
    -0
      test/_files/apostrophe.mustache
  48. +0
    -0
      test/_files/apostrophe.txt
  49. +3
    -0
      test/_files/array_of_strings.js
  50. +0
    -0
      test/_files/array_of_strings.mustache
  51. +0
    -0
      test/_files/array_of_strings.txt
  52. +3
    -0
      test/_files/backslashes.js
  53. +0
    -0
      test/_files/backslashes.mustache
  54. +0
    -0
      test/_files/backslashes.txt
  55. +3
    -0
      test/_files/bug_11_eating_whitespace.js
  56. +0
    -0
      test/_files/bug_11_eating_whitespace.mustache
  57. +0
    -0
      test/_files/bug_11_eating_whitespace.txt
  58. +4
    -0
      test/_files/changing_delimiters.js
  59. +0
    -0
      test/_files/changing_delimiters.mustache
  60. +0
    -0
      test/_files/changing_delimiters.txt
  61. +5
    -0
      test/_files/comments.js
  62. +0
    -0
      test/_files/comments.mustache
  63. +0
    -0
      test/_files/comments.txt
  64. +6
    -6
      test/_files/complex.js
  65. +0
    -0
      test/_files/complex.mustache
  66. +0
    -0
      test/_files/complex.txt
  67. +2
    -2
      test/_files/context_lookup.js
  68. +0
    -0
      test/_files/context_lookup.mustache
  69. +0
    -0
      test/_files/context_lookup.txt
  70. +2
    -2
      test/_files/delimiters.js
  71. +0
    -0
      test/_files/delimiters.mustache
  72. +0
    -0
      test/_files/delimiters.txt
  73. +4
    -0
      test/_files/disappearing_whitespace.js
  74. +0
    -0
      test/_files/disappearing_whitespace.mustache
  75. +0
    -0
      test/_files/disappearing_whitespace.txt
  76. +7
    -7
      test/_files/dot_notation.js
  77. +2
    -2
      test/_files/dot_notation.mustache
  78. +2
    -2
      test/_files/dot_notation.txt
  79. +2
    -2
      test/_files/double_render.js
  80. +0
    -0
      test/_files/double_render.mustache
  81. +0
    -0
      test/_files/double_render.txt
  82. +3
    -0
      test/_files/empty_list.js
  83. +0
    -0
      test/_files/empty_list.mustache
  84. +0
    -0
      test/_files/empty_list.txt
  85. +1
    -0
      test/_files/empty_sections.js
  86. +0
    -0
      test/_files/empty_sections.mustache
  87. +0
    -0
      test/_files/empty_sections.txt
  88. +2
    -2
      test/_files/empty_string.js
  89. +0
    -0
      test/_files/empty_string.mustache
  90. +0
    -0
      test/_files/empty_string.txt
  91. +1
    -0
      test/_files/empty_template.js
  92. +0
    -0
      test/_files/empty_template.mustache
  93. +0
    -0
      test/_files/empty_template.txt
  94. +3
    -0
      test/_files/error_not_found.js
  95. +0
    -0
      test/_files/error_not_found.mustache
  96. +0
    -0
      test/_files/error_not_found.txt
  97. +6
    -0
      test/_files/escaped.js
  98. +2
    -0
      test/_files/escaped.mustache
  99. +2
    -0
      test/_files/escaped.txt
  100. +8
    -0
      test/_files/falsy.js

+ 1
- 0
.gitignore Прегледај датотеку

@@ -1,5 +1,6 @@
.DS_Store
.rvmrc
node_modules
runner.js
jquery.mustache.js
qooxdoo.mustache.js


+ 5
- 0
.jshintrc Прегледај датотеку

@@ -0,0 +1,5 @@
{
"eqnull": true,
"evil": true
}


+ 4
- 5
.travis.yml Прегледај датотеку

@@ -1,5 +1,4 @@
rvm:
- 1.9.2
before_script:
- sudo apt-get -y install xulrunner-2.0
- gem install rspec
language: node_js
node_js:
- 0.6


+ 27
- 0
CHANGES Прегледај датотеку

@@ -0,0 +1,27 @@
= HEAD / 22 Sep 2012

* 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).

+ 5
- 18
LICENSE Прегледај датотеку

@@ -3,21 +3,8 @@ The MIT License
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.
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.

+ 100
- 144
README.md Прегледај датотеку

@@ -2,31 +2,23 @@

> What could be more logical awesome than no logic at all?

[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 templates in many various scenarios where you
can use JavaScript. For example, you can render templates in a browser,
server-side using [node](http://nodejs.org/), in [CouchDB](http://couchdb.apache.org/)
views, or in almost any other environment where you can use JavaScript.
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.

## 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!

## Usage

@@ -41,36 +33,26 @@ Below is quick example how to use mustache.js:

var output = Mustache.render("{{title}} spends {{calc}}", view);

In this example, the `Mustache.render` function takes two parameters: 1) the
[mustache](http://mustache.github.com/) template and 2) a `view` object that
contains the data and code needed to render the template.

### CommonJS

mustache.js is usable without any modification in both browsers and [CommonJS](http://www.commonjs.org/)
environments like [node.js](http://nodejs.org/). To use it as a CommonJS module,
simply require the file, like this:

var Mustache = require("mustache");
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.

There are several types of tags available in mustache.js.

### Variables

The most basic tag type is a simple variable. A `{{name}}` tag renders the value
of the `name` key in the current context. If there is no such key, nothing is
rendered.
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.

View:

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.
{
"name": "Chris",
"company": "<b>GitHub</b>"
}

Template:

@@ -80,13 +62,6 @@ Template:
* {{{company}}}
* {{&company}}

View:

{
"name": "Chris",
"company": "<b>GitHub</b>"
}

Output:

* Chris
@@ -95,13 +70,7 @@ Output:
* <b>GitHub</b>
* <b>GitHub</b>

JavaScript's dot notation may be used to access keys that are properties of
objects in a view.

Template:

* {{name.first}} {{name.last}}
* {{age}}
JavaScript's dot notation may be used to access keys that are properties of objects in a view.

View:

@@ -113,6 +82,11 @@ View:
"age": "RIP"
}

Template:

* {{name.first}} {{name.last}}
* {{age}}

Output:

* Michael Jackson
@@ -120,19 +94,21 @@ Output:

### Sections

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".

The behavior of the section is determined by the value of the key.

#### False Values or Empty Lists

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 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.

View:

{
"person": false
}

Template:

@@ -141,30 +117,15 @@ Template:
Never shown!
{{/person}}

View:

{
"person": true
}

Output:

Shown.

#### Non-Empty Lists

If the `person` key exists and is not `null`, `undefined`, or `false`, and is
not an empty list the block will be rendered one or more times.

When the value is a list, the block is rendered once for each item in the list.
The context of the block is set to the current item in the list for each
iteration. In this way we can loop over collections.

Template:
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.

{{#stooges}}
<b>{{name}}</b>
{{/stooges}}
When the value is a list, the block is rendered once for each item in the list. The context of the block is set to the current item in the list for each iteration. In this way we can loop over collections.

View:

@@ -176,20 +137,19 @@ View:
]
}

Template:

{{#stooges}}
<b>{{name}}</b>
{{/stooges}}

Output:

<b>Moe</b>
<b>Larry</b>
<b>Curly</b>

When looping over an array of strings, a `.` can be used to refer to the current
item in the list.

Template:

{{#musketeers}}
* {{.}}
{{/musketeers}}
When looping over an array of strings, a `.` can be used to refer to the current item in the list.

View:

@@ -197,6 +157,12 @@ View:
"musketeers": ["Athos", "Aramis", "Porthos", "D'Artagnan"]
}

Template:

{{#musketeers}}
* {{.}}
{{/musketeers}}

Output:

* Athos
@@ -204,14 +170,7 @@ Output:
* Porthos
* D'Artagnan

If the value of a section variable is a function, it will be called in the
context of the current item in the list on each iteration.

Template:

{{#beatles}}
* {{name}}
{{/beatles}}
If the value of a section variable is a function, it will be called in the context of the current item in the list on each iteration.

View:

@@ -227,6 +186,12 @@ View:
}
}

Template:

{{#beatles}}
* {{name}}
{{/beatles}}

Output:

* John Lennon
@@ -236,14 +201,7 @@ Output:

#### Functions

If the value of a section key is a function, it is called with the section's
literal block of text, un-rendered, as its first argument. The second argument
is a special rendering function that uses the current view as its view argument.
It is called in the context of the current view object.

Template:

{{#bold}}Hi {{name}}.{{/bold}}
If the value of a section key is a function, it is called with the section's literal block of text, un-rendered, as its first argument. The second argument is a special rendering function that uses the current view as its view argument. It is called in the context of the current view object.

View:

@@ -256,20 +214,17 @@ View:
}
}

Template:

{{#bold}}Hi {{name}}.{{/bold}}

Output:

<b>Hi Tater.</b>

### Inverted Sections

An inverted section opens with `{{^section}}` instead of `{{#section}}`. The
block of an inverted section is rendered only if the value of that section's tag
is `null`, `undefined`, `false`, or an empty list.

Template:

{{#repos}}<b>{{name}}</b>{{/repos}}
{{^repos}}No repos :({{/repos}}
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.

View:

@@ -277,6 +232,11 @@ View:
"repos": []
}

Template:

{{#repos}}<b>{{name}}</b>{{/repos}}
{{^repos}}No repos :({{/repos}}

Output:

No repos :(
@@ -297,8 +257,7 @@ Comments may contain newlines.

Partials begin with a greater than sign, like {{> box}}.

Partials are rendered at runtime (as opposed to compile time), so recursive
partials are possible. Just avoid infinite loops.
Partials are rendered at runtime (as opposed to compile time), so recursive partials are possible. Just avoid infinite loops.

They also inherit the calling context. Whereas in ERB you may have this:

@@ -308,9 +267,7 @@ Mustache requires only this:

{{> next_more}}

Why? Because the `next_more.mustache` file will inherit the `size` and `start`
variables from the calling context. In this way you may want to think of
partials as includes, 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.

For example, this template and partial:

@@ -330,14 +287,11 @@ Can be thought of as a single, expanded template:
<strong>{{name}}</strong>
{{/names}}

In mustache.js an object of partials may be passed as the third argument to
`Mustache.render`. The object should be keyed by the name of the partial, and
its value should be the partial text.
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.

Consider the following contrived example:

@@ -347,55 +301,57 @@ Consider the following contrived example:
<%={{ }}=%>
* {{ default_tags_again }}

Here we have a list with three items. The first item uses the default tag style,
the second uses ERB style as defined by the Set Delimiter tag, and the third
returns to the default style after yet another Set Delimiter declaration.
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."

Custom delimiters may not contain whitespace or the equals sign.

## Streaming

To stream template results out of mustache.js, you can pass an optional callback
to the call to `Mustache.render`:

Mustache.render(template, view, partials, function (chunk) {
print(chunk);
});

When the template is finished rendering, the callback will be called with `null`
after which it won't be called anymore for that rendering.

## Plugins for JavaScript Libraries

By default mustache.js may be used in a browser or any [CommonJS](http://www.commonjs.org/)
environment, including [node](http://nodejs.org/). Additionally, mustache.js may
be built specifically for several different client libraries and platforms,
including the following:
mustache.js may be built specifically for several different client libraries, including the following:

- [jQuery](http://jquery.com/)
- [MooTools](http://mootools.net/)
- [Dojo](http://www.dojotoolkit.org/)
- [YUI](http://developer.yahoo.com/yui/)
- [RequireJS](http://requirejs.org/)
- [qooxdoo](http://qooxdoo.org/)

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:

$ rake jquery
$ rake mootools
$ rake dojo
$ rake yui
$ rake requirejs
$ rake qooxdoo

## Testing

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/).

$ npm install -g vows

Then run the tests.

$ vows --spec

The test suite consists of both unit and integration tests. If a template isn't rendering correctly for you, you can make a test for it by doing the following:

1. Create a template file named `mytest.mustache` in the `test/_files`
directory. Replace `mytest` with the name of your test.
2. Create a corresponding view file named `mytest.js` in the same directory.
This file should contain a JavaScript object literal enclosed in
parentheses. See any of the other view files for an example.
3. Create a file with the expected output in `mytest.txt` in the same
directory.

Then, you can run the test with:

$ TEST=mytest vows test/render_test.js

## Thanks

Mustache.js wouldn't kick ass if it weren't for these fine souls:
mustache.js wouldn't kick ass if it weren't for these fine souls:

* Chris Wanstrath / defunkt
* Alexander Lang / langalex


+ 27
- 18
Rakefile Прегледај датотеку

@@ -1,15 +1,33 @@
require 'rake'
require 'rake/clean'

task :default => :spec

desc "Run all specs"
task :spec do
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |t|
#t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
t.pattern = 'spec/*_spec.rb'
end
task :default => :test

ROOT = File.expand_path('..', __FILE__)
MUSTACHE_JS = File.read(File.join(ROOT, 'mustache.js'))

def mustache_version
match = MUSTACHE_JS.match(/exports\.version = "([^"]+)";/)
match[1]
end

def minified_file
ENV['FILE'] || 'mustache.min.js'
end

desc "Run all tests, requires vows (see http://vowsjs.org)"
task :test do
sh "vows --spec"
end

desc "Minify to #{minified_file}, requires UglifyJS (see http://marijnhaverbeke.nl/uglifyjs)"
task :minify do
sh "uglifyjs mustache.js > #{minified_file}"
end

desc "Run JSHint, requires jshint (see http://www.jshint.com)"
task :lint do
sh "jshint mustache.js"
end

# Creates a task that uses the various template wrappers to make a wrapped
@@ -47,13 +65,4 @@ templated_build "jQuery"
templated_build "MooTools"
templated_build "Dojo", :location => "dojox/string"
templated_build "YUI3", :location => "yui3/mustache"
templated_build "RequireJS"
templated_build "qooxdoo"

task :minify do
# npm install uglify-js
mmjs = "mustache.min.js"
`echo "/*! Version: 0.5.1-dev */" > #{mmjs}`
`uglifyjs mustache.js >> #{mmjs}`
puts "Created #{mmjs}"
end

+ 0
- 62
TESTING.md Прегледај датотеку

@@ -1,62 +0,0 @@
## Running the mustache.js test suite

The mustache.js test suite uses the [RSpec](http://rspec.info/) testing
framework. In order to run the tests you'll need to install [Ruby](http://ruby-lang.org/)
as well as the `rake`, `rspec` (>=2), and `json` [RubyGems](http://rubygems.org/).

### How to install Ruby and the required gems from source

Make sure you have the required tools to compile it:

$ apt-get install build-essential libssl-dev libreadline5-dev zlib1g-dev

Download and extract the Ruby source, and install it:

$ wget ftp://ftp.ruby-lang.org/pub/ruby/stable-snapshot.tar.gz
$ tar xvzf stable-snapshot.tar.gz
$ cd ruby
$ ./configure && make && make install

Download and extract RubyGems, and install it:

$ wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.12.tgz
$ tar xzvf rubygems-1.8.12.tgz
$ cd rubygems-1.8.12
$ ruby setup.rb

If you want to update RubyGems:

$ gem update --system

Install the required gems:

$ gem install rake rspec json

That's it!

### How to run the tests

The mustache.js test suite currently uses 4 different JavaScript runtime engines
to maximize portability across platforms and browsers. They are:

* node
* SpiderMonkey (Mozilla, Firefox)
* JavaScriptCore (WebKit, Safari)
* Rhino (Mozilla, Java)

When the test suite runs it will automatically determine which platforms are
available on your machine and run on all of them. The suite must run on at least
one platform in order to succeed.

Once you have at least one JavaScript platform installed, you can run the test
suite with the following command:

$ rake

### How to create a test

All test files live in the spec/_files directory. To create a new test:

* Create a template file called `somename.mustache`
* Create a JavaScript file containing the view called `somename.js`
* Create a text file with the expected result called `somename.txt`

+ 496
- 410
mustache.js
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 1
- 1
mustache.js.nuspec Прегледај датотеку

@@ -2,7 +2,7 @@
<package >
<metadata>
<id>mustache.js</id>
<version>0.5.0-dev</version>
<version>0.7.0</version>
<authors>mustache.js Authors</authors>
<licenseUrl>https://github.com/janl/mustache.js/blob/master/LICENSE</licenseUrl>
<projectUrl>http://mustache.github.com/</projectUrl>


+ 11
- 2
package.json Прегледај датотеку

@@ -1,8 +1,17 @@
{
"name": "mustache",
"version": "0.5.0-dev",
"version": "0.7.0",
"description": "Logic-less {{mustache}} templates with JavaScript",
"author": "mustache.js Authors <http://github.com/janl/mustache.js>",
"keywords": ["mustache", "template", "templates", "ejs"],
"main": "./mustache"
"main": "./mustache.js",
"devDependencies": {
"vows": "0.6.x"
},
"volo": {
"url": "https://raw.github.com/janl/mustache.js/0.7.0/mustache.js"
},
"scripts": {
"test": "vows --spec"
}
}

+ 0
- 3
spec/_files/ampersand_escape.js Прегледај датотеку

@@ -1,3 +0,0 @@
var ampersand_escape = {
message: "Some <code>"
};

+ 0
- 1
spec/_files/apostrophe.js Прегледај датотеку

@@ -1 +0,0 @@
var apostrophe = {'apos': "'", 'control':'X'};

+ 0
- 1
spec/_files/array_of_strings.js Прегледај датотеку

@@ -1 +0,0 @@
var array_of_strings = {array_of_strings: ['hello', 'world']};

+ 0
- 3
spec/_files/backslashes.js Прегледај датотеку

@@ -1,3 +0,0 @@
var backslashes = {
value: "\\abc"
};

+ 0
- 3
spec/_files/bug_11_eating_whitespace.js Прегледај датотеку

@@ -1,3 +0,0 @@
var bug_11_eating_whitespace = {
tag: "yo"
};

+ 0
- 4
spec/_files/changing_delimiters.js Прегледај датотеку

@@ -1,4 +0,0 @@
var changing_delimiters = {
"foo": "foooooooooooooo",
"bar":"<b>bar!</b>"
};

+ 0
- 5
spec/_files/comments.js Прегледај датотеку

@@ -1,5 +0,0 @@
var comments = {
title: function() {
return "A Comedy of Errors";
}
};

+ 0
- 4
spec/_files/disappearing_whitespace.js Прегледај датотеку

@@ -1,4 +0,0 @@
var disappearing_whitespace = {
bedrooms: true,
total: 1
};

+ 0
- 3
spec/_files/empty_list.js Прегледај датотеку

@@ -1,3 +0,0 @@
var empty_list = {
jobs: []
};

+ 0
- 1
spec/_files/empty_sections.js Прегледај датотеку

@@ -1 +0,0 @@
var empty_sections = {};

+ 0
- 1
spec/_files/empty_template.js Прегледај датотеку

@@ -1 +0,0 @@
var empty_template = {};

+ 0
- 1
spec/_files/error_not_found.js Прегледај датотеку

@@ -1 +0,0 @@
var error_not_found = {bar: 2};

+ 0
- 6
spec/_files/escaped.js Прегледај датотеку

@@ -1,6 +0,0 @@
var escaped = {
title: function() {
return "Bear > Shark";
},
entities: "&quot;"
};

+ 0
- 2
spec/_files/escaped.mustache Прегледај датотеку

@@ -1,2 +0,0 @@
<h1>{{title}}</h1>
But not {{entities}}.

+ 0
- 2
spec/_files/escaped.txt Прегледај датотеку

@@ -1,2 +0,0 @@
<h1>Bear &gt; Shark</h1>
But not &quot;.

+ 0
- 9
spec/_files/higher_order_sections.js Прегледај датотеку

@@ -1,9 +0,0 @@
var higher_order_sections = {
"name": "Tater",
"helper": "To tinker?",
"bolder": function() {
return function(text, render) {
return "<b>" + render(text) + '</b> ' + this.helper;
}
}
}

+ 0
- 1
spec/_files/higher_order_sections.txt Прегледај датотеку

@@ -1 +0,0 @@
<b>Hi Tater.</b> To tinker?

+ 0
- 3
spec/_files/inverted_section.js Прегледај датотеку

@@ -1,3 +0,0 @@
var inverted_section = {
"repos": []
};

+ 0
- 1
spec/_files/multiline_comment.js Прегледај датотеку

@@ -1 +0,0 @@
var multiline_comment = {};

+ 0
- 3
spec/_files/partial_array_of_partials.js Прегледај датотеку

@@ -1,3 +0,0 @@
var partial_array_of_partials = {
numbers: [{i: '1'}, {i: '2'}, {i: '3'}, {i: '4'}]
};

+ 0
- 3
spec/_files/partial_array_of_partials_implicit.js Прегледај датотеку

@@ -1,3 +0,0 @@
var partial_array_of_partials_implicit = {
numbers: ['1', '2', '3', '4']
};

+ 0
- 3
spec/_files/partial_empty.js Прегледај датотеку

@@ -1,3 +0,0 @@
var partial_empty = {
foo: 1
};

+ 0
- 11
spec/_files/partial_recursion.js Прегледај датотеку

@@ -1,11 +0,0 @@
var partial_recursion = {
name: '1',
kids: [
{
name: '1.1',
children: [
{name: '1.1.1'}
]
}
]
};

+ 0
- 4
spec/_files/partial_recursion.mustache Прегледај датотеку

@@ -1,4 +0,0 @@
{{name}}
{{#kids}}
{{>partial}}
{{/kids}}

+ 0
- 4
spec/_files/partial_recursion.partial Прегледај датотеку

@@ -1,4 +0,0 @@
{{name}}
{{#children}}
{{>partial}}
{{/children}}

+ 0
- 3
spec/_files/partial_recursion.txt Прегледај датотеку

@@ -1,3 +0,0 @@
1
1.1
1.1.1

+ 0
- 6
spec/_files/partial_template.js Прегледај датотеку

@@ -1,6 +0,0 @@
var partial_template = {
title: function() {
return "Welcome";
},
again: "Goodbye"
};

+ 0
- 4
spec/_files/string_as_context.js Прегледај датотеку

@@ -1,4 +0,0 @@
var string_as_context = {
a_string: 'aa',
a_list: ['a','b','c']
};

+ 0
- 1
spec/_files/two_sections.js Прегледај датотеку

@@ -1 +0,0 @@
var two_sections = {};

+ 0
- 5
spec/_files/unescaped.js Прегледај датотеку

@@ -1,5 +0,0 @@
var unescaped = {
title: function() {
return "Bear > Shark";
}
};

+ 0
- 218
spec/mustache_spec.rb Прегледај датотеку

@@ -1,218 +0,0 @@
require 'rubygems'
require 'json'

ROOT = File.expand_path('../..', __FILE__)
SPEC = File.join(ROOT, 'spec')
FILES = File.join(SPEC, '_files')

MUSTACHE = File.read(File.join(ROOT, "mustache.js"))

TESTS = Dir.glob(File.join(FILES, '*.js')).map do |name|
File.basename name, '.js'
end

NODE_PATH = `which node`.strip
JS_PATH = `which js`.strip
JSC_PATH = "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc"
RHINO_JAR = "org.mozilla.javascript.tools.shell.Main"

def load_test(name)
template = File.read(File.join(FILES, "#{name}.mustache"))
view = File.read(File.join(FILES, "#{name}.js"))
partial_file = File.join(FILES, "#{name}.partial")
partial = if File.exist?(partial_file)
File.read(partial_file)
end
expect = File.read(File.join(FILES, "#{name}.txt"))

[template, view, partial, expect]
end

def run_js(runner, js)
cmd = case runner
when :spidermonkey
JS_PATH
when :jsc
JSC_PATH
when :rhino
"java #{RHINO_JAR}"
when :v8
NODE_PATH
end

runner_file = "runner.js"
File.open(runner_file, 'w') {|file| file.write(js) }
`#{cmd} #{runner_file}`
ensure
FileUtils.rm_r(runner_file)
end

$engines_run = 0

describe "mustache" do
shared_examples_for "mustache rendering" do
before(:all) do
$engines_run += 1
end

it "should return the same result when invoked multiple times" do
js = <<-JS
#{@boilerplate}
Mustache.render("x")
print(Mustache.render("x"));
JS

run_js(@runner, js).should == "x\n"
end

it "should clear the context after each run" do
js = <<-JS
#{@boilerplate}
Mustache.render("{{#list}}{{x}}{{/list}}", {list: [{x: 1}]})
try {
print(Mustache.render("{{#list}}{{x}}{{/list}}", {list: [{}]}));
} catch(e) {
print('ERROR: ' + e.message);
}
JS

run_js(@runner, js).should == "\n"
end

TESTS.each do |test|
describe test do
it "should render the correct output" do
template, view, partial, expect = load_test(test)

js = <<-JS
try {
#{@boilerplate}
var template = #{template.to_json};
#{view}
var partials = {partial: #{partial ? partial.to_json : '""'}};
print(Mustache.render(template, #{test}, partials));
} catch(e) {
print('ERROR: ' + e.message);
}
JS

run_js(@runner, js).chomp.should == expect
end

# it "should send the correct output" do
# template, view, partial, expect = load_test(test)
#
# js = <<-JS
# try {
# #{@boilerplate}
# var template = #{template.to_json};
# #{view}
# var partials = {
# "partial": #{(partial || '').to_json}
# };
# var buffer = [];
# var send = function (chunk) {
# buffer.push(chunk);
# };
# Mustache.render(template, #{test}, partials, send);
# print(buffer.join(""));
# } catch(e) {
# print('ERROR: ' + e.message);
# }
# JS
#
# run_js(@runner, js).chomp.should == expect
# end
end
end
end

context "running in V8 (Chrome, node)" do
if File.exist?(NODE_PATH)
before(:all) do
$stdout.write "Testing in V8 "
@runner = :v8
@boilerplate = MUSTACHE.dup
@boilerplate << <<-JS
var print = console.log;
JS
end

after(:all) do
puts " Done!"
end

it_should_behave_like "mustache rendering"
else
puts "Skipping tests in V8 (node not found)"
end
end

context "running in SpiderMonkey (Mozilla, Firefox)" do
if File.exist?(JS_PATH)
before(:all) do
$stdout.write "Testing in SpiderMonkey "
@runner = :spidermonkey
@boilerplate = MUSTACHE.dup
end

after(:all) do
puts " Done!"
end

it_should_behave_like "mustache rendering"
else
puts "Skipping tests in SpiderMonkey (js not found)"
end
end

context "running in JavaScriptCore (WebKit, Safari)" do
if File.exist?(JSC_PATH)
before(:all) do
$stdout.write "Testing in JavaScriptCore "
@runner = :jsc
@boilerplate = MUSTACHE.dup
end

after(:all) do
puts " Done!"
end

it_should_behave_like "mustache rendering"
else
puts "Skipping tests in JavaScriptCore (jsc not found)"
end
end

context "running in Rhino (Mozilla, Java)" do
if `java #{RHINO_JAR} 'foo' 2>&1` !~ /ClassNotFoundException/
before(:all) do
$stdout.write "Testing in Rhino "
@runner = :rhino
@boilerplate = MUSTACHE.dup
end

after(:all) do
puts " Done!"
end

it_should_behave_like "mustache rendering"
else
puts "Skipping tests in Rhino (JAR #{RHINO_JAR} was not found)"
end
end

context "suite" do
before(:each) do
$stdout.write "Verifying that we ran the tests in at least one engine ... "
end

after(:each) do
puts @exception.nil? ? "OK" : "ERROR"
end

it "should have run at least one time" do
$engines_run.should > 0
end
end
end

+ 3
- 0
test/_files/ampersand_escape.js Прегледај датотеку

@@ -0,0 +1,3 @@
({
message: "Some <code>"
})

spec/_files/ampersand_escape.mustache → test/_files/ampersand_escape.mustache Прегледај датотеку


spec/_files/ampersand_escape.txt → test/_files/ampersand_escape.txt Прегледај датотеку


+ 4
- 0
test/_files/apostrophe.js Прегледај датотеку

@@ -0,0 +1,4 @@
({
'apos': "'",
'control': 'X'
})

spec/_files/apostrophe.mustache → test/_files/apostrophe.mustache Прегледај датотеку


spec/_files/apostrophe.txt → test/_files/apostrophe.txt Прегледај датотеку


+ 3
- 0
test/_files/array_of_strings.js Прегледај датотеку

@@ -0,0 +1,3 @@
({
array_of_strings: ['hello', 'world']
})

spec/_files/array_of_strings.mustache → test/_files/array_of_strings.mustache Прегледај датотеку


spec/_files/array_of_strings.txt → test/_files/array_of_strings.txt Прегледај датотеку


+ 3
- 0
test/_files/backslashes.js Прегледај датотеку

@@ -0,0 +1,3 @@
({
value: "\\abc"
})

spec/_files/backslashes.mustache → test/_files/backslashes.mustache Прегледај датотеку


spec/_files/backslashes.txt → test/_files/backslashes.txt Прегледај датотеку


+ 3
- 0
test/_files/bug_11_eating_whitespace.js Прегледај датотеку

@@ -0,0 +1,3 @@
({
tag: "yo"
})

spec/_files/bug_11_eating_whitespace.mustache → test/_files/bug_11_eating_whitespace.mustache Прегледај датотеку


spec/_files/bug_11_eating_whitespace.txt → test/_files/bug_11_eating_whitespace.txt Прегледај датотеку


+ 4
- 0
test/_files/changing_delimiters.js Прегледај датотеку

@@ -0,0 +1,4 @@
({
"foo": "foooooooooooooo",
"bar": "<b>bar!</b>"
})

spec/_files/changing_delimiters.mustache → test/_files/changing_delimiters.mustache Прегледај датотеку


spec/_files/changing_delimiters.txt → test/_files/changing_delimiters.txt Прегледај датотеку


+ 5
- 0
test/_files/comments.js Прегледај датотеку

@@ -0,0 +1,5 @@
({
title: function () {
return "A Comedy of Errors";
}
})

spec/_files/comments.mustache → test/_files/comments.mustache Прегледај датотеку


spec/_files/comments.txt → test/_files/comments.txt Прегледај датотеку


spec/_files/complex.js → test/_files/complex.js Прегледај датотеку

@@ -1,5 +1,5 @@
var complex = {
header: function() {
({
header: function () {
return "Colors";
},
item: [
@@ -7,13 +7,13 @@ var complex = {
{name: "green", current: false, url: "#Green"},
{name: "blue", current: false, url: "#Blue"}
],
link: function() {
link: function () {
return this["current"] !== true;
},
list: function() {
list: function () {
return this.item.length !== 0;
},
empty: function() {
empty: function () {
return this.item.length === 0;
}
};
})

spec/_files/complex.mustache → test/_files/complex.mustache Прегледај датотеку


spec/_files/complex.txt → test/_files/complex.txt Прегледај датотеку


spec/_files/context_lookup.js → test/_files/context_lookup.js Прегледај датотеку

@@ -1,8 +1,8 @@
var context_lookup = {
({
"outer": {
"id": 1,
"second": {
"nothing": 2
}
}
};
})

spec/_files/context_lookup.mustache → test/_files/context_lookup.mustache Прегледај датотеку


spec/_files/context_lookup.txt → test/_files/context_lookup.txt Прегледај датотеку


spec/_files/delimiters.js → test/_files/delimiters.js Прегледај датотеку

@@ -1,6 +1,6 @@
var delimiters = {
({
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!."
}
})

spec/_files/delimiters.mustache → test/_files/delimiters.mustache Прегледај датотеку


spec/_files/delimiters.txt → test/_files/delimiters.txt Прегледај датотеку


+ 4
- 0
test/_files/disappearing_whitespace.js Прегледај датотеку

@@ -0,0 +1,4 @@
({
bedrooms: true,
total: 1
})

spec/_files/disappearing_whitespace.mustache → test/_files/disappearing_whitespace.mustache Прегледај датотеку


spec/_files/disappearing_whitespace.txt → test/_files/disappearing_whitespace.txt Прегледај датотеку


spec/_files/dot_notation.js → test/_files/dot_notation.js Прегледај датотеку

@@ -1,17 +1,17 @@
var dot_notation = {
({
name: "A Book",
authors: ["John Power", "Jamie Walsh"],
price:{
price: {
value: 200,
vat: function() {
vat: function () {
return this.value * 0.2;
},
currency: {
symbol: '&euro;',
name: 'Euro'
symbol: '$',
name: 'USD'
}
},
availability:{
availability: {
status: true,
text: "In Stock"
},
@@ -20,4 +20,4 @@ var dot_notation = {
zero: 0,
notTrue: false
}
};
})

spec/_files/dot_notation.mustache → test/_files/dot_notation.mustache Прегледај датотеку

@@ -1,8 +1,8 @@
<!-- exciting part -->
<h1>{{name}}</h1>
<p>Authors: <ul>{{#authors}}<li>{{.}}</li>{{/authors}}</ul></p>
<p>Price: {{price.currency.symbol}}{{price.value}} {{#price.currency}}{{name}} <b>{{availability.text}}</b>{{/price.currency}}</p>
<p>VAT: {{price.currency.symbol}}{{price.vat}}</p>
<p>Price: {{{price.currency.symbol}}}{{price.value}} {{#price.currency}}{{name}} <b>{{availability.text}}</b>{{/price.currency}}</p>
<p>VAT: {{{price.currency.symbol}}}{{#price}}{{vat}}{{/price}}</p>
<!-- boring part -->
<h2>Test truthy false values:</h2>
<p>Zero: {{truthy.zero}}</p>

spec/_files/dot_notation.txt → test/_files/dot_notation.txt Прегледај датотеку

@@ -1,8 +1,8 @@
<!-- exciting part -->
<h1>A Book</h1>
<p>Authors: <ul><li>John Power</li><li>Jamie Walsh</li></ul></p>
<p>Price: &euro;200 Euro <b>In Stock</b></p>
<p>VAT: &euro;40</p>
<p>Price: $200 USD <b>In Stock</b></p>
<p>VAT: $40</p>
<!-- boring part -->
<h2>Test truthy false values:</h2>
<p>Zero: 0</p>

spec/_files/double_render.js → test/_files/double_render.js Прегледај датотеку

@@ -1,5 +1,5 @@
var double_render = {
({
foo: true,
bar: "{{win}}",
win: "FAIL"
};
})

spec/_files/double_render.mustache → test/_files/double_render.mustache Прегледај датотеку


spec/_files/double_render.txt → test/_files/double_render.txt Прегледај датотеку


+ 3
- 0
test/_files/empty_list.js Прегледај датотеку

@@ -0,0 +1,3 @@
({
jobs: []
})

spec/_files/empty_list.mustache → test/_files/empty_list.mustache Прегледај датотеку


spec/_files/empty_list.txt → test/_files/empty_list.txt Прегледај датотеку


+ 1
- 0
test/_files/empty_sections.js Прегледај датотеку

@@ -0,0 +1 @@
({})

spec/_files/empty_sections.mustache → test/_files/empty_sections.mustache Прегледај датотеку


spec/_files/empty_sections.txt → test/_files/empty_sections.txt Прегледај датотеку


spec/_files/empty_string.js → test/_files/empty_string.js Прегледај датотеку

@@ -1,6 +1,6 @@
var empty_string = {
({
description: "That is all!",
child: {
description: ""
}
};
})

spec/_files/empty_string.mustache → test/_files/empty_string.mustache Прегледај датотеку


spec/_files/empty_string.txt → test/_files/empty_string.txt Прегледај датотеку


+ 1
- 0
test/_files/empty_template.js Прегледај датотеку

@@ -0,0 +1 @@
({})

spec/_files/empty_template.mustache → test/_files/empty_template.mustache Прегледај датотеку


spec/_files/empty_template.txt → test/_files/empty_template.txt Прегледај датотеку


+ 3
- 0
test/_files/error_not_found.js Прегледај датотеку

@@ -0,0 +1,3 @@
({
bar: 2
})

spec/_files/error_not_found.mustache → test/_files/error_not_found.mustache Прегледај датотеку


spec/_files/error_not_found.txt → test/_files/error_not_found.txt Прегледај датотеку


+ 6
- 0
test/_files/escaped.js Прегледај датотеку

@@ -0,0 +1,6 @@
({
title: function () {
return "Bear > Shark";
},
entities: "&quot; \"'<>/"
})

+ 2
- 0
test/_files/escaped.mustache Прегледај датотеку

@@ -0,0 +1,2 @@
<h1>{{title}}</h1>
And even {{entities}}, but not {{{entities}}}.

+ 2
- 0
test/_files/escaped.txt Прегледај датотеку

@@ -0,0 +1,2 @@
<h1>Bear &gt; Shark</h1>
And even &amp;quot; &quot;&#39;&lt;&gt;&#x2F;, but not &quot; "'<>/.

+ 8
- 0
test/_files/falsy.js Прегледај датотеку

@@ -0,0 +1,8 @@
({
"emptyString": "",
"emptyArray": [],
"zero": 0,
"null": null,
"undefined": undefined,
"NaN": 0/0
})

Неке датотеке нису приказане због велике количине промена

Loading…
Откажи
Сачувај