neo4j-meta_model 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/javascripts/admin/models.js.coffee +25 -0
  6. data/app/assets/javascripts/meta_model.js.coffee +217 -0
  7. data/app/assets/javascripts/router.js.coffee +5 -0
  8. data/app/assets/javascripts/store.js.coffee +12 -0
  9. data/app/assets/javascripts/templates/application.emblem +3 -0
  10. data/app/assets/javascripts/templates/components/model-list-item.emblem +6 -0
  11. data/app/assets/javascripts/templates/components/model-list.emblem +4 -0
  12. data/app/assets/javascripts/templates/has_associations/index.emblem +25 -0
  13. data/app/assets/javascripts/templates/has_associations/new.emblem +50 -0
  14. data/app/assets/javascripts/templates/index.emblem +6 -0
  15. data/app/assets/javascripts/templates/models/edit.emblem +40 -0
  16. data/app/assets/javascripts/templates/models/hierarchy.emblem +8 -0
  17. data/app/assets/stylesheets/meta_model.css.scss +113 -0
  18. data/app/controllers/meta_model/application_controller.rb +12 -0
  19. data/app/controllers/meta_model/meta/has_associations_controller.rb +44 -0
  20. data/app/controllers/meta_model/meta/models_controller.rb +80 -0
  21. data/app/controllers/meta_model/meta/properties_controller.rb +36 -0
  22. data/app/controllers/meta_model/meta_controller.rb +7 -0
  23. data/app/controllers/meta_model/models_controller.rb +69 -0
  24. data/app/helpers/meta_model/application_helper.rb +10 -0
  25. data/app/helpers/meta_model/model_helper.rb +10 -0
  26. data/app/models/concerns/meta_model/model_base.rb +43 -0
  27. data/app/models/meta_model/has_association.rb +46 -0
  28. data/app/models/meta_model/meta_model_base.rb +7 -0
  29. data/app/models/meta_model/model.rb +51 -0
  30. data/app/models/meta_model/property.rb +11 -0
  31. data/app/serializers/meta_model/has_association_serializer.rb +13 -0
  32. data/app/serializers/meta_model/model_serializer.rb +11 -0
  33. data/app/serializers/meta_model/property_serializer.rb +6 -0
  34. data/app/views/layouts/meta_model.html.slim +28 -0
  35. data/app/views/meta_model/meta/associations/index.html.slim +12 -0
  36. data/app/views/meta_model/meta/index.html.slim +2 -0
  37. data/app/views/meta_model/meta/models/edit.html.slim +39 -0
  38. data/app/views/meta_model/models/_form.html.slim +72 -0
  39. data/app/views/meta_model/models/_has_many_association.html.slim +4 -0
  40. data/app/views/meta_model/models/_record_details.html.slim +13 -0
  41. data/app/views/meta_model/models/edit.html.slim +6 -0
  42. data/app/views/meta_model/models/index.html.slim +14 -0
  43. data/app/views/meta_model/models/meta_index.html.slim +6 -0
  44. data/app/views/meta_model/models/new.html.slim +7 -0
  45. data/app/views/meta_model/models/show.html.slim +18 -0
  46. data/config/initializers/active_model_serializer.rb +6 -0
  47. data/config/routes.rb +19 -0
  48. data/lib/ext/hash.rb +7 -0
  49. data/lib/meta_model/engine.rb +23 -0
  50. data/lib/meta_model/version.rb +3 -0
  51. data/lib/meta_model.rb +4 -0
  52. data/lib/meta_models.rb +70 -0
  53. data/lib/tasks/meta_model_tasks.rake +4 -0
  54. data/test/dummy/README.rdoc +28 -0
  55. data/test/dummy/Rakefile +6 -0
  56. data/test/dummy/app/assets/javascripts/application.js +14 -0
  57. data/test/dummy/app/assets/stylesheets/meta_model.css.scss +55 -0
  58. data/test/dummy/app/controllers/meta_model/application_controller.rb +8 -0
  59. data/test/dummy/app/helpers/application_helper.rb +2 -0
  60. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  61. data/test/dummy/bin/bundle +3 -0
  62. data/test/dummy/bin/rails +4 -0
  63. data/test/dummy/bin/rake +4 -0
  64. data/test/dummy/bin/setup +29 -0
  65. data/test/dummy/config/application.rb +29 -0
  66. data/test/dummy/config/boot.rb +5 -0
  67. data/test/dummy/config/database.yml +25 -0
  68. data/test/dummy/config/environment.rb +5 -0
  69. data/test/dummy/config/environments/development.rb +41 -0
  70. data/test/dummy/config/environments/production.rb +79 -0
  71. data/test/dummy/config/environments/test.rb +42 -0
  72. data/test/dummy/config/initializers/assets.rb +11 -0
  73. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  74. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  75. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  76. data/test/dummy/config/initializers/inflections.rb +16 -0
  77. data/test/dummy/config/initializers/mime_types.rb +4 -0
  78. data/test/dummy/config/initializers/session_store.rb +3 -0
  79. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  80. data/test/dummy/config/locales/en.yml +23 -0
  81. data/test/dummy/config/routes.rb +21 -0
  82. data/test/dummy/config/secrets.yml +22 -0
  83. data/test/dummy/config.ru +4 -0
  84. data/test/dummy/public/404.html +67 -0
  85. data/test/dummy/public/422.html +67 -0
  86. data/test/dummy/public/500.html +66 -0
  87. data/test/dummy/public/favicon.ico +0 -0
  88. data/test/integration/navigation_test.rb +10 -0
  89. data/test/meta_model_test.rb +7 -0
  90. data/test/test_helper.rb +19 -0
  91. data/vendor/assets/fonts/bootstrap/glyphicons-halflings-regular.eot +0 -0
  92. data/vendor/assets/fonts/bootstrap/glyphicons-halflings-regular.svg +288 -0
  93. data/vendor/assets/fonts/bootstrap/glyphicons-halflings-regular.ttf +0 -0
  94. data/vendor/assets/fonts/bootstrap/glyphicons-halflings-regular.woff +0 -0
  95. data/vendor/assets/fonts/bootstrap/glyphicons-halflings-regular.woff2 +0 -0
  96. data/vendor/assets/javascripts/backbone.js +1608 -0
  97. data/vendor/assets/javascripts/bootstrap/affix.js +162 -0
  98. data/vendor/assets/javascripts/bootstrap/alert.js +94 -0
  99. data/vendor/assets/javascripts/bootstrap/button.js +116 -0
  100. data/vendor/assets/javascripts/bootstrap/carousel.js +240 -0
  101. data/vendor/assets/javascripts/bootstrap/collapse.js +211 -0
  102. data/vendor/assets/javascripts/bootstrap/dropdown.js +161 -0
  103. data/vendor/assets/javascripts/bootstrap/modal.js +324 -0
  104. data/vendor/assets/javascripts/bootstrap/popover.js +119 -0
  105. data/vendor/assets/javascripts/bootstrap/scrollspy.js +175 -0
  106. data/vendor/assets/javascripts/bootstrap/tab.js +153 -0
  107. data/vendor/assets/javascripts/bootstrap/tooltip.js +478 -0
  108. data/vendor/assets/javascripts/bootstrap/transition.js +59 -0
  109. data/vendor/assets/javascripts/bootstrap-sprockets.js +12 -0
  110. data/vendor/assets/javascripts/bootstrap.js +2304 -0
  111. data/vendor/assets/javascripts/lodash.js +6785 -0
  112. data/vendor/assets/javascripts/rivets-backbone.js +97 -0
  113. data/vendor/assets/javascripts/rivets.js +1273 -0
  114. data/vendor/assets/javascripts/sightglass.js +203 -0
  115. data/vendor/assets/stylesheets/_bootstrap-compass.scss +7 -0
  116. data/vendor/assets/stylesheets/_bootstrap-mincer.scss +17 -0
  117. data/vendor/assets/stylesheets/_bootstrap-sprockets.scss +7 -0
  118. data/vendor/assets/stylesheets/_bootstrap.scss +50 -0
  119. data/vendor/assets/stylesheets/bootstrap/_alerts.scss +68 -0
  120. data/vendor/assets/stylesheets/bootstrap/_badges.scss +63 -0
  121. data/vendor/assets/stylesheets/bootstrap/_breadcrumbs.scss +26 -0
  122. data/vendor/assets/stylesheets/bootstrap/_button-groups.scss +243 -0
  123. data/vendor/assets/stylesheets/bootstrap/_buttons.scss +160 -0
  124. data/vendor/assets/stylesheets/bootstrap/_carousel.scss +267 -0
  125. data/vendor/assets/stylesheets/bootstrap/_close.scss +35 -0
  126. data/vendor/assets/stylesheets/bootstrap/_code.scss +69 -0
  127. data/vendor/assets/stylesheets/bootstrap/_component-animations.scss +38 -0
  128. data/vendor/assets/stylesheets/bootstrap/_dropdowns.scss +213 -0
  129. data/vendor/assets/stylesheets/bootstrap/_forms.scss +548 -0
  130. data/vendor/assets/stylesheets/bootstrap/_glyphicons.scss +236 -0
  131. data/vendor/assets/stylesheets/bootstrap/_grid.scss +84 -0
  132. data/vendor/assets/stylesheets/bootstrap/_input-groups.scss +166 -0
  133. data/vendor/assets/stylesheets/bootstrap/_jumbotron.scss +49 -0
  134. data/vendor/assets/stylesheets/bootstrap/_labels.scss +66 -0
  135. data/vendor/assets/stylesheets/bootstrap/_list-group.scss +124 -0
  136. data/vendor/assets/stylesheets/bootstrap/_media.scss +47 -0
  137. data/vendor/assets/stylesheets/bootstrap/_mixins.scss +39 -0
  138. data/vendor/assets/stylesheets/bootstrap/_modals.scss +148 -0
  139. data/vendor/assets/stylesheets/bootstrap/_navbar.scss +662 -0
  140. data/vendor/assets/stylesheets/bootstrap/_navs.scss +244 -0
  141. data/vendor/assets/stylesheets/bootstrap/_normalize.scss +427 -0
  142. data/vendor/assets/stylesheets/bootstrap/_pager.scss +54 -0
  143. data/vendor/assets/stylesheets/bootstrap/_pagination.scss +88 -0
  144. data/vendor/assets/stylesheets/bootstrap/_panels.scss +261 -0
  145. data/vendor/assets/stylesheets/bootstrap/_popovers.scss +135 -0
  146. data/vendor/assets/stylesheets/bootstrap/_print.scss +107 -0
  147. data/vendor/assets/stylesheets/bootstrap/_progress-bars.scss +87 -0
  148. data/vendor/assets/stylesheets/bootstrap/_responsive-embed.scss +35 -0
  149. data/vendor/assets/stylesheets/bootstrap/_responsive-utilities.scss +174 -0
  150. data/vendor/assets/stylesheets/bootstrap/_scaffolding.scss +150 -0
  151. data/vendor/assets/stylesheets/bootstrap/_tables.scss +234 -0
  152. data/vendor/assets/stylesheets/bootstrap/_theme.scss +272 -0
  153. data/vendor/assets/stylesheets/bootstrap/_thumbnails.scss +38 -0
  154. data/vendor/assets/stylesheets/bootstrap/_tooltip.scss +103 -0
  155. data/vendor/assets/stylesheets/bootstrap/_type.scss +298 -0
  156. data/vendor/assets/stylesheets/bootstrap/_utilities.scss +56 -0
  157. data/vendor/assets/stylesheets/bootstrap/_variables.scss +864 -0
  158. data/vendor/assets/stylesheets/bootstrap/_wells.scss +29 -0
  159. data/vendor/assets/stylesheets/bootstrap/mixins/_alerts.scss +14 -0
  160. data/vendor/assets/stylesheets/bootstrap/mixins/_background-variant.scss +11 -0
  161. data/vendor/assets/stylesheets/bootstrap/mixins/_border-radius.scss +18 -0
  162. data/vendor/assets/stylesheets/bootstrap/mixins/_buttons.scss +52 -0
  163. data/vendor/assets/stylesheets/bootstrap/mixins/_center-block.scss +7 -0
  164. data/vendor/assets/stylesheets/bootstrap/mixins/_clearfix.scss +22 -0
  165. data/vendor/assets/stylesheets/bootstrap/mixins/_forms.scss +88 -0
  166. data/vendor/assets/stylesheets/bootstrap/mixins/_gradients.scss +58 -0
  167. data/vendor/assets/stylesheets/bootstrap/mixins/_grid-framework.scss +81 -0
  168. data/vendor/assets/stylesheets/bootstrap/mixins/_grid.scss +122 -0
  169. data/vendor/assets/stylesheets/bootstrap/mixins/_hide-text.scss +21 -0
  170. data/vendor/assets/stylesheets/bootstrap/mixins/_image.scss +33 -0
  171. data/vendor/assets/stylesheets/bootstrap/mixins/_labels.scss +12 -0
  172. data/vendor/assets/stylesheets/bootstrap/mixins/_list-group.scss +31 -0
  173. data/vendor/assets/stylesheets/bootstrap/mixins/_nav-divider.scss +10 -0
  174. data/vendor/assets/stylesheets/bootstrap/mixins/_nav-vertical-align.scss +9 -0
  175. data/vendor/assets/stylesheets/bootstrap/mixins/_opacity.scss +8 -0
  176. data/vendor/assets/stylesheets/bootstrap/mixins/_pagination.scss +23 -0
  177. data/vendor/assets/stylesheets/bootstrap/mixins/_panels.scss +24 -0
  178. data/vendor/assets/stylesheets/bootstrap/mixins/_progress-bar.scss +10 -0
  179. data/vendor/assets/stylesheets/bootstrap/mixins/_reset-filter.scss +8 -0
  180. data/vendor/assets/stylesheets/bootstrap/mixins/_resize.scss +6 -0
  181. data/vendor/assets/stylesheets/bootstrap/mixins/_responsive-visibility.scss +21 -0
  182. data/vendor/assets/stylesheets/bootstrap/mixins/_size.scss +10 -0
  183. data/vendor/assets/stylesheets/bootstrap/mixins/_tab-focus.scss +9 -0
  184. data/vendor/assets/stylesheets/bootstrap/mixins/_table-row.scss +28 -0
  185. data/vendor/assets/stylesheets/bootstrap/mixins/_text-emphasis.scss +11 -0
  186. data/vendor/assets/stylesheets/bootstrap/mixins/_text-overflow.scss +8 -0
  187. data/vendor/assets/stylesheets/bootstrap/mixins/_vendor-prefixes.scss +222 -0
  188. metadata +365 -0
@@ -0,0 +1,1273 @@
1
+ // Rivets.js
2
+ // version: 0.7.1
3
+ // author: Michael Richards
4
+ // license: MIT
5
+ (function() {
6
+ var Rivets, bindMethod, unbindMethod, _ref,
7
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
8
+ __slice = [].slice,
9
+ __hasProp = {}.hasOwnProperty,
10
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
11
+ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
12
+
13
+ Rivets = {
14
+ options: ['prefix', 'templateDelimiters', 'rootInterface', 'preloadData', 'handler'],
15
+ extensions: ['binders', 'formatters', 'components', 'adapters'],
16
+ "public": {
17
+ binders: {},
18
+ components: {},
19
+ formatters: {},
20
+ adapters: {},
21
+ prefix: 'rv',
22
+ templateDelimiters: ['{', '}'],
23
+ rootInterface: '.',
24
+ preloadData: true,
25
+ handler: function(context, ev, binding) {
26
+ return this.call(context, ev, binding.view.models);
27
+ },
28
+ configure: function(options) {
29
+ var descriptor, key, option, value;
30
+ if (options == null) {
31
+ options = {};
32
+ }
33
+ for (option in options) {
34
+ value = options[option];
35
+ if (option === 'binders' || option === 'components' || option === 'formatters' || option === 'adapters') {
36
+ for (key in value) {
37
+ descriptor = value[key];
38
+ Rivets[option][key] = descriptor;
39
+ }
40
+ } else {
41
+ Rivets["public"][option] = value;
42
+ }
43
+ }
44
+ },
45
+ bind: function(el, models, options) {
46
+ var view;
47
+ if (models == null) {
48
+ models = {};
49
+ }
50
+ if (options == null) {
51
+ options = {};
52
+ }
53
+ view = new Rivets.View(el, models, options);
54
+ view.bind();
55
+ return view;
56
+ }
57
+ }
58
+ };
59
+
60
+ if (window['jQuery'] || window['$']) {
61
+ _ref = 'on' in jQuery.prototype ? ['on', 'off'] : ['bind', 'unbind'], bindMethod = _ref[0], unbindMethod = _ref[1];
62
+ Rivets.Util = {
63
+ bindEvent: function(el, event, handler) {
64
+ return jQuery(el)[bindMethod](event, handler);
65
+ },
66
+ unbindEvent: function(el, event, handler) {
67
+ return jQuery(el)[unbindMethod](event, handler);
68
+ },
69
+ getInputValue: function(el) {
70
+ var $el;
71
+ $el = jQuery(el);
72
+ if ($el.attr('type') === 'checkbox') {
73
+ return $el.is(':checked');
74
+ } else {
75
+ return $el.val();
76
+ }
77
+ }
78
+ };
79
+ } else {
80
+ Rivets.Util = {
81
+ bindEvent: (function() {
82
+ if ('addEventListener' in window) {
83
+ return function(el, event, handler) {
84
+ return el.addEventListener(event, handler, false);
85
+ };
86
+ }
87
+ return function(el, event, handler) {
88
+ return el.attachEvent('on' + event, handler);
89
+ };
90
+ })(),
91
+ unbindEvent: (function() {
92
+ if ('removeEventListener' in window) {
93
+ return function(el, event, handler) {
94
+ return el.removeEventListener(event, handler, false);
95
+ };
96
+ }
97
+ return function(el, event, handler) {
98
+ return el.detachEvent('on' + event, handler);
99
+ };
100
+ })(),
101
+ getInputValue: function(el) {
102
+ var o, _i, _len, _results;
103
+ if (el.type === 'checkbox') {
104
+ return el.checked;
105
+ } else if (el.type === 'select-multiple') {
106
+ _results = [];
107
+ for (_i = 0, _len = el.length; _i < _len; _i++) {
108
+ o = el[_i];
109
+ if (o.selected) {
110
+ _results.push(o.value);
111
+ }
112
+ }
113
+ return _results;
114
+ } else {
115
+ return el.value;
116
+ }
117
+ }
118
+ };
119
+ }
120
+
121
+ Rivets.TypeParser = (function() {
122
+ function TypeParser() {}
123
+
124
+ TypeParser.types = {
125
+ primitive: 0,
126
+ keypath: 1
127
+ };
128
+
129
+ TypeParser.parse = function(string) {
130
+ if (/^'.*'$|^".*"$/.test(string)) {
131
+ return {
132
+ type: this.types.primitive,
133
+ value: string.slice(1, -1)
134
+ };
135
+ } else if (string === 'true') {
136
+ return {
137
+ type: this.types.primitive,
138
+ value: true
139
+ };
140
+ } else if (string === 'false') {
141
+ return {
142
+ type: this.types.primitive,
143
+ value: false
144
+ };
145
+ } else if (string === 'null') {
146
+ return {
147
+ type: this.types.primitive,
148
+ value: null
149
+ };
150
+ } else if (string === 'undefined') {
151
+ return {
152
+ type: this.types.primitive,
153
+ value: void 0
154
+ };
155
+ } else if (isNaN(Number(string)) === false) {
156
+ return {
157
+ type: this.types.primitive,
158
+ value: Number(string)
159
+ };
160
+ } else {
161
+ return {
162
+ type: this.types.keypath,
163
+ value: string
164
+ };
165
+ }
166
+ };
167
+
168
+ return TypeParser;
169
+
170
+ })();
171
+
172
+ Rivets.TextTemplateParser = (function() {
173
+ function TextTemplateParser() {}
174
+
175
+ TextTemplateParser.types = {
176
+ text: 0,
177
+ binding: 1
178
+ };
179
+
180
+ TextTemplateParser.parse = function(template, delimiters) {
181
+ var index, lastIndex, lastToken, length, substring, tokens, value;
182
+ tokens = [];
183
+ length = template.length;
184
+ index = 0;
185
+ lastIndex = 0;
186
+ while (lastIndex < length) {
187
+ index = template.indexOf(delimiters[0], lastIndex);
188
+ if (index < 0) {
189
+ tokens.push({
190
+ type: this.types.text,
191
+ value: template.slice(lastIndex)
192
+ });
193
+ break;
194
+ } else {
195
+ if (index > 0 && lastIndex < index) {
196
+ tokens.push({
197
+ type: this.types.text,
198
+ value: template.slice(lastIndex, index)
199
+ });
200
+ }
201
+ lastIndex = index + delimiters[0].length;
202
+ index = template.indexOf(delimiters[1], lastIndex);
203
+ if (index < 0) {
204
+ substring = template.slice(lastIndex - delimiters[1].length);
205
+ lastToken = tokens[tokens.length - 1];
206
+ if ((lastToken != null ? lastToken.type : void 0) === this.types.text) {
207
+ lastToken.value += substring;
208
+ } else {
209
+ tokens.push({
210
+ type: this.types.text,
211
+ value: substring
212
+ });
213
+ }
214
+ break;
215
+ }
216
+ value = template.slice(lastIndex, index).trim();
217
+ tokens.push({
218
+ type: this.types.binding,
219
+ value: value
220
+ });
221
+ lastIndex = index + delimiters[1].length;
222
+ }
223
+ }
224
+ return tokens;
225
+ };
226
+
227
+ return TextTemplateParser;
228
+
229
+ })();
230
+
231
+ Rivets.View = (function() {
232
+ function View(els, models, options) {
233
+ var k, option, v, _base, _i, _j, _len, _len1, _ref1, _ref2, _ref3, _ref4;
234
+ this.els = els;
235
+ this.models = models;
236
+ if (options == null) {
237
+ options = {};
238
+ }
239
+ this.update = __bind(this.update, this);
240
+ this.publish = __bind(this.publish, this);
241
+ this.sync = __bind(this.sync, this);
242
+ this.unbind = __bind(this.unbind, this);
243
+ this.bind = __bind(this.bind, this);
244
+ this.select = __bind(this.select, this);
245
+ this.build = __bind(this.build, this);
246
+ this.componentRegExp = __bind(this.componentRegExp, this);
247
+ this.bindingRegExp = __bind(this.bindingRegExp, this);
248
+ this.options = __bind(this.options, this);
249
+ if (!(this.els.jquery || this.els instanceof Array)) {
250
+ this.els = [this.els];
251
+ }
252
+ _ref1 = Rivets.extensions;
253
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
254
+ option = _ref1[_i];
255
+ this[option] = {};
256
+ if (options[option]) {
257
+ _ref2 = options[option];
258
+ for (k in _ref2) {
259
+ v = _ref2[k];
260
+ this[option][k] = v;
261
+ }
262
+ }
263
+ _ref3 = Rivets["public"][option];
264
+ for (k in _ref3) {
265
+ v = _ref3[k];
266
+ if ((_base = this[option])[k] == null) {
267
+ _base[k] = v;
268
+ }
269
+ }
270
+ }
271
+ _ref4 = Rivets.options;
272
+ for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) {
273
+ option = _ref4[_j];
274
+ this[option] = options[option] || Rivets["public"][option];
275
+ }
276
+ this.build();
277
+ }
278
+
279
+ View.prototype.options = function() {
280
+ var option, options, _i, _len, _ref1;
281
+ options = {};
282
+ _ref1 = Rivets.extensions.concat(Rivets.options);
283
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
284
+ option = _ref1[_i];
285
+ options[option] = this[option];
286
+ }
287
+ return options;
288
+ };
289
+
290
+ View.prototype.bindingRegExp = function() {
291
+ return new RegExp("^" + this.prefix + "-");
292
+ };
293
+
294
+ View.prototype.componentRegExp = function() {
295
+ return new RegExp("^" + (this.prefix.toUpperCase()) + "-");
296
+ };
297
+
298
+ View.prototype.build = function() {
299
+ var bindingRegExp, buildBinding, componentRegExp, el, parse, _i, _len, _ref1;
300
+ this.bindings = [];
301
+ bindingRegExp = this.bindingRegExp();
302
+ componentRegExp = this.componentRegExp();
303
+ buildBinding = (function(_this) {
304
+ return function(binding, node, type, declaration) {
305
+ var context, ctx, dependencies, keypath, options, pipe, pipes;
306
+ options = {};
307
+ pipes = (function() {
308
+ var _i, _len, _ref1, _results;
309
+ _ref1 = declaration.split('|');
310
+ _results = [];
311
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
312
+ pipe = _ref1[_i];
313
+ _results.push(pipe.trim());
314
+ }
315
+ return _results;
316
+ })();
317
+ context = (function() {
318
+ var _i, _len, _ref1, _results;
319
+ _ref1 = pipes.shift().split('<');
320
+ _results = [];
321
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
322
+ ctx = _ref1[_i];
323
+ _results.push(ctx.trim());
324
+ }
325
+ return _results;
326
+ })();
327
+ keypath = context.shift();
328
+ options.formatters = pipes;
329
+ if (dependencies = context.shift()) {
330
+ options.dependencies = dependencies.split(/\s+/);
331
+ }
332
+ return _this.bindings.push(new Rivets[binding](_this, node, type, keypath, options));
333
+ };
334
+ })(this);
335
+ parse = (function(_this) {
336
+ return function(node) {
337
+ var attribute, attributes, binder, block, childNode, delimiters, identifier, n, parser, regexp, text, token, tokens, type, value, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref1, _ref2, _ref3, _ref4, _results;
338
+ if (node.nodeType === 3) {
339
+ parser = Rivets.TextTemplateParser;
340
+ if (delimiters = _this.templateDelimiters) {
341
+ if ((tokens = parser.parse(node.data, delimiters)).length) {
342
+ if (!(tokens.length === 1 && tokens[0].type === parser.types.text)) {
343
+ for (_i = 0, _len = tokens.length; _i < _len; _i++) {
344
+ token = tokens[_i];
345
+ text = document.createTextNode(token.value);
346
+ node.parentNode.insertBefore(text, node);
347
+ if (token.type === 1) {
348
+ buildBinding('TextBinding', text, null, token.value);
349
+ }
350
+ }
351
+ node.parentNode.removeChild(node);
352
+ }
353
+ }
354
+ }
355
+ } else if (node.nodeType === 1) {
356
+ if (componentRegExp.test(node.nodeName)) {
357
+ type = node.nodeName.replace(componentRegExp, '').toLowerCase();
358
+ _this.bindings.push(new Rivets.ComponentBinding(_this, node, type));
359
+ } else {
360
+ block = node.nodeName === 'SCRIPT' || node.nodeName === 'STYLE';
361
+ _ref1 = node.attributes;
362
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
363
+ attribute = _ref1[_j];
364
+ if (bindingRegExp.test(attribute.name)) {
365
+ type = attribute.name.replace(bindingRegExp, '');
366
+ if (!(binder = _this.binders[type])) {
367
+ _ref2 = _this.binders;
368
+ for (identifier in _ref2) {
369
+ value = _ref2[identifier];
370
+ if (identifier !== '*' && identifier.indexOf('*') !== -1) {
371
+ regexp = new RegExp("^" + (identifier.replace(/\*/g, '.+')) + "$");
372
+ if (regexp.test(type)) {
373
+ binder = value;
374
+ }
375
+ }
376
+ }
377
+ }
378
+ binder || (binder = _this.binders['*']);
379
+ if (binder.block) {
380
+ block = true;
381
+ attributes = [attribute];
382
+ }
383
+ }
384
+ }
385
+ _ref3 = attributes || node.attributes;
386
+ for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
387
+ attribute = _ref3[_k];
388
+ if (bindingRegExp.test(attribute.name)) {
389
+ type = attribute.name.replace(bindingRegExp, '');
390
+ buildBinding('Binding', node, type, attribute.value);
391
+ }
392
+ }
393
+ }
394
+ }
395
+ if (!block) {
396
+ _ref4 = (function() {
397
+ var _len3, _m, _ref4, _results1;
398
+ _ref4 = node.childNodes;
399
+ _results1 = [];
400
+ for (_m = 0, _len3 = _ref4.length; _m < _len3; _m++) {
401
+ n = _ref4[_m];
402
+ _results1.push(n);
403
+ }
404
+ return _results1;
405
+ })();
406
+ _results = [];
407
+ for (_l = 0, _len3 = _ref4.length; _l < _len3; _l++) {
408
+ childNode = _ref4[_l];
409
+ _results.push(parse(childNode));
410
+ }
411
+ return _results;
412
+ }
413
+ };
414
+ })(this);
415
+ _ref1 = this.els;
416
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
417
+ el = _ref1[_i];
418
+ parse(el);
419
+ }
420
+ this.bindings.sort(function(a, b) {
421
+ var _ref2, _ref3;
422
+ return (((_ref2 = b.binder) != null ? _ref2.priority : void 0) || 0) - (((_ref3 = a.binder) != null ? _ref3.priority : void 0) || 0);
423
+ });
424
+ };
425
+
426
+ View.prototype.select = function(fn) {
427
+ var binding, _i, _len, _ref1, _results;
428
+ _ref1 = this.bindings;
429
+ _results = [];
430
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
431
+ binding = _ref1[_i];
432
+ if (fn(binding)) {
433
+ _results.push(binding);
434
+ }
435
+ }
436
+ return _results;
437
+ };
438
+
439
+ View.prototype.bind = function() {
440
+ var binding, _i, _len, _ref1, _results;
441
+ _ref1 = this.bindings;
442
+ _results = [];
443
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
444
+ binding = _ref1[_i];
445
+ _results.push(binding.bind());
446
+ }
447
+ return _results;
448
+ };
449
+
450
+ View.prototype.unbind = function() {
451
+ var binding, _i, _len, _ref1, _results;
452
+ _ref1 = this.bindings;
453
+ _results = [];
454
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
455
+ binding = _ref1[_i];
456
+ _results.push(binding.unbind());
457
+ }
458
+ return _results;
459
+ };
460
+
461
+ View.prototype.sync = function() {
462
+ var binding, _i, _len, _ref1, _results;
463
+ _ref1 = this.bindings;
464
+ _results = [];
465
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
466
+ binding = _ref1[_i];
467
+ _results.push(binding.sync());
468
+ }
469
+ return _results;
470
+ };
471
+
472
+ View.prototype.publish = function() {
473
+ var binding, _i, _len, _ref1, _results;
474
+ _ref1 = this.select(function(b) {
475
+ return b.binder.publishes;
476
+ });
477
+ _results = [];
478
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
479
+ binding = _ref1[_i];
480
+ _results.push(binding.publish());
481
+ }
482
+ return _results;
483
+ };
484
+
485
+ View.prototype.update = function(models) {
486
+ var binding, key, model, _i, _len, _ref1, _results;
487
+ if (models == null) {
488
+ models = {};
489
+ }
490
+ for (key in models) {
491
+ model = models[key];
492
+ this.models[key] = model;
493
+ }
494
+ _ref1 = this.bindings;
495
+ _results = [];
496
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
497
+ binding = _ref1[_i];
498
+ _results.push(binding.update(models));
499
+ }
500
+ return _results;
501
+ };
502
+
503
+ return View;
504
+
505
+ })();
506
+
507
+ Rivets.Binding = (function() {
508
+ function Binding(view, el, type, keypath, options) {
509
+ this.view = view;
510
+ this.el = el;
511
+ this.type = type;
512
+ this.keypath = keypath;
513
+ this.options = options != null ? options : {};
514
+ this.getValue = __bind(this.getValue, this);
515
+ this.update = __bind(this.update, this);
516
+ this.unbind = __bind(this.unbind, this);
517
+ this.bind = __bind(this.bind, this);
518
+ this.publish = __bind(this.publish, this);
519
+ this.sync = __bind(this.sync, this);
520
+ this.set = __bind(this.set, this);
521
+ this.eventHandler = __bind(this.eventHandler, this);
522
+ this.formattedValue = __bind(this.formattedValue, this);
523
+ this.parseTarget = __bind(this.parseTarget, this);
524
+ this.observe = __bind(this.observe, this);
525
+ this.setBinder = __bind(this.setBinder, this);
526
+ this.formatters = this.options.formatters || [];
527
+ this.dependencies = [];
528
+ this.formatterObservers = {};
529
+ this.model = void 0;
530
+ this.setBinder();
531
+ }
532
+
533
+ Binding.prototype.setBinder = function() {
534
+ var identifier, regexp, value, _ref1;
535
+ if (!(this.binder = this.view.binders[this.type])) {
536
+ _ref1 = this.view.binders;
537
+ for (identifier in _ref1) {
538
+ value = _ref1[identifier];
539
+ if (identifier !== '*' && identifier.indexOf('*') !== -1) {
540
+ regexp = new RegExp("^" + (identifier.replace(/\*/g, '.+')) + "$");
541
+ if (regexp.test(this.type)) {
542
+ this.binder = value;
543
+ this.args = new RegExp("^" + (identifier.replace(/\*/g, '(.+)')) + "$").exec(this.type);
544
+ this.args.shift();
545
+ }
546
+ }
547
+ }
548
+ }
549
+ this.binder || (this.binder = this.view.binders['*']);
550
+ if (this.binder instanceof Function) {
551
+ return this.binder = {
552
+ routine: this.binder
553
+ };
554
+ }
555
+ };
556
+
557
+ Binding.prototype.observe = function(obj, keypath, callback) {
558
+ return Rivets.sightglass(obj, keypath, callback, {
559
+ root: this.view.rootInterface,
560
+ adapters: this.view.adapters
561
+ });
562
+ };
563
+
564
+ Binding.prototype.parseTarget = function() {
565
+ var token;
566
+ token = Rivets.TypeParser.parse(this.keypath);
567
+ if (token.type === 0) {
568
+ return this.value = token.value;
569
+ } else {
570
+ this.observer = this.observe(this.view.models, this.keypath, this.sync);
571
+ return this.model = this.observer.target;
572
+ }
573
+ };
574
+
575
+ Binding.prototype.formattedValue = function(value) {
576
+ var ai, arg, args, fi, formatter, id, observer, processedArgs, _base, _i, _j, _len, _len1, _ref1;
577
+ _ref1 = this.formatters;
578
+ for (fi = _i = 0, _len = _ref1.length; _i < _len; fi = ++_i) {
579
+ formatter = _ref1[fi];
580
+ args = formatter.match(/[^\s']+|'([^']|'[^\s])*'|"([^"]|"[^\s])*"/g);
581
+ id = args.shift();
582
+ formatter = this.view.formatters[id];
583
+ args = (function() {
584
+ var _j, _len1, _results;
585
+ _results = [];
586
+ for (_j = 0, _len1 = args.length; _j < _len1; _j++) {
587
+ arg = args[_j];
588
+ _results.push(Rivets.TypeParser.parse(arg));
589
+ }
590
+ return _results;
591
+ })();
592
+ processedArgs = [];
593
+ for (ai = _j = 0, _len1 = args.length; _j < _len1; ai = ++_j) {
594
+ arg = args[ai];
595
+ processedArgs.push(arg.type === 0 ? arg.value : ((_base = this.formatterObservers)[fi] || (_base[fi] = {}), !(observer = this.formatterObservers[fi][ai]) ? (observer = this.observe(this.view.models, arg.value, this.sync), this.formatterObservers[fi][ai] = observer) : void 0, observer.value()));
596
+ }
597
+ if ((formatter != null ? formatter.read : void 0) instanceof Function) {
598
+ value = formatter.read.apply(formatter, [value].concat(__slice.call(processedArgs)));
599
+ } else if (formatter instanceof Function) {
600
+ value = formatter.apply(null, [value].concat(__slice.call(processedArgs)));
601
+ }
602
+ }
603
+ return value;
604
+ };
605
+
606
+ Binding.prototype.eventHandler = function(fn) {
607
+ var binding, handler;
608
+ handler = (binding = this).view.handler;
609
+ return function(ev) {
610
+ return handler.call(fn, this, ev, binding);
611
+ };
612
+ };
613
+
614
+ Binding.prototype.set = function(value) {
615
+ var _ref1;
616
+ value = value instanceof Function && !this.binder["function"] ? this.formattedValue(value.call(this.model)) : this.formattedValue(value);
617
+ return (_ref1 = this.binder.routine) != null ? _ref1.call(this, this.el, value) : void 0;
618
+ };
619
+
620
+ Binding.prototype.sync = function() {
621
+ var dependency, observer;
622
+ return this.set((function() {
623
+ var _i, _j, _len, _len1, _ref1, _ref2, _ref3;
624
+ if (this.observer) {
625
+ if (this.model !== this.observer.target) {
626
+ _ref1 = this.dependencies;
627
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
628
+ observer = _ref1[_i];
629
+ observer.unobserve();
630
+ }
631
+ this.dependencies = [];
632
+ if (((this.model = this.observer.target) != null) && ((_ref2 = this.options.dependencies) != null ? _ref2.length : void 0)) {
633
+ _ref3 = this.options.dependencies;
634
+ for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
635
+ dependency = _ref3[_j];
636
+ observer = this.observe(this.model, dependency, this.sync);
637
+ this.dependencies.push(observer);
638
+ }
639
+ }
640
+ }
641
+ return this.observer.value();
642
+ } else {
643
+ return this.value;
644
+ }
645
+ }).call(this));
646
+ };
647
+
648
+ Binding.prototype.publish = function() {
649
+ var args, formatter, id, value, _i, _len, _ref1, _ref2, _ref3;
650
+ if (this.observer) {
651
+ value = this.getValue(this.el);
652
+ _ref1 = this.formatters.slice(0).reverse();
653
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
654
+ formatter = _ref1[_i];
655
+ args = formatter.split(/\s+/);
656
+ id = args.shift();
657
+ if ((_ref2 = this.view.formatters[id]) != null ? _ref2.publish : void 0) {
658
+ value = (_ref3 = this.view.formatters[id]).publish.apply(_ref3, [value].concat(__slice.call(args)));
659
+ }
660
+ }
661
+ return this.observer.setValue(value);
662
+ }
663
+ };
664
+
665
+ Binding.prototype.bind = function() {
666
+ var dependency, observer, _i, _len, _ref1, _ref2, _ref3;
667
+ this.parseTarget();
668
+ if ((_ref1 = this.binder.bind) != null) {
669
+ _ref1.call(this, this.el);
670
+ }
671
+ if ((this.model != null) && ((_ref2 = this.options.dependencies) != null ? _ref2.length : void 0)) {
672
+ _ref3 = this.options.dependencies;
673
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
674
+ dependency = _ref3[_i];
675
+ observer = this.observe(this.model, dependency, this.sync);
676
+ this.dependencies.push(observer);
677
+ }
678
+ }
679
+ if (this.view.preloadData) {
680
+ return this.sync();
681
+ }
682
+ };
683
+
684
+ Binding.prototype.unbind = function() {
685
+ var ai, args, fi, observer, _i, _len, _ref1, _ref2, _ref3, _ref4;
686
+ if ((_ref1 = this.binder.unbind) != null) {
687
+ _ref1.call(this, this.el);
688
+ }
689
+ if ((_ref2 = this.observer) != null) {
690
+ _ref2.unobserve();
691
+ }
692
+ _ref3 = this.dependencies;
693
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
694
+ observer = _ref3[_i];
695
+ observer.unobserve();
696
+ }
697
+ this.dependencies = [];
698
+ _ref4 = this.formatterObservers;
699
+ for (fi in _ref4) {
700
+ args = _ref4[fi];
701
+ for (ai in args) {
702
+ observer = args[ai];
703
+ observer.unobserve();
704
+ }
705
+ }
706
+ return this.formatterObservers = {};
707
+ };
708
+
709
+ Binding.prototype.update = function(models) {
710
+ var _ref1, _ref2;
711
+ if (models == null) {
712
+ models = {};
713
+ }
714
+ this.model = (_ref1 = this.observer) != null ? _ref1.target : void 0;
715
+ this.unbind();
716
+ if ((_ref2 = this.binder.update) != null) {
717
+ _ref2.call(this, models);
718
+ }
719
+ return this.bind();
720
+ };
721
+
722
+ Binding.prototype.getValue = function(el) {
723
+ if (this.binder && (this.binder.getValue != null)) {
724
+ return this.binder.getValue.call(this, el);
725
+ } else {
726
+ return Rivets.Util.getInputValue(el);
727
+ }
728
+ };
729
+
730
+ return Binding;
731
+
732
+ })();
733
+
734
+ Rivets.ComponentBinding = (function(_super) {
735
+ __extends(ComponentBinding, _super);
736
+
737
+ function ComponentBinding(view, el, type) {
738
+ var attribute, _i, _len, _ref1, _ref2;
739
+ this.view = view;
740
+ this.el = el;
741
+ this.type = type;
742
+ this.unbind = __bind(this.unbind, this);
743
+ this.bind = __bind(this.bind, this);
744
+ this.update = __bind(this.update, this);
745
+ this.locals = __bind(this.locals, this);
746
+ this.component = this.view.components[this.type];
747
+ this.attributes = {};
748
+ this.inflections = {};
749
+ _ref1 = this.el.attributes || [];
750
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
751
+ attribute = _ref1[_i];
752
+ if (_ref2 = attribute.name, __indexOf.call(this.component.attributes, _ref2) >= 0) {
753
+ this.attributes[attribute.name] = attribute.value;
754
+ } else {
755
+ this.inflections[attribute.name] = attribute.value;
756
+ }
757
+ }
758
+ }
759
+
760
+ ComponentBinding.prototype.sync = function() {};
761
+
762
+ ComponentBinding.prototype.locals = function(models) {
763
+ var inverse, key, model, path, result, _i, _len, _ref1, _ref2;
764
+ if (models == null) {
765
+ models = this.view.models;
766
+ }
767
+ result = {};
768
+ _ref1 = this.inflections;
769
+ for (key in _ref1) {
770
+ inverse = _ref1[key];
771
+ _ref2 = inverse.split('.');
772
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
773
+ path = _ref2[_i];
774
+ result[key] = (result[key] || models)[path];
775
+ }
776
+ }
777
+ for (key in models) {
778
+ model = models[key];
779
+ if (result[key] == null) {
780
+ result[key] = model;
781
+ }
782
+ }
783
+ return result;
784
+ };
785
+
786
+ ComponentBinding.prototype.update = function(models) {
787
+ var _ref1;
788
+ return (_ref1 = this.componentView) != null ? _ref1.update(this.locals(models)) : void 0;
789
+ };
790
+
791
+ ComponentBinding.prototype.bind = function() {
792
+ var el, _ref1;
793
+ if (this.componentView != null) {
794
+ return (_ref1 = this.componentView) != null ? _ref1.bind() : void 0;
795
+ } else {
796
+ el = this.component.build.call(this.attributes);
797
+ (this.componentView = new Rivets.View(el, this.locals(), this.view.options)).bind();
798
+ return this.el.parentNode.replaceChild(el, this.el);
799
+ }
800
+ };
801
+
802
+ ComponentBinding.prototype.unbind = function() {
803
+ var _ref1;
804
+ return (_ref1 = this.componentView) != null ? _ref1.unbind() : void 0;
805
+ };
806
+
807
+ return ComponentBinding;
808
+
809
+ })(Rivets.Binding);
810
+
811
+ Rivets.TextBinding = (function(_super) {
812
+ __extends(TextBinding, _super);
813
+
814
+ function TextBinding(view, el, type, keypath, options) {
815
+ this.view = view;
816
+ this.el = el;
817
+ this.type = type;
818
+ this.keypath = keypath;
819
+ this.options = options != null ? options : {};
820
+ this.sync = __bind(this.sync, this);
821
+ this.formatters = this.options.formatters || [];
822
+ this.dependencies = [];
823
+ this.formatterObservers = {};
824
+ }
825
+
826
+ TextBinding.prototype.binder = {
827
+ routine: function(node, value) {
828
+ return node.data = value != null ? value : '';
829
+ }
830
+ };
831
+
832
+ TextBinding.prototype.sync = function() {
833
+ return TextBinding.__super__.sync.apply(this, arguments);
834
+ };
835
+
836
+ return TextBinding;
837
+
838
+ })(Rivets.Binding);
839
+
840
+ Rivets["public"].binders.text = function(el, value) {
841
+ if (el.textContent != null) {
842
+ return el.textContent = value != null ? value : '';
843
+ } else {
844
+ return el.innerText = value != null ? value : '';
845
+ }
846
+ };
847
+
848
+ Rivets["public"].binders.html = function(el, value) {
849
+ return el.innerHTML = value != null ? value : '';
850
+ };
851
+
852
+ Rivets["public"].binders.show = function(el, value) {
853
+ return el.style.display = value ? '' : 'none';
854
+ };
855
+
856
+ Rivets["public"].binders.hide = function(el, value) {
857
+ return el.style.display = value ? 'none' : '';
858
+ };
859
+
860
+ Rivets["public"].binders.enabled = function(el, value) {
861
+ return el.disabled = !value;
862
+ };
863
+
864
+ Rivets["public"].binders.disabled = function(el, value) {
865
+ return el.disabled = !!value;
866
+ };
867
+
868
+ Rivets["public"].binders.checked = {
869
+ publishes: true,
870
+ priority: 2000,
871
+ bind: function(el) {
872
+ return Rivets.Util.bindEvent(el, 'change', this.publish);
873
+ },
874
+ unbind: function(el) {
875
+ return Rivets.Util.unbindEvent(el, 'change', this.publish);
876
+ },
877
+ routine: function(el, value) {
878
+ var _ref1;
879
+ if (el.type === 'radio') {
880
+ return el.checked = ((_ref1 = el.value) != null ? _ref1.toString() : void 0) === (value != null ? value.toString() : void 0);
881
+ } else {
882
+ return el.checked = !!value;
883
+ }
884
+ }
885
+ };
886
+
887
+ Rivets["public"].binders.unchecked = {
888
+ publishes: true,
889
+ priority: 2000,
890
+ bind: function(el) {
891
+ return Rivets.Util.bindEvent(el, 'change', this.publish);
892
+ },
893
+ unbind: function(el) {
894
+ return Rivets.Util.unbindEvent(el, 'change', this.publish);
895
+ },
896
+ routine: function(el, value) {
897
+ var _ref1;
898
+ if (el.type === 'radio') {
899
+ return el.checked = ((_ref1 = el.value) != null ? _ref1.toString() : void 0) !== (value != null ? value.toString() : void 0);
900
+ } else {
901
+ return el.checked = !value;
902
+ }
903
+ }
904
+ };
905
+
906
+ Rivets["public"].binders.value = {
907
+ publishes: true,
908
+ priority: 2000,
909
+ bind: function(el) {
910
+ this.event = el.tagName === 'SELECT' ? 'change' : 'input';
911
+ return Rivets.Util.bindEvent(el, this.event, this.publish);
912
+ },
913
+ unbind: function(el) {
914
+ return Rivets.Util.unbindEvent(el, this.event, this.publish);
915
+ },
916
+ routine: function(el, value) {
917
+ var o, _i, _len, _ref1, _ref2, _ref3, _results;
918
+ if (window.jQuery != null) {
919
+ el = jQuery(el);
920
+ if ((value != null ? value.toString() : void 0) !== ((_ref1 = el.val()) != null ? _ref1.toString() : void 0)) {
921
+ return el.val(value != null ? value : '');
922
+ }
923
+ } else {
924
+ if (el.type === 'select-multiple') {
925
+ if (value != null) {
926
+ _results = [];
927
+ for (_i = 0, _len = el.length; _i < _len; _i++) {
928
+ o = el[_i];
929
+ _results.push(o.selected = (_ref2 = o.value, __indexOf.call(value, _ref2) >= 0));
930
+ }
931
+ return _results;
932
+ }
933
+ } else if ((value != null ? value.toString() : void 0) !== ((_ref3 = el.value) != null ? _ref3.toString() : void 0)) {
934
+ return el.value = value != null ? value : '';
935
+ }
936
+ }
937
+ }
938
+ };
939
+
940
+ Rivets["public"].binders["if"] = {
941
+ block: true,
942
+ priority: 3000,
943
+ bind: function(el) {
944
+ var attr, declaration;
945
+ if (this.marker == null) {
946
+ attr = [this.view.prefix, this.type].join('-').replace('--', '-');
947
+ declaration = el.getAttribute(attr);
948
+ this.marker = document.createComment(" rivets: " + this.type + " " + declaration + " ");
949
+ this.bound = false;
950
+ el.removeAttribute(attr);
951
+ el.parentNode.insertBefore(this.marker, el);
952
+ return el.parentNode.removeChild(el);
953
+ }
954
+ },
955
+ unbind: function() {
956
+ var _ref1;
957
+ return (_ref1 = this.nested) != null ? _ref1.unbind() : void 0;
958
+ },
959
+ routine: function(el, value) {
960
+ var key, model, models, _ref1;
961
+ if (!!value === !this.bound) {
962
+ if (value) {
963
+ models = {};
964
+ _ref1 = this.view.models;
965
+ for (key in _ref1) {
966
+ model = _ref1[key];
967
+ models[key] = model;
968
+ }
969
+ (this.nested || (this.nested = new Rivets.View(el, models, this.view.options()))).bind();
970
+ this.marker.parentNode.insertBefore(el, this.marker.nextSibling);
971
+ return this.bound = true;
972
+ } else {
973
+ el.parentNode.removeChild(el);
974
+ this.nested.unbind();
975
+ return this.bound = false;
976
+ }
977
+ }
978
+ },
979
+ update: function(models) {
980
+ var _ref1;
981
+ return (_ref1 = this.nested) != null ? _ref1.update(models) : void 0;
982
+ }
983
+ };
984
+
985
+ Rivets["public"].binders.unless = {
986
+ block: true,
987
+ priority: 3000,
988
+ bind: function(el) {
989
+ return Rivets["public"].binders["if"].bind.call(this, el);
990
+ },
991
+ unbind: function() {
992
+ return Rivets["public"].binders["if"].unbind.call(this);
993
+ },
994
+ routine: function(el, value) {
995
+ return Rivets["public"].binders["if"].routine.call(this, el, !value);
996
+ },
997
+ update: function(models) {
998
+ return Rivets["public"].binders["if"].update.call(this, models);
999
+ }
1000
+ };
1001
+
1002
+ Rivets["public"].binders['on-*'] = {
1003
+ "function": true,
1004
+ priority: 1000,
1005
+ unbind: function(el) {
1006
+ if (this.handler) {
1007
+ return Rivets.Util.unbindEvent(el, this.args[0], this.handler);
1008
+ }
1009
+ },
1010
+ routine: function(el, value) {
1011
+ if (this.handler) {
1012
+ Rivets.Util.unbindEvent(el, this.args[0], this.handler);
1013
+ }
1014
+ return Rivets.Util.bindEvent(el, this.args[0], this.handler = this.eventHandler(value));
1015
+ }
1016
+ };
1017
+
1018
+ Rivets["public"].binders['each-*'] = {
1019
+ block: true,
1020
+ priority: 3000,
1021
+ bind: function(el) {
1022
+ var attr, view, _i, _len, _ref1;
1023
+ if (this.marker == null) {
1024
+ attr = [this.view.prefix, this.type].join('-').replace('--', '-');
1025
+ this.marker = document.createComment(" rivets: " + this.type + " ");
1026
+ this.iterated = [];
1027
+ el.removeAttribute(attr);
1028
+ el.parentNode.insertBefore(this.marker, el);
1029
+ el.parentNode.removeChild(el);
1030
+ } else {
1031
+ _ref1 = this.iterated;
1032
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
1033
+ view = _ref1[_i];
1034
+ view.bind();
1035
+ }
1036
+ }
1037
+ },
1038
+ unbind: function(el) {
1039
+ var view, _i, _len, _ref1, _results;
1040
+ if (this.iterated != null) {
1041
+ _ref1 = this.iterated;
1042
+ _results = [];
1043
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
1044
+ view = _ref1[_i];
1045
+ _results.push(view.unbind());
1046
+ }
1047
+ return _results;
1048
+ }
1049
+ },
1050
+ routine: function(el, collection) {
1051
+ var binding, data, i, index, key, model, modelName, options, previous, template, view, _i, _j, _k, _len, _len1, _len2, _ref1, _ref2, _ref3, _results;
1052
+ modelName = this.args[0];
1053
+ collection = collection || [];
1054
+ if (this.iterated.length > collection.length) {
1055
+ _ref1 = Array(this.iterated.length - collection.length);
1056
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
1057
+ i = _ref1[_i];
1058
+ view = this.iterated.pop();
1059
+ view.unbind();
1060
+ this.marker.parentNode.removeChild(view.els[0]);
1061
+ }
1062
+ }
1063
+ for (index = _j = 0, _len1 = collection.length; _j < _len1; index = ++_j) {
1064
+ model = collection[index];
1065
+ data = {
1066
+ index: index
1067
+ };
1068
+ data[modelName] = model;
1069
+ if (this.iterated[index] == null) {
1070
+ _ref2 = this.view.models;
1071
+ for (key in _ref2) {
1072
+ model = _ref2[key];
1073
+ if (data[key] == null) {
1074
+ data[key] = model;
1075
+ }
1076
+ }
1077
+ previous = this.iterated.length ? this.iterated[this.iterated.length - 1].els[0] : this.marker;
1078
+ options = this.view.options();
1079
+ options.preloadData = true;
1080
+ template = el.cloneNode(true);
1081
+ view = new Rivets.View(template, data, options);
1082
+ view.bind();
1083
+ this.iterated.push(view);
1084
+ this.marker.parentNode.insertBefore(template, previous.nextSibling);
1085
+ } else if (this.iterated[index].models[modelName] !== model) {
1086
+ this.iterated[index].update(data);
1087
+ }
1088
+ }
1089
+ if (el.nodeName === 'OPTION') {
1090
+ _ref3 = this.view.bindings;
1091
+ _results = [];
1092
+ for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
1093
+ binding = _ref3[_k];
1094
+ if (binding.el === this.marker.parentNode && binding.type === 'value') {
1095
+ _results.push(binding.sync());
1096
+ } else {
1097
+ _results.push(void 0);
1098
+ }
1099
+ }
1100
+ return _results;
1101
+ }
1102
+ },
1103
+ update: function(models) {
1104
+ var data, key, model, view, _i, _len, _ref1, _results;
1105
+ data = {};
1106
+ for (key in models) {
1107
+ model = models[key];
1108
+ if (key !== this.args[0]) {
1109
+ data[key] = model;
1110
+ }
1111
+ }
1112
+ _ref1 = this.iterated;
1113
+ _results = [];
1114
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
1115
+ view = _ref1[_i];
1116
+ _results.push(view.update(data));
1117
+ }
1118
+ return _results;
1119
+ }
1120
+ };
1121
+
1122
+ Rivets["public"].binders['class-*'] = function(el, value) {
1123
+ var elClass;
1124
+ elClass = " " + el.className + " ";
1125
+ if (!value === (elClass.indexOf(" " + this.args[0] + " ") !== -1)) {
1126
+ return el.className = value ? "" + el.className + " " + this.args[0] : elClass.replace(" " + this.args[0] + " ", ' ').trim();
1127
+ }
1128
+ };
1129
+
1130
+ Rivets["public"].binders['*'] = function(el, value) {
1131
+ if (value != null) {
1132
+ return el.setAttribute(this.type, value);
1133
+ } else {
1134
+ return el.removeAttribute(this.type);
1135
+ }
1136
+ };
1137
+
1138
+ Rivets["public"].adapters['.'] = {
1139
+ id: '_rv',
1140
+ counter: 0,
1141
+ weakmap: {},
1142
+ weakReference: function(obj) {
1143
+ var id;
1144
+ if (!obj.hasOwnProperty(this.id)) {
1145
+ id = this.counter++;
1146
+ this.weakmap[id] = {
1147
+ callbacks: {}
1148
+ };
1149
+ Object.defineProperty(obj, this.id, {
1150
+ value: id
1151
+ });
1152
+ }
1153
+ return this.weakmap[obj[this.id]];
1154
+ },
1155
+ stubFunction: function(obj, fn) {
1156
+ var map, original, weakmap;
1157
+ original = obj[fn];
1158
+ map = this.weakReference(obj);
1159
+ weakmap = this.weakmap;
1160
+ return obj[fn] = function() {
1161
+ var callback, k, r, response, _i, _len, _ref1, _ref2, _ref3, _ref4;
1162
+ response = original.apply(obj, arguments);
1163
+ _ref1 = map.pointers;
1164
+ for (r in _ref1) {
1165
+ k = _ref1[r];
1166
+ _ref4 = (_ref2 = (_ref3 = weakmap[r]) != null ? _ref3.callbacks[k] : void 0) != null ? _ref2 : [];
1167
+ for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
1168
+ callback = _ref4[_i];
1169
+ callback();
1170
+ }
1171
+ }
1172
+ return response;
1173
+ };
1174
+ },
1175
+ observeMutations: function(obj, ref, keypath) {
1176
+ var fn, functions, map, _base, _i, _len;
1177
+ if (Array.isArray(obj)) {
1178
+ map = this.weakReference(obj);
1179
+ if (map.pointers == null) {
1180
+ map.pointers = {};
1181
+ functions = ['push', 'pop', 'shift', 'unshift', 'sort', 'reverse', 'splice'];
1182
+ for (_i = 0, _len = functions.length; _i < _len; _i++) {
1183
+ fn = functions[_i];
1184
+ this.stubFunction(obj, fn);
1185
+ }
1186
+ }
1187
+ if ((_base = map.pointers)[ref] == null) {
1188
+ _base[ref] = [];
1189
+ }
1190
+ if (__indexOf.call(map.pointers[ref], keypath) < 0) {
1191
+ return map.pointers[ref].push(keypath);
1192
+ }
1193
+ }
1194
+ },
1195
+ unobserveMutations: function(obj, ref, keypath) {
1196
+ var idx, keypaths, _ref1;
1197
+ if (Array.isArray(obj && (obj[this.id] != null))) {
1198
+ if (keypaths = (_ref1 = this.weakReference(obj).pointers) != null ? _ref1[ref] : void 0) {
1199
+ idx = keypaths.indexOf(keypath);
1200
+ if (idx >= 0) {
1201
+ return keypaths.splice(idx, 1);
1202
+ }
1203
+ }
1204
+ }
1205
+ },
1206
+ observe: function(obj, keypath, callback) {
1207
+ var callbacks, value;
1208
+ callbacks = this.weakReference(obj).callbacks;
1209
+ if (callbacks[keypath] == null) {
1210
+ callbacks[keypath] = [];
1211
+ value = obj[keypath];
1212
+ Object.defineProperty(obj, keypath, {
1213
+ enumerable: true,
1214
+ get: function() {
1215
+ return value;
1216
+ },
1217
+ set: (function(_this) {
1218
+ return function(newValue) {
1219
+ var _i, _len, _ref1;
1220
+ if (newValue !== value) {
1221
+ value = newValue;
1222
+ _ref1 = callbacks[keypath].slice();
1223
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
1224
+ callback = _ref1[_i];
1225
+ if (__indexOf.call(callbacks[keypath], callback) >= 0) {
1226
+ callback();
1227
+ }
1228
+ }
1229
+ return _this.observeMutations(newValue, obj[_this.id], keypath);
1230
+ }
1231
+ };
1232
+ })(this)
1233
+ });
1234
+ }
1235
+ if (__indexOf.call(callbacks[keypath], callback) < 0) {
1236
+ callbacks[keypath].push(callback);
1237
+ }
1238
+ return this.observeMutations(obj[keypath], obj[this.id], keypath);
1239
+ },
1240
+ unobserve: function(obj, keypath, callback) {
1241
+ var callbacks, idx;
1242
+ callbacks = this.weakmap[obj[this.id]].callbacks[keypath];
1243
+ idx = callbacks.indexOf(callback);
1244
+ if (idx >= 0) {
1245
+ callbacks.splice(idx, 1);
1246
+ }
1247
+ return this.unobserveMutations(obj[keypath], obj[this.id], keypath);
1248
+ },
1249
+ get: function(obj, keypath) {
1250
+ return obj[keypath];
1251
+ },
1252
+ set: function(obj, keypath, value) {
1253
+ return obj[keypath] = value;
1254
+ }
1255
+ };
1256
+
1257
+ Rivets.factory = function(sightglass) {
1258
+ Rivets.sightglass = sightglass;
1259
+ Rivets["public"]._ = Rivets;
1260
+ return Rivets["public"];
1261
+ };
1262
+
1263
+ if (typeof (typeof module !== "undefined" && module !== null ? module.exports : void 0) === 'object') {
1264
+ module.exports = Rivets.factory(require('sightglass'));
1265
+ } else if (typeof define === 'function' && define.amd) {
1266
+ define(['sightglass'], function(sightglass) {
1267
+ return this.rivets = Rivets.factory(sightglass);
1268
+ });
1269
+ } else {
1270
+ this.rivets = Rivets.factory(sightglass);
1271
+ }
1272
+
1273
+ }).call(this);