Skip to content

Commit

Permalink
Support vertical space between attributes in polymer element definition
Browse files Browse the repository at this point in the history
Add tests for comma and vertical space delimiters

Fixes Polymer#393
  • Loading branch information
dfreedm committed Jan 17, 2014
1 parent f0ae7b8 commit 09fa217
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/declaration/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// magic words

var ATTRIBUTES_ATTRIBUTE = 'attributes';
var ATTRIBUTES_REGEX = /\s|,/;

// attributes api

Expand All @@ -25,7 +26,7 @@
// get properties to publish
var publish = prototype.publish || (prototype.publish = {});
// names='a b c' or names='a,b,c'
var names = attributes.split(attributes.indexOf(',') >= 0 ? ',' : ' ');
var names = attributes.split(ATTRIBUTES_REGEX);
// record each name for publishing
for (var i=0, l=names.length, n; i<l; i++) {
// remove excess ws
Expand Down
47 changes: 47 additions & 0 deletions test/html/take-attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,40 @@
<x-obj id="obj2" values='{ "color": "Red" }'></x-obj>
<x-obj id="obj3" values="{ 'movie': 'Buckaroo Banzai', 'DOB': '07/31/1978' }"></x-obj>

<polymer-element name="x-commas" attributes="bool,num,str">
<script>
Polymer('x-commas', {
bool: false,
num: 42,
str: "don't panic"
});
</script>
</polymer-element>

<x-commas id="comma1" bool="true"></x-commas>
<x-commas id="comma2" bool="false"></x-commas>
<x-commas id="comma3" bool></x-commas>
<x-commas id="comma4" num="1"></x-commas>
<x-commas id="comma5" str="hi"></x-commas>

<polymer-element name="x-vertspace" attributes="bool
num
str">
<script>
Polymer('x-vertspace', {
bool: false,
num: 42,
str: "don't panic"
});
</script>
</polymer-element>

<x-vertspace id="vertspace1" bool="true"></x-vertspace>
<x-vertspace id="vertspace2" bool="false"></x-vertspace>
<x-vertspace id="vertspace3" bool></x-vertspace>
<x-vertspace id="vertspace4" num="1"></x-vertspace>
<x-vertspace id="vertspace5" str="hi"></x-vertspace>

<script>
var assert = chai.assert;
document.addEventListener('WebComponentsReady', function() {
Expand Down Expand Up @@ -158,6 +192,19 @@
assert.deepEqual(document.querySelector("#obj2").values, { "color": "Red" });
assert.deepEqual(document.querySelector("#obj3").values, { movie: 'Buckaroo Banzai', DOB: '07/31/1978' });
//
// Comma test
assert.isTrue(document.querySelector('#comma1').bool);
assert.isFalse(document.querySelector('#comma2').bool);
assert.isTrue(document.querySelector('#comma3').bool);
assert.equal(document.querySelector('#comma4').num, 1);
assert.equal(document.querySelector('#comma5').str, 'hi');
//
// Vertical Space test
assert.isTrue(document.querySelector('#vertspace1').bool);
assert.isFalse(document.querySelector('#vertspace2').bool);
assert.isTrue(document.querySelector('#vertspace3').bool);
assert.equal(document.querySelector('#vertspace4').num, 1);
assert.equal(document.querySelector('#vertspace5').str, 'hi');
done();
});
</script>
Expand Down

0 comments on commit 09fa217

Please sign in to comment.