Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup, comment. Other tests ignore whitespace, I guess I will, too.

  • Loading branch information...
commit d4f646e563af74e63d3f85c9a58a8be7bfffe2cb 1 parent 36223d5
@dougalcampbell authored
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': (
+
+ 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>
Please sign in to comment.
Something went wrong with that request. Please try again.