rivets-rails 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -41,16 +41,25 @@ module.exports = (grunt) ->
41
41
  report: 'gzip'
42
42
  files:
43
43
  'dist/rivets.general_custom.js.min.js': 'dist/rivets.general_custom.js'
44
+
45
+ copy:
46
+ main:
47
+ files: [
48
+ {expand: true, flatten: true, src: ['dist/**'], dest: 'vendor/assets/javascripts/'}
49
+ ]
44
50
 
45
51
  watch:
46
52
  all:
47
53
  files: ['src/*.coffee']
48
54
  tasks: ['build']
55
+
56
+
49
57
 
50
58
  grunt.loadNpmTasks 'grunt-contrib-coffee'
51
59
  grunt.loadNpmTasks 'grunt-contrib-concat'
52
60
  grunt.loadNpmTasks 'grunt-contrib-uglify'
53
61
  grunt.loadNpmTasks 'grunt-contrib-watch'
62
+ grunt.loadNpmTasks 'grunt-contrib-copy'
54
63
 
55
64
  grunt.registerTask 'default', ['watch']
56
- grunt.registerTask 'build', ['coffee', 'concat', 'uglify']
65
+ grunt.registerTask 'build', ['coffee', 'concat', 'uglify', 'copy']
@@ -1,5 +1,5 @@
1
1
  require "rivets-rails/version"
2
- require "rivets-rails/railtie"
2
+ require "rivets-rails/engine"
3
3
 
4
4
  module Rivets
5
5
  module Rails
@@ -0,0 +1,7 @@
1
+ module Rivets
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
7
+
@@ -1,5 +1,5 @@
1
1
  module Rivets
2
2
  module Rails
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -29,7 +29,8 @@
29
29
  "grunt-contrib-coffee": "~0.7.0",
30
30
  "grunt-contrib-concat": "~0.3.0",
31
31
  "grunt-contrib-uglify": "~0.2.0",
32
- "grunt-contrib-watch": "~0.3.1"
32
+ "grunt-contrib-watch": "~0.3.1",
33
+ "grunt-contrib-copy": "~0.4.1"
33
34
  },
34
35
  "engines": {
35
36
  "node": ">= 0.8.0"
@@ -16,4 +16,5 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+
19
20
  end
File without changes
@@ -0,0 +1,22 @@
1
+ (function() {
2
+ var rivets;
3
+
4
+ rivets = this.rivets;
5
+
6
+ rivets.binders.content = {
7
+ routine: rivets.binders.text,
8
+ bind: function(el) {
9
+ var self;
10
+
11
+ self = this;
12
+ this.callback = function() {
13
+ return rivets.config.adapter.publish(self.model, self.keypath, el.textContent);
14
+ };
15
+ return el.addEventListener("input", this.callback, false);
16
+ },
17
+ unbind: function(el) {
18
+ return el.removeEventListener("input", this.callback, false);
19
+ }
20
+ };
21
+
22
+ }).call(this);
@@ -0,0 +1,10 @@
1
+ (function() {
2
+ var rivets;
3
+
4
+ rivets = this.rivets;
5
+
6
+ rivets.configure({
7
+ prefix: 'bind'
8
+ });
9
+
10
+ }).call(this);
@@ -0,0 +1,54 @@
1
+ (function() {
2
+ var rivets;
3
+
4
+ rivets = this.rivets;
5
+
6
+ rivets.formatters.shortdate = function(value) {
7
+ return moment(value).format("YYYY-MM-DD");
8
+ };
9
+
10
+ rivets.formatters.number = function(value) {
11
+ return +value;
12
+ };
13
+
14
+ rivets.formatters.string = function(value) {
15
+ return String(value);
16
+ };
17
+
18
+ rivets.formatters.negate = function(value) {
19
+ return !value;
20
+ };
21
+
22
+ rivets.formatters.eq = function(value, args) {
23
+ return value === args;
24
+ };
25
+
26
+ rivets.formatters.not_eq = function(value, args) {
27
+ return value !== args;
28
+ };
29
+
30
+ rivets.formatters.gt = function(value, arg) {
31
+ return value > arg;
32
+ };
33
+
34
+ rivets.formatters.lt = function(value, arg) {
35
+ return value < arg;
36
+ };
37
+
38
+ rivets.formatters.blank = function(value) {
39
+ return (value == null) || value === "";
40
+ };
41
+
42
+ rivets.formatters.preventDefault = function(value) {
43
+ return function(e) {
44
+ e.preventDefault();
45
+ value.call(this, e);
46
+ return false;
47
+ };
48
+ };
49
+
50
+ rivets.formatters.length = function(value) {
51
+ return value.length;
52
+ };
53
+
54
+ }).call(this);
@@ -0,0 +1,27 @@
1
+ (function() {
2
+ var rivets;
3
+
4
+ rivets = this.rivets;
5
+
6
+ rivets.configure({
7
+ adapter: {
8
+ subscribe: function(obj, keypath, callback) {
9
+ if (obj.on != null) {
10
+ return obj.on("change:" + keypath, callback);
11
+ }
12
+ },
13
+ unsubscribe: function(obj, keypath, callback) {
14
+ if (obj.off != null) {
15
+ return obj.off("change:" + keypath, callback);
16
+ }
17
+ },
18
+ read: function(obj, keypath) {
19
+ return obj[keypath];
20
+ },
21
+ publish: function(obj, keypath, value) {
22
+ return obj[keypath] = value;
23
+ }
24
+ }
25
+ });
26
+
27
+ }).call(this);
@@ -0,0 +1,120 @@
1
+ // rivets.custom_by_vkill.js
2
+ // version: 0.1.0
3
+ // author: vkill
4
+ // license: MIT
5
+ (function() {
6
+ var rivets;
7
+
8
+ rivets = this.rivets;
9
+
10
+ rivets.configure({
11
+ prefix: 'bind'
12
+ });
13
+
14
+ }).call(this);
15
+
16
+ (function() {
17
+ var rivets;
18
+
19
+ rivets = this.rivets;
20
+
21
+ rivets.binders.content = {
22
+ routine: rivets.binders.text,
23
+ bind: function(el) {
24
+ var self;
25
+
26
+ self = this;
27
+ this.callback = function() {
28
+ return rivets.config.adapter.publish(self.model, self.keypath, el.textContent);
29
+ };
30
+ return el.addEventListener("input", this.callback, false);
31
+ },
32
+ unbind: function(el) {
33
+ return el.removeEventListener("input", this.callback, false);
34
+ }
35
+ };
36
+
37
+ }).call(this);
38
+
39
+ (function() {
40
+ var rivets;
41
+
42
+ rivets = this.rivets;
43
+
44
+ rivets.formatters.shortdate = function(value) {
45
+ return moment(value).format("YYYY-MM-DD");
46
+ };
47
+
48
+ rivets.formatters.number = function(value) {
49
+ return +value;
50
+ };
51
+
52
+ rivets.formatters.string = function(value) {
53
+ return String(value);
54
+ };
55
+
56
+ rivets.formatters.negate = function(value) {
57
+ return !value;
58
+ };
59
+
60
+ rivets.formatters.eq = function(value, args) {
61
+ return value === args;
62
+ };
63
+
64
+ rivets.formatters.not_eq = function(value, args) {
65
+ return value !== args;
66
+ };
67
+
68
+ rivets.formatters.gt = function(value, arg) {
69
+ return value > arg;
70
+ };
71
+
72
+ rivets.formatters.lt = function(value, arg) {
73
+ return value < arg;
74
+ };
75
+
76
+ rivets.formatters.blank = function(value) {
77
+ return (value == null) || value === "";
78
+ };
79
+
80
+ rivets.formatters.preventDefault = function(value) {
81
+ return function(e) {
82
+ e.preventDefault();
83
+ value.call(this, e);
84
+ return false;
85
+ };
86
+ };
87
+
88
+ rivets.formatters.length = function(value) {
89
+ return value.length;
90
+ };
91
+
92
+ }).call(this);
93
+
94
+ (function() {
95
+ var rivets;
96
+
97
+ rivets = this.rivets;
98
+
99
+ rivets.configure({
100
+ adapter: {
101
+ subscribe: function(obj, keypath, callback) {
102
+ if (obj.on != null) {
103
+ return obj.on("change:" + keypath, callback);
104
+ }
105
+ },
106
+ unsubscribe: function(obj, keypath, callback) {
107
+ if (obj.off != null) {
108
+ return obj.off("change:" + keypath, callback);
109
+ }
110
+ },
111
+ read: function(obj, keypath) {
112
+ return obj[keypath];
113
+ },
114
+ publish: function(obj, keypath, value) {
115
+ return obj[keypath] = value;
116
+ }
117
+ }
118
+ });
119
+
120
+ }).call(this);
@@ -0,0 +1,5 @@
1
+ // rivets.custom_by_vkill.js
2
+ // version: 0.1.0
3
+ // author: vkill
4
+ // license: MIT
5
+ !function(){var a;a=this.rivets,a.configure({prefix:"bind"})}.call(this),function(){var a;a=this.rivets,a.binders.content={routine:a.binders.text,bind:function(b){var c;return c=this,this.callback=function(){return a.config.adapter.publish(c.model,c.keypath,b.textContent)},b.addEventListener("input",this.callback,!1)},unbind:function(a){return a.removeEventListener("input",this.callback,!1)}}}.call(this),function(){var a;a=this.rivets,a.formatters.shortdate=function(a){return moment(a).format("YYYY-MM-DD")},a.formatters.number=function(a){return+a},a.formatters.string=function(a){return String(a)},a.formatters.negate=function(a){return!a},a.formatters.eq=function(a,b){return a===b},a.formatters.not_eq=function(a,b){return a!==b},a.formatters.gt=function(a,b){return a>b},a.formatters.lt=function(a,b){return b>a},a.formatters.blank=function(a){return null==a||""===a},a.formatters.preventDefault=function(a){return function(b){return b.preventDefault(),a.call(this,b),!1}},a.formatters.length=function(a){return a.length}}.call(this),function(){var a;a=this.rivets,a.configure({adapter:{subscribe:function(a,b,c){return null!=a.on?a.on("change:"+b,c):void 0},unsubscribe:function(a,b,c){return null!=a.off?a.off("change:"+b,c):void 0},read:function(a,b){return a[b]},publish:function(a,b,c){return a[b]=c}}})}.call(this);
@@ -0,0 +1,809 @@
1
+ // Rivets.js
2
+ // version: 0.5.7
3
+ // author: Michael Richards
4
+ // license: MIT
5
+ (function() {
6
+ var Rivets,
7
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
8
+ __slice = [].slice,
9
+ __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; };
10
+
11
+ Rivets = {};
12
+
13
+ if (!String.prototype.trim) {
14
+ String.prototype.trim = function() {
15
+ return this.replace(/^\s+|\s+$/g, '');
16
+ };
17
+ }
18
+
19
+ Rivets.Binding = (function() {
20
+ function Binding(view, el, type, key, keypath, options) {
21
+ var identifier, regexp, value, _ref;
22
+
23
+ this.view = view;
24
+ this.el = el;
25
+ this.type = type;
26
+ this.key = key;
27
+ this.keypath = keypath;
28
+ this.options = options != null ? options : {};
29
+ this.update = __bind(this.update, this);
30
+ this.unbind = __bind(this.unbind, this);
31
+ this.bind = __bind(this.bind, this);
32
+ this.publish = __bind(this.publish, this);
33
+ this.sync = __bind(this.sync, this);
34
+ this.set = __bind(this.set, this);
35
+ this.eventHandler = __bind(this.eventHandler, this);
36
+ this.formattedValue = __bind(this.formattedValue, this);
37
+ if (!(this.binder = this.view.binders[type])) {
38
+ _ref = this.view.binders;
39
+ for (identifier in _ref) {
40
+ value = _ref[identifier];
41
+ if (identifier !== '*' && identifier.indexOf('*') !== -1) {
42
+ regexp = new RegExp("^" + (identifier.replace('*', '.+')) + "$");
43
+ if (regexp.test(type)) {
44
+ this.binder = value;
45
+ this.args = new RegExp("^" + (identifier.replace('*', '(.+)')) + "$").exec(type);
46
+ this.args.shift();
47
+ }
48
+ }
49
+ }
50
+ }
51
+ this.binder || (this.binder = this.view.binders['*']);
52
+ if (this.binder instanceof Function) {
53
+ this.binder = {
54
+ routine: this.binder
55
+ };
56
+ }
57
+ this.formatters = this.options.formatters || [];
58
+ this.model = this.key ? this.view.models[this.key] : this.view.models;
59
+ }
60
+
61
+ Binding.prototype.formattedValue = function(value) {
62
+ var args, formatter, id, _i, _len, _ref;
63
+
64
+ _ref = this.formatters;
65
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
66
+ formatter = _ref[_i];
67
+ args = formatter.split(/\s+/);
68
+ id = args.shift();
69
+ formatter = this.model[id] instanceof Function ? this.model[id] : this.view.formatters[id];
70
+ if ((formatter != null ? formatter.read : void 0) instanceof Function) {
71
+ value = formatter.read.apply(formatter, [value].concat(__slice.call(args)));
72
+ } else if (formatter instanceof Function) {
73
+ value = formatter.apply(null, [value].concat(__slice.call(args)));
74
+ }
75
+ }
76
+ return value;
77
+ };
78
+
79
+ Binding.prototype.eventHandler = function(fn) {
80
+ var binding, handler;
81
+
82
+ handler = (binding = this).view.config.handler;
83
+ return function(ev) {
84
+ return handler.call(fn, this, ev, binding);
85
+ };
86
+ };
87
+
88
+ Binding.prototype.set = function(value) {
89
+ var _ref;
90
+
91
+ value = value instanceof Function && !this.binder["function"] ? this.formattedValue(value.call(this.model)) : this.formattedValue(value);
92
+ return (_ref = this.binder.routine) != null ? _ref.call(this, this.el, value) : void 0;
93
+ };
94
+
95
+ Binding.prototype.sync = function() {
96
+ return this.set(this.options.bypass ? this.model[this.keypath] : this.view.config.adapter.read(this.model, this.keypath));
97
+ };
98
+
99
+ Binding.prototype.publish = function() {
100
+ var args, formatter, id, value, _i, _len, _ref, _ref1, _ref2;
101
+
102
+ value = Rivets.Util.getInputValue(this.el);
103
+ _ref = this.formatters.slice(0).reverse();
104
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
105
+ formatter = _ref[_i];
106
+ args = formatter.split(/\s+/);
107
+ id = args.shift();
108
+ if ((_ref1 = this.view.formatters[id]) != null ? _ref1.publish : void 0) {
109
+ value = (_ref2 = this.view.formatters[id]).publish.apply(_ref2, [value].concat(__slice.call(args)));
110
+ }
111
+ }
112
+ return this.view.config.adapter.publish(this.model, this.keypath, value);
113
+ };
114
+
115
+ Binding.prototype.bind = function() {
116
+ var dependency, keypath, model, _i, _len, _ref, _ref1, _ref2, _results;
117
+
118
+ if ((_ref = this.binder.bind) != null) {
119
+ _ref.call(this, this.el);
120
+ }
121
+ if (this.options.bypass) {
122
+ this.sync();
123
+ } else {
124
+ this.view.config.adapter.subscribe(this.model, this.keypath, this.sync);
125
+ if (this.view.config.preloadData) {
126
+ this.sync();
127
+ }
128
+ }
129
+ if ((_ref1 = this.options.dependencies) != null ? _ref1.length : void 0) {
130
+ _ref2 = this.options.dependencies;
131
+ _results = [];
132
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
133
+ dependency = _ref2[_i];
134
+ if (/^\./.test(dependency)) {
135
+ model = this.model;
136
+ keypath = dependency.substr(1);
137
+ } else {
138
+ dependency = dependency.split('.');
139
+ model = this.view.models[dependency.shift()];
140
+ keypath = dependency.join('.');
141
+ }
142
+ _results.push(this.view.config.adapter.subscribe(model, keypath, this.sync));
143
+ }
144
+ return _results;
145
+ }
146
+ };
147
+
148
+ Binding.prototype.unbind = function() {
149
+ var dependency, keypath, model, _i, _len, _ref, _ref1, _ref2, _results;
150
+
151
+ if ((_ref = this.binder.unbind) != null) {
152
+ _ref.call(this, this.el);
153
+ }
154
+ if (!this.options.bypass) {
155
+ this.view.config.adapter.unsubscribe(this.model, this.keypath, this.sync);
156
+ }
157
+ if ((_ref1 = this.options.dependencies) != null ? _ref1.length : void 0) {
158
+ _ref2 = this.options.dependencies;
159
+ _results = [];
160
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
161
+ dependency = _ref2[_i];
162
+ if (/^\./.test(dependency)) {
163
+ model = this.model;
164
+ keypath = dependency.substr(1);
165
+ } else {
166
+ dependency = dependency.split('.');
167
+ model = this.view.models[dependency.shift()];
168
+ keypath = dependency.join('.');
169
+ }
170
+ _results.push(this.view.config.adapter.unsubscribe(model, keypath, this.sync));
171
+ }
172
+ return _results;
173
+ }
174
+ };
175
+
176
+ Binding.prototype.update = function() {
177
+ this.unbind();
178
+ this.model = this.key ? this.view.models[this.key] : this.view.models;
179
+ return this.bind();
180
+ };
181
+
182
+ return Binding;
183
+
184
+ })();
185
+
186
+ Rivets.View = (function() {
187
+ function View(els, models, options) {
188
+ var k, option, v, _base, _i, _len, _ref, _ref1, _ref2, _ref3;
189
+
190
+ this.els = els;
191
+ this.models = models;
192
+ this.options = options != null ? options : {};
193
+ this.update = __bind(this.update, this);
194
+ this.publish = __bind(this.publish, this);
195
+ this.sync = __bind(this.sync, this);
196
+ this.unbind = __bind(this.unbind, this);
197
+ this.bind = __bind(this.bind, this);
198
+ this.select = __bind(this.select, this);
199
+ this.build = __bind(this.build, this);
200
+ this.bindingRegExp = __bind(this.bindingRegExp, this);
201
+ if (!(this.els.jquery || this.els instanceof Array)) {
202
+ this.els = [this.els];
203
+ }
204
+ _ref = ['config', 'binders', 'formatters'];
205
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
206
+ option = _ref[_i];
207
+ this[option] = {};
208
+ if (this.options[option]) {
209
+ _ref1 = this.options[option];
210
+ for (k in _ref1) {
211
+ v = _ref1[k];
212
+ this[option][k] = v;
213
+ }
214
+ }
215
+ _ref2 = Rivets[option];
216
+ for (k in _ref2) {
217
+ v = _ref2[k];
218
+ if ((_ref3 = (_base = this[option])[k]) == null) {
219
+ _base[k] = v;
220
+ }
221
+ }
222
+ }
223
+ this.build();
224
+ }
225
+
226
+ View.prototype.bindingRegExp = function() {
227
+ var prefix;
228
+
229
+ prefix = this.config.prefix;
230
+ if (prefix) {
231
+ return new RegExp("^data-" + prefix + "-");
232
+ } else {
233
+ return /^data-/;
234
+ }
235
+ };
236
+
237
+ View.prototype.build = function() {
238
+ var bindingRegExp, el, node, parse, skipNodes, _i, _j, _len, _len1, _ref, _ref1,
239
+ _this = this;
240
+
241
+ this.bindings = [];
242
+ skipNodes = [];
243
+ bindingRegExp = this.bindingRegExp();
244
+ parse = function(node) {
245
+ var attribute, attributes, binder, context, ctx, dependencies, identifier, key, keypath, n, options, path, pipe, pipes, regexp, splitPath, type, value, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3;
246
+
247
+ if (__indexOf.call(skipNodes, node) < 0) {
248
+ _ref = node.attributes;
249
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
250
+ attribute = _ref[_i];
251
+ if (bindingRegExp.test(attribute.name)) {
252
+ type = attribute.name.replace(bindingRegExp, '');
253
+ if (!(binder = _this.binders[type])) {
254
+ _ref1 = _this.binders;
255
+ for (identifier in _ref1) {
256
+ value = _ref1[identifier];
257
+ if (identifier !== '*' && identifier.indexOf('*') !== -1) {
258
+ regexp = new RegExp("^" + (identifier.replace('*', '.+')) + "$");
259
+ if (regexp.test(type)) {
260
+ binder = value;
261
+ }
262
+ }
263
+ }
264
+ }
265
+ binder || (binder = _this.binders['*']);
266
+ if (binder.block) {
267
+ _ref2 = node.getElementsByTagName('*');
268
+ for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
269
+ n = _ref2[_j];
270
+ skipNodes.push(n);
271
+ }
272
+ attributes = [attribute];
273
+ }
274
+ }
275
+ }
276
+ _ref3 = attributes || node.attributes;
277
+ for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
278
+ attribute = _ref3[_k];
279
+ if (bindingRegExp.test(attribute.name)) {
280
+ options = {};
281
+ type = attribute.name.replace(bindingRegExp, '');
282
+ pipes = (function() {
283
+ var _l, _len3, _ref4, _results;
284
+
285
+ _ref4 = attribute.value.split('|');
286
+ _results = [];
287
+ for (_l = 0, _len3 = _ref4.length; _l < _len3; _l++) {
288
+ pipe = _ref4[_l];
289
+ _results.push(pipe.trim());
290
+ }
291
+ return _results;
292
+ })();
293
+ context = (function() {
294
+ var _l, _len3, _ref4, _results;
295
+
296
+ _ref4 = pipes.shift().split('<');
297
+ _results = [];
298
+ for (_l = 0, _len3 = _ref4.length; _l < _len3; _l++) {
299
+ ctx = _ref4[_l];
300
+ _results.push(ctx.trim());
301
+ }
302
+ return _results;
303
+ })();
304
+ path = context.shift();
305
+ splitPath = path.split(/\.|:/);
306
+ options.formatters = pipes;
307
+ options.bypass = path.indexOf(':') !== -1;
308
+ if (splitPath[0]) {
309
+ key = splitPath.shift();
310
+ } else {
311
+ key = null;
312
+ splitPath.shift();
313
+ }
314
+ keypath = splitPath.join('.');
315
+ if (!key || (_this.models[key] != null)) {
316
+ if (dependencies = context.shift()) {
317
+ options.dependencies = dependencies.split(/\s+/);
318
+ }
319
+ _this.bindings.push(new Rivets.Binding(_this, node, type, key, keypath, options));
320
+ }
321
+ }
322
+ }
323
+ if (attributes) {
324
+ attributes = null;
325
+ }
326
+ }
327
+ };
328
+ _ref = this.els;
329
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
330
+ el = _ref[_i];
331
+ parse(el);
332
+ _ref1 = el.getElementsByTagName('*');
333
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
334
+ node = _ref1[_j];
335
+ if (node.attributes != null) {
336
+ parse(node);
337
+ }
338
+ }
339
+ }
340
+ };
341
+
342
+ View.prototype.select = function(fn) {
343
+ var binding, _i, _len, _ref, _results;
344
+
345
+ _ref = this.bindings;
346
+ _results = [];
347
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
348
+ binding = _ref[_i];
349
+ if (fn(binding)) {
350
+ _results.push(binding);
351
+ }
352
+ }
353
+ return _results;
354
+ };
355
+
356
+ View.prototype.bind = function() {
357
+ var binding, _i, _len, _ref, _results;
358
+
359
+ _ref = this.bindings;
360
+ _results = [];
361
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
362
+ binding = _ref[_i];
363
+ _results.push(binding.bind());
364
+ }
365
+ return _results;
366
+ };
367
+
368
+ View.prototype.unbind = function() {
369
+ var binding, _i, _len, _ref, _results;
370
+
371
+ _ref = this.bindings;
372
+ _results = [];
373
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
374
+ binding = _ref[_i];
375
+ _results.push(binding.unbind());
376
+ }
377
+ return _results;
378
+ };
379
+
380
+ View.prototype.sync = function() {
381
+ var binding, _i, _len, _ref, _results;
382
+
383
+ _ref = this.bindings;
384
+ _results = [];
385
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
386
+ binding = _ref[_i];
387
+ _results.push(binding.sync());
388
+ }
389
+ return _results;
390
+ };
391
+
392
+ View.prototype.publish = function() {
393
+ var binding, _i, _len, _ref, _results;
394
+
395
+ _ref = this.select(function(b) {
396
+ return b.binder.publishes;
397
+ });
398
+ _results = [];
399
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
400
+ binding = _ref[_i];
401
+ _results.push(binding.publish());
402
+ }
403
+ return _results;
404
+ };
405
+
406
+ View.prototype.update = function(models) {
407
+ var binding, key, model, _results;
408
+
409
+ if (models == null) {
410
+ models = {};
411
+ }
412
+ _results = [];
413
+ for (key in models) {
414
+ model = models[key];
415
+ this.models[key] = model;
416
+ _results.push((function() {
417
+ var _i, _len, _ref, _results1;
418
+
419
+ _ref = this.select(function(b) {
420
+ return b.key === key;
421
+ });
422
+ _results1 = [];
423
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
424
+ binding = _ref[_i];
425
+ _results1.push(binding.update());
426
+ }
427
+ return _results1;
428
+ }).call(this));
429
+ }
430
+ return _results;
431
+ };
432
+
433
+ return View;
434
+
435
+ })();
436
+
437
+ Rivets.Util = {
438
+ bindEvent: function(el, event, handler) {
439
+ if (window.jQuery != null) {
440
+ el = jQuery(el);
441
+ if (el.on != null) {
442
+ return el.on(event, handler);
443
+ } else {
444
+ return el.bind(event, handler);
445
+ }
446
+ } else if (window.addEventListener != null) {
447
+ return el.addEventListener(event, handler, false);
448
+ } else {
449
+ event = 'on' + event;
450
+ return el.attachEvent(event, handler);
451
+ }
452
+ },
453
+ unbindEvent: function(el, event, handler) {
454
+ if (window.jQuery != null) {
455
+ el = jQuery(el);
456
+ if (el.off != null) {
457
+ return el.off(event, handler);
458
+ } else {
459
+ return el.unbind(event, handler);
460
+ }
461
+ } else if (window.removeEventListener != null) {
462
+ return el.removeEventListener(event, handler, false);
463
+ } else {
464
+ event = 'on' + event;
465
+ return el.detachEvent(event, handler);
466
+ }
467
+ },
468
+ getInputValue: function(el) {
469
+ var o, _i, _len, _results;
470
+
471
+ if (window.jQuery != null) {
472
+ el = jQuery(el);
473
+ switch (el[0].type) {
474
+ case 'checkbox':
475
+ return el.is(':checked');
476
+ default:
477
+ return el.val();
478
+ }
479
+ } else {
480
+ switch (el.type) {
481
+ case 'checkbox':
482
+ return el.checked;
483
+ case 'select-multiple':
484
+ _results = [];
485
+ for (_i = 0, _len = el.length; _i < _len; _i++) {
486
+ o = el[_i];
487
+ if (o.selected) {
488
+ _results.push(o.value);
489
+ }
490
+ }
491
+ return _results;
492
+ break;
493
+ default:
494
+ return el.value;
495
+ }
496
+ }
497
+ }
498
+ };
499
+
500
+ Rivets.binders = {
501
+ enabled: function(el, value) {
502
+ return el.disabled = !value;
503
+ },
504
+ disabled: function(el, value) {
505
+ return el.disabled = !!value;
506
+ },
507
+ checked: {
508
+ publishes: true,
509
+ bind: function(el) {
510
+ return Rivets.Util.bindEvent(el, 'change', this.publish);
511
+ },
512
+ unbind: function(el) {
513
+ return Rivets.Util.unbindEvent(el, 'change', this.publish);
514
+ },
515
+ routine: function(el, value) {
516
+ var _ref;
517
+
518
+ if (el.type === 'radio') {
519
+ return el.checked = ((_ref = el.value) != null ? _ref.toString() : void 0) === (value != null ? value.toString() : void 0);
520
+ } else {
521
+ return el.checked = !!value;
522
+ }
523
+ }
524
+ },
525
+ unchecked: {
526
+ publishes: true,
527
+ bind: function(el) {
528
+ return Rivets.Util.bindEvent(el, 'change', this.publish);
529
+ },
530
+ unbind: function(el) {
531
+ return Rivets.Util.unbindEvent(el, 'change', this.publish);
532
+ },
533
+ routine: function(el, value) {
534
+ var _ref;
535
+
536
+ if (el.type === 'radio') {
537
+ return el.checked = ((_ref = el.value) != null ? _ref.toString() : void 0) !== (value != null ? value.toString() : void 0);
538
+ } else {
539
+ return el.checked = !value;
540
+ }
541
+ }
542
+ },
543
+ show: function(el, value) {
544
+ return el.style.display = value ? '' : 'none';
545
+ },
546
+ hide: function(el, value) {
547
+ return el.style.display = value ? 'none' : '';
548
+ },
549
+ html: function(el, value) {
550
+ return el.innerHTML = value != null ? value : '';
551
+ },
552
+ value: {
553
+ publishes: true,
554
+ bind: function(el) {
555
+ return Rivets.Util.bindEvent(el, 'change', this.publish);
556
+ },
557
+ unbind: function(el) {
558
+ return Rivets.Util.unbindEvent(el, 'change', this.publish);
559
+ },
560
+ routine: function(el, value) {
561
+ var o, _i, _len, _ref, _ref1, _ref2, _results;
562
+
563
+ if (window.jQuery != null) {
564
+ el = jQuery(el);
565
+ if ((value != null ? value.toString() : void 0) !== ((_ref = el.val()) != null ? _ref.toString() : void 0)) {
566
+ return el.val(value != null ? value : '');
567
+ }
568
+ } else {
569
+ if (el.type === 'select-multiple') {
570
+ if (value != null) {
571
+ _results = [];
572
+ for (_i = 0, _len = el.length; _i < _len; _i++) {
573
+ o = el[_i];
574
+ _results.push(o.selected = (_ref1 = o.value, __indexOf.call(value, _ref1) >= 0));
575
+ }
576
+ return _results;
577
+ }
578
+ } else if ((value != null ? value.toString() : void 0) !== ((_ref2 = el.value) != null ? _ref2.toString() : void 0)) {
579
+ return el.value = value != null ? value : '';
580
+ }
581
+ }
582
+ }
583
+ },
584
+ text: function(el, value) {
585
+ if (el.innerText != null) {
586
+ return el.innerText = value != null ? value : '';
587
+ } else {
588
+ return el.textContent = value != null ? value : '';
589
+ }
590
+ },
591
+ "if": {
592
+ block: true,
593
+ bind: function(el) {
594
+ var attr, declaration;
595
+
596
+ if (this.marker == null) {
597
+ attr = ['data', this.view.config.prefix, this.type].join('-').replace('--', '-');
598
+ declaration = el.getAttribute(attr);
599
+ this.marker = document.createComment(" rivets: " + this.type + " " + declaration + " ");
600
+ el.removeAttribute(attr);
601
+ el.parentNode.insertBefore(this.marker, el);
602
+ return el.parentNode.removeChild(el);
603
+ }
604
+ },
605
+ unbind: function() {
606
+ var _ref;
607
+
608
+ return (_ref = this.nested) != null ? _ref.unbind() : void 0;
609
+ },
610
+ routine: function(el, value) {
611
+ var key, model, models, options, _ref;
612
+
613
+ if (value === (this.nested == null)) {
614
+ if (value) {
615
+ models = {};
616
+ _ref = this.view.models;
617
+ for (key in _ref) {
618
+ model = _ref[key];
619
+ models[key] = model;
620
+ }
621
+ options = {
622
+ binders: this.view.options.binders,
623
+ formatters: this.view.options.formatters,
624
+ config: this.view.options.config
625
+ };
626
+ (this.nested = new Rivets.View(el, models, options)).bind();
627
+ return this.marker.parentNode.insertBefore(el, this.marker.nextSibling);
628
+ } else {
629
+ el.parentNode.removeChild(el);
630
+ this.nested.unbind();
631
+ return delete this.nested;
632
+ }
633
+ }
634
+ }
635
+ },
636
+ unless: {
637
+ block: true,
638
+ bind: function(el) {
639
+ return Rivets.binders["if"].bind.call(this, el);
640
+ },
641
+ unbind: function() {
642
+ return Rivets.binders["if"].unbind.call(this);
643
+ },
644
+ routine: function(el, value) {
645
+ return Rivets.binders["if"].routine.call(this, el, !value);
646
+ }
647
+ },
648
+ "on-*": {
649
+ "function": true,
650
+ unbind: function(el) {
651
+ if (this.handler) {
652
+ return Rivets.Util.unbindEvent(el, this.args[0], this.handler);
653
+ }
654
+ },
655
+ routine: function(el, value) {
656
+ if (this.handler) {
657
+ Rivets.Util.unbindEvent(el, this.args[0], this.handler);
658
+ }
659
+ return Rivets.Util.bindEvent(el, this.args[0], this.handler = this.eventHandler(value));
660
+ }
661
+ },
662
+ "each-*": {
663
+ block: true,
664
+ bind: function(el) {
665
+ var attr;
666
+
667
+ if (this.marker == null) {
668
+ attr = ['data', this.view.config.prefix, this.type].join('-').replace('--', '-');
669
+ this.marker = document.createComment(" rivets: " + this.type + " ");
670
+ this.iterated = [];
671
+ el.removeAttribute(attr);
672
+ el.parentNode.insertBefore(this.marker, el);
673
+ return el.parentNode.removeChild(el);
674
+ }
675
+ },
676
+ unbind: function(el) {
677
+ var view, _i, _len, _ref, _results;
678
+
679
+ if (this.iterated != null) {
680
+ _ref = this.iterated;
681
+ _results = [];
682
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
683
+ view = _ref[_i];
684
+ _results.push(view.unbind());
685
+ }
686
+ return _results;
687
+ }
688
+ },
689
+ routine: function(el, collection) {
690
+ var data, i, index, k, key, model, modelName, options, previous, template, v, view, _i, _j, _len, _len1, _ref, _ref1, _ref2, _ref3, _results;
691
+
692
+ modelName = this.args[0];
693
+ collection = collection || [];
694
+ if (this.iterated.length > collection.length) {
695
+ _ref = Array(this.iterated.length - collection.length);
696
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
697
+ i = _ref[_i];
698
+ view = this.iterated.pop();
699
+ view.unbind();
700
+ this.marker.parentNode.removeChild(view.els[0]);
701
+ }
702
+ }
703
+ _results = [];
704
+ for (index = _j = 0, _len1 = collection.length; _j < _len1; index = ++_j) {
705
+ model = collection[index];
706
+ data = {};
707
+ data[modelName] = model;
708
+ if (this.iterated[index] == null) {
709
+ _ref1 = this.view.models;
710
+ for (key in _ref1) {
711
+ model = _ref1[key];
712
+ if ((_ref2 = data[key]) == null) {
713
+ data[key] = model;
714
+ }
715
+ }
716
+ previous = this.iterated.length ? this.iterated[this.iterated.length - 1].els[0] : this.marker;
717
+ options = {
718
+ binders: this.view.options.binders,
719
+ formatters: this.view.options.formatters,
720
+ config: {}
721
+ };
722
+ _ref3 = this.view.options.config;
723
+ for (k in _ref3) {
724
+ v = _ref3[k];
725
+ options.config[k] = v;
726
+ }
727
+ options.config.preloadData = true;
728
+ template = el.cloneNode(true);
729
+ view = new Rivets.View(template, data, options);
730
+ view.bind();
731
+ this.iterated.push(view);
732
+ _results.push(this.marker.parentNode.insertBefore(template, previous.nextSibling));
733
+ } else if (this.iterated[index].models[modelName] !== model) {
734
+ _results.push(this.iterated[index].update(data));
735
+ } else {
736
+ _results.push(void 0);
737
+ }
738
+ }
739
+ return _results;
740
+ }
741
+ },
742
+ "class-*": function(el, value) {
743
+ var elClass;
744
+
745
+ elClass = " " + el.className + " ";
746
+ if (!value === (elClass.indexOf(" " + this.args[0] + " ") !== -1)) {
747
+ return el.className = value ? "" + el.className + " " + this.args[0] : elClass.replace(" " + this.args[0] + " ", ' ').trim();
748
+ }
749
+ },
750
+ "*": function(el, value) {
751
+ if (value) {
752
+ return el.setAttribute(this.type, value);
753
+ } else {
754
+ return el.removeAttribute(this.type);
755
+ }
756
+ }
757
+ };
758
+
759
+ Rivets.config = {
760
+ preloadData: true,
761
+ handler: function(context, ev, binding) {
762
+ return this.call(context, ev, binding.view.models);
763
+ }
764
+ };
765
+
766
+ Rivets.formatters = {};
767
+
768
+ Rivets.factory = function(exports) {
769
+ exports.binders = Rivets.binders;
770
+ exports.formatters = Rivets.formatters;
771
+ exports.config = Rivets.config;
772
+ exports.configure = function(options) {
773
+ var property, value;
774
+
775
+ if (options == null) {
776
+ options = {};
777
+ }
778
+ for (property in options) {
779
+ value = options[property];
780
+ Rivets.config[property] = value;
781
+ }
782
+ };
783
+ return exports.bind = function(el, models, options) {
784
+ var view;
785
+
786
+ if (models == null) {
787
+ models = {};
788
+ }
789
+ if (options == null) {
790
+ options = {};
791
+ }
792
+ view = new Rivets.View(el, models, options);
793
+ view.bind();
794
+ return view;
795
+ };
796
+ };
797
+
798
+ if (typeof exports === 'object') {
799
+ Rivets.factory(exports);
800
+ } else if (typeof define === 'function' && define.amd) {
801
+ define(['exports'], function(exports) {
802
+ Rivets.factory(this.rivets = exports);
803
+ return exports;
804
+ });
805
+ } else {
806
+ Rivets.factory(this.rivets = {});
807
+ }
808
+
809
+ }).call(this);
@@ -0,0 +1,5 @@
1
+ // Rivets.js
2
+ // version: 0.5.7
3
+ // author: Michael Richards
4
+ // license: MIT
5
+ (function(){var t,i=function(t,i){return function(){return t.apply(i,arguments)}},e=[].slice,n=[].indexOf||function(t){for(var i=0,e=this.length;e>i;i++)if(i in this&&this[i]===t)return i;return-1};t={},String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),t.Binding=function(){function n(t,e,n,s,r,h){var o,l,u,d;if(this.view=t,this.el=e,this.type=n,this.key=s,this.keypath=r,this.options=null!=h?h:{},this.update=i(this.update,this),this.unbind=i(this.unbind,this),this.bind=i(this.bind,this),this.publish=i(this.publish,this),this.sync=i(this.sync,this),this.set=i(this.set,this),this.eventHandler=i(this.eventHandler,this),this.formattedValue=i(this.formattedValue,this),!(this.binder=this.view.binders[n])){d=this.view.binders;for(o in d)u=d[o],"*"!==o&&-1!==o.indexOf("*")&&(l=RegExp("^"+o.replace("*",".+")+"$"),l.test(n)&&(this.binder=u,this.args=RegExp("^"+o.replace("*","(.+)")+"$").exec(n),this.args.shift()))}this.binder||(this.binder=this.view.binders["*"]),this.binder instanceof Function&&(this.binder={routine:this.binder}),this.formatters=this.options.formatters||[],this.model=this.key?this.view.models[this.key]:this.view.models}return n.prototype.formattedValue=function(t){var i,n,s,r,h,o;for(o=this.formatters,r=0,h=o.length;h>r;r++)n=o[r],i=n.split(/\s+/),s=i.shift(),n=this.model[s]instanceof Function?this.model[s]:this.view.formatters[s],(null!=n?n.read:void 0)instanceof Function?t=n.read.apply(n,[t].concat(e.call(i))):n instanceof Function&&(t=n.apply(null,[t].concat(e.call(i))));return t},n.prototype.eventHandler=function(t){var i,e;return e=(i=this).view.config.handler,function(n){return e.call(t,this,n,i)}},n.prototype.set=function(t){var i;return t=t instanceof Function&&!this.binder["function"]?this.formattedValue(t.call(this.model)):this.formattedValue(t),null!=(i=this.binder.routine)?i.call(this,this.el,t):void 0},n.prototype.sync=function(){return this.set(this.options.bypass?this.model[this.keypath]:this.view.config.adapter.read(this.model,this.keypath))},n.prototype.publish=function(){var i,n,s,r,h,o,l,u,d;for(r=t.Util.getInputValue(this.el),l=this.formatters.slice(0).reverse(),h=0,o=l.length;o>h;h++)n=l[h],i=n.split(/\s+/),s=i.shift(),(null!=(u=this.view.formatters[s])?u.publish:void 0)&&(r=(d=this.view.formatters[s]).publish.apply(d,[r].concat(e.call(i))));return this.view.config.adapter.publish(this.model,this.keypath,r)},n.prototype.bind=function(){var t,i,e,n,s,r,h,o,l;if(null!=(r=this.binder.bind)&&r.call(this,this.el),this.options.bypass?this.sync():(this.view.config.adapter.subscribe(this.model,this.keypath,this.sync),this.view.config.preloadData&&this.sync()),null!=(h=this.options.dependencies)?h.length:void 0){for(o=this.options.dependencies,l=[],n=0,s=o.length;s>n;n++)t=o[n],/^\./.test(t)?(e=this.model,i=t.substr(1)):(t=t.split("."),e=this.view.models[t.shift()],i=t.join(".")),l.push(this.view.config.adapter.subscribe(e,i,this.sync));return l}},n.prototype.unbind=function(){var t,i,e,n,s,r,h,o,l;if(null!=(r=this.binder.unbind)&&r.call(this,this.el),this.options.bypass||this.view.config.adapter.unsubscribe(this.model,this.keypath,this.sync),null!=(h=this.options.dependencies)?h.length:void 0){for(o=this.options.dependencies,l=[],n=0,s=o.length;s>n;n++)t=o[n],/^\./.test(t)?(e=this.model,i=t.substr(1)):(t=t.split("."),e=this.view.models[t.shift()],i=t.join(".")),l.push(this.view.config.adapter.unsubscribe(e,i,this.sync));return l}},n.prototype.update=function(){return this.unbind(),this.model=this.key?this.view.models[this.key]:this.view.models,this.bind()},n}(),t.View=function(){function e(e,n,s){var r,h,o,l,u,d,a,c,f,p;for(this.els=e,this.models=n,this.options=null!=s?s:{},this.update=i(this.update,this),this.publish=i(this.publish,this),this.sync=i(this.sync,this),this.unbind=i(this.unbind,this),this.bind=i(this.bind,this),this.select=i(this.select,this),this.build=i(this.build,this),this.bindingRegExp=i(this.bindingRegExp,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),a=["config","binders","formatters"],u=0,d=a.length;d>u;u++){if(h=a[u],this[h]={},this.options[h]){c=this.options[h];for(r in c)o=c[r],this[h][r]=o}f=t[h];for(r in f)o=f[r],null==(p=(l=this[h])[r])&&(l[r]=o)}this.build()}return e.prototype.bindingRegExp=function(){var t;return t=this.config.prefix,t?RegExp("^data-"+t+"-"):/^data-/},e.prototype.build=function(){var i,e,s,r,h,o,l,u,d,a,c,f=this;for(this.bindings=[],h=[],i=this.bindingRegExp(),r=function(e){var s,r,o,l,u,d,a,c,p,b,v,g,m,y,w,k,x,E,j,N,U,V,B,Q,R,A,C,F;if(0>n.call(h,e)){for(R=e.attributes,j=0,V=R.length;V>j;j++)if(s=R[j],i.test(s.name)){if(x=s.name.replace(i,""),!(o=f.binders[x])){A=f.binders;for(a in A)E=A[a],"*"!==a&&-1!==a.indexOf("*")&&(w=RegExp("^"+a.replace("*",".+")+"$"),w.test(x)&&(o=E))}if(o||(o=f.binders["*"]),o.block){for(C=e.getElementsByTagName("*"),N=0,B=C.length;B>N;N++)b=C[N],h.push(b);r=[s]}}for(F=r||e.attributes,U=0,Q=F.length;Q>U;U++)s=F[U],i.test(s.name)&&(v={},x=s.name.replace(i,""),y=function(){var t,i,e,n;for(e=s.value.split("|"),n=[],t=0,i=e.length;i>t;t++)m=e[t],n.push(m.trim());return n}(),l=function(){var t,i,e,n;for(e=y.shift().split("<"),n=[],t=0,i=e.length;i>t;t++)u=e[t],n.push(u.trim());return n}(),g=l.shift(),k=g.split(/\.|:/),v.formatters=y,v.bypass=-1!==g.indexOf(":"),k[0]?c=k.shift():(c=null,k.shift()),p=k.join("."),c&&null==f.models[c]||((d=l.shift())&&(v.dependencies=d.split(/\s+/)),f.bindings.push(new t.Binding(f,e,x,c,p,v))));r&&(r=null)}},a=this.els,o=0,u=a.length;u>o;o++)for(e=a[o],r(e),c=e.getElementsByTagName("*"),l=0,d=c.length;d>l;l++)s=c[l],null!=s.attributes&&r(s)},e.prototype.select=function(t){var i,e,n,s,r;for(s=this.bindings,r=[],e=0,n=s.length;n>e;e++)i=s[e],t(i)&&r.push(i);return r},e.prototype.bind=function(){var t,i,e,n,s;for(n=this.bindings,s=[],i=0,e=n.length;e>i;i++)t=n[i],s.push(t.bind());return s},e.prototype.unbind=function(){var t,i,e,n,s;for(n=this.bindings,s=[],i=0,e=n.length;e>i;i++)t=n[i],s.push(t.unbind());return s},e.prototype.sync=function(){var t,i,e,n,s;for(n=this.bindings,s=[],i=0,e=n.length;e>i;i++)t=n[i],s.push(t.sync());return s},e.prototype.publish=function(){var t,i,e,n,s;for(n=this.select(function(t){return t.binder.publishes}),s=[],i=0,e=n.length;e>i;i++)t=n[i],s.push(t.publish());return s},e.prototype.update=function(t){var i,e,n,s;null==t&&(t={}),s=[];for(e in t)n=t[e],this.models[e]=n,s.push(function(){var t,n,s,r;for(s=this.select(function(t){return t.key===e}),r=[],t=0,n=s.length;n>t;t++)i=s[t],r.push(i.update());return r}.call(this));return s},e}(),t.Util={bindEvent:function(t,i,e){return null!=window.jQuery?(t=jQuery(t),null!=t.on?t.on(i,e):t.bind(i,e)):null!=window.addEventListener?t.addEventListener(i,e,!1):(i="on"+i,t.attachEvent(i,e))},unbindEvent:function(t,i,e){return null!=window.jQuery?(t=jQuery(t),null!=t.off?t.off(i,e):t.unbind(i,e)):null!=window.removeEventListener?t.removeEventListener(i,e,!1):(i="on"+i,t.detachEvent(i,e))},getInputValue:function(t){var i,e,n,s;if(null!=window.jQuery)switch(t=jQuery(t),t[0].type){case"checkbox":return t.is(":checked");default:return t.val()}else switch(t.type){case"checkbox":return t.checked;case"select-multiple":for(s=[],e=0,n=t.length;n>e;e++)i=t[e],i.selected&&s.push(i.value);return s;default:return t.value}}},t.binders={enabled:function(t,i){return t.disabled=!i},disabled:function(t,i){return t.disabled=!!i},checked:{publishes:!0,bind:function(i){return t.Util.bindEvent(i,"change",this.publish)},unbind:function(i){return t.Util.unbindEvent(i,"change",this.publish)},routine:function(t,i){var e;return t.checked="radio"===t.type?(null!=(e=t.value)?""+e:void 0)===(null!=i?""+i:void 0):!!i}},unchecked:{publishes:!0,bind:function(i){return t.Util.bindEvent(i,"change",this.publish)},unbind:function(i){return t.Util.unbindEvent(i,"change",this.publish)},routine:function(t,i){var e;return t.checked="radio"===t.type?(null!=(e=t.value)?""+e:void 0)!==(null!=i?""+i:void 0):!i}},show:function(t,i){return t.style.display=i?"":"none"},hide:function(t,i){return t.style.display=i?"none":""},html:function(t,i){return t.innerHTML=null!=i?i:""},value:{publishes:!0,bind:function(i){return t.Util.bindEvent(i,"change",this.publish)},unbind:function(i){return t.Util.unbindEvent(i,"change",this.publish)},routine:function(t,i){var e,s,r,h,o,l,u;if(null!=window.jQuery){if(t=jQuery(t),(null!=i?""+i:void 0)!==(null!=(h=t.val())?""+h:void 0))return t.val(null!=i?i:"")}else if("select-multiple"===t.type){if(null!=i){for(u=[],s=0,r=t.length;r>s;s++)e=t[s],u.push(e.selected=(o=e.value,n.call(i,o)>=0));return u}}else if((null!=i?""+i:void 0)!==(null!=(l=t.value)?""+l:void 0))return t.value=null!=i?i:""}},text:function(t,i){return null!=t.innerText?t.innerText=null!=i?i:"":t.textContent=null!=i?i:""},"if":{block:!0,bind:function(t){var i,e;return null==this.marker?(i=["data",this.view.config.prefix,this.type].join("-").replace("--","-"),e=t.getAttribute(i),this.marker=document.createComment(" rivets: "+this.type+" "+e+" "),t.removeAttribute(i),t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t)):void 0},unbind:function(){var t;return null!=(t=this.nested)?t.unbind():void 0},routine:function(i,e){var n,s,r,h,o;if(e===(null==this.nested)){if(e){r={},o=this.view.models;for(n in o)s=o[n],r[n]=s;return h={binders:this.view.options.binders,formatters:this.view.options.formatters,config:this.view.options.config},(this.nested=new t.View(i,r,h)).bind(),this.marker.parentNode.insertBefore(i,this.marker.nextSibling)}return i.parentNode.removeChild(i),this.nested.unbind(),delete this.nested}}},unless:{block:!0,bind:function(i){return t.binders["if"].bind.call(this,i)},unbind:function(){return t.binders["if"].unbind.call(this)},routine:function(i,e){return t.binders["if"].routine.call(this,i,!e)}},"on-*":{"function":!0,unbind:function(i){return this.handler?t.Util.unbindEvent(i,this.args[0],this.handler):void 0},routine:function(i,e){return this.handler&&t.Util.unbindEvent(i,this.args[0],this.handler),t.Util.bindEvent(i,this.args[0],this.handler=this.eventHandler(e))}},"each-*":{block:!0,bind:function(t){var i;return null==this.marker?(i=["data",this.view.config.prefix,this.type].join("-").replace("--","-"),this.marker=document.createComment(" rivets: "+this.type+" "),this.iterated=[],t.removeAttribute(i),t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t)):void 0},unbind:function(){var t,i,e,n,s;if(null!=this.iterated){for(n=this.iterated,s=[],i=0,e=n.length;e>i;i++)t=n[i],s.push(t.unbind());return s}},routine:function(i,e){var n,s,r,h,o,l,u,d,a,c,f,p,b,v,g,m,y,w,k,x,E;if(u=this.args[0],e=e||[],this.iterated.length>e.length)for(y=Array(this.iterated.length-e.length),b=0,g=y.length;g>b;b++)s=y[b],p=this.iterated.pop(),p.unbind(),this.marker.parentNode.removeChild(p.els[0]);for(E=[],r=v=0,m=e.length;m>v;r=++v)if(l=e[r],n={},n[u]=l,null==this.iterated[r]){w=this.view.models;for(o in w)l=w[o],null==(k=n[o])&&(n[o]=l);a=this.iterated.length?this.iterated[this.iterated.length-1].els[0]:this.marker,d={binders:this.view.options.binders,formatters:this.view.options.formatters,config:{}},x=this.view.options.config;for(h in x)f=x[h],d.config[h]=f;d.config.preloadData=!0,c=i.cloneNode(!0),p=new t.View(c,n,d),p.bind(),this.iterated.push(p),E.push(this.marker.parentNode.insertBefore(c,a.nextSibling))}else this.iterated[r].models[u]!==l?E.push(this.iterated[r].update(n)):E.push(void 0);return E}},"class-*":function(t,i){var e;return e=" "+t.className+" ",!i==(-1!==e.indexOf(" "+this.args[0]+" "))?t.className=i?""+t.className+" "+this.args[0]:e.replace(" "+this.args[0]+" "," ").trim():void 0},"*":function(t,i){return i?t.setAttribute(this.type,i):t.removeAttribute(this.type)}},t.config={preloadData:!0,handler:function(t,i,e){return this.call(t,i,e.view.models)}},t.formatters={},t.factory=function(i){return i.binders=t.binders,i.formatters=t.formatters,i.config=t.config,i.configure=function(i){var e,n;null==i&&(i={});for(e in i)n=i[e],t.config[e]=n},i.bind=function(i,e,n){var s;return null==e&&(e={}),null==n&&(n={}),s=new t.View(i,e,n),s.bind(),s}},"object"==typeof exports?t.factory(exports):"function"==typeof define&&define.amd?define(["exports"],function(i){return t.factory(this.rivets=i),i}):t.factory(this.rivets={})}).call(this);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rivets-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-05 00:00:00.000000000 Z
12
+ date: 2013-06-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Rivets plugin for Rails
15
15
  email:
@@ -34,7 +34,7 @@ files:
34
34
  - dist/rivets.js
35
35
  - dist/rivets.min.js
36
36
  - lib/rivets-rails.rb
37
- - lib/rivets-rails/railtie.rb
37
+ - lib/rivets-rails/engine.rb
38
38
  - lib/rivets-rails/version.rb
39
39
  - package.json
40
40
  - rivets-rails.gemspec
@@ -42,6 +42,15 @@ files:
42
42
  - src/rivets.custom.configure.coffee
43
43
  - src/rivets.custom.formatters.coffee
44
44
  - src/rivets.custom.general_adapter.coffee
45
+ - vendor/assets/javascripts/.gitkeep
46
+ - vendor/assets/javascripts/rivets.custom.binders.js
47
+ - vendor/assets/javascripts/rivets.custom.configure.js
48
+ - vendor/assets/javascripts/rivets.custom.formatters.js
49
+ - vendor/assets/javascripts/rivets.custom.general_adapter.js
50
+ - vendor/assets/javascripts/rivets.general_custom.js
51
+ - vendor/assets/javascripts/rivets.general_custom.js.min.js
52
+ - vendor/assets/javascripts/rivets.js
53
+ - vendor/assets/javascripts/rivets.min.js
45
54
  homepage: https://github.com/vkill/rivets-rails
46
55
  licenses: []
47
56
  post_install_message:
@@ -1,14 +0,0 @@
1
- module Rivets
2
- module Rails
3
- class Railtie < ::Rails::Railtie
4
-
5
- initializer "sprockets.rivets-rails", after: "append_asset_paths", group: :all do |app|
6
- next unless app.config.assets.enabled
7
- path = File.expand_path("../../../dist", __FILE__)
8
- app.config.assets.paths << path unless app.config.assets.paths.include?(path)
9
- end
10
-
11
- end
12
- end
13
- end
14
-