rivets-rails 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  // Rivets.js
2
- // version: 0.5.7
2
+ // version: 0.5.10
3
3
  // author: Michael Richards
4
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);
5
+ (function(){var t,i=function(t,i){return function(){return t.apply(i,arguments)}},e=[].slice,n={}.hasOwnProperty,s=function(t,i){function e(){this.constructor=t}for(var s in i)n.call(i,s)&&(t[s]=i[s]);return e.prototype=i.prototype,t.prototype=new e,t.__super__=i.prototype,t},r=[].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(e,n,s,r,o,h){var l,u,a,d;if(this.view=e,this.el=n,this.type=s,this.key=r,this.keypath=o,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=t.internalBinders[this.type]||this.view.binders[s])){d=this.view.binders;for(l in d)a=d[l],"*"!==l&&-1!==l.indexOf("*")&&(u=RegExp("^"+l.replace("*",".+")+"$"),u.test(s)&&(this.binder=a,this.args=RegExp("^"+l.replace("*","(.+)")+"$").exec(s),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,o,h;for(h=this.formatters,r=0,o=h.length;o>r;r++)n=h[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,o,h,l,u,a;for(r=t.Util.getInputValue(this.el),l=this.formatters.slice(0).reverse(),o=0,h=l.length;h>o;o++)n=l[o],i=n.split(/\s+/),s=i.shift(),(null!=(u=this.view.formatters[s])?u.publish:void 0)&&(r=(a=this.view.formatters[s]).publish.apply(a,[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,o,h,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!=(o=this.options.dependencies)?o.length:void 0){for(h=this.options.dependencies,l=[],n=0,s=h.length;s>n;n++)t=h[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,o,h,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!=(o=this.options.dependencies)?o.length:void 0){for(h=this.options.dependencies,l=[],n=0,s=h.length;s>n;n++)t=h[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(t){var i;return null==t&&(t={}),this.key?t[this.key]&&(this.options.bypass||this.view.config.adapter.unsubscribe(this.model,this.keypath,this.sync),this.model=t[this.key],this.options.bypass?this.sync():(this.view.config.adapter.subscribe(this.model,this.keypath,this.sync),this.view.config.preloadData&&this.sync())):this.sync(),null!=(i=this.binder.update)?i.call(this,t):void 0},n}(),t.ComponentBinding=function(e){function n(e,n,s){var o,h,l,u,a;for(this.view=e,this.el=n,this.type=s,this.unbind=i(this.unbind,this),this.bind=i(this.bind,this),this.update=i(this.update,this),this.locals=i(this.locals,this),this.component=t.components[this.type],this.attributes={},this.inflections={},u=this.el.attributes||[],h=0,l=u.length;l>h;h++)o=u[h],a=o.name,r.call(this.component.attributes,a)>=0?this.attributes[o.name]=o.value:this.inflections[o.name]=o.value}return s(n,e),n.prototype.sync=function(){},n.prototype.locals=function(t){var i,e,n,s,r,o;null==t&&(t=this.view.models),s={},r=this.inflections;for(e in r)i=r[e],s[e]=t[i];for(e in t)n=t[e],null==(o=s[e])&&(s[e]=n);return s},n.prototype.update=function(t){var i;return null!=(i=this.componentView)?i.update(this.locals(t)):void 0},n.prototype.bind=function(){var i,e;return null!=this.componentView?null!=(e=this.componentView)?e.bind():void 0:(i=this.component.build.call(this.attributes),(this.componentView=new t.View(i,this.locals(),this.view.options)).bind(),this.el.parentNode.replaceChild(i,this.el))},n.prototype.unbind=function(){var t;return null!=(t=this.componentView)?t.unbind():void 0},n}(t.Binding),t.View=function(){function n(e,n,s){var r,o,h,l,u,a,d,p,c,f;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.componentRegExp=i(this.componentRegExp,this),this.bindingRegExp=i(this.bindingRegExp,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),d=["config","binders","formatters"],u=0,a=d.length;a>u;u++){if(o=d[u],this[o]={},this.options[o]){p=this.options[o];for(r in p)h=p[r],this[o][r]=h}c=t[o];for(r in c)h=c[r],null==(f=(l=this[o])[r])&&(l[r]=h)}this.build()}return n.prototype.bindingRegExp=function(){var t;return t=this.config.prefix,t?RegExp("^data-"+t+"-"):/^data-/},n.prototype.componentRegExp=function(){var t,i;return RegExp("^"+(null!=(t=null!=(i=this.config.prefix)?i.toUpperCase():void 0)?t:"RV")+"-")},n.prototype.build=function(){var i,n,s,o,h,l,u,a,d,p=this;for(this.bindings=[],l=[],i=this.bindingRegExp(),s=this.componentRegExp(),n=function(i,e,n){var s,r,o,h,l,u,a,d,c,f;return u={},c=function(){var t,i,e,s;for(e=n.split("|"),s=[],t=0,i=e.length;i>t;t++)d=e[t],s.push(d.trim());return s}(),s=function(){var t,i,e,n;for(e=c.shift().split("<"),n=[],t=0,i=e.length;i>t;t++)r=e[t],n.push(r.trim());return n}(),a=s.shift(),f=a.split(/\.|:/),u.formatters=c,u.bypass=-1!==a.indexOf(":"),f[0]?h=f.shift():(h=null,f.shift()),l=f.join("."),(o=s.shift())&&(u.dependencies=o.split(/\s+/)),p.bindings.push(new t.Binding(p,i,e,h,l,u))},h=function(o){var u,a,d,c,f,b,v,g,y,m,w,x,k,E,N,V,j,R,C,U,B,T,O,Q,A,D,L,_,F,H,S,$;if(0>r.call(l,o)){if(o.nodeType===Node.TEXT_NODE){if(g=t.TextTemplateParser,(f=p.config.templateDelimiters)&&(E=g.parse(o.data,f)).length&&(1!==E.length||E[0].type!==g.types.text)){switch(w=E[0],m=E.length>=2?e.call(E,1):[],o.data=w.value,w.type){case 0:o.data=w.value;break;case 1:n(o,"textNode",w.value)}for(j=0,B=m.length;B>j;j++)k=m[j],o.parentNode.appendChild(x=document.createTextNode(k.value)),1===k.type&&n(x,"textNode",k.value)}}else if(s.test(o.tagName))N=o.tagName.replace(s,"").toLowerCase(),p.bindings.push(new t.ComponentBinding(p,o,N));else if(null!=o.attributes){for(L=o.attributes,R=0,T=L.length;T>R;R++)if(u=L[R],i.test(u.name)){if(N=u.name.replace(i,""),!(d=p.binders[N])){_=p.binders;for(b in _)V=_[b],"*"!==b&&-1!==b.indexOf("*")&&(y=RegExp("^"+b.replace("*",".+")+"$"),y.test(N)&&(d=V))}if(d||(d=p.binders["*"]),d.block){for(F=o.childNodes,C=0,O=F.length;O>C;C++)v=F[C],l.push(v);a=[u]}}for(H=a||o.attributes,U=0,Q=H.length;Q>U;U++)u=H[U],i.test(u.name)&&(N=u.name.replace(i,""),n(o,N,u.value))}for(S=o.childNodes,$=[],D=0,A=S.length;A>D;D++)c=S[D],$.push(h(c));return $}},d=this.els,u=0,a=d.length;a>u;u++)o=d[u],h(o)},n.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},n.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},n.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},n.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},n.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},n.prototype.update=function(t){var i,e,n,s,r,o,h;null==t&&(t={});for(e in t)n=t[e],this.models[e]=n;for(o=this.bindings,h=[],s=0,r=o.length;r>s;s++)i=o[s],h.push(i.update(t));return h},n}(),t.TextTemplateParser=function(){function t(){}return t.types={text:0,binding:1},t.parse=function(t,i){var e,n,s,r,o,h,l;for(h=[],r=t.length,e=0,n=0;r>n;){if(e=t.indexOf(i[0],n),0>e){h.push({type:this.types.text,value:t.slice(n)});break}if(e>0&&e>n&&h.push({type:this.types.text,value:t.slice(n,e)}),n=e+2,e=t.indexOf(i[1],n),0>e){o=t.slice(n-2),s=h[h.length-1],(null!=s?s.type:void 0)===this.types.text?s.value+=o:h.push({type:this.types.text,value:o});break}l=t.slice(n,e).trim(),h.push({type:this.types.binding,value:l}),n=e+2}return h},t}(),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,n,s,o,h,l,u;if(null!=window.jQuery){if(t=jQuery(t),(null!=i?""+i:void 0)!==(null!=(o=t.val())?""+o:void 0))return t.val(null!=i?i:"")}else if("select-multiple"===t.type){if(null!=i){for(u=[],n=0,s=t.length;s>n;n++)e=t[n],u.push(e.selected=(h=e.value,r.call(i,h)>=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,o,h;if(!!e==(null==this.nested)){if(e){r={},h=this.view.models;for(n in h)s=h[n],r[n]=s;return o={binders:this.view.options.binders,formatters:this.view.options.formatters,config:this.view.options.config},(this.nested=new t.View(i,r,o)).bind(),this.marker.parentNode.insertBefore(i,this.marker.nextSibling)}return i.parentNode.removeChild(i),this.nested.unbind(),delete this.nested}},update:function(t){return this.nested.update(t)}},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)},update:function(i){return t.binders["if"].update.call(this,i)}},"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,o,h,l,u,a,d,p,c,f,b,v,g,y,m,w,x,k,E;if(u=this.args[0],e=e||[],this.iterated.length>e.length)for(m=Array(this.iterated.length-e.length),b=0,g=m.length;g>b;b++)s=m[b],f=this.iterated.pop(),f.unbind(),this.marker.parentNode.removeChild(f.els[0]);for(E=[],r=v=0,y=e.length;y>v;r=++v)if(l=e[r],n={},n[u]=l,null==this.iterated[r]){w=this.view.models;for(h in w)l=w[h],null==(x=n[h])&&(n[h]=l);d=this.iterated.length?this.iterated[this.iterated.length-1].els[0]:this.marker,a={binders:this.view.options.binders,formatters:this.view.options.formatters,config:{}},k=this.view.options.config;for(o in k)c=k[o],a.config[o]=c;a.config.preloadData=!0,p=i.cloneNode(!0),f=new t.View(p,n,a),f.bind(),this.iterated.push(f),E.push(this.marker.parentNode.insertBefore(p,d.nextSibling))}else this.iterated[r].models[u]!==l?E.push(this.iterated[r].update(n)):E.push(void 0);return E},update:function(t){var i,e,n,s,r,o,h,l;i={};for(e in t)n=t[e],e!==this.args[0]&&(i[e]=n);for(h=this.iterated,l=[],r=0,o=h.length;o>r;r++)s=h[r],l.push(s.update(i));return l}},"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.internalBinders={textNode:function(t,i){return t.data=null!=i?i:""}},t.components={},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._=t,i.binders=t.binders,i.components=t.components,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);
@@ -1,5 +1,5 @@
1
1
  module Rivets
2
2
  module Rails
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -7,7 +7,7 @@
7
7
  "binders",
8
8
  "formatters"
9
9
  ],
10
- "version": "0.1.0",
10
+ "version": "0.1.1",
11
11
  "author": "vkill",
12
12
  "url": "https://github.com/vkill/rivets-rails",
13
13
  "main": "./dist/rivets.custom.binders.js",
@@ -22,7 +22,7 @@
22
22
  "url": "https://github.com/vkill/rivets-rails.git"
23
23
  },
24
24
  "dependencies": {
25
- "rivets": "~0.5.4"
25
+ "rivets": "~0.5.10"
26
26
  },
27
27
  "devDependencies": {
28
28
  "grunt": "~0.4.1",
@@ -1,5 +1,5 @@
1
1
  // rivets.custom_by_vkill.js
2
- // version: 0.1.0
2
+ // version: 0.1.1
3
3
  // author: vkill
4
4
  // license: MIT
5
5
  (function() {
@@ -1,5 +1,5 @@
1
1
  // rivets.custom_by_vkill.js
2
- // version: 0.1.0
2
+ // version: 0.1.1
3
3
  // author: vkill
4
4
  // license: MIT
5
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);
@@ -1,11 +1,13 @@
1
1
  // Rivets.js
2
- // version: 0.5.7
2
+ // version: 0.5.10
3
3
  // author: Michael Richards
4
4
  // license: MIT
5
5
  (function() {
6
6
  var Rivets,
7
7
  __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
8
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
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
13
  Rivets = {};
@@ -34,7 +36,7 @@
34
36
  this.set = __bind(this.set, this);
35
37
  this.eventHandler = __bind(this.eventHandler, this);
36
38
  this.formattedValue = __bind(this.formattedValue, this);
37
- if (!(this.binder = this.view.binders[type])) {
39
+ if (!(this.binder = Rivets.internalBinders[this.type] || this.view.binders[type])) {
38
40
  _ref = this.view.binders;
39
41
  for (identifier in _ref) {
40
42
  value = _ref[identifier];
@@ -173,16 +175,115 @@
173
175
  }
174
176
  };
175
177
 
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();
178
+ Binding.prototype.update = function(models) {
179
+ var _ref;
180
+
181
+ if (models == null) {
182
+ models = {};
183
+ }
184
+ if (this.key) {
185
+ if (models[this.key]) {
186
+ if (!this.options.bypass) {
187
+ this.view.config.adapter.unsubscribe(this.model, this.keypath, this.sync);
188
+ }
189
+ this.model = models[this.key];
190
+ if (this.options.bypass) {
191
+ this.sync();
192
+ } else {
193
+ this.view.config.adapter.subscribe(this.model, this.keypath, this.sync);
194
+ if (this.view.config.preloadData) {
195
+ this.sync();
196
+ }
197
+ }
198
+ }
199
+ } else {
200
+ this.sync();
201
+ }
202
+ return (_ref = this.binder.update) != null ? _ref.call(this, models) : void 0;
180
203
  };
181
204
 
182
205
  return Binding;
183
206
 
184
207
  })();
185
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
+
186
287
  Rivets.View = (function() {
187
288
  function View(els, models, options) {
188
289
  var k, option, v, _base, _i, _len, _ref, _ref1, _ref2, _ref3;
@@ -197,6 +298,7 @@
197
298
  this.bind = __bind(this.bind, this);
198
299
  this.select = __bind(this.select, this);
199
300
  this.build = __bind(this.build, this);
301
+ this.componentRegExp = __bind(this.componentRegExp, this);
200
302
  this.bindingRegExp = __bind(this.bindingRegExp, this);
201
303
  if (!(this.els.jquery || this.els instanceof Array)) {
202
304
  this.els = [this.els];
@@ -234,108 +336,144 @@
234
336
  }
235
337
  };
236
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
+
237
345
  View.prototype.build = function() {
238
- var bindingRegExp, el, node, parse, skipNodes, _i, _j, _len, _len1, _ref, _ref1,
346
+ var bindingRegExp, buildBinding, componentRegExp, el, parse, skipNodes, _i, _len, _ref,
239
347
  _this = this;
240
348
 
241
349
  this.bindings = [];
242
350
  skipNodes = [];
243
351
  bindingRegExp = this.bindingRegExp();
352
+ componentRegExp = this.componentRegExp();
353
+ buildBinding = function(node, type, declaration) {
354
+ var context, ctx, dependencies, key, keypath, options, path, pipe, pipes, splitPath;
355
+
356
+ options = {};
357
+ pipes = (function() {
358
+ var _i, _len, _ref, _results;
359
+
360
+ _ref = declaration.split('|');
361
+ _results = [];
362
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
363
+ pipe = _ref[_i];
364
+ _results.push(pipe.trim());
365
+ }
366
+ return _results;
367
+ })();
368
+ context = (function() {
369
+ var _i, _len, _ref, _results;
370
+
371
+ _ref = pipes.shift().split('<');
372
+ _results = [];
373
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
374
+ ctx = _ref[_i];
375
+ _results.push(ctx.trim());
376
+ }
377
+ return _results;
378
+ })();
379
+ path = context.shift();
380
+ splitPath = path.split(/\.|:/);
381
+ options.formatters = pipes;
382
+ options.bypass = path.indexOf(':') !== -1;
383
+ if (splitPath[0]) {
384
+ key = splitPath.shift();
385
+ } else {
386
+ key = null;
387
+ splitPath.shift();
388
+ }
389
+ keypath = splitPath.join('.');
390
+ if (dependencies = context.shift()) {
391
+ options.dependencies = dependencies.split(/\s+/);
392
+ }
393
+ return _this.bindings.push(new Rivets.Binding(_this, node, type, key, keypath, options));
394
+ };
244
395
  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;
396
+ var attribute, attributes, binder, childNode, delimiters, identifier, n, parser, regexp, restTokens, startToken, text, token, tokens, type, value, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4, _results;
246
397
 
247
398
  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;
399
+ if (node.nodeType === Node.TEXT_NODE) {
400
+ parser = Rivets.TextTemplateParser;
401
+ if (delimiters = _this.config.templateDelimiters) {
402
+ if ((tokens = parser.parse(node.data, delimiters)).length) {
403
+ if (!(tokens.length === 1 && tokens[0].type === parser.types.text)) {
404
+ startToken = tokens[0], restTokens = 2 <= tokens.length ? __slice.call(tokens, 1) : [];
405
+ node.data = startToken.value;
406
+ switch (startToken.type) {
407
+ case 0:
408
+ node.data = startToken.value;
409
+ break;
410
+ case 1:
411
+ buildBinding(node, 'textNode', startToken.value);
412
+ }
413
+ for (_i = 0, _len = restTokens.length; _i < _len; _i++) {
414
+ token = restTokens[_i];
415
+ node.parentNode.appendChild((text = document.createTextNode(token.value)));
416
+ if (token.type === 1) {
417
+ buildBinding(text, 'textNode', token.value);
261
418
  }
262
419
  }
263
420
  }
264
421
  }
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
422
  }
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());
423
+ } else if (componentRegExp.test(node.tagName)) {
424
+ type = node.tagName.replace(componentRegExp, '').toLowerCase();
425
+ _this.bindings.push(new Rivets.ComponentBinding(_this, node, type));
426
+ } else if (node.attributes != null) {
427
+ _ref = node.attributes;
428
+ for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
429
+ attribute = _ref[_j];
430
+ if (bindingRegExp.test(attribute.name)) {
431
+ type = attribute.name.replace(bindingRegExp, '');
432
+ if (!(binder = _this.binders[type])) {
433
+ _ref1 = _this.binders;
434
+ for (identifier in _ref1) {
435
+ value = _ref1[identifier];
436
+ if (identifier !== '*' && identifier.indexOf('*') !== -1) {
437
+ regexp = new RegExp("^" + (identifier.replace('*', '.+')) + "$");
438
+ if (regexp.test(type)) {
439
+ binder = value;
440
+ }
441
+ }
442
+ }
290
443
  }
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());
444
+ binder || (binder = _this.binders['*']);
445
+ if (binder.block) {
446
+ _ref2 = node.childNodes;
447
+ for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
448
+ n = _ref2[_k];
449
+ skipNodes.push(n);
450
+ }
451
+ attributes = [attribute];
301
452
  }
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
453
  }
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));
454
+ }
455
+ _ref3 = attributes || node.attributes;
456
+ for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
457
+ attribute = _ref3[_l];
458
+ if (bindingRegExp.test(attribute.name)) {
459
+ type = attribute.name.replace(bindingRegExp, '');
460
+ buildBinding(node, type, attribute.value);
320
461
  }
321
462
  }
322
463
  }
323
- if (attributes) {
324
- attributes = null;
464
+ _ref4 = node.childNodes;
465
+ _results = [];
466
+ for (_m = 0, _len4 = _ref4.length; _m < _len4; _m++) {
467
+ childNode = _ref4[_m];
468
+ _results.push(parse(childNode));
325
469
  }
470
+ return _results;
326
471
  }
327
472
  };
328
473
  _ref = this.els;
329
474
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
330
475
  el = _ref[_i];
331
476
  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
477
  }
340
478
  };
341
479
 
@@ -404,33 +542,85 @@
404
542
  };
405
543
 
406
544
  View.prototype.update = function(models) {
407
- var binding, key, model, _results;
545
+ var binding, key, model, _i, _len, _ref, _results;
408
546
 
409
547
  if (models == null) {
410
548
  models = {};
411
549
  }
412
- _results = [];
413
550
  for (key in models) {
414
551
  model = models[key];
415
552
  this.models[key] = model;
416
- _results.push((function() {
417
- var _i, _len, _ref, _results1;
553
+ }
554
+ _ref = this.bindings;
555
+ _results = [];
556
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
557
+ binding = _ref[_i];
558
+ _results.push(binding.update(models));
559
+ }
560
+ return _results;
561
+ };
562
+
563
+ return View;
564
+
565
+ })();
566
+
567
+ Rivets.TextTemplateParser = (function() {
568
+ function TextTemplateParser() {}
418
569
 
419
- _ref = this.select(function(b) {
420
- return b.key === key;
570
+ TextTemplateParser.types = {
571
+ text: 0,
572
+ binding: 1
573
+ };
574
+
575
+ TextTemplateParser.parse = function(template, delimiters) {
576
+ var index, lastIndex, lastToken, length, substring, tokens, value;
577
+
578
+ tokens = [];
579
+ length = template.length;
580
+ index = 0;
581
+ lastIndex = 0;
582
+ while (lastIndex < length) {
583
+ index = template.indexOf(delimiters[0], lastIndex);
584
+ if (index < 0) {
585
+ tokens.push({
586
+ type: this.types.text,
587
+ value: template.slice(lastIndex)
421
588
  });
422
- _results1 = [];
423
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
424
- binding = _ref[_i];
425
- _results1.push(binding.update());
589
+ break;
590
+ } else {
591
+ if (index > 0 && lastIndex < index) {
592
+ tokens.push({
593
+ type: this.types.text,
594
+ value: template.slice(lastIndex, index)
595
+ });
426
596
  }
427
- return _results1;
428
- }).call(this));
597
+ lastIndex = index + 2;
598
+ index = template.indexOf(delimiters[1], lastIndex);
599
+ if (index < 0) {
600
+ substring = template.slice(lastIndex - 2);
601
+ lastToken = tokens[tokens.length - 1];
602
+ if ((lastToken != null ? lastToken.type : void 0) === this.types.text) {
603
+ lastToken.value += substring;
604
+ } else {
605
+ tokens.push({
606
+ type: this.types.text,
607
+ value: substring
608
+ });
609
+ }
610
+ break;
611
+ }
612
+ value = template.slice(lastIndex, index).trim();
613
+ tokens.push({
614
+ type: this.types.binding,
615
+ value: value
616
+ });
617
+ lastIndex = index + 2;
618
+ }
429
619
  }
430
- return _results;
620
+ return tokens;
431
621
  };
432
622
 
433
- return View;
623
+ return TextTemplateParser;
434
624
 
435
625
  })();
436
626
 
@@ -610,7 +800,7 @@
610
800
  routine: function(el, value) {
611
801
  var key, model, models, options, _ref;
612
802
 
613
- if (value === (this.nested == null)) {
803
+ if (!!value === (this.nested == null)) {
614
804
  if (value) {
615
805
  models = {};
616
806
  _ref = this.view.models;
@@ -631,6 +821,9 @@
631
821
  return delete this.nested;
632
822
  }
633
823
  }
824
+ },
825
+ update: function(models) {
826
+ return this.nested.update(models);
634
827
  }
635
828
  },
636
829
  unless: {
@@ -643,6 +836,9 @@
643
836
  },
644
837
  routine: function(el, value) {
645
838
  return Rivets.binders["if"].routine.call(this, el, !value);
839
+ },
840
+ update: function(models) {
841
+ return Rivets.binders["if"].update.call(this, models);
646
842
  }
647
843
  },
648
844
  "on-*": {
@@ -737,6 +933,24 @@
737
933
  }
738
934
  }
739
935
  return _results;
936
+ },
937
+ update: function(models) {
938
+ var data, key, model, view, _i, _len, _ref, _results;
939
+
940
+ data = {};
941
+ for (key in models) {
942
+ model = models[key];
943
+ if (key !== this.args[0]) {
944
+ data[key] = model;
945
+ }
946
+ }
947
+ _ref = this.iterated;
948
+ _results = [];
949
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
950
+ view = _ref[_i];
951
+ _results.push(view.update(data));
952
+ }
953
+ return _results;
740
954
  }
741
955
  },
742
956
  "class-*": function(el, value) {
@@ -756,6 +970,14 @@
756
970
  }
757
971
  };
758
972
 
973
+ Rivets.internalBinders = {
974
+ textNode: function(node, value) {
975
+ return node.data = value != null ? value : '';
976
+ }
977
+ };
978
+
979
+ Rivets.components = {};
980
+
759
981
  Rivets.config = {
760
982
  preloadData: true,
761
983
  handler: function(context, ev, binding) {
@@ -766,7 +988,9 @@
766
988
  Rivets.formatters = {};
767
989
 
768
990
  Rivets.factory = function(exports) {
991
+ exports._ = Rivets;
769
992
  exports.binders = Rivets.binders;
993
+ exports.components = Rivets.components;
770
994
  exports.formatters = Rivets.formatters;
771
995
  exports.config = Rivets.config;
772
996
  exports.configure = function(options) {