Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping to array with different values ex map.class('name').use('fullname') #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/plates.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,12 @@ function matchClosing(input, tagname, html) {
newdata = tagbody + newdata;

if (Array.isArray(v)) {
newdata = that.iterate(html, v, components, tagname, value, map);
newdata = that.iterate(html, v, components, tagname, mapping.dataKey, map);
// If the item is an array, then we need to tell
// Plates that we're dealing with nests
that.nest.push(tagname);
} else if (typeof v === 'object') {
newdata = tagbody + that.iterate(html, v, components, tagname, value, map);
newdata = tagbody + that.iterate(html, v, components, tagname, null, map);
}

buffer += newdata || '';
Expand Down
25 changes: 25 additions & 0 deletions test/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,31 @@ vows.describe('merge data into markup').addBatch({

return common.createTest('test-41', map);
}()
),

'(42) Should bind according to the mapping for an array': (

function() {
var map = Plates.Map();

map.class("names").use("names");
map.class("last").use("lastname");

return common.createTest('test-42', map);
}()
),

'(43) Should bind to according to the mapping for an object': (

function() {
var map = Plates.Map();

map.class("name").use("fullname");
map.class("first").use("firstname");
map.class("last").use("lastname");

return common.createTest('test-43', map);
}()
)
}

Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/test-42.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<div class="names">
<div class="last"></div>
</div>
</div>
5 changes: 5 additions & 0 deletions test/fixtures/test-42.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"names" : {
"lastname": [1,2,3]
}
}
5 changes: 5 additions & 0 deletions test/fixtures/test-42.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<div class="names">
<div class="last">1</div><div class="last">2</div><div class="last">3</div>
</div>
</div>
6 changes: 6 additions & 0 deletions test/fixtures/test-43.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div>
<div class="name">
<div class="first"></div>
<div class="last"></div>
</div>
</div>
6 changes: 6 additions & 0 deletions test/fixtures/test-43.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"fullname" : {
"firstname": "bob",
"lastname": "jones"
}
}
6 changes: 6 additions & 0 deletions test/fixtures/test-43.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div>
<div class="name">
<div class="first">bob</div>
<div class="last">jones</div>
</div>
</div>