Skip to content

Commit e25eeae

Browse files
agibralterjanl
authored andcommitted
Allow arbitrary whitespace within tags. Closes janl#34.
1 parent 595f3fb commit e25eeae

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

examples/whitespace_partial.2.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Hello {{ name}}
2+
You have just won ${{value }}!
3+
{{# in_ca }}
4+
Well, ${{ taxed_value }}, after taxes.
5+
{{/ in_ca }}

examples/whitespace_partial.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h1>{{ greeting }}</h1>
2+
{{> partial }}
3+
<h3>{{ farewell }}</h3>

examples/whitespace_partial.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var partial_context = {
2+
greeting: function() {
3+
return "Welcome";
4+
},
5+
6+
farewell: function() {
7+
return "Fair enough, right?";
8+
},
9+
10+
partial: {
11+
name: "Chris",
12+
value: 10000,
13+
taxed_value: function() {
14+
return this.value - (this.value * 0.4);
15+
},
16+
in_ca: true
17+
}
18+
};
19+

examples/whitespace_partial.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<h1>Welcome</h1>
2+
Hello Chris
3+
You have just won $10000!
4+
Well, $6000, after taxes.
5+
6+
<h3>Fair enough, right?</h3>

mustache.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ var Mustache = function() {
8484
Tries to find a partial in the global scope and render it
8585
*/
8686
render_partial: function(name, context, partials) {
87+
name = this.trim(name);
8788
if(!partials || !partials[name]) {
8889
throw({message: "unknown_partial '" + name + "'"});
8990
}
@@ -103,8 +104,8 @@ var Mustache = function() {
103104

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

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

0 commit comments

Comments
 (0)