20ce9590 by Michael Richards

Build 0.5.10.

1 parent 203892c1
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
2 "name": "rivets", 2 "name": "rivets",
3 "repo": "mikeric/rivets", 3 "repo": "mikeric/rivets",
4 "description": "Declarative data binding facility.", 4 "description": "Declarative data binding facility.",
5 "version": "0.5.9", 5 "version": "0.5.10",
6 "keywords": ["data binding", "templating"], 6 "keywords": ["data binding", "templating"],
7 "scripts": ["dist/rivets.js"], 7 "scripts": ["dist/rivets.js"],
8 "main": "dist/rivets.js", 8 "main": "dist/rivets.js",
......
1 // Rivets.js 1 // Rivets.js
2 // version: 0.5.9 2 // version: 0.5.10
3 // author: Michael Richards 3 // author: Michael Richards
4 // license: MIT 4 // license: MIT
5 (function() { 5 (function() {
6 var Rivets, 6 var Rivets,
7 __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 7 __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
8 __slice = [].slice, 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; },
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; }; 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; };
10 12
11 Rivets = {}; 13 Rivets = {};
...@@ -204,6 +206,84 @@ ...@@ -204,6 +206,84 @@
204 206
205 })(); 207 })();
206 208
209 Rivets.ComponentBinding = (function(_super) {
210 __extends(ComponentBinding, _super);
211
212 function ComponentBinding(view, el, type) {
213 var attribute, _i, _len, _ref, _ref1;
214
215 this.view = view;
216 this.el = el;
217 this.type = type;
218 this.unbind = __bind(this.unbind, this);
219 this.bind = __bind(this.bind, this);
220 this.update = __bind(this.update, this);
221 this.locals = __bind(this.locals, this);
222 this.component = Rivets.components[this.type];
223 this.attributes = {};
224 this.inflections = {};
225 _ref = this.el.attributes || [];
226 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
227 attribute = _ref[_i];
228 if (_ref1 = attribute.name, __indexOf.call(this.component.attributes, _ref1) >= 0) {
229 this.attributes[attribute.name] = attribute.value;
230 } else {
231 this.inflections[attribute.name] = attribute.value;
232 }
233 }
234 }
235
236 ComponentBinding.prototype.sync = function() {};
237
238 ComponentBinding.prototype.locals = function(models) {
239 var inverse, key, model, result, _ref, _ref1;
240
241 if (models == null) {
242 models = this.view.models;
243 }
244 result = {};
245 _ref = this.inflections;
246 for (key in _ref) {
247 inverse = _ref[key];
248 result[key] = models[inverse];
249 }
250 for (key in models) {
251 model = models[key];
252 if ((_ref1 = result[key]) == null) {
253 result[key] = model;
254 }
255 }
256 return result;
257 };
258
259 ComponentBinding.prototype.update = function(models) {
260 var _ref;
261
262 return (_ref = this.componentView) != null ? _ref.update(this.locals(models)) : void 0;
263 };
264
265 ComponentBinding.prototype.bind = function() {
266 var el, _ref;
267
268 if (this.componentView != null) {
269 return (_ref = this.componentView) != null ? _ref.bind() : void 0;
270 } else {
271 el = this.component.build.call(this.attributes);
272 (this.componentView = new Rivets.View(el, this.locals(), this.view.options)).bind();
273 return this.el.parentNode.replaceChild(el, this.el);
274 }
275 };
276
277 ComponentBinding.prototype.unbind = function() {
278 var _ref;
279
280 return (_ref = this.componentView) != null ? _ref.unbind() : void 0;
281 };
282
283 return ComponentBinding;
284
285 })(Rivets.Binding);
286
207 Rivets.View = (function() { 287 Rivets.View = (function() {
208 function View(els, models, options) { 288 function View(els, models, options) {
209 var k, option, v, _base, _i, _len, _ref, _ref1, _ref2, _ref3; 289 var k, option, v, _base, _i, _len, _ref, _ref1, _ref2, _ref3;
...@@ -218,6 +298,7 @@ ...@@ -218,6 +298,7 @@
218 this.bind = __bind(this.bind, this); 298 this.bind = __bind(this.bind, this);
219 this.select = __bind(this.select, this); 299 this.select = __bind(this.select, this);
220 this.build = __bind(this.build, this); 300 this.build = __bind(this.build, this);
301 this.componentRegExp = __bind(this.componentRegExp, this);
221 this.bindingRegExp = __bind(this.bindingRegExp, this); 302 this.bindingRegExp = __bind(this.bindingRegExp, this);
222 if (!(this.els.jquery || this.els instanceof Array)) { 303 if (!(this.els.jquery || this.els instanceof Array)) {
223 this.els = [this.els]; 304 this.els = [this.els];
...@@ -255,13 +336,20 @@ ...@@ -255,13 +336,20 @@
255 } 336 }
256 }; 337 };
257 338
339 View.prototype.componentRegExp = function() {
340 var _ref, _ref1;
341
342 return new RegExp("^" + ((_ref = (_ref1 = this.config.prefix) != null ? _ref1.toUpperCase() : void 0) != null ? _ref : 'RV') + "-");
343 };
344
258 View.prototype.build = function() { 345 View.prototype.build = function() {
259 var bindingRegExp, buildBinding, el, parse, skipNodes, _i, _len, _ref, 346 var bindingRegExp, buildBinding, componentRegExp, el, parse, skipNodes, _i, _len, _ref,
260 _this = this; 347 _this = this;
261 348
262 this.bindings = []; 349 this.bindings = [];
263 skipNodes = []; 350 skipNodes = [];
264 bindingRegExp = this.bindingRegExp(); 351 bindingRegExp = this.bindingRegExp();
352 componentRegExp = this.componentRegExp();
265 buildBinding = function(node, type, declaration) { 353 buildBinding = function(node, type, declaration) {
266 var context, ctx, dependencies, key, keypath, options, path, pipe, pipes, splitPath; 354 var context, ctx, dependencies, key, keypath, options, path, pipe, pipes, splitPath;
267 355
...@@ -332,6 +420,9 @@ ...@@ -332,6 +420,9 @@
332 } 420 }
333 } 421 }
334 } 422 }
423 } else if (componentRegExp.test(node.tagName)) {
424 type = node.tagName.replace(componentRegExp, '').toLowerCase();
425 _this.bindings.push(new Rivets.ComponentBinding(_this, node, type));
335 } else if (node.attributes != null) { 426 } else if (node.attributes != null) {
336 _ref = node.attributes; 427 _ref = node.attributes;
337 for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { 428 for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
...@@ -885,6 +976,8 @@ ...@@ -885,6 +976,8 @@
885 } 976 }
886 }; 977 };
887 978
979 Rivets.components = {};
980
888 Rivets.config = { 981 Rivets.config = {
889 preloadData: true, 982 preloadData: true,
890 handler: function(context, ev, binding) { 983 handler: function(context, ev, binding) {
...@@ -897,6 +990,7 @@ ...@@ -897,6 +990,7 @@
897 Rivets.factory = function(exports) { 990 Rivets.factory = function(exports) {
898 exports._ = Rivets; 991 exports._ = Rivets;
899 exports.binders = Rivets.binders; 992 exports.binders = Rivets.binders;
993 exports.components = Rivets.components;
900 exports.formatters = Rivets.formatters; 994 exports.formatters = Rivets.formatters;
901 exports.config = Rivets.config; 995 exports.config = Rivets.config;
902 exports.configure = function(options) { 996 exports.configure = function(options) {
......
1 { 1 {
2 "name": "rivets", 2 "name": "rivets",
3 "description": "Declarative data binding facility.", 3 "description": "Declarative data binding facility.",
4 "version": "0.5.9", 4 "version": "0.5.10",
5 "author": "Michael Richards", 5 "author": "Michael Richards",
6 "url": "http://rivetsjs.com", 6 "url": "http://rivetsjs.com",
7 "main": "./dist/rivets.js", 7 "main": "./dist/rivets.js",
......
1 # Rivets.js 1 # Rivets.js
2 # ========= 2 # =========
3 3
4 # > version: 0.5.9 4 # > version: 0.5.10
5 # > author: Michael Richards 5 # > author: Michael Richards
6 # > license: MIT 6 # > license: MIT
7 # > 7 # >
......