Permalink
Browse files

Adds the ability to properly map an iterative object, as tested in th…

…e newly added case 14.
  • Loading branch information...
nhunzaker authored and pksunkara committed Feb 23, 2012
1 parent d1fd5a2 commit d2680fe367e43f148e02780c7475d59e81ed5995
Showing with 40 additions and 2 deletions.
  1. +8 −1 lib/plates.js
  2. +15 −1 test/api-test.js
  3. +1 −0 test/fixtures/test-14.html
  4. +15 −0 test/fixtures/test-14.json
  5. +1 −0 test/fixtures/test-14.out
View
@@ -183,8 +183,15 @@
if (mappings[ii].value === value || that.hasClass(value, mappings[ii].value || mappings.conf.where === key)) {
- buffer += tagbody + (newdata || '');
+ var v = data[mappings[ii].dataKey];
+
+ newdata = isArray(v) ? that.iterate(html, v, components, tagname, value)
+ : tagbody + (typeof v === 'object' ? that.iterate(html, v, components, tagname, value) : newdata);
+
+ buffer += newdata || '';
+
matchmode = true;
+
}
}
View
@@ -184,7 +184,21 @@ vows.describe('merge data into markup').addBatch({
}()
- )
+ ),
+
+ '(14) It should be able to iterate over collections with maps': (
+
+ function() {
+
+ var map = Plates.Map();
+
+ map.class("names").use("names");
+
+ return common.createTest('test-14', map);
+
+ }()
+
+ ),
}
}).export(module);
@@ -0,0 +1 @@
+<table><tr class="names"><td class="first"></td><td class="last"></td></tr></table>
View
@@ -0,0 +1,15 @@
+{
+ "names" : [
+
+ {
+ "first" : "John",
+ "last" : "Smith"
+ },
+ {
+ "first" : "Jane",
+ "last" : "Doe"
+ }
+ ],
+
+ "className" : "jim"
+}
@@ -0,0 +1 @@
+<table><tr class="names"><td class="first">John</td><td class="last">Smith</td></tr><tr class="names"><td class="first">Jane</td><td class="last">Doe</td></tr></table>

0 comments on commit d2680fe

Please sign in to comment.