Explorar el Código

Allow arbitrary whitespace within tags. Closes #34.

tags/0.3.0
Aaron Gibralter Jan Lehnardt <jan@apache.org> hace 16 años
padre
commit
e25eeaebb8
Se han modificado 5 ficheros con 36 adiciones y 2 borrados
  1. +5
    -0
      examples/whitespace_partial.2.html
  2. +3
    -0
      examples/whitespace_partial.html
  3. +19
    -0
      examples/whitespace_partial.js
  4. +6
    -0
      examples/whitespace_partial.txt
  5. +3
    -2
      mustache.js

+ 5
- 0
examples/whitespace_partial.2.html Ver fichero

@@ -0,0 +1,5 @@
Hello {{ name}}
You have just won ${{value }}!
{{# in_ca }}
Well, ${{ taxed_value }}, after taxes.
{{/ in_ca }}

+ 3
- 0
examples/whitespace_partial.html Ver fichero

@@ -0,0 +1,3 @@
<h1>{{ greeting }}</h1>
{{> partial }}
<h3>{{ farewell }}</h3>

+ 19
- 0
examples/whitespace_partial.js Ver fichero

@@ -0,0 +1,19 @@
var partial_context = {
greeting: function() {
return "Welcome";
},

farewell: function() {
return "Fair enough, right?";
},

partial: {
name: "Chris",
value: 10000,
taxed_value: function() {
return this.value - (this.value * 0.4);
},
in_ca: true
}
};


+ 6
- 0
examples/whitespace_partial.txt Ver fichero

@@ -0,0 +1,6 @@
<h1>Welcome</h1>
Hello Chris
You have just won $10000!
Well, $6000, after taxes.

<h3>Fair enough, right?</h3>

+ 3
- 2
mustache.js Ver fichero

@@ -84,6 +84,7 @@ var Mustache = function() {
Tries to find a partial in the global scope and render it
*/
render_partial: function(name, context, partials) {
name = this.trim(name);
if(!partials || !partials[name]) {
throw({message: "unknown_partial '" + name + "'"});
}
@@ -103,8 +104,8 @@ var Mustache = function() {

var that = this;
// CSW - Added "+?" so it finds the tighest bound, not the widest
var regex = new RegExp(this.otag + "(\\^|\\#)(.+)" + this.ctag +
"\\s*([\\s\\S]+?)" + this.otag + "\\/\\2" + this.ctag +
var regex = new RegExp(this.otag + "(\\^|\\#)\\s*(.+)\\s*" + this.ctag +
"\\s*([\\s\\S]+?)" + this.otag + "\\/\\s*\\2\\s*" + this.ctag +
"\\s*", "mg");

// for each {{#foo}}{{/foo}} section do...


Cargando…
Cancelar
Guardar