polymer-rails 0.2.8 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -3
  3. data/app/assets/javascripts/polymer/polymer-micro.html +36 -0
  4. data/app/assets/javascripts/polymer/polymer-mini.html +45 -0
  5. data/app/assets/javascripts/polymer/polymer.html +59 -11
  6. data/app/assets/javascripts/polymer/src/lib/annotations/annotations.html +262 -0
  7. data/app/assets/javascripts/polymer/src/lib/annotations/demo/app-chrome.html +60 -0
  8. data/app/assets/javascripts/polymer/src/lib/array-observe.html +118 -0
  9. data/app/assets/javascripts/polymer/src/lib/array-splice.html +262 -0
  10. data/app/assets/javascripts/polymer/src/lib/async.html +68 -0
  11. data/app/assets/javascripts/polymer/src/lib/base.html +117 -0
  12. data/app/assets/javascripts/polymer/src/lib/bind/accessors.html +223 -0
  13. data/app/assets/javascripts/polymer/src/lib/bind/demo/app-chrome.html +28 -0
  14. data/app/assets/javascripts/polymer/src/lib/bind/demo/app.html +29 -0
  15. data/app/assets/javascripts/polymer/src/lib/bind/demo/src/annotations-bind-demo.html +76 -0
  16. data/app/assets/javascripts/polymer/src/lib/bind/demo/src/bind-demo.html +83 -0
  17. data/app/assets/javascripts/polymer/src/lib/bind/effects.html +80 -0
  18. data/app/assets/javascripts/polymer/src/lib/case-map.html +46 -0
  19. data/app/assets/javascripts/polymer/src/lib/collection.html +179 -0
  20. data/app/assets/javascripts/polymer/src/lib/css-parse.html +131 -0
  21. data/app/assets/javascripts/polymer/src/lib/debounce.html +69 -0
  22. data/app/assets/javascripts/polymer/src/lib/dom-api.html +467 -0
  23. data/app/assets/javascripts/polymer/src/lib/dom-module.html +68 -0
  24. data/app/assets/javascripts/polymer/src/lib/event-api.html +92 -0
  25. data/app/assets/javascripts/polymer/src/lib/expr/focus.html +22 -0
  26. data/app/assets/javascripts/polymer/src/lib/expr/gestures.html +1 -0
  27. data/app/assets/javascripts/polymer/src/lib/expr/log.html +21 -0
  28. data/app/assets/javascripts/polymer/src/lib/expr/sinspect.html +235 -0
  29. data/app/assets/javascripts/polymer/src/lib/expr/style-auditor.html +123 -0
  30. data/app/assets/javascripts/polymer/src/lib/expr/style-protector.html +52 -0
  31. data/app/assets/javascripts/polymer/src/lib/gestures.html +284 -0
  32. data/app/assets/javascripts/polymer/src/lib/lang.html +21 -0
  33. data/app/assets/javascripts/polymer/src/lib/module.html +56 -0
  34. data/app/assets/javascripts/polymer/src/lib/polymer-bootstrap.html +78 -0
  35. data/app/assets/javascripts/polymer/src/lib/resolve-url.html +82 -0
  36. data/app/assets/javascripts/polymer/src/lib/settings.html +52 -0
  37. data/app/assets/javascripts/polymer/src/lib/style-defaults.html +32 -0
  38. data/app/assets/javascripts/polymer/src/lib/style-transformer.html +185 -0
  39. data/app/assets/javascripts/polymer/src/lib/style-util.html +77 -0
  40. data/app/assets/javascripts/polymer/src/lib/template/templatizer.html +132 -0
  41. data/app/assets/javascripts/polymer/src/lib/template/x-array-selector.html +178 -0
  42. data/app/assets/javascripts/polymer/src/lib/template/x-autobind.html +80 -0
  43. data/app/assets/javascripts/polymer/src/lib/template/x-if.html +115 -0
  44. data/app/assets/javascripts/polymer/src/lib/template/x-repeat.html +510 -0
  45. data/app/assets/javascripts/polymer/src/lib/template/x-template.html +39 -0
  46. data/app/assets/javascripts/polymer/src/lib/x-style.html +115 -0
  47. data/app/assets/javascripts/polymer/src/micro/attributes.html +180 -0
  48. data/app/assets/javascripts/polymer/src/micro/constructor.html +74 -0
  49. data/app/assets/javascripts/polymer/src/micro/extends.html +79 -0
  50. data/app/assets/javascripts/polymer/src/micro/mixins.html +40 -0
  51. data/app/assets/javascripts/polymer/src/micro/properties.html +96 -0
  52. data/app/assets/javascripts/polymer/src/micro/tag.html +28 -0
  53. data/app/assets/javascripts/polymer/src/mini/ready.html +180 -0
  54. data/app/assets/javascripts/polymer/src/mini/shadow.html +41 -0
  55. data/app/assets/javascripts/polymer/src/mini/shady.html +365 -0
  56. data/app/assets/javascripts/polymer/src/mini/template.html +56 -0
  57. data/app/assets/javascripts/polymer/src/polymer-lib.html +15 -0
  58. data/app/assets/javascripts/polymer/src/standard/annotations.html +198 -0
  59. data/app/assets/javascripts/polymer/src/standard/configure.html +160 -0
  60. data/app/assets/javascripts/polymer/src/standard/effects.html +215 -0
  61. data/app/assets/javascripts/polymer/src/standard/events.html +127 -0
  62. data/app/assets/javascripts/polymer/src/standard/notify-path.html +260 -0
  63. data/app/assets/javascripts/polymer/src/standard/resolveUrl.html +27 -0
  64. data/app/assets/javascripts/polymer/src/standard/styling.html +157 -0
  65. data/app/assets/javascripts/polymer/src/standard/utils.html +158 -0
  66. data/app/assets/javascripts/polymer/src/standard/x-styling.html +300 -0
  67. data/app/assets/javascripts/webcomponentsjs/webcomponents-lite.js +2270 -0
  68. data/lib/generators/polymer/component/templates/component.html.erb +3 -3
  69. data/lib/generators/polymer/install/install_generator.rb +1 -1
  70. data/lib/polymer-rails/version.rb +1 -1
  71. metadata +80 -5
  72. data/app/assets/javascripts/polymer/layout.html +0 -286
  73. data/app/assets/javascripts/polymer/polymer.js +0 -14
  74. data/app/assets/javascripts/polymer/webcomponents.js +0 -14
@@ -0,0 +1,83 @@
1
+ <link rel="import" href="../../../module.html">
2
+ <link rel="import" href="../../bind.html">
3
+ <link rel="import" href="../../bind-effects.html">
4
+
5
+ <script>
6
+
7
+ using(['bind'], function(Bind) {
8
+
9
+ var out = document.querySelector('#bd');
10
+ out.innerHTML += '<hr><h3>bind demo</h3><hr>';
11
+
12
+ // phase one: prototyping
13
+
14
+ var model = {};
15
+
16
+ Bind.prepareModel(model);
17
+
18
+ // 'observer' effects are called if foo changes value as fx(foo, old)
19
+
20
+ Bind.addPropertyEffect(model, 'foo', 'observer', 'fooChange');
21
+ Bind.addPropertyEffect(model, 'foo', 'observer', 'fooWork');
22
+
23
+ model.fooChange = function(foo) {
24
+ out.innerHTML += '<b>fooChange</b>: effect of changing foo to ' + foo + '\n';
25
+ console.log('fooChange: effect of changing foo to %d', foo);
26
+ };
27
+
28
+ model.fooWork = function(foo) {
29
+ out.innerHTML += '<b>fooWork</b>: effect of changing foo to ' + foo + '\n';
30
+ console.log('fooWork: effect of changing foo to %d', foo);
31
+ };
32
+
33
+ // 'compute' effect sets the value of bar to the result of computeBar when
34
+ // foo changes value
35
+
36
+ /*
37
+ Bind.addPropertyEffect(model, 'foo', 'compute', {
38
+ method: 'computeBar',
39
+ property: 'bar'
40
+ });
41
+ */
42
+ Bind.addComputedPropertyEffect(model, 'bar', 'computeFooTimes2(foo)');
43
+
44
+ model.computeFooTimes2 = function(foo) {
45
+ var foo2 = foo * 2;
46
+ out.innerHTML += '<b>computeFooTimes2</b>: calculated ' + foo2 + ' as an effect of changing foo to ' + foo + '\n';
47
+ console.log('computeFooTimes2: calculated %d as effect of changing foo to %d', foo2, foo);
48
+ return foo2;
49
+ };
50
+
51
+ // custom effect
52
+
53
+ Bind.addBuilder('async', function(model, property, effect) {
54
+ var fn = function() {
55
+ var flag = '_propertyTask';
56
+ clearTimeout(this[flag]);
57
+ this[flag] = setTimeout(function() {
58
+ this.effect(this.property);
59
+ this[flag] = 0;
60
+ }.bind(this));
61
+ };
62
+ var code = fn.toString().split('\n').slice(1, -1).join('\n');
63
+ return code.replace(/property/g, property).replace(/effect/g, effect);
64
+ });
65
+
66
+ Bind.addPropertyEffect(model, 'foo', 'async', 'asyncFoo');
67
+
68
+ model.asyncFoo = function(foo) {
69
+ out.innerHTML += '<b>asyncFoo</b>: effect of changing foo to ' + foo + '\n';
70
+ console.log('asyncFoo: effect of changing foo to %d', foo);
71
+ };
72
+
73
+ // phase two: instancing
74
+
75
+ Bind.prepareInstance(model);
76
+ Bind.createBindings(model);
77
+
78
+ model.foo = 3;
79
+ model.foo = 6;
80
+
81
+ });
82
+
83
+ </script>
@@ -0,0 +1,80 @@
1
+ <!--
2
+ @license
3
+ Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4
+ This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5
+ The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6
+ The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7
+ Code distributed by Google as part of the polymer project is also
8
+ subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9
+ -->
10
+ <link rel="import" href="../case-map.html">
11
+ <script>
12
+
13
+ Polymer.Base.extend(Polymer.Bind, {
14
+
15
+ _shouldAddListener: function(info) {
16
+ return info.name &&
17
+ info.mode === '{' &&
18
+ !info.negate &&
19
+ info.kind != 'attribute'
20
+ ;
21
+ },
22
+
23
+ annotationEffect: function(source, value, info) {
24
+ if (source != info.value) {
25
+ value = this.getPathValue(info.value);
26
+ }
27
+ var calc = info.negate ? !value : value;
28
+ return this._applyEffectValue(calc, info);
29
+ },
30
+
31
+ reflectEffect: function(source) {
32
+ this.reflectPropertyToAttribute(source);
33
+ },
34
+
35
+ notifyEffect: function(source) {
36
+ this._notifyChange(source);
37
+ },
38
+
39
+ observerEffect: function(source, value, info, old) {
40
+ //console.log(value, info);
41
+ if (info.property) {
42
+ this[info.method](value, old);
43
+ } else {
44
+ var args = Polymer.Bind._marshalArgs(this._data, info.properties);
45
+ if (args) {
46
+ this[info.method].apply(this, args);
47
+ }
48
+ }
49
+ },
50
+
51
+ computeEffect: function(source, value, info) {
52
+ var args = Polymer.Bind._marshalArgs(this._data, info.args);
53
+ if (args) {
54
+ this[info.property] = this[info.methodName].apply(this, args);
55
+ }
56
+ },
57
+
58
+ annotatedComputationEffect: function(source, value, info) {
59
+ var args = Polymer.Bind._marshalArgs(this._data, info.args);
60
+ if (args) {
61
+ var value = this[info.methodName].apply(this, args);
62
+ this._applyEffectValue(value, info);
63
+ }
64
+ },
65
+
66
+ _marshalArgs: function(model, properties) {
67
+ var a=[];
68
+ for (var i=0, l=properties.length, v; i<l; i++) {
69
+ v = model[properties[i]];
70
+ if (v === undefined) {
71
+ return;
72
+ }
73
+ a[i] = v;
74
+ }
75
+ return a;
76
+ }
77
+
78
+ });
79
+
80
+ </script>
@@ -0,0 +1,46 @@
1
+ <!--
2
+ @license
3
+ Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4
+ This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5
+ The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6
+ The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7
+ Code distributed by Google as part of the polymer project is also
8
+ subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9
+ -->
10
+ <script>
11
+
12
+ Polymer.CaseMap = {
13
+
14
+ _caseMap: {},
15
+
16
+ dashToCamelCase: function(dash) {
17
+ var mapped = Polymer.CaseMap._caseMap[dash];
18
+ if (mapped) {
19
+ return mapped;
20
+ }
21
+ // TODO(sjmiles): is rejection test actually helping perf?
22
+ if (dash.indexOf('-') < 0) {
23
+ return Polymer.CaseMap._caseMap[dash] = dash;
24
+ }
25
+ return Polymer.CaseMap._caseMap[dash] = dash.replace(/-([a-z])/g,
26
+ function(m) {
27
+ return m[1].toUpperCase();
28
+ }
29
+ );
30
+ },
31
+
32
+ camelToDashCase: function(camel) {
33
+ var mapped = Polymer.CaseMap._caseMap[camel];
34
+ if (mapped) {
35
+ return mapped;
36
+ }
37
+ return Polymer.CaseMap._caseMap[camel] = camel.replace(/([a-z][A-Z])/g,
38
+ function (g) {
39
+ return g[0] + '-' + g[1].toLowerCase()
40
+ }
41
+ );
42
+ }
43
+
44
+ };
45
+
46
+ </script>
@@ -0,0 +1,179 @@
1
+ <!--
2
+ @license
3
+ Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4
+ This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5
+ The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6
+ The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7
+ Code distributed by Google as part of the polymer project is also
8
+ subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9
+ -->
10
+
11
+ <link rel="import" href="array-observe.html">
12
+ <link rel="import" href="debounce.html">
13
+
14
+ <script>
15
+
16
+ Polymer._collections = new WeakMap();
17
+
18
+ Polymer.Collection = function(userArray, noObserve) {
19
+ Polymer._collections.set(userArray, this);
20
+ this.userArray = userArray;
21
+ this.store = userArray.slice();
22
+ this.callbacks = [];
23
+ this.debounce = null;
24
+ this.map = null;
25
+ this.added = [];
26
+ this.removed = [];
27
+ if (!noObserve) {
28
+ Polymer.ArrayObserve.observe(userArray, this.applySplices.bind(this));
29
+ this.initMap();
30
+ }
31
+ };
32
+
33
+ Polymer.Collection.prototype = {
34
+ constructor: Polymer.Collection,
35
+
36
+ initMap: function() {
37
+ var map = this.map = new WeakMap();
38
+ var s = this.store;
39
+ var u = this.userArray;
40
+ for (var i=0; i<s.length; i++) {
41
+ var v = s[i];
42
+ if (v) {
43
+ switch (typeof v) {
44
+ case 'string':
45
+ v = s[i] = u[i]= new String(v);
46
+ break;
47
+ case 'number':
48
+ v = s[i] = u[i]= new Number(v);
49
+ break;
50
+ case 'boolean':
51
+ v = s[i] = u[i]= new Boolean(v);
52
+ break;
53
+ }
54
+ map.set(v, i);
55
+ }
56
+ }
57
+ },
58
+
59
+ add: function(item, squelch) {
60
+ var key = this.store.push(item) - 1;
61
+ if (item != null && this.map) {
62
+ this.map.set(item, key);
63
+ }
64
+ if (!squelch) {
65
+ this.added.push(key);
66
+ this.debounce = Polymer.Debounce(this.debounce, this.notify.bind(this));
67
+ }
68
+ return key;
69
+ },
70
+
71
+ removeKey: function(key) {
72
+ if (this.map) {
73
+ this.map.delete(this.store[key]);
74
+ }
75
+ delete this.store[key];
76
+ this.removed.push(key);
77
+ this.debounce = Polymer.Debounce(this.debounce, this.notify.bind(this));
78
+ },
79
+
80
+ remove: function(item, squelch) {
81
+ var key = this.getKey(item);
82
+ if (item != null && this.map) {
83
+ this.map.delete(item);
84
+ }
85
+ delete this.store[key];
86
+ if (!squelch) {
87
+ this.removed.push(key);
88
+ this.debounce = Polymer.Debounce(this.debounce, this.notify.bind(this));
89
+ }
90
+ return key;
91
+ },
92
+
93
+ notify: function(splices) {
94
+ if (!splices) {
95
+ splices = [{
96
+ added: this.added,
97
+ removed: this.removed
98
+ }];
99
+ this.added = [];
100
+ this.removed = [];
101
+ }
102
+ this.callbacks.forEach(function(cb) {
103
+ cb(splices);
104
+ }, this);
105
+ },
106
+
107
+ observe: function(callback) {
108
+ this.callbacks.push(callback);
109
+ },
110
+
111
+ unobserve: function(callback) {
112
+ this.callbacks.splice(this.callbacks.indexOf(callback), 1);
113
+ },
114
+
115
+ getKey: function(item) {
116
+ if (item != null && this.map) {
117
+ return this.map.get(item);
118
+ } else {
119
+ return this.store.indexOf(item);
120
+ }
121
+ },
122
+
123
+ getKeys: function() {
124
+ return Object.keys(this.store);
125
+ },
126
+
127
+ setItem: function(key, value) {
128
+ this.store[key] = value;
129
+ },
130
+
131
+ getItem: function(key) {
132
+ return this.store[key];
133
+ },
134
+
135
+ getItems: function() {
136
+ var items = [], store = this.store;
137
+ for (var key in store) {
138
+ items.push(store[key]);
139
+ }
140
+ return items;
141
+ },
142
+
143
+ applySplices: function(splices) {
144
+ var map = this.map;
145
+ var keySplices = [];
146
+ for (var i=0; i<splices.length; i++) {
147
+ var j, o, key, s = splices[i];
148
+ // Removed keys
149
+ var removed = [];
150
+ for (j=0; j<s.removed.length; j++) {
151
+ o = s.removed[j];
152
+ key = this.remove(o, true);
153
+ removed.push(key);
154
+ }
155
+ // Added keys
156
+ var added = [];
157
+ for (j=0; j<s.addedCount; j++) {
158
+ o = this.userArray[s.index + j];
159
+ key = this.add(o, true);
160
+ added.push(key);
161
+ }
162
+ // Record splice
163
+ keySplices.push({
164
+ index: s.index,
165
+ removed: removed,
166
+ added: added
167
+ });
168
+ }
169
+ this.notify(keySplices);
170
+ }
171
+
172
+ };
173
+
174
+ Polymer.Collection.get = function(userArray, noObserve) {
175
+ return Polymer._collections.get(userArray)
176
+ || new Polymer.Collection(userArray, noObserve);
177
+ };
178
+
179
+ </script>
@@ -0,0 +1,131 @@
1
+ <script>
2
+
3
+ /*
4
+ Extremely simple css parser. Intended to be not more than what we need
5
+ and definitely not necessarly correct =).
6
+ */
7
+ (function() {
8
+
9
+ // given a string of css, return a simple rule tree
10
+ function parse(text) {
11
+ text = clean(text);
12
+ return parseCss(lex(text), text);
13
+ }
14
+
15
+ // remove stuff we don't care about that may hinder parsing
16
+ function clean(cssText) {
17
+ return cssText.replace(rx.comments, '').replace(rx.port, '');
18
+ }
19
+
20
+ // super simple {...} lexer that returns a node tree
21
+ function lex(text) {
22
+ var root = {start: 0, end: text.length};
23
+ var n = root;
24
+ for (var i=0, s=0, l=text.length; i < l; i++) {
25
+ switch (text[i]) {
26
+ case OPEN_BRACE:
27
+ //console.group(i);
28
+ if (!n.rules) {
29
+ n.rules = [];
30
+ }
31
+ var p = n;
32
+ var previous = p.rules[p.rules.length-1];
33
+ n = {start: i+1, parent: p, previous: previous};
34
+ p.rules.push(n);
35
+ break;
36
+ case CLOSE_BRACE:
37
+ //console.groupEnd(n.start);
38
+ n.end = i+1;
39
+ n = n.parent || root;
40
+ break;
41
+ }
42
+ }
43
+ return root;
44
+ }
45
+
46
+ // add selectors/cssText to node tree
47
+ function parseCss(node, text) {
48
+ var t = text.substring(node.start, node.end-1);
49
+ node.cssText = t.trim();
50
+ if (node.parent) {
51
+ var ss = node.previous ? node.previous.end : node.parent.start;
52
+ t = text.substring(ss, node.start-1);
53
+ // TODO(sorvell): ad hoc; make selector include only after last ;
54
+ // helps with mixin syntax
55
+ t = t.substring(t.lastIndexOf(';')+1);
56
+ node.selector = t.trim();
57
+ }
58
+ var r$ = node.rules;
59
+ if (r$) {
60
+ for (var i=0, l=r$.length, r; (i<l) && (r=r$[i]); i++) {
61
+ parseCss(r, text);
62
+ }
63
+ }
64
+ return node;
65
+ }
66
+
67
+ // stringify parsed css.
68
+ function stringify(node, text) {
69
+ text = text || '';
70
+ // calc rule cssText
71
+ var cssText = '';
72
+ if (node.cssText || node.rules) {
73
+ var r$ = node.rules;
74
+ if (r$ && !hasMixinRules(r$)) {
75
+ for (var i=0, l=r$.length, r; (i<l) && (r=r$[i]); i++) {
76
+ cssText = stringify(r, cssText);
77
+ }
78
+ } else {
79
+ cssText = removeCustomProps(node.cssText).trim();
80
+ if (cssText) {
81
+ cssText = ' ' + cssText + '\n';
82
+ }
83
+ }
84
+ }
85
+ // emit rule iff there is cssText
86
+ if (cssText) {
87
+ if (node.selector) {
88
+ text += node.selector + ' ' + OPEN_BRACE + '\n';
89
+ }
90
+ text += cssText;
91
+ if (node.selector) {
92
+ text += CLOSE_BRACE + '\n\n';
93
+ }
94
+ }
95
+ return text;
96
+ }
97
+
98
+ var OPEN_BRACE = '{';
99
+ var CLOSE_BRACE = '}';
100
+
101
+ function hasMixinRules(rules) {
102
+ return (rules[0].selector.indexOf(VAR_START) >= 0);
103
+ }
104
+
105
+ function removeCustomProps(cssText) {
106
+ return cssText
107
+ .replace(rx.customProp, '')
108
+ .replace(rx.mixinProp, '')
109
+ .replace(rx.mixinApply, '');
110
+ }
111
+
112
+ var VAR_START = '--';
113
+
114
+ // helper regexp's
115
+ var rx = {
116
+ comments: /\/\*[^*]*\*+([^/*][^*]*\*+)*\//gim,
117
+ port: /@import[^;]*;/gim,
118
+ customProp: /--[^;{]*?:[^{};]*?;/gim,
119
+ mixinProp: /--[^;{]*?:[^{;]*?{[^}]*?}/gim,
120
+ mixinApply: /@mixin[\s]*\([^)]*?\)[\s]*;/gim
121
+ };
122
+
123
+ // exports
124
+ Polymer.CssParse = {
125
+ parse: parse,
126
+ stringify: stringify
127
+ };
128
+
129
+ })();
130
+
131
+ </script>