Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
21 lib/plates.js
@@ -31,32 +31,31 @@ var Plates = (typeof process !== 'undefined' && typeof process.title !== 'undefi
},
balance: function(html, tagname) {
- var i = -1;
- var idx = skip = 0;
- matches = html.match(new RegExp(this.tag.source, 'g'));
+ var i = idx = skip = 0;
+ matches = html.match(new RegExp(this.tag.source, 'g')); // globalize
do {
var components = this.tag.exec(matches[idx]);
if ( components[2] === tagname) {
if (components[4]) {
- continue;
+ continue; // ignore isSelfClosing
}
if (components[1]) {
--i;
- ++skip;
+ ++skip; // isClosing
} else {
- ++i;
+ ++i; // opening, matches segment-wrapping tagname
}
}
++idx;
- } while (i >= 0);
+ } while (i > 0);
// Now skip should tell us how many closing tags to look for
- var start = 0;
+ var end = 0;
for (var i = 0; i < skip; i++) {
- start = html.indexOf('</' + tagname, start) + tagname.length + 3;
+ end = html.indexOf('</' + tagname, end) + tagname.length + 3;
}
-
- return html.substr(0, start);
+
+ return html.substr(0, end);
},
iterate: function(html, value, components, tagname, key) {
View
7 test/api-test.js
@@ -222,6 +222,13 @@ vows.describe('merge data into markup').addBatch({
function() {
return common.createTest('test-21');
}()
+ ),
+
+ '(22) Keep your place after handling nested objects, more varied html': (
+
+ function() {
+ return common.createTest('test-22');
+ }()
)
}
View
12 test/fixtures/test-21.html
@@ -1,11 +1 @@
-<div id="entries">
- <div class="entry">
- <div class="created"></div>
- <div class="user">
- <div class="name"></div>
- <div class="city"></div>
- <div class="state"></div>
- </div>
- <div class="custid"></div>
- </div>
-</div>
+<div id="entries"><div class="entry"><div class="created"></div><div class="user"><div class="name"></div><div class="city"></div><div class="state"></div></div><div class="custid"></div></div></div>
View
2  test/fixtures/test-21.json
@@ -1,5 +1,5 @@
{
- "entries": [
+ "entry": [
{
"custid": 10101,
"created": "2001-01-01",
View
30 test/fixtures/test-21.out
@@ -1,29 +1 @@
-<div id="entries">
- <div class="entry">
- <div class="created">2001-01-01</div>
- <div class="user">
- <div class="name">John Q. User</div>
- <div class="city">Atlanta</div>
- <div class="state">GA</div>
- </div>
- <div class="custid">10101</div>
- </div>
- <div class="entry">
- <div class="created">2002-02-02</div>
- <div class="user">
- <div class="name">Jane Q. User</div>
- <div class="city">Mobile</div>
- <div class="state">AL</div>
- </div>
- <div class="custid">20202</div>
- </div>
- <div class="entry">
- <div class="created">2003-0303</div>
- <div class="user">
- <div class="name">Professor X</div>
- <div class="city">Menlo</div>
- <div class="state">CA</div>
- </div>
- <div class="custid">30303</div>
- </div>
-</div>
+<div id="entries"><div class="entry"><div class="created">2001-01-01</div><div class="user"><div class="name">John Q. User</div><div class="city">Atlanta</div><div class="state">GA</div></div><div class="custid">10101</div></div><div class="entry"><div class="created">2002-02-02</div><div class="user"><div class="name">Jane Q. User</div><div class="city">Mobile</div><div class="state">AL</div></div><div class="custid">20202</div></div><div class="entry"><div class="created">2003-0303</div><div class="user"><div class="name">Professor X</div><div class="city">Menlo</div><div class="state">CA</div></div><div class="custid">30303</div></div></div>
View
1  test/fixtures/test-22.html
@@ -0,0 +1 @@
+<ul id="entries"><li class="entry"><div class="created"></div><div class="user"><div class="name"></div><div class="city"></div><div class="state"></div></div><div class="custid"></div></li></ul>
View
31 test/fixtures/test-22.json
@@ -0,0 +1,31 @@
+{
+ "entry": [
+ {
+ "custid": 10101,
+ "created": "2001-01-01",
+ "user": {
+ "name": "John Q. User",
+ "city": "Atlanta",
+ "state": "GA"
+ }
+ },
+ {
+ "custid": 20202,
+ "created": "2002-02-02",
+ "user": {
+ "name": "Jane Q. User",
+ "city": "Mobile",
+ "state": "AL"
+ }
+ },
+ {
+ "custid": 30303,
+ "created": "2003-0303",
+ "user": {
+ "name": "Professor X",
+ "city": "Menlo",
+ "state": "CA"
+ }
+ }
+ ]
+}
View
1  test/fixtures/test-22.out
@@ -0,0 +1 @@
+<ul id="entries"><li class="entry"><div class="created">2001-01-01</div><div class="user"><div class="name">John Q. User</div><div class="city">Atlanta</div><div class="state">GA</div></div><div class="custid">10101</div></li><li class="entry"><div class="created">2002-02-02</div><div class="user"><div class="name">Jane Q. User</div><div class="city">Mobile</div><div class="state">AL</div></div><div class="custid">20202</div></li><li class="entry"><div class="created">2003-0303</div><div class="user"><div class="name">Professor X</div><div class="city">Menlo</div><div class="state">CA</div></div><div class="custid">30303</div></li></ul>

No commit comments for this range

Something went wrong with that request. Please try again.