Skip to content

Commit b1feec3

Browse files
committed
Add support for dash attributes
Fixes #18
1 parent f3b5f72 commit b1feec3

File tree

5 files changed

+54
-10
lines changed

5 files changed

+54
-10
lines changed

angular_bind_polymer.js

+8
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@ directive('bindPolymer', ['$parse', function($parse) {
88
var attrMap = {};
99

1010
for (var prop in $attr) {
11+
var dash_prop = prop.
12+
replace(/([a-z])([A-Z])/g, '$1-$2').
13+
toLowerCase();
14+
1115
if (angular.isString($attr[prop])) {
1216
var _match = $attr[prop].match(/\{\{\s*([\.\w]+)\s*\}\}/);
1317
if (_match) {
18+
// console.log(prop + ': ' + _match[1])
1419
attrMap[prop] = $parse(_match[1]);
20+
if (dash_prop != prop) {
21+
attrMap[dash_prop] = $parse(_match[1]);
22+
}
1523
}
1624
}
1725
}

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-bind-polymer",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"authors": [
55
"Chris Strom <[email protected]>"
66
],

test/BindingSpec.js

+29-4
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,42 @@ describe('Double binding', function(done){
4444
});
4545
});
4646

47+
describe('Custom Elements with dash attributes', function(){
48+
// Build in setup, check expectations in tests
49+
var ngElement, polymerElement;
50+
51+
beforeEach(function(done){
52+
// The angular element is the first child (the <pre> tag)
53+
ngElement = container2.children[0];
54+
polymerElement = container2.children[1];
55+
56+
polymerElement.setAttribute('in', '2');
57+
58+
// Must wait one event loop for ??? to do its thing
59+
setTimeout(done, 0); // One event loop for Polymer to process
60+
});
61+
62+
it('sees polymer update properly', function(){
63+
expect(polymerElement.getAttribute('out-value')).toEqual('4');
64+
});
65+
66+
// The actual test
67+
it('sees values from polymer', function(){
68+
expect(ngElement.innerHTML).toEqual('4');
69+
});
70+
});
71+
4772
describe('Double binding multiple polymer instances', function(done){
4873
// Build in setup, check expectations in tests
4974
var ngElementA, polymerElementA;
5075
var ngElementB, polymerElementB;
5176

5277
beforeEach(function(done){
5378
// The angular element is the first child (the <pre> tag)
54-
ngElementA = container2.children[0];
55-
polymerElementA = container2.children[1];
56-
ngElementB = container2.children[2];
57-
polymerElementB = container2.children[3];
79+
ngElementA = container3.children[0];
80+
polymerElementA = container3.children[1];
81+
ngElementB = container3.children[2];
82+
polymerElementB = container3.children[3];
5883

5984
polymerElementA.setAttribute('in', '2');
6085
polymerElementB.setAttribute('in', '4');

test/PolymerSetup.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ container.appendChild(container1);
1919

2020
var container2 = document.createElement('div');
2121
container2.innerHTML =
22-
'<pre ng-bind="answer2a"></pre>' +
23-
'<x-double bind-polymer in="1" out="{{answer2a}}"></x-double>' +
24-
'<pre ng-bind="answer2b"></pre>' +
25-
'<x-double bind-polymer in="1" out="{{answer2b}}"></x-double>';
22+
'<pre ng-bind="answer2"></pre>' +
23+
'<x-double bind-polymer in="1" out-value="{{answer2}}"></x-double>';
2624
container.appendChild(container2);
2725

26+
var container3 = document.createElement('div');
27+
container3.innerHTML =
28+
'<pre ng-bind="answer3a"></pre>' +
29+
'<x-double bind-polymer in="1" out="{{answer3a}}"></x-double>' +
30+
'<pre ng-bind="answer3b"></pre>' +
31+
'<x-double bind-polymer in="1" out="{{answer3b}}"></x-double>';
32+
container.appendChild(container3);
33+
2834
var object_container = document.createElement('div');
2935
object_container.innerHTML =
3036
'<pre ng-bind="my.answer"></pre>' +

test/x-double.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<link rel="import" href="../bower_components/polymer/polymer.html">
2-
<dom-module name="x-double" attributes="in out">
2+
<dom-module name="x-double" attributes="in out outValue">
33
<template></template>
44
<script>
55
Polymer({
@@ -13,13 +13,18 @@
1313
out: {
1414
type: Number,
1515
reflectToAttribute: true
16+
},
17+
outValue: {
18+
type: Number,
19+
reflectToAttribute: true
1620
}
1721
},
1822
ready: function(){
1923
this.inChanged();
2024
},
2125
inChanged: function(){
2226
this.out = parseInt(this.in) * 2;
27+
this.outValue = parseInt(this.in) * 2;
2328
}
2429
});
2530
</script>

0 commit comments

Comments
 (0)