serenade_rails 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/assets/javascripts/serenade.js +2503 -2
- data/lib/serenade_rails/version.rb +1 -1
- data/serenade_rails.gemspec +1 -0
- data/spec/template_spec.rb +12 -0
- metadata +21 -8
@@ -1,8 +1,2509 @@
|
|
1
1
|
/**
|
2
|
-
* Serenade.js JavaScript Framework v0.
|
2
|
+
* Serenade.js JavaScript Framework v0.2.0
|
3
3
|
* http://github.com/elabs/serenade.js
|
4
4
|
*
|
5
5
|
* Copyright 2011, Jonas Nicklas, Elabs AB
|
6
6
|
* Released under the MIT License
|
7
7
|
*/
|
8
|
-
(function(a){var b=function(){function a(b){return a[b]}return a["./events"]=new function(){var a=this;((function(){var b=Array.prototype.slice;a.Events={bind:function(a,b){var c,d,e,f,g;d=a.split(" "),c=this.hasOwnProperty("_callbacks")&&this._callbacks||(this._callbacks={});for(f=0,g=d.length;f<g;f++)e=d[f],c[e]||(c[e]=[]),c[e].push(b);return this},one:function(a,b){return this.bind(a,function(){return this.unbind(a,arguments.callee),b.apply(this,arguments)})},trigger:function(){var a,c,d,e,f,g,h;a=1<=arguments.length?b.call(arguments,0):[],d=a.shift(),typeof recordEvents!="undefined"&&recordEvents!==null&&(this._triggeredEvents||(this._triggeredEvents={}),this._triggeredEvents[d]=a),e=this.hasOwnProperty("_callbacks")&&((h=this._callbacks)!=null?h[d]:void 0);if(!e)return!1;for(f=0,g=e.length;f<g;f++)c=e[f],c.apply(this,a);return!0},unbind:function(a,b){var c,d,e,f,g;if(!a)return this._callbacks={},this;e=(g=this._callbacks)!=null?g[a]:void 0;if(!e)return this;if(!b)return delete this._callbacks[a],this;for(d=0,f=e.length;d<f;d++){c=e[d];if(c!==b)continue;e=e.slice(),e.splice(d,1),this._callbacks[a]=e;break}return this}}})).call(this)},a["./helpers"]=new function(){var a=this;((function(){var b;b={extend:function(a,b){var c,d,e;e=[];for(c in b)d=b[c],Object.prototype.hasOwnProperty.call(b,c)?e.push(a[c]=d):e.push(void 0);return e},get:function(a,b,c){return c==null&&(c=!0),c&&(a!=null?a.get:void 0)?a.get(b):c?a!=null?a[b]:void 0:b},format:function(a,c,d){return d==null&&(d=!0),d&&a.format?a.format(c):b.get(a,c,d)},forEach:function(a,b){var c,d,e,f;if(typeof a.forEach=="function")return a.forEach(b);f=[];for(d=0,e=a.length;d<e;d++)c=a[d],f.push(b(c));return f},map:function(a,b){var c,d,e,f;if(typeof a.map=="function")return a.map(b);f=[];for(d=0,e=a.length;d<e;d++)c=a[d],f.push(b(c));return f},isArray:function(a){return Object.prototype.toString.call(a)==="[object Array]"},pairToObject:function(a,b){var c;return c={},c[a]=b,c},serializeObject:function(a){return a&&typeof a.serialize=="function"?a.serialize():b.isArray(a)?b.map(a,function(a){return b.serializeObject(a)}):a},indexOf:function(a,b){var c,d,e;if(a.indexOf)return a.indexOf(b);for(c=0,e=a.length;c<e;c++){d=a[c];if(d===b)return c}return-1},deleteItem:function(a,c){return a.splice(b.indexOf(c),1)},getFunctionName:function(a){var b,c,d;return b=a.modelName,b||(b=a.name),b||(b=(c=a.toString().match(/\[object (.+?)\]/))!=null?c[1]:void 0),b||(b=(d=a.toString().match(/function (.+?)\(\)/))!=null?d[1]:void 0),b},preventDefault:function(a){return a.preventDefault?a.preventDefault():a.returnValue=!1}},b.extend(a,b)})).call(this)},a["./cache"]=new function(){var b=this;((function(){var c,d,e,f;f=a("./helpers"),e=f.serializeObject,d=f.getFunctionName,c={_storage:typeof window!="undefined"&&window!==null?window.localStorage:void 0,_identityMap:{},get:function(a,b){var c,e;c=d(a);if(c&&b)return((e=this._identityMap[c])!=null?e[b]:void 0)||this.retrieve(a,b)},set:function(a,b,c){var e,f;e=d(a);if(e&&b)return(f=this._identityMap)[e]||(f[e]={}),this._identityMap[e][b]=c},store:function(a,b,c){var f;f=d(a);if(f&&b&&typeof JSON!="undefined"&&JSON!==null)return this._storage.setItem(""+f+"_"+b,JSON.stringify(e(c)))},retrieve:function(a,b){var c,e;e=d(a);if(e&&b&&a.localStorage&&typeof JSON!="undefined"&&JSON!==null){c=this._storage.getItem(""+e+"_"+b);if(c)return new a(JSON.parse(c),!0)}}},b.Cache=c})).call(this)},a["./collection"]=new function(){var b=this;((function(){var c,d,e,f,g,h,i;c=a("./events").Events,i=a("./helpers"),e=i.extend,f=i.forEach,h=i.serializeObject,d=i.deleteItem,g=i.indexOf,b.Collection=function(){function a(a){var b=this;this.list=a,this.length=this.list.length,this.bind("change",function(){return b.length=b.list.length})}return e(a.prototype,c),a.prototype.get=function(a){return this.list[a]},a.prototype.set=function(a,b){return this._notIn(this.list[a]),this.list[a]=b,this._in(b),this.trigger("change:"+a,b),this.trigger("set",a,b),this.trigger("change",this.list)},a.prototype.push=function(a){return this.list.push(a),this._in(a),this.trigger("add",a),this.trigger("change",this.list)},a.prototype.update=function(a){var b,c,d,e,f,g;g=this.list;for(c=0,e=g.length;c<e;c++)b=g[c],this._notIn(b);this.list=a;for(d=0,f=a.length;d<f;d++)b=a[d],this._in(b);return this.trigger("update",a),this.trigger("change",this.list)},a.prototype.forEach=function(a){return f(this.list,a)},a.prototype.map=function(a){var b,c,d,e,f;e=this.list,f=[];for(c=0,d=e.length;c<d;c++)b=e[c],f.push(a(b));return f},a.prototype.indexOf=function(a){return g(this.list,a)},a.prototype.deleteAt=function(a){return this._notIn(this.list[a]),this.list.splice(a,1),this.trigger("delete",a),this.trigger("change",this.list)},a.prototype["delete"]=function(a){return this.deleteAt(this.indexOf(a))},a.prototype.serialize=function(){return h(this.list)},a.prototype.select=function(a){var b,c,d,e,f;e=this.list,f=[];for(c=0,d=e.length;c<d;c++)b=e[c],a(b)&&f.push(b);return f},a.prototype._in=function(a){var b;if(a!=null?a._triggerChangesTo:void 0)return a._inCollections||(a._inCollections=[]),(b=a._inCollections)!=null?b.push(this):void 0},a.prototype._notIn=function(a){if(a!=null?a._inCollections:void 0)return d(a._inCollections,this)},a}()})).call(this)},a["./association_collection"]=new function(){var b=this;((function(){var c,d,e=Object.prototype.hasOwnProperty,f=function(a,b){function d(){this.constructor=a}for(var c in b)e.call(b,c)&&(a[c]=b[c]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a};d=a("./collection").Collection,c=function(a){function b(a,c){var d;this.ctor=a,this.list=c,b.__super__.constructor.call(this,function(){var a,b,e;e=[];for(a=0,b=c.length;a<b;a++)d=c[a],e.push(this._convert(d));return e}.call(this))}return f(b,a),b.prototype.set=function(a,c){return b.__super__.set.call(this,a,this._convert(c))},b.prototype.push=function(a){return b.__super__.push.call(this,this._convert(a))},b.prototype.update=function(a){var c;return b.__super__.update.call(this,function(){var b,d,e;e=[];for(b=0,d=a.length;b<d;b++)c=a[b],e.push(this._convert(c));return e}.call(this))},b.prototype._convert=function(a){return a.constructor===Object&&this.ctor?new(this.ctor())(a):a},b}(d),b.AssociationCollection=c})).call(this)},a["./associations"]=new function(){var b=this;((function(){var c,d,e,f,g,h,i;c=a("./association_collection").AssociationCollection,e=a("./collection").Collection,i=a("./helpers"),f=i.extend,h=i.map,g=i.get,d=function(){function a(){}return a.belongsTo=function(a,b){return b==null&&(b={}),f(b,{set:function(c){return c.constructor===Object&&b.as&&(c=new(b.as())(c)),this.attributes[a]=c}}),this.property(a,b),this.property(a+"Id",{get:function(){return g(this.get(a),"id")},set:function(c){return this.attributes[a]=b.as().find(c)},dependsOn:a,serialize:b.serializeId})},a.hasMany=function(a,b){return b==null&&(b={}),f(b,{get:function(){var d=this;return this.attributes[a]||(this.attributes[a]=new c(b.as,[]),this.attributes[a].bind("change",function(){return d._triggerChangesTo([a])})),this.attributes[a]},set:function(b){return this.get(a).update(b)}}),this.property(a,b),this.property(a+"Ids",{get:function(){return new e(this.get(a).map(function(a){return g(a,"id")}))},set:function(d){var e;return e=h(d,function(a){return b.as().find(a)}),this.attributes[a]=new c(b.as,e)},dependsOn:a,serialize:b.serializeIds})},a}(),b.Associations=d})).call(this)},a["./serenade"]=new function(){var b=this;((function(){var c,d,e;c=a("./cache").Cache,e=a("./helpers").extend,d={VERSION:"0.1.3",_views:{},_controllers:{},_formats:{},document:typeof window!="undefined"&&window!==null?window.document:void 0,view:function(b,c){var d;return d=a("./view").View,c?this._views[b]=new d(b,c):new d(void 0,b)},render:function(a,b,c){return this._views[a].render(b,c)},controller:function(a,b){return this._controllers[a]=b},controllerFor:function(a,b){if(this._controllers[a])return new this._controllers[a](b)},registerFormat:function(a,b){return this._formats[a]=b},clearIdentityMap:function(){return c._identityMap={}},clearLocalStorage:function(){return c._storage.clear()},clearCache:function(){return d.clearIdentityMap(),d.clearLocalStorage()},unregisterAll:function(){return d._views={},d._controllers={},d._formats={}},bindEvent:function(a,b,c){return typeof a.addEventListener=="function"?a.addEventListener(b,c,!1):a.attachEvent("on"+b,c)},useJQuery:function(){return this.bindEvent=function(a,b,c){return jQuery(a).bind(b,c)}},extend:e,Events:a("./events").Events,Collection:a("./collection").Collection,Helpers:{}},b.Serenade=d,b.compile=function(){var b,c,e;return b=a("jsdom").jsdom(null,null,{}),c=a("fs"),e=b.createWindow(),d.document=b,function(a){var e,f,g,h;return g=a.model,h=a.filename.split("/").reverse()[0].replace(/\.serenade$/,""),d.view(h,c.readFileSync(a.filename).toString()),e=d.render(h,g,{}),b.body.appendChild(e),f=b.body.innerHTML,a.doctype!==!1&&(f="<!DOCTYPE html>\n"+f),f}}})).call(this)},a["./lexer"]=new function(){var a=this;((function(){var b,c,d,e,f,g;b=/^[a-zA-Z][a-zA-Z0-9\-_]*/,c=/^[\[\]=\:\-!#\.@]/,f=/^"((?:\\.|[^"])*)"/,e=/^(?:\n[^\n\S]*)+/,g=/^[^\n\S]+/,d=function(){function a(){}return a.prototype.tokenize=function(a,b){var c,d;b==null&&(b={}),this.code=a.replace(/^\s*/,""),this.line=b.line||0,this.indent=0,this.indents=[],this.ends=[],this.tokens=[],c=0;while(this.chunk=this.code.slice(c))c+=this.identifierToken()||this.whitespaceToken()||this.lineToken()||this.stringToken()||this.literalToken();while(d=this.ends.pop())d==="OUTDENT"?this.token("OUTDENT"):this.error("missing "+d);return this.tokens},a.prototype.whitespaceToken=function(){var a;return(a=g.exec(this.chunk))?(this.token("WHITESPACE",a[0].length),a[0].length):0},a.prototype.token=function(a,b){return this.tokens.push([a,b,this.line])},a.prototype.identifierToken=function(){var a;return(a=b.exec(this.chunk))?(this.token("IDENTIFIER",a[0]),a[0].length):0},a.prototype.stringToken=function(){var a;return(a=f.exec(this.chunk))?(this.token("STRING_LITERAL",a[1]),a[0].length):0},a.prototype.lineToken=function(){var a,b,c,d,f;if(!(c=e.exec(this.chunk)))return 0;b=c[0],this.line+=this.count(b,"\n"),d=this.last(this.tokens,1),f=b.length-1-b.lastIndexOf("\n"),a=f-this.indent;if(f===this.indent)this.newlineToken();else if(f>this.indent)this.token("INDENT"),this.indents.push(a),this.ends.push("OUTDENT");else{while(a<0)this.last(this.ends)!=="OUTDENT"&&this.error("Should be an OUTDENT, yo"),this.ends.pop(),a+=this.indents.pop(),this.token("OUTDENT");this.token("TERMINATOR","\n")}return this.indent=f,b.length},a.prototype.literalToken=function(){var a;return(a=c.exec(this.chunk))?(this.token(a[0]),1):this.error("WUT??? is '"+this.chunk.charAt(0)+"'")},a.prototype.newlineToken=function(){if(this.tag()!=="TERMINATOR")return this.token("TERMINATOR","\n")},a.prototype.tag=function(a,b){var c;return(c=this.last(this.tokens,a))&&(b?c[0]=b:c[0])},a.prototype.value=function(a,b){var c;return(c=this.last(this.tokens,a))&&(b?c[1]=b:c[1])},a.prototype.error=function(a){throw SyntaxError(""+a+" on line "+(this.line+1))},a.prototype.count=function(a,b){var c,d;c=d=0;if(!b.length)return 1/0;while(d=1+a.indexOf(b,d))c++;return c},a.prototype.last=function(a,b){return a[a.length-(b||0)-1]},a}(),a.Lexer=d})).call(this)},a["./nodes"]=new function(){var b=this;((function(){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u=function(a,b){return function(){return a.apply(b,arguments)}};l=a("./serenade").Serenade,t=a("./helpers"),q=t.format,r=t.get,p=t.forEach,s=t.preventDefault,j=function(){function a(a,b,c,d){var e,f,g,h,i,j,l,m,n;this.ast=a,this.document=b,this.model=c,this.controller=d,this.element=this.document.createElement(this.ast.name),this.ast.id&&this.element.setAttribute("id",this.ast.id),((l=this.ast.classes)!=null?l.length:void 0)&&this.element.setAttribute("class",this.ast.classes.join(" ")),m=this.ast.properties;for(g=0,i=m.length;g<i;g++)f=m[g],k.property(f,this,this.document,this.model,this.controller);n=this.ast.children;for(h=0,j=n.length;h<j;h++)e=n[h],k.compile(e,this.document,this.model,this.controller).append(this.element)}return a.prototype.append=function(a){return a.appendChild(this.element)},a.prototype.insertAfter=function(a){return a.parentNode.insertBefore(this.element,a.nextSibling)},a.prototype.remove=function(){return this.element.parentNode.removeChild(this.element)},a.prototype.lastElement=function(){return this.element},a}(),m=function(){function a(a,b,c,d,e){var f,g=this;this.ast=a,this.node=b,this.document=c,this.model=d,this.controller=e,this.element=this.node.element,this.update(),this.ast.bound&&typeof (f=this.model).bind=="function"&&f.bind("change:"+this.ast.value,function(a){return g.update()})}return a.prototype.update=function(){return this.element.style[this.ast.name]=this.get()},a.prototype.get=function(){return q(this.model,this.ast.value,this.ast.bound)},a}(),f=function(){function a(a,b,c,d,e){var f,g;this.ast=a,this.node=b,this.document=c,this.model=d,this.controller=e,this.element=this.node.element,g=this,f=function(a){return g.ast.preventDefault&&s(a),g.controller[g.ast.value](a)},l.bindEvent(this.element,this.ast.name,f)}return a}(),c=function(){function a(a,b,c,d,e){var f,g=this;this.ast=a,this.node=b,this.document=c,this.model=d,this.controller=e,this.element=this.node.element,this.update(),this.ast.bound&&typeof (f=this.model).bind=="function"&&f.bind("change:"+this.ast.value,function(a){return g.update()})}return a.prototype.update=function(){var a,b;return b=this.get(),this.ast.name==="value"?this.element.value=b||"":this.node.ast.name==="input"&&this.ast.name==="checked"?this.element.checked=!!b:this.ast.name==="class"?(a=this.node.ast.classes,b!==void 0&&(a=a.concat(b)),a.length?this.element.setAttribute(this.ast.name,a.join(" ")):this.element.removeAttribute(this.ast.name)):b===void 0?this.element.removeAttribute(this.ast.name):(b===0&&(b="0"),this.element.setAttribute(this.ast.name,b))},a.prototype.get=function(){return q(this.model,this.ast.value,this.ast.bound)},a}(),n=function(){function a(a,b,c,d){var e=this;this.ast=a,this.document=b,this.model=c,this.controller=d,this.textNode=b.createTextNode(this.get()),this.ast.bound&&typeof c.bind=="function"&&c.bind("change:"+this.ast.value,function(){return e.textNode.nodeValue=e.get()})}return a.prototype.append=function(a){return a.appendChild(this.textNode)},a.prototype.insertAfter=function(a){return a.parentNode.insertBefore(this.textNode,a.nextSibling)},a.prototype.remove=function(){return this.textNode.parentNode.removeChild(this.textNode)},a.prototype.lastElement=function(){return this.textNode},a.prototype.get=function(){var a;return a=q(this.model,this.ast.value,this.ast.bound),a===0&&(a="0"),a||""},a}(),o=function(){function a(a,b,c,d){this.ast=a,this.document=b,this.model=c,this.parentController=d,this.controller=l.controllerFor(this.ast.arguments[0],this.model),this.controller&&(this.controller.parent=this.parentController),this.view=l.render(this.ast.arguments[0],this.model,this.controller||this.parentController,this.document)}return a.prototype.append=function(a){return a.appendChild(this.view)},a.prototype.insertAfter=function(a){return a.parentNode.insertBefore(this.view,a.nextSibling)},a.prototype.remove=function(){return this.view.parentNode.removeChild(this.view)},a.prototype.lastElement=function(){return this.view},a}(),h=function(){function a(a,b,c,d){var e;this.ast=a,this.document=b,this.model=c,this.controller=d,this.build=u(this.build,this),this.anchor=b.createTextNode(""),typeof (e=this.model).bind=="function"&&e.bind("change:"+this.ast.arguments[0],this.build)}return a.prototype.build=function(){var a,b,c,d,e,f,g;if(r(this.model,this.ast.arguments[0])){this.nodes||(this.nodes=function(){var b,c,d,e;d=this.ast.children,e=[];for(b=0,c=d.length;b<c;b++)a=d[b],e.push(k.compile(a,this.document,this.model,this.controller));return e}.call(this)),e=this.nodes,g=[];for(b=0,d=e.length;b<d;b++)c=e[b],g.push(c.insertAfter(((f=this.nodes[b-1])!=null?f.lastElement():void 0)||this.anchor));return g}return this.removeNodes()},a.prototype.append=function(a){return a.appendChild(this.anchor),this.build()},a.prototype.insertAfter=function(a){return a.parentNode.insertBefore(this.anchor,a.nextSibling),this.build()},a.prototype.remove=function(){return this.removeNodes(),this.anchor.parentNode.removeChild(this.anchor)},a.prototype.removeNodes=function(){var a,b,c,d;if(this.nodes){d=this.nodes;for(b=0,c=d.length;b<c;b++)a=d[b],a.remove()}return this.nodes=void 0},a.prototype.lastElement=function(){return this.nodes[this.nodes.length-1].lastElement()},a}(),i=function(){function a(a,b,c,d){var e;this.ast=a,this.document=b,this.model=c,this.controller=d,this.build=u(this.build,this),this.anchor=b.createTextNode(""),typeof (e=this.model).bind=="function"&&e.bind("change:"+this.ast.arguments[0],this.build)}return a.prototype.build=function(){var a,b,c,d,e,f,g,h;this.removeNodes(),d=r(this.model,this.ast.arguments[0]),this.nodes=function(){var b,c,e,f;e=this.ast.children,f=[];for(b=0,c=e.length;b<c;b++)a=e[b],f.push(k.compile(a,this.document,d,this.controller));return f}.call(this),f=this.nodes,h=[];for(b=0,e=f.length;b<e;b++)c=f[b],h.push(c.insertAfter(((g=this.nodes[b-1])!=null?g.lastElement():void 0)||this.anchor));return h},a.prototype.append=function(a){return a.appendChild(this.anchor),this.build()},a.prototype.insertAfter=function(a){return a.parentNode.insertBefore(this.anchor,a.nextSibling),this.build()},a.prototype.remove=function(){return this.removeNodes(),this.anchor.parentNode.removeChild(this.anchor)},a.prototype.removeNodes=function(){var a,b,c,d;if(this.nodes){d=this.nodes;for(b=0,c=d.length;b<c;b++)a=d[b],a.remove()}return this.nodes=void 0},a.prototype.lastElement=function(){return this.nodes[this.nodes.length-1].lastElement()},a}(),d=function(){function a(a,b,c,d){var e=this;this.ast=a,this.document=b,this.model=c,this.controller=d,this.anchor=b.createTextNode(""),this.collection=this.get(),this.collection.bind&&(this.collection.bind("update",function(){return e.rebuild()}),this.collection.bind("set",function(){return e.rebuild()}),this.collection.bind("add",function(a){return e.appendItem(a)}),this.collection.bind("delete",function(a){return e["delete"](a)}))}return a.prototype.rebuild=function(){var a,b,c,d;d=this.items;for(b=0,c=d.length;b<c;b++)a=d[b],a.remove();return this.build()},a.prototype.build=function(){var a=this;return this.items=[],p(this.collection,function(b){return a.appendItem(b)})},a.prototype.appendItem=function(a){var b;return b=new e(this.ast.children,this.document,a,this.controller),b.insertAfter(this.lastElement()),this.items.push(b)},a.prototype["delete"]=function(a){return this.items[a].remove(),this.items.splice(a,1)},a.prototype.lastItem=function(){return this.items[this.items.length-1]},a.prototype.lastElement=function(){var a;return a=this.lastItem(),a?a.lastElement():this.anchor},a.prototype.remove=function(){var a,b,c,d,e;this.anchor.parentNode.removeChild(this.anchor),d=this.items,e=[];for(b=0,c=d.length;b<c;b++)a=d[b],e.push(a.remove());return e},a.prototype.append=function(a){return a.appendChild(this.anchor),this.build()},a.prototype.insertAfter=function(a){return a.parentNode.insertBefore(this.anchor,a.nextSibling),this.build()},a.prototype.get=function(){return r(this.model,this.ast.arguments[0])},a}(),g=function(){function a(a,b,c,d){this.ast=a,this.document=b,this.model=c,this.controller=d,this.render=u(this.render,this),this.helperFunction=l.Helpers[this.ast.command]||function(){throw SyntaxError("no helper "+this.ast.command+" defined")}.call(this),this.context={document:this.document,render:this.render,model:this.model,controller:this.controller},this.element=this.helperFunction.apply(this.context,this.ast.arguments)}return a.prototype.render=function(a,b,c){var d,e,f,g,h,i;b==null&&(b=this.model),c==null&&(c=this.controller),h=this.ast.children,i=[];for(f=0,g=h.length;f<g;f++)d=h[f],e=k.compile(d,this.document,b,c),i.push(e.append(a));return i},a.prototype.lastElement=function(){var a;return a=this.lastItem(),a?a.lastElement():this.anchor},a.prototype.remove=function(){var a,b,c,d,e;this.element.parentNode.removeChild(this.element),d=this.items,e=[];for(b=0,c=d.length;b<c;b++)a=d[b],e.push(a.remove());return e},a.prototype.append=function(a){return a.appendChild(this.element)},a.prototype.insertAfter=function(a){return a.parentNode.insertBefore(this.element,a.nextSibling)},a}(),e=function(){function a(a,b,c,d){var e;this.children=a,this.document=b,this.model=c,this.controller=d,this.nodes=function(){var a,b,c,d;c=this.children,d=[];for(a=0,b=c.length;a<b;a++)e=c[a],d.push(k.compile(e,this.document,this.model,this.controller));return d}.call(this)}return a.prototype.insertAfter=function(a){var b,c,d,e,f,g;b=a,f=this.nodes,g=[];for(d=0,e=f.length;d<e;d++)c=f[d],c.insertAfter(b),g.push(b=c.lastElement());return g},a.prototype.lastElement=function(){return this.nodes[this.nodes.length-1].lastElement()},a.prototype.remove=function(){var a,b,c,d,e;d=this.nodes,e=[];for(b=0,c=d.length;b<c;b++)a=d[b],e.push(a.remove());return e},a}(),k={compile:function(a,b,c,e){switch(a.type){case"element":return new j(a,b,c,e);case"text":return new n(a,b,c,e);case"instruction":switch(a.command){case"view":return new o(a,b,c,e);case"collection":return new d(a,b,c,e);case"if":return new h(a,b,c,e);case"in":return new i(a,b,c,e);default:return new g(a,b,c,e)}break;default:throw SyntaxError("unknown type '"+a.type+"'")}},property:function(a,b,d,e,g){switch(a.scope){case"attribute":return new c(a,b,d,e,g);case"style":return new m(a,b,d,e,g);case"event":return new f(a,b,d,e,g);default:throw SyntaxError(""+a.scope+" is not a valid scope")}}},b.Nodes=k})).call(this)},a["./parser"]=new function(){var b=this,c=function(){undefined;var a={trace:function(){},yy:{},symbols_:{error:2,Root:3,Element:4,TERMINATOR:5,ElementIdentifier:6,IDENTIFIER:7,"#":8,".":9,"[":10,"]":11,PropertyList:12,WHITESPACE:13,Text:14,INDENT:15,ChildList:16,OUTDENT:17,TextList:18,Bound:19,STRING_LITERAL:20,Child:21,Instruction:22,Property:23,"=":24,"!":25,":":26,"-":27,"@":28,$accept:0,$end:1},terminals_:{2:"error",5:"TERMINATOR",7:"IDENTIFIER",8:"#",9:".",10:"[",11:"]",13:"WHITESPACE",15:"INDENT",17:"OUTDENT",20:"STRING_LITERAL",24:"=",25:"!",26:":",27:"-",28:"@"},productions_:[0,[3,0],[3,1],[3,2],[6,1],[6,3],[6,2],[6,2],[6,3],[4,1],[4,3],[4,4],[4,3],[4,4],[18,1],[18,3],[14,1],[14,1],[16,1],[16,3],[21,1],[21,1],[21,1],[12,1],[12,3],[23,3],[23,3],[23,4],[23,4],[23,3],[23,3],[22,3],[22,3],[22,4],[19,2]],performAction:function(b,c,d,e,f,g,h){var i=g.length-1;switch(f){case 1:this.$=null;break;case 2:return this.$;case 3:return this.$;case 4:this.$={name:g[i],classes:[]};break;case 5:this.$={name:g[i-2],id:g[i],classes:[]};break;case 6:this.$={name:"div",id:g[i],classes:[]};break;case 7:this.$={name:"div",classes:[g[i]]};break;case 8:this.$=function(){return g[i-2].classes.push(g[i]),g[i-2]}();break;case 9:this.$={name:g[i].name,id:g[i].id,classes:g[i].classes,properties:[],children:[],type:"element"};break;case 10:this.$=g[i-2];break;case 11:this.$=function(){return g[i-3].properties=g[i-1],g[i-3]}();break;case 12:this.$=function(){return g[i-2].children=g[i-2].children.concat(g[i]),g[i-2]}();break;case 13:this.$=function(){return g[i-3].children=g[i-3].children.concat(g[i-1]),g[i-3]}();break;case 14:this.$=[g[i]];break;case 15:this.$=g[i-2].concat(g[i]);break;case 16:this.$={type:"text",value:g[i],bound:!0};break;case 17:this.$={type:"text",value:g[i],bound:!1};break;case 18:this.$=[].concat(g[i]);break;case 19:this.$=g[i-2].concat(g[i]);break;case 20:this.$=g[i];break;case 21:this.$=g[i];break;case 22:this.$=g[i];break;case 23:this.$=[g[i]];break;case 24:this.$=g[i-2].concat(g[i]);break;case 25:this.$={name:g[i-2],value:g[i],bound:!0,scope:"attribute"};break;case 26:this.$={name:g[i-2],value:g[i],bound:!0,scope:"attribute"};break;case 27:this.$={name:g[i-3],value:g[i-1],bound:!0,scope:"attribute",preventDefault:!0};break;case 28:this.$={name:g[i-3],value:g[i-1],bound:!0,scope:"attribute",preventDefault:!0};break;case 29:this.$={name:g[i-2],value:g[i],bound:!1,scope:"attribute"};break;case 30:this.$=function(){return g[i].scope=g[i-2],g[i]}();break;case 31:this.$={command:g[i],arguments:[],children:[],type:"instruction"};break;case 32:this.$=function(){return g[i-2].arguments.push(g[i].value),g[i-2]}();break;case 33:this.$=function(){return g[i-3].children=g[i-1],g[i-3]}();break;case 34:this.$=g[i]}},table:[{1:[2,1],3:1,4:2,6:3,7:[1,4],8:[1,5],9:[1,6]},{1:[3]},{1:[2,2],5:[1,7],10:[1,8],13:[1,9],15:[1,10]},{1:[2,9],5:[2,9],9:[1,11],10:[2,9],13:[2,9],15:[2,9],17:[2,9]},{1:[2,4],5:[2,4],8:[1,12],9:[2,4],10:[2,4],13:[2,4],15:[2,4],17:[2,4]},{7:[1,13]},{7:[1,14]},{1:[2,3]},{7:[1,18],11:[1,15],12:16,23:17},{14:19,19:20,20:[1,21],28:[1,22]},{4:25,6:3,7:[1,4],8:[1,5],9:[1,6],14:29,16:23,18:27,19:20,20:[1,21],21:24,22:26,27:[1,28],28:[1,22]},{7:[1,30]},{7:[1,31]},{1:[2,6],5:[2,6],9:[2,6],10:[2,6],13:[2,6],15:[2,6],17:[2,6]},{1:[2,7],5:[2,7],9:[2,7],10:[2,7],13:[2,7],15:[2,7],17:[2,7]},{1:[2,10],5:[2,10],10:[2,10],13:[2,10],15:[2,10],17:[2,10]},{11:[1,32],13:[1,33]},{11:[2,23],13:[2,23]},{24:[1,34],26:[1,35]},{1:[2,12],5:[2,12],10:[2,12],13:[2,12],15:[2,12],17:[2,12]},{1:[2,16],5:[2,16],10:[2,16],13:[2,16],15:[2,16],17:[2,16]},{1:[2,17],5:[2,17],10:[2,17],13:[2,17],15:[2,17],17:[2,17]},{7:[1,36]},{5:[1,38],17:[1,37]},{5:[2,18],17:[2,18]},{5:[2,20],10:[1,8],13:[1,9],15:[1,10],17:[2,20]},{5:[2,21],13:[1,39],15:[1,40],17:[2,21]},{5:[2,22],13:[1,41],17:[2,22]},{13:[1,42]},{5:[2,14],13:[2,14],17:[2,14]},{1:[2,8],5:[2,8],9:[2,8],10:[2,8],13:[2,8],15:[2,8],17:[2,8]},{1:[2,5],5:[2,5],9:[2,5],10:[2,5],13:[2,5],15:[2,5],17:[2,5]},{1:[2,11],5:[2,11],10:[2,11],13:[2,11],15:[2,11],17:[2,11]},{7:[1,18],23:43},{7:[1,44],19:45,20:[1,46],28:[1,22]},{7:[1,18],23:47},{1:[2,34],5:[2,34],10:[2,34],11:[2,34],13:[2,34],15:[2,34],17:[2,34],25:[2,34]},{1:[2,13],5:[2,13],10:[2,13],13:[2,13],15:[2,13],17:[2,13]},{4:25,6:3,7:[1,4],8:[1,5],9:[1,6],14:29,18:27,19:20,20:[1,21],21:48,22:26,27:[1,28],28:[1,22]},{14:49,19:20,20:[1,21],28:[1,22]},{4:25,6:3,7:[1,4],8:[1,5],9:[1,6],14:29,16:50,18:27,19:20,20:[1,21],21:24,22:26,27:[1,28],28:[1,22]},{14:51,19:20,20:[1,21],28:[1,22]},{7:[1,52]},{11:[2,24],13:[2,24]},{11:[2,25],13:[2,25],25:[1,53]},{11:[2,26],13:[2,26],25:[1,54]},{11:[2,29],13:[2,29]},{11:[2,30],13:[2,30]},{5:[2,19],17:[2,19]},{5:[2,32],13:[2,32],15:[2,32],17:[2,32]},{5:[1,38],17:[1,55]},{5:[2,15],13:[2,15],17:[2,15]},{5:[2,31],13:[2,31],15:[2,31],17:[2,31]},{11:[2,27],13:[2,27]},{11:[2,28],13:[2,28]},{5:[2,33],13:[2,33],15:[2,33],17:[2,33]}],defaultActions:{7:[2,3]},parseError:function(b,c){throw new Error(b)},parse:function(b){function o(a){d.length=d.length-2*a,e.length=e.length-a,f.length=f.length-a}function p(){var a;return a=c.lexer.lex()||1,typeof a!="number"&&(a=c.symbols_[a]||a),a}var c=this,d=[0],e=[null],f=[],g=this.table,h="",i=0,j=0,k=0,l=2,m=1;this.lexer.setInput(b),this.lexer.yy=this.yy,this.yy.lexer=this.lexer,typeof this.lexer.yylloc=="undefined"&&(this.lexer.yylloc={});var n=this.lexer.yylloc;f.push(n),typeof this.yy.parseError=="function"&&(this.parseError=this.yy.parseError);var q,r,s,t,u,v,w={},x,y,z,A;for(;;){s=d[d.length-1],this.defaultActions[s]?t=this.defaultActions[s]:(q==null&&(q=p()),t=g[s]&&g[s][q]);if(typeof t=="undefined"||!t.length||!t[0]){if(!k){A=[];for(x in g[s])this.terminals_[x]&&x>2&&A.push("'"+this.terminals_[x]+"'");var B="";this.lexer.showPosition?B="Parse error on line "+(i+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+A.join(", ")+", got '"+this.terminals_[q]+"'":B="Parse error on line "+(i+1)+": Unexpected "+(q==1?"end of input":"'"+(this.terminals_[q]||q)+"'"),this.parseError(B,{text:this.lexer.match,token:this.terminals_[q]||q,line:this.lexer.yylineno,loc:n,expected:A})}if(k==3){if(q==m)throw new Error(B||"Parsing halted.");j=this.lexer.yyleng,h=this.lexer.yytext,i=this.lexer.yylineno,n=this.lexer.yylloc,q=p()}for(;;){if(l.toString()in g[s])break;if(s==0)throw new Error(B||"Parsing halted.");o(1),s=d[d.length-1]}r=q,q=l,s=d[d.length-1],t=g[s]&&g[s][l],k=3}if(t[0]instanceof Array&&t.length>1)throw new Error("Parse Error: multiple actions possible at state: "+s+", token: "+q);switch(t[0]){case 1:d.push(q),e.push(this.lexer.yytext),f.push(this.lexer.yylloc),d.push(t[1]),q=null,r?(q=r,r=null):(j=this.lexer.yyleng,h=this.lexer.yytext,i=this.lexer.yylineno,n=this.lexer.yylloc,k>0&&k--);break;case 2:y=this.productions_[t[1]][1],w.$=e[e.length-y],w._$={first_line:f[f.length-(y||1)].first_line,last_line:f[f.length-1].last_line,first_column:f[f.length-(y||1)].first_column,last_column:f[f.length-1].last_column},v=this.performAction.call(w,h,j,i,this.yy,t[1],e,f);if(typeof v!="undefined")return v;y&&(d=d.slice(0,-1*y*2),e=e.slice(0,-1*y),f=f.slice(0,-1*y)),d.push(this.productions_[t[1]][0]),e.push(w.$),f.push(w._$),z=g[d[d.length-2]][d[d.length-1]],d.push(z);break;case 3:return!0}}return!0}};return a}();typeof a!="undefined"&&typeof b!="undefined"&&(b.parser=c,b.parse=function(){return c.parse.apply(c,arguments)},b.main=function(d){if(!d[1])throw new Error("Usage: "+d[0]+" FILE");if(typeof process!="undefined")var e=a("fs").readFileSync(a("path").join(process.cwd(),d[1]),"utf8");else var f=a("file").path(a("file").cwd()),e=f.join(d[1]).read({charset:"utf-8"});return b.parser.parse(e)},typeof module!="undefined"&&a.main===module&&b.main(typeof process!="undefined"?process.argv.slice(1):a("system").args))},a["./properties"]=new function(){var b=this;((function(){var b,c,d,e,f,g,h,i,j,k,l,m=Array.prototype.indexOf||function(a){for(var b=0,c=this.length;b<c;b++)if(b in this&&this[b]===a)return b;return-1};d=a("./serenade").Serenade,b=a("./collection").Collection,c=a("./events").Events,l=a("./helpers"),i=l.pairToObject,k=l.serializeObject,g=l.extend,h=l.map,j="_prop_",f=/^_prop_/,e=Object.defineProperties,d.Properties={property:function(a,b){b==null&&(b={}),this[j+a]=b,this[j+a].name=a,e&&Object.defineProperty(this,a,{get:function(){return d.Properties.get.call(this,a)},set:function(b){return d.Properties.set.call(this,a,b)}});if(typeof b.serialize=="string")return this.property(b.serialize,{get:function(){return this.get(a)},set:function(b){return this.set(a,b)}})},collection:function(a,c){return this.property(a,{get:function(){var c=this;return this.attributes[a]||(this.attributes[a]=new b([]),this.attributes[a].bind("change",function(){return c._triggerChangesTo([a])}),this.attributes[a]._deferTo=i(a,this)),this.attributes[a]},set:function(b){return this.get(a).update(b)}})},set:function(a,b){var c,d,e;typeof a=="string"&&(a=i(a,b)),d=[];for(c in a)b=a[c],this._undefer(c),d.push(c),this.attributes||(this.attributes={}),((e=this[j+c])!=null?e.set:void 0)?this[j+c].set.call(this,b):this.attributes[c]=b,this._defer(c);return this._triggerChangesTo(d)},get:function(a){var b;return this.attributes||(this.attributes={}),((b=this[j+a])!=null?b.get:void 0)?this[j+a].get.call(this):this.attributes[a]},format:function(a){var b,c;return b=(c=this[j+a])!=null?c.format:void 0,typeof b=="string"?d._formats[b].call(this,this.get(a)):typeof b=="function"?b.call(this,this.get(a)):this.get(a)},serialize:function(){var a,b,c,d,e,g;d={};for(b in this)c=this[b],b.match(f)&&(typeof c.serialize=="string"?d[c.serialize]=k(this.get(c.name)):typeof c.serialize=="function"?(g=c.serialize.call(this),a=g[0],e=g[1],d[a]=k(e)):c.serialize&&(d[c.name]=k(this.get(c.name))));return d},_defer:function(a){var b,c;b=this.get(a);if(b!=null?b._triggerChangesTo:void 0)return b._deferTo||(b._deferTo={}),(c=b._deferTo)!=null?c[a]=this:void 0},_undefer:function(a){var b;b=this.get(a);if(b!=null?b._deferTo:void 0)return delete b._deferTo[a]},_triggerChangesTo:function(a){var b,c,d,i,j,k,l,n,o,p,q,r,s,t,u,v,w,x,y,z=this;o=function(a){return[].concat(a)},d=function(b){var c,e,g,h;h=[];for(c in z)e=z[c],c.match(f)&&e.dependsOn&&(m.call(o(e.dependsOn),b)>=0&&(g=e.name,m.call(a,g)<0)?(a.push(e.name),h.push(d(e.name))):h.push(void 0));return h};for(r=0,u=a.length;r<u;r++)p=a[r],d(p);c={};for(s=0,v=a.length;s<v;s++)n=a[s],q=this.get(n),this.trigger("change:"+n,q),c[n]=q,e||(this[n]=this.get(n));this.trigger("change",c),b=this._deferTo||[];if(this._inCollections){x=this._inCollections;for(t=0,w=x.length;t<w;t++)i=x[t],g(b,i._deferTo)}y=[];for(j in b){k=b[j];if(!b.hasOwnProperty(j))continue;l=h(a,function(a){return""+j+"."+a}),y.push(k._triggerChangesTo(l))}return y}},g(d.Properties,c)})).call(this)},a["./model"]=new function(){var b=this;((function(){var b,c,d,e,f=Object.prototype.hasOwnProperty,g=function(a,b){function d(){this.constructor=a}for(var c in b)f.call(b,c)&&(a[c]=b[c]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a};d=a("./serenade").Serenade,c=a("./cache").Cache,b=a("./associations").Associations,e=a("./helpers").extend,d.Model=function(){function a(a,b){var d,e=this;b==null&&(b=!1);if(!b)if(a!=null?a.id:void 0){d=c.get(this.constructor,a.id);if(d)return d.set(a),this.set(a),d;c.set(this.constructor,a.id,this)}this.constructor.localStorage==="save"?this.bind("saved",function(){return c.store(e.constructor,e.get("id"),e)}):this.constructor.localStorage&&this.bind("change",function(){return c.store(e.constructor,e.get("id"),e)}),this.set(a)}return e(a.prototype,d.Properties),e(a.prototype,b),a.property=function(){var a;return(a=this.prototype).property.apply(a,arguments)},a.collection=function(){var a;return(a=this.prototype).collection.apply(a,arguments)},a.belongsTo=function(){var a;return(a=this.prototype).belongsTo.apply(a,arguments)},a.hasMany=function(){var a;return(a=this.prototype).hasMany.apply(a,arguments)},a.find=function(a){return c.get(this,a)||new this({id:a})},a.property("id",{serialize:!0}),a.extend=function(a,b){var c;return c=function(c){function d(){d.__super__.constructor.apply(this,arguments),b&&b.apply(this,arguments)}return g(d,c),d.modelName=a,d}(this)},a.prototype.save=function(){return this.trigger("saved")},a}()})).call(this)},a["./view"]=new function(){var b=this;((function(){var c,d,e,f,g;g=a("./parser").parser,c=a("./lexer").Lexer,d=a("./nodes").Nodes,e=a("./serenade").Serenade,g.lexer={lex:function(){var a,b;return b=this.tokens[this.pos++]||[""],a=b[0],this.yytext=b[1],this.yylineno=b[2],a},setInput:function(a){return this.tokens=a,this.pos=0},upcomingInput:function(){return""}},f=function(){function a(a,b){this.name=a,this.view=b}return a.prototype.parse=function(){return typeof this.view=="string"?g.parse((new c).tokenize(this.view)):this.view},a.prototype.render=function(a,b){var c;return this.name&&(b||(b=e.controllerFor(this.name,a))),b||(b={}),c=d.compile(this.parse(),e.document,a,b),b.model||(b.model=a),b.view||(b.view=c.element),c.element},a}(),b.View=f})).call(this)},a["./serenade"].Serenade}();typeof define=="function"&&define.amd?define(function(){return b}):a.Serenade=b})(this)
|
8
|
+
(function(root) {
|
9
|
+
var Serenade = function() {
|
10
|
+
function require(path){ return require[path]; }
|
11
|
+
require['./events'] = new function() {
|
12
|
+
var exports = this;
|
13
|
+
(function() {
|
14
|
+
var __slice = [].slice;
|
15
|
+
|
16
|
+
exports.Events = {
|
17
|
+
bind: function(ev, callback) {
|
18
|
+
var calls, evs, name, _i, _len;
|
19
|
+
evs = ev.split(' ');
|
20
|
+
calls = this.hasOwnProperty('_callbacks') && this._callbacks || (this._callbacks = {});
|
21
|
+
for (_i = 0, _len = evs.length; _i < _len; _i++) {
|
22
|
+
name = evs[_i];
|
23
|
+
calls[name] || (calls[name] = []);
|
24
|
+
calls[name].push(callback);
|
25
|
+
}
|
26
|
+
return this;
|
27
|
+
},
|
28
|
+
one: function(ev, callback) {
|
29
|
+
return this.bind(ev, function() {
|
30
|
+
this.unbind(ev, arguments.callee);
|
31
|
+
return callback.apply(this, arguments);
|
32
|
+
});
|
33
|
+
},
|
34
|
+
trigger: function() {
|
35
|
+
var args, callback, ev, list, _i, _len, _ref;
|
36
|
+
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
37
|
+
ev = args.shift();
|
38
|
+
list = this.hasOwnProperty('_callbacks') && ((_ref = this._callbacks) != null ? _ref[ev] : void 0);
|
39
|
+
if (!list) {
|
40
|
+
return false;
|
41
|
+
}
|
42
|
+
for (_i = 0, _len = list.length; _i < _len; _i++) {
|
43
|
+
callback = list[_i];
|
44
|
+
callback.apply(this, args);
|
45
|
+
}
|
46
|
+
return true;
|
47
|
+
},
|
48
|
+
unbind: function(ev, callback) {
|
49
|
+
var cb, i, list, _i, _len, _ref;
|
50
|
+
if (!ev) {
|
51
|
+
this._callbacks = {};
|
52
|
+
return this;
|
53
|
+
}
|
54
|
+
list = (_ref = this._callbacks) != null ? _ref[ev] : void 0;
|
55
|
+
if (!list) {
|
56
|
+
return this;
|
57
|
+
}
|
58
|
+
if (!callback) {
|
59
|
+
delete this._callbacks[ev];
|
60
|
+
return this;
|
61
|
+
}
|
62
|
+
for (i = _i = 0, _len = list.length; _i < _len; i = ++_i) {
|
63
|
+
cb = list[i];
|
64
|
+
if (!(cb === callback)) {
|
65
|
+
continue;
|
66
|
+
}
|
67
|
+
list = list.slice();
|
68
|
+
list.splice(i, 1);
|
69
|
+
this._callbacks[ev] = list;
|
70
|
+
break;
|
71
|
+
}
|
72
|
+
return this;
|
73
|
+
}
|
74
|
+
};
|
75
|
+
|
76
|
+
}).call(this);
|
77
|
+
|
78
|
+
};require['./helpers'] = new function() {
|
79
|
+
var exports = this;
|
80
|
+
(function() {
|
81
|
+
var Helpers,
|
82
|
+
__hasProp = {}.hasOwnProperty;
|
83
|
+
|
84
|
+
Helpers = {
|
85
|
+
extend: function(target, source) {
|
86
|
+
var key, value, _results;
|
87
|
+
_results = [];
|
88
|
+
for (key in source) {
|
89
|
+
if (!__hasProp.call(source, key)) continue;
|
90
|
+
value = source[key];
|
91
|
+
_results.push(target[key] = value);
|
92
|
+
}
|
93
|
+
return _results;
|
94
|
+
},
|
95
|
+
get: function(model, value, format) {
|
96
|
+
if (typeof (model != null ? model.get : void 0) === "function") {
|
97
|
+
return model.get(value, format);
|
98
|
+
} else {
|
99
|
+
return model != null ? model[value] : void 0;
|
100
|
+
}
|
101
|
+
},
|
102
|
+
set: function(model, key, value) {
|
103
|
+
if (model != null ? model.set : void 0) {
|
104
|
+
return model.set(key, value);
|
105
|
+
} else {
|
106
|
+
return model[key] = value;
|
107
|
+
}
|
108
|
+
},
|
109
|
+
isArray: function(object) {
|
110
|
+
return Object.prototype.toString.call(object) === "[object Array]";
|
111
|
+
},
|
112
|
+
pairToObject: function(one, two) {
|
113
|
+
var temp;
|
114
|
+
temp = {};
|
115
|
+
temp[one] = two;
|
116
|
+
return temp;
|
117
|
+
},
|
118
|
+
serializeObject: function(object) {
|
119
|
+
var item, _i, _len, _results;
|
120
|
+
if (object && typeof object.serialize === 'function') {
|
121
|
+
return object.serialize();
|
122
|
+
} else if (Helpers.isArray(object)) {
|
123
|
+
_results = [];
|
124
|
+
for (_i = 0, _len = object.length; _i < _len; _i++) {
|
125
|
+
item = object[_i];
|
126
|
+
_results.push(Helpers.serializeObject(item));
|
127
|
+
}
|
128
|
+
return _results;
|
129
|
+
} else {
|
130
|
+
return object;
|
131
|
+
}
|
132
|
+
},
|
133
|
+
getFunctionName: function(fun) {
|
134
|
+
var name, _ref, _ref1;
|
135
|
+
name = fun.modelName;
|
136
|
+
name || (name = fun.name);
|
137
|
+
name || (name = (_ref = fun.toString().match(/\[object (.+?)\]/)) != null ? _ref[1] : void 0);
|
138
|
+
name || (name = (_ref1 = fun.toString().match(/function (.+?)\(\)/)) != null ? _ref1[1] : void 0);
|
139
|
+
return name;
|
140
|
+
},
|
141
|
+
preventDefault: function(event) {
|
142
|
+
if (event.preventDefault) {
|
143
|
+
return event.preventDefault();
|
144
|
+
} else {
|
145
|
+
return event.returnValue = false;
|
146
|
+
}
|
147
|
+
}
|
148
|
+
};
|
149
|
+
|
150
|
+
Helpers.extend(exports, Helpers);
|
151
|
+
|
152
|
+
}).call(this);
|
153
|
+
|
154
|
+
};require['./cache'] = new function() {
|
155
|
+
var exports = this;
|
156
|
+
(function() {
|
157
|
+
var Cache, getFunctionName, serializeObject, _ref;
|
158
|
+
|
159
|
+
_ref = require('./helpers'), serializeObject = _ref.serializeObject, getFunctionName = _ref.getFunctionName;
|
160
|
+
|
161
|
+
Cache = {
|
162
|
+
_storage: typeof window !== "undefined" && window !== null ? window.localStorage : void 0,
|
163
|
+
_identityMap: {},
|
164
|
+
get: function(ctor, id) {
|
165
|
+
var name, _ref1;
|
166
|
+
name = getFunctionName(ctor);
|
167
|
+
if (name && id) {
|
168
|
+
return ((_ref1 = this._identityMap[name]) != null ? _ref1[id] : void 0) || this.retrieve(ctor, id);
|
169
|
+
}
|
170
|
+
},
|
171
|
+
set: function(ctor, id, obj) {
|
172
|
+
var name, _base;
|
173
|
+
name = getFunctionName(ctor);
|
174
|
+
if (name && id) {
|
175
|
+
(_base = this._identityMap)[name] || (_base[name] = {});
|
176
|
+
return this._identityMap[name][id] = obj;
|
177
|
+
}
|
178
|
+
},
|
179
|
+
store: function(ctor, id, obj) {
|
180
|
+
var name;
|
181
|
+
name = getFunctionName(ctor);
|
182
|
+
if (name && id && (typeof JSON !== "undefined" && JSON !== null)) {
|
183
|
+
return this._storage.setItem("" + name + "_" + id, JSON.stringify(serializeObject(obj)));
|
184
|
+
}
|
185
|
+
},
|
186
|
+
retrieve: function(ctor, id) {
|
187
|
+
var data, name;
|
188
|
+
name = getFunctionName(ctor);
|
189
|
+
if (name && id && ctor.localStorage && (typeof JSON !== "undefined" && JSON !== null)) {
|
190
|
+
data = this._storage.getItem("" + name + "_" + id);
|
191
|
+
if (data) {
|
192
|
+
return new ctor(JSON.parse(data), true);
|
193
|
+
}
|
194
|
+
}
|
195
|
+
}
|
196
|
+
};
|
197
|
+
|
198
|
+
exports.Cache = Cache;
|
199
|
+
|
200
|
+
}).call(this);
|
201
|
+
|
202
|
+
};require['./collection'] = new function() {
|
203
|
+
var exports = this;
|
204
|
+
(function() {
|
205
|
+
var Events, extend, get, getLength, isArrayIndex, serializeObject, _ref,
|
206
|
+
__slice = [].slice;
|
207
|
+
|
208
|
+
Events = require('./events').Events;
|
209
|
+
|
210
|
+
_ref = require('./helpers'), extend = _ref.extend, serializeObject = _ref.serializeObject, get = _ref.get;
|
211
|
+
|
212
|
+
isArrayIndex = function(index) {
|
213
|
+
return index.match(/^\d+$/);
|
214
|
+
};
|
215
|
+
|
216
|
+
getLength = function(arr) {
|
217
|
+
var index, indices, val;
|
218
|
+
indices = (function() {
|
219
|
+
var _results;
|
220
|
+
_results = [];
|
221
|
+
for (index in arr) {
|
222
|
+
val = arr[index];
|
223
|
+
if (isArrayIndex(index)) {
|
224
|
+
_results.push(parseInt(index, 10));
|
225
|
+
}
|
226
|
+
}
|
227
|
+
return _results;
|
228
|
+
})();
|
229
|
+
if (indices.length) {
|
230
|
+
return Math.max.apply(Math, indices) + 1;
|
231
|
+
} else {
|
232
|
+
return 0;
|
233
|
+
}
|
234
|
+
};
|
235
|
+
|
236
|
+
exports.Collection = (function() {
|
237
|
+
|
238
|
+
extend(Collection.prototype, Events);
|
239
|
+
|
240
|
+
function Collection(list) {
|
241
|
+
var index, val, _i, _len;
|
242
|
+
for (index = _i = 0, _len = list.length; _i < _len; index = ++_i) {
|
243
|
+
val = list[index];
|
244
|
+
this[index] = val;
|
245
|
+
}
|
246
|
+
this.length = getLength(this);
|
247
|
+
}
|
248
|
+
|
249
|
+
Collection.prototype.get = function(index) {
|
250
|
+
return this[index];
|
251
|
+
};
|
252
|
+
|
253
|
+
Collection.prototype.set = function(index, value) {
|
254
|
+
this[index] = value;
|
255
|
+
this.length = getLength(this);
|
256
|
+
this.trigger("change:" + index, value);
|
257
|
+
this.trigger("set", index, value);
|
258
|
+
this.trigger("change", this);
|
259
|
+
return value;
|
260
|
+
};
|
261
|
+
|
262
|
+
Collection.prototype.push = function(element) {
|
263
|
+
this[this.length] = element;
|
264
|
+
this.length = getLength(this);
|
265
|
+
this.trigger("add", element);
|
266
|
+
this.trigger("change", this);
|
267
|
+
return element;
|
268
|
+
};
|
269
|
+
|
270
|
+
Collection.prototype.pop = function() {
|
271
|
+
return this.deleteAt(this.length - 1);
|
272
|
+
};
|
273
|
+
|
274
|
+
Collection.prototype.unshift = function(item) {
|
275
|
+
return this.insertAt(0, item);
|
276
|
+
};
|
277
|
+
|
278
|
+
Collection.prototype.shift = function() {
|
279
|
+
return this.deleteAt(0);
|
280
|
+
};
|
281
|
+
|
282
|
+
Collection.prototype.update = function(list) {
|
283
|
+
var index, old, val, _, _i, _len;
|
284
|
+
old = this.clone();
|
285
|
+
for (index in this) {
|
286
|
+
_ = this[index];
|
287
|
+
if (isArrayIndex(index)) {
|
288
|
+
delete this[index];
|
289
|
+
}
|
290
|
+
}
|
291
|
+
for (index = _i = 0, _len = list.length; _i < _len; index = ++_i) {
|
292
|
+
val = list[index];
|
293
|
+
this[index] = val;
|
294
|
+
}
|
295
|
+
this.length = getLength(this);
|
296
|
+
this.trigger("update", old, this);
|
297
|
+
this.trigger("change", this);
|
298
|
+
return list;
|
299
|
+
};
|
300
|
+
|
301
|
+
Collection.prototype.splice = function() {
|
302
|
+
var deleteCount, deleted, list, old, start;
|
303
|
+
start = arguments[0], deleteCount = arguments[1], list = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
|
304
|
+
old = this.clone();
|
305
|
+
deleted = Array.prototype.splice.apply(this, [start, deleteCount].concat(__slice.call(list)));
|
306
|
+
this.length = getLength(this);
|
307
|
+
this.trigger("update", old, this);
|
308
|
+
this.trigger("change", this);
|
309
|
+
return new Collection(deleted);
|
310
|
+
};
|
311
|
+
|
312
|
+
Collection.prototype.sort = function(fun) {
|
313
|
+
var old;
|
314
|
+
old = this.clone();
|
315
|
+
Array.prototype.sort.call(this, fun);
|
316
|
+
this.trigger("update", old, this);
|
317
|
+
this.trigger("change", this);
|
318
|
+
return this;
|
319
|
+
};
|
320
|
+
|
321
|
+
Collection.prototype.sortBy = function(attribute) {
|
322
|
+
return this.sort(function(a, b) {
|
323
|
+
if (get(a, attribute) < get(b, attribute)) {
|
324
|
+
return -1;
|
325
|
+
} else {
|
326
|
+
return 1;
|
327
|
+
}
|
328
|
+
});
|
329
|
+
};
|
330
|
+
|
331
|
+
Collection.prototype.reverse = function() {
|
332
|
+
var old;
|
333
|
+
old = this.clone();
|
334
|
+
Array.prototype.reverse.call(this);
|
335
|
+
this.trigger("update", old, this);
|
336
|
+
this.trigger("change", this);
|
337
|
+
return this;
|
338
|
+
};
|
339
|
+
|
340
|
+
Collection.prototype.forEach = function(fun) {
|
341
|
+
if (typeof Array.prototype.forEach === 'function') {
|
342
|
+
return Array.prototype.forEach.call(this, fun);
|
343
|
+
} else {
|
344
|
+
this.map(fun);
|
345
|
+
return void 0;
|
346
|
+
}
|
347
|
+
};
|
348
|
+
|
349
|
+
Collection.prototype.map = function(fun) {
|
350
|
+
var element, index;
|
351
|
+
if (typeof Array.prototype.map === 'function') {
|
352
|
+
return new Collection(Array.prototype.map.call(this, fun));
|
353
|
+
} else {
|
354
|
+
return new Collection((function() {
|
355
|
+
var _i, _len, _results;
|
356
|
+
_results = [];
|
357
|
+
for (index = _i = 0, _len = this.length; _i < _len; index = ++_i) {
|
358
|
+
element = this[index];
|
359
|
+
_results.push(fun(element, index));
|
360
|
+
}
|
361
|
+
return _results;
|
362
|
+
}).call(this));
|
363
|
+
}
|
364
|
+
};
|
365
|
+
|
366
|
+
Collection.prototype.indexOf = function(search) {
|
367
|
+
var index, item, _i, _len;
|
368
|
+
if (typeof Array.prototype.indexOf === "function") {
|
369
|
+
return Array.prototype.indexOf.call(this, search);
|
370
|
+
} else {
|
371
|
+
for (index = _i = 0, _len = this.length; _i < _len; index = ++_i) {
|
372
|
+
item = this[index];
|
373
|
+
if (item === search) {
|
374
|
+
return index;
|
375
|
+
}
|
376
|
+
}
|
377
|
+
return -1;
|
378
|
+
}
|
379
|
+
};
|
380
|
+
|
381
|
+
Collection.prototype.lastIndexOf = function(search) {
|
382
|
+
var index, item, last;
|
383
|
+
if (typeof Array.prototype.lastIndexOf === "function") {
|
384
|
+
return Array.prototype.lastIndexOf.call(this, search);
|
385
|
+
} else {
|
386
|
+
last = ((function() {
|
387
|
+
var _i, _len, _results;
|
388
|
+
_results = [];
|
389
|
+
for (index = _i = 0, _len = this.length; _i < _len; index = ++_i) {
|
390
|
+
item = this[index];
|
391
|
+
if (item === search) {
|
392
|
+
_results.push(index);
|
393
|
+
}
|
394
|
+
}
|
395
|
+
return _results;
|
396
|
+
}).call(this)).pop();
|
397
|
+
if (last != null) {
|
398
|
+
return last;
|
399
|
+
} else {
|
400
|
+
return -1;
|
401
|
+
}
|
402
|
+
}
|
403
|
+
};
|
404
|
+
|
405
|
+
Collection.prototype.includes = function(item) {
|
406
|
+
return this.indexOf(item) >= 0;
|
407
|
+
};
|
408
|
+
|
409
|
+
Collection.prototype.find = function(fun) {
|
410
|
+
var item, _i, _len;
|
411
|
+
for (_i = 0, _len = this.length; _i < _len; _i++) {
|
412
|
+
item = this[_i];
|
413
|
+
if (fun(item)) {
|
414
|
+
return item;
|
415
|
+
}
|
416
|
+
}
|
417
|
+
};
|
418
|
+
|
419
|
+
Collection.prototype.insertAt = function(index, value) {
|
420
|
+
Array.prototype.splice.call(this, index, 0, value);
|
421
|
+
this.length = getLength(this);
|
422
|
+
this.trigger("insert", index, value);
|
423
|
+
this.trigger("change", this);
|
424
|
+
return value;
|
425
|
+
};
|
426
|
+
|
427
|
+
Collection.prototype.deleteAt = function(index) {
|
428
|
+
var value;
|
429
|
+
value = this[index];
|
430
|
+
Array.prototype.splice.call(this, index, 1);
|
431
|
+
this.length = getLength(this);
|
432
|
+
this.trigger("delete", index, value);
|
433
|
+
this.trigger("change", this);
|
434
|
+
return value;
|
435
|
+
};
|
436
|
+
|
437
|
+
Collection.prototype["delete"] = function(item) {
|
438
|
+
var index;
|
439
|
+
index = this.indexOf(item);
|
440
|
+
if (index !== -1) {
|
441
|
+
return this.deleteAt(index);
|
442
|
+
}
|
443
|
+
};
|
444
|
+
|
445
|
+
Collection.prototype.serialize = function() {
|
446
|
+
return serializeObject(this.toArray());
|
447
|
+
};
|
448
|
+
|
449
|
+
Collection.prototype.filter = function(fun) {
|
450
|
+
var item;
|
451
|
+
if (typeof Array.prototype.filter === "function") {
|
452
|
+
return new Collection(Array.prototype.filter.call(this, fun));
|
453
|
+
} else {
|
454
|
+
return new Collection((function() {
|
455
|
+
var _i, _len, _results;
|
456
|
+
_results = [];
|
457
|
+
for (_i = 0, _len = this.length; _i < _len; _i++) {
|
458
|
+
item = this[_i];
|
459
|
+
if (fun(item)) {
|
460
|
+
_results.push(item);
|
461
|
+
}
|
462
|
+
}
|
463
|
+
return _results;
|
464
|
+
}).call(this));
|
465
|
+
}
|
466
|
+
};
|
467
|
+
|
468
|
+
Collection.prototype.join = function() {
|
469
|
+
var args;
|
470
|
+
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
471
|
+
return Array.prototype.join.apply(this, args);
|
472
|
+
};
|
473
|
+
|
474
|
+
Collection.prototype.toString = function() {
|
475
|
+
return this.toArray().toString();
|
476
|
+
};
|
477
|
+
|
478
|
+
Collection.prototype.toLocaleString = function() {
|
479
|
+
return this.toArray().toLocaleString();
|
480
|
+
};
|
481
|
+
|
482
|
+
Collection.prototype.concat = function() {
|
483
|
+
var args, _ref1;
|
484
|
+
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
485
|
+
return new Collection((_ref1 = this.toArray()).concat.apply(_ref1, args));
|
486
|
+
};
|
487
|
+
|
488
|
+
Collection.prototype.slice = function() {
|
489
|
+
var args, _ref1;
|
490
|
+
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
491
|
+
return new Collection((_ref1 = this.toArray()).slice.apply(_ref1, args));
|
492
|
+
};
|
493
|
+
|
494
|
+
Collection.prototype.every = function(fun) {
|
495
|
+
var item, _i, _len;
|
496
|
+
if (typeof Array.prototype.every === "function") {
|
497
|
+
return Array.prototype.every.call(this, fun);
|
498
|
+
} else {
|
499
|
+
for (_i = 0, _len = this.length; _i < _len; _i++) {
|
500
|
+
item = this[_i];
|
501
|
+
if (!fun(item)) {
|
502
|
+
return false;
|
503
|
+
}
|
504
|
+
}
|
505
|
+
return true;
|
506
|
+
}
|
507
|
+
};
|
508
|
+
|
509
|
+
Collection.prototype.some = function(fun) {
|
510
|
+
var item, _i, _len;
|
511
|
+
if (typeof Array.prototype.some === "function") {
|
512
|
+
return Array.prototype.some.call(this, fun);
|
513
|
+
} else {
|
514
|
+
for (_i = 0, _len = this.length; _i < _len; _i++) {
|
515
|
+
item = this[_i];
|
516
|
+
if (fun(item)) {
|
517
|
+
return true;
|
518
|
+
}
|
519
|
+
}
|
520
|
+
return false;
|
521
|
+
}
|
522
|
+
};
|
523
|
+
|
524
|
+
Collection.prototype.reduce = function(fun, initial) {
|
525
|
+
var carry, index, item, _i, _len;
|
526
|
+
if (typeof Array.prototype.reduce === "function") {
|
527
|
+
return Array.prototype.reduce.apply(this, arguments);
|
528
|
+
} else {
|
529
|
+
carry = initial ? initial : this[0];
|
530
|
+
for (index = _i = 0, _len = this.length; _i < _len; index = ++_i) {
|
531
|
+
item = this[index];
|
532
|
+
if (initial || index !== 0) {
|
533
|
+
carry = fun(carry, item, index, this);
|
534
|
+
}
|
535
|
+
}
|
536
|
+
return carry;
|
537
|
+
}
|
538
|
+
};
|
539
|
+
|
540
|
+
Collection.prototype.reduceRight = function(fun, initial) {
|
541
|
+
var carry, index, item, traversed, _i, _len;
|
542
|
+
if (typeof Array.prototype.reduceRight === "function") {
|
543
|
+
return Array.prototype.reduceRight.apply(this, arguments);
|
544
|
+
} else {
|
545
|
+
traversed = this.toArray().reverse();
|
546
|
+
carry = initial ? initial : traversed[0];
|
547
|
+
for (index = _i = 0, _len = traversed.length; _i < _len; index = ++_i) {
|
548
|
+
item = traversed[index];
|
549
|
+
if (initial || index !== 0) {
|
550
|
+
carry = fun(carry, item, traversed.length - index - 1, this);
|
551
|
+
}
|
552
|
+
}
|
553
|
+
return carry;
|
554
|
+
}
|
555
|
+
};
|
556
|
+
|
557
|
+
Collection.prototype.first = function() {
|
558
|
+
return this[0];
|
559
|
+
};
|
560
|
+
|
561
|
+
Collection.prototype.last = function() {
|
562
|
+
return this[this.length - 1];
|
563
|
+
};
|
564
|
+
|
565
|
+
Collection.prototype.toArray = function() {
|
566
|
+
var array, index, val;
|
567
|
+
array = [];
|
568
|
+
for (index in this) {
|
569
|
+
val = this[index];
|
570
|
+
if (isArrayIndex(index)) {
|
571
|
+
array[index] = val;
|
572
|
+
}
|
573
|
+
}
|
574
|
+
return array;
|
575
|
+
};
|
576
|
+
|
577
|
+
Collection.prototype.toJSON = function() {
|
578
|
+
return this.serialize();
|
579
|
+
};
|
580
|
+
|
581
|
+
Collection.prototype.clone = function() {
|
582
|
+
return new Collection(this.toArray());
|
583
|
+
};
|
584
|
+
|
585
|
+
Collection.prototype._useDefer = true;
|
586
|
+
|
587
|
+
return Collection;
|
588
|
+
|
589
|
+
})();
|
590
|
+
|
591
|
+
}).call(this);
|
592
|
+
|
593
|
+
};require['./association_collection'] = new function() {
|
594
|
+
var exports = this;
|
595
|
+
(function() {
|
596
|
+
var AssociationCollection, Collection,
|
597
|
+
__hasProp = {}.hasOwnProperty,
|
598
|
+
__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; };
|
599
|
+
|
600
|
+
Collection = require('./collection').Collection;
|
601
|
+
|
602
|
+
AssociationCollection = (function(_super) {
|
603
|
+
|
604
|
+
__extends(AssociationCollection, _super);
|
605
|
+
|
606
|
+
function AssociationCollection(ctor, list) {
|
607
|
+
var item;
|
608
|
+
this.ctor = ctor;
|
609
|
+
AssociationCollection.__super__.constructor.call(this, (function() {
|
610
|
+
var _i, _len, _results;
|
611
|
+
_results = [];
|
612
|
+
for (_i = 0, _len = list.length; _i < _len; _i++) {
|
613
|
+
item = list[_i];
|
614
|
+
_results.push(this._convert(item));
|
615
|
+
}
|
616
|
+
return _results;
|
617
|
+
}).call(this));
|
618
|
+
}
|
619
|
+
|
620
|
+
AssociationCollection.prototype.set = function(index, item) {
|
621
|
+
return AssociationCollection.__super__.set.call(this, index, this._convert(item));
|
622
|
+
};
|
623
|
+
|
624
|
+
AssociationCollection.prototype.push = function(item) {
|
625
|
+
return AssociationCollection.__super__.push.call(this, this._convert(item));
|
626
|
+
};
|
627
|
+
|
628
|
+
AssociationCollection.prototype.update = function(list) {
|
629
|
+
var item;
|
630
|
+
return AssociationCollection.__super__.update.call(this, (function() {
|
631
|
+
var _i, _len, _results;
|
632
|
+
_results = [];
|
633
|
+
for (_i = 0, _len = list.length; _i < _len; _i++) {
|
634
|
+
item = list[_i];
|
635
|
+
_results.push(this._convert(item));
|
636
|
+
}
|
637
|
+
return _results;
|
638
|
+
}).call(this));
|
639
|
+
};
|
640
|
+
|
641
|
+
AssociationCollection.prototype._convert = function(item) {
|
642
|
+
if (item.constructor === Object && this.ctor) {
|
643
|
+
return new (this.ctor())(item);
|
644
|
+
} else {
|
645
|
+
return item;
|
646
|
+
}
|
647
|
+
};
|
648
|
+
|
649
|
+
return AssociationCollection;
|
650
|
+
|
651
|
+
})(Collection);
|
652
|
+
|
653
|
+
exports.AssociationCollection = AssociationCollection;
|
654
|
+
|
655
|
+
}).call(this);
|
656
|
+
|
657
|
+
};require['./properties'] = new function() {
|
658
|
+
var exports = this;
|
659
|
+
(function() {
|
660
|
+
var AssociationCollection, Associations, Collection, Events, Properties, addDependencies, addGlobalDependencies, define, exp, extend, get, globalDependencies, pairToObject, prefix, serializeObject, triggerChangesTo, triggerGlobal, _ref,
|
661
|
+
__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; },
|
662
|
+
__hasProp = {}.hasOwnProperty;
|
663
|
+
|
664
|
+
Collection = require('./collection').Collection;
|
665
|
+
|
666
|
+
AssociationCollection = require('./association_collection').AssociationCollection;
|
667
|
+
|
668
|
+
Events = require('./events').Events;
|
669
|
+
|
670
|
+
_ref = require('./helpers'), pairToObject = _ref.pairToObject, serializeObject = _ref.serializeObject, extend = _ref.extend, get = _ref.get;
|
671
|
+
|
672
|
+
prefix = "_prop_";
|
673
|
+
|
674
|
+
exp = /^_prop_/;
|
675
|
+
|
676
|
+
define = Object.defineProperties;
|
677
|
+
|
678
|
+
globalDependencies = {};
|
679
|
+
|
680
|
+
addGlobalDependencies = function(object, dependency, names) {
|
681
|
+
var name, subname, type, _i, _len, _ref1, _ref2, _results;
|
682
|
+
if (!object["_glb_" + dependency]) {
|
683
|
+
object["_glb_" + dependency] = true;
|
684
|
+
_results = [];
|
685
|
+
for (_i = 0, _len = names.length; _i < _len; _i++) {
|
686
|
+
name = names[_i];
|
687
|
+
if (name.match(/\./)) {
|
688
|
+
type = "singular";
|
689
|
+
_ref1 = name.split("."), name = _ref1[0], subname = _ref1[1];
|
690
|
+
} else if (name.match(/:/)) {
|
691
|
+
type = "collection";
|
692
|
+
_ref2 = name.split(":"), name = _ref2[0], subname = _ref2[1];
|
693
|
+
}
|
694
|
+
if (subname) {
|
695
|
+
globalDependencies[subname] || (globalDependencies[subname] = []);
|
696
|
+
_results.push(globalDependencies[subname].push({
|
697
|
+
object: object,
|
698
|
+
dependency: dependency,
|
699
|
+
subname: subname,
|
700
|
+
name: name,
|
701
|
+
type: type
|
702
|
+
}));
|
703
|
+
} else {
|
704
|
+
_results.push(void 0);
|
705
|
+
}
|
706
|
+
}
|
707
|
+
return _results;
|
708
|
+
}
|
709
|
+
};
|
710
|
+
|
711
|
+
addDependencies = function(object, dependency, names) {
|
712
|
+
var name, subname, _i, _len, _name, _ref1, _results;
|
713
|
+
names = [].concat(names);
|
714
|
+
_results = [];
|
715
|
+
for (_i = 0, _len = names.length; _i < _len; _i++) {
|
716
|
+
name = names[_i];
|
717
|
+
if (name.match(/[:\.]/)) {
|
718
|
+
_ref1 = name.split(/[:\.]/), name = _ref1[0], subname = _ref1[1];
|
719
|
+
}
|
720
|
+
object[_name = "_dep_" + name] || (object[_name] = []);
|
721
|
+
if (object["_dep_" + name].indexOf(dependency) === -1) {
|
722
|
+
_results.push(object["_dep_" + name].push(dependency));
|
723
|
+
} else {
|
724
|
+
_results.push(void 0);
|
725
|
+
}
|
726
|
+
}
|
727
|
+
return _results;
|
728
|
+
};
|
729
|
+
|
730
|
+
triggerGlobal = function(object, names) {
|
731
|
+
var dependency, name, _i, _len, _results;
|
732
|
+
_results = [];
|
733
|
+
for (_i = 0, _len = names.length; _i < _len; _i++) {
|
734
|
+
name = names[_i];
|
735
|
+
if (globalDependencies[name]) {
|
736
|
+
_results.push((function() {
|
737
|
+
var _j, _len1, _ref1, _results1;
|
738
|
+
_ref1 = globalDependencies[name];
|
739
|
+
_results1 = [];
|
740
|
+
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
741
|
+
dependency = _ref1[_j];
|
742
|
+
if (dependency.type === "singular") {
|
743
|
+
if (object === dependency.object.get(dependency.name)) {
|
744
|
+
_results1.push(triggerChangesTo(dependency.object, [dependency.dependency]));
|
745
|
+
} else {
|
746
|
+
_results1.push(void 0);
|
747
|
+
}
|
748
|
+
} else if (dependency.type === "collection") {
|
749
|
+
if (__indexOf.call(dependency.object.get(dependency.name), object) >= 0) {
|
750
|
+
_results1.push(triggerChangesTo(dependency.object, [dependency.dependency]));
|
751
|
+
} else {
|
752
|
+
_results1.push(void 0);
|
753
|
+
}
|
754
|
+
} else {
|
755
|
+
_results1.push(void 0);
|
756
|
+
}
|
757
|
+
}
|
758
|
+
return _results1;
|
759
|
+
})());
|
760
|
+
} else {
|
761
|
+
_results.push(void 0);
|
762
|
+
}
|
763
|
+
}
|
764
|
+
return _results;
|
765
|
+
};
|
766
|
+
|
767
|
+
triggerChangesTo = function(object, names) {
|
768
|
+
var changes, findDependencies, name, value, _i, _j, _len, _len1, _results;
|
769
|
+
findDependencies = function(name) {
|
770
|
+
var dependencies, dependency, _i, _len, _results;
|
771
|
+
dependencies = object["_dep_" + name];
|
772
|
+
if (dependencies) {
|
773
|
+
_results = [];
|
774
|
+
for (_i = 0, _len = dependencies.length; _i < _len; _i++) {
|
775
|
+
dependency = dependencies[_i];
|
776
|
+
if (names.indexOf(dependency) === -1) {
|
777
|
+
names.push(dependency);
|
778
|
+
_results.push(findDependencies(dependency));
|
779
|
+
} else {
|
780
|
+
_results.push(void 0);
|
781
|
+
}
|
782
|
+
}
|
783
|
+
return _results;
|
784
|
+
}
|
785
|
+
};
|
786
|
+
for (_i = 0, _len = names.length; _i < _len; _i++) {
|
787
|
+
name = names[_i];
|
788
|
+
findDependencies(name);
|
789
|
+
}
|
790
|
+
changes = {};
|
791
|
+
for (_j = 0, _len1 = names.length; _j < _len1; _j++) {
|
792
|
+
name = names[_j];
|
793
|
+
changes[name] = object.get(name);
|
794
|
+
}
|
795
|
+
object.trigger("change", changes);
|
796
|
+
triggerGlobal(object, names);
|
797
|
+
_results = [];
|
798
|
+
for (name in changes) {
|
799
|
+
if (!__hasProp.call(changes, name)) continue;
|
800
|
+
value = changes[name];
|
801
|
+
_results.push(object.trigger("change:" + name, value));
|
802
|
+
}
|
803
|
+
return _results;
|
804
|
+
};
|
805
|
+
|
806
|
+
Properties = {
|
807
|
+
property: function(name, options) {
|
808
|
+
if (options == null) {
|
809
|
+
options = {};
|
810
|
+
}
|
811
|
+
this[prefix + name] = options;
|
812
|
+
this[prefix + name].name = name;
|
813
|
+
if (this.hasOwnProperty(name)) {
|
814
|
+
this.set(name, this[name]);
|
815
|
+
}
|
816
|
+
if (options.dependsOn) {
|
817
|
+
addDependencies(this, name, options.dependsOn);
|
818
|
+
}
|
819
|
+
if (define) {
|
820
|
+
Object.defineProperty(this, name, {
|
821
|
+
get: function() {
|
822
|
+
return Properties.get.call(this, name);
|
823
|
+
},
|
824
|
+
set: function(value) {
|
825
|
+
return Properties.set.call(this, name, value);
|
826
|
+
},
|
827
|
+
configurable: true
|
828
|
+
});
|
829
|
+
}
|
830
|
+
if (typeof options.serialize === 'string') {
|
831
|
+
return this.property(options.serialize, {
|
832
|
+
get: function() {
|
833
|
+
return this.get(name);
|
834
|
+
},
|
835
|
+
set: function(v) {
|
836
|
+
return this.set(name, v);
|
837
|
+
},
|
838
|
+
configurable: true
|
839
|
+
});
|
840
|
+
}
|
841
|
+
},
|
842
|
+
collection: function(name, options) {
|
843
|
+
if (options == null) {
|
844
|
+
options = {};
|
845
|
+
}
|
846
|
+
extend(options, {
|
847
|
+
get: function() {
|
848
|
+
var _this = this;
|
849
|
+
if (!this.attributes[name]) {
|
850
|
+
this.attributes[name] = new Collection([]);
|
851
|
+
this.attributes[name].bind('change', function() {
|
852
|
+
return triggerChangesTo(_this, [name]);
|
853
|
+
});
|
854
|
+
}
|
855
|
+
return this.attributes[name];
|
856
|
+
},
|
857
|
+
set: function(value) {
|
858
|
+
return this.get(name).update(value);
|
859
|
+
}
|
860
|
+
});
|
861
|
+
return this.property(name, options);
|
862
|
+
},
|
863
|
+
set: function(attributes, value) {
|
864
|
+
var name, names, _ref1;
|
865
|
+
if (typeof attributes === 'string') {
|
866
|
+
attributes = pairToObject(attributes, value);
|
867
|
+
}
|
868
|
+
names = [];
|
869
|
+
for (name in attributes) {
|
870
|
+
value = attributes[name];
|
871
|
+
names.push(name);
|
872
|
+
this.attributes || (this.attributes = {});
|
873
|
+
if (!this[prefix + name]) {
|
874
|
+
Properties.property.call(this, name);
|
875
|
+
}
|
876
|
+
if ((_ref1 = this[prefix + name]) != null ? _ref1.set : void 0) {
|
877
|
+
this[prefix + name].set.call(this, value);
|
878
|
+
} else {
|
879
|
+
this.attributes[name] = value;
|
880
|
+
}
|
881
|
+
}
|
882
|
+
return triggerChangesTo(this, names);
|
883
|
+
},
|
884
|
+
get: function(name, format) {
|
885
|
+
var formatter, value, _ref1, _ref2, _ref3, _ref4;
|
886
|
+
if ((_ref1 = this[prefix + name]) != null ? _ref1.dependsOn : void 0) {
|
887
|
+
addGlobalDependencies(this, name, [].concat(this[prefix + name].dependsOn));
|
888
|
+
}
|
889
|
+
this.attributes || (this.attributes = {});
|
890
|
+
value = ((_ref2 = this[prefix + name]) != null ? _ref2.get : void 0) ? this[prefix + name].get.call(this) : ((_ref3 = this[prefix + name]) != null ? _ref3.hasOwnProperty("default") : void 0) && !this.attributes.hasOwnProperty(name) ? this[prefix + name]["default"] : this.attributes[name];
|
891
|
+
formatter = (_ref4 = this[prefix + name]) != null ? _ref4.format : void 0;
|
892
|
+
if (format && typeof formatter === 'function') {
|
893
|
+
return formatter.call(this, value);
|
894
|
+
} else {
|
895
|
+
return value;
|
896
|
+
}
|
897
|
+
},
|
898
|
+
serialize: function() {
|
899
|
+
var key, name, options, serialized, value, _ref1;
|
900
|
+
serialized = {};
|
901
|
+
for (name in this) {
|
902
|
+
options = this[name];
|
903
|
+
if (name.match(exp)) {
|
904
|
+
if (typeof options.serialize === 'string') {
|
905
|
+
serialized[options.serialize] = serializeObject(this.get(options.name));
|
906
|
+
} else if (typeof options.serialize === 'function') {
|
907
|
+
_ref1 = options.serialize.call(this), key = _ref1[0], value = _ref1[1];
|
908
|
+
serialized[key] = serializeObject(value);
|
909
|
+
} else if (options.serialize) {
|
910
|
+
serialized[options.name] = serializeObject(this.get(options.name));
|
911
|
+
}
|
912
|
+
}
|
913
|
+
}
|
914
|
+
return serialized;
|
915
|
+
}
|
916
|
+
};
|
917
|
+
|
918
|
+
extend(Properties, Events);
|
919
|
+
|
920
|
+
Associations = {
|
921
|
+
belongsTo: function(name, attributes) {
|
922
|
+
if (attributes == null) {
|
923
|
+
attributes = {};
|
924
|
+
}
|
925
|
+
extend(attributes, {
|
926
|
+
set: function(model) {
|
927
|
+
if (model.constructor === Object && attributes.as) {
|
928
|
+
model = new (attributes.as())(model);
|
929
|
+
}
|
930
|
+
return this.attributes[name] = model;
|
931
|
+
}
|
932
|
+
});
|
933
|
+
this.property(name, attributes);
|
934
|
+
return this.property(name + 'Id', {
|
935
|
+
get: function() {
|
936
|
+
return get(this.get(name), 'id');
|
937
|
+
},
|
938
|
+
set: function(id) {
|
939
|
+
return this.attributes[name] = attributes.as().find(id);
|
940
|
+
},
|
941
|
+
dependsOn: name,
|
942
|
+
serialize: attributes.serializeId
|
943
|
+
});
|
944
|
+
},
|
945
|
+
hasMany: function(name, attributes) {
|
946
|
+
if (attributes == null) {
|
947
|
+
attributes = {};
|
948
|
+
}
|
949
|
+
extend(attributes, {
|
950
|
+
get: function() {
|
951
|
+
var _this = this;
|
952
|
+
if (!this.attributes[name]) {
|
953
|
+
this.attributes[name] = new AssociationCollection(attributes.as, []);
|
954
|
+
this.attributes[name].bind('change', function() {
|
955
|
+
return triggerChangesTo(_this, [name]);
|
956
|
+
});
|
957
|
+
}
|
958
|
+
return this.attributes[name];
|
959
|
+
},
|
960
|
+
set: function(value) {
|
961
|
+
return this.get(name).update(value);
|
962
|
+
}
|
963
|
+
});
|
964
|
+
this.property(name, attributes);
|
965
|
+
return this.property(name + 'Ids', {
|
966
|
+
get: function() {
|
967
|
+
return new Collection(this.get(name)).map(function(item) {
|
968
|
+
return get(item, 'id');
|
969
|
+
});
|
970
|
+
},
|
971
|
+
set: function(ids) {
|
972
|
+
var id, objects;
|
973
|
+
objects = (function() {
|
974
|
+
var _i, _len, _results;
|
975
|
+
_results = [];
|
976
|
+
for (_i = 0, _len = ids.length; _i < _len; _i++) {
|
977
|
+
id = ids[_i];
|
978
|
+
_results.push(attributes.as().find(id));
|
979
|
+
}
|
980
|
+
return _results;
|
981
|
+
})();
|
982
|
+
return this.get(name).update(objects);
|
983
|
+
},
|
984
|
+
dependsOn: name,
|
985
|
+
serialize: attributes.serializeIds
|
986
|
+
});
|
987
|
+
}
|
988
|
+
};
|
989
|
+
|
990
|
+
exports.Properties = Properties;
|
991
|
+
|
992
|
+
exports.Associations = Associations;
|
993
|
+
|
994
|
+
exports.globalDependencies = globalDependencies;
|
995
|
+
|
996
|
+
}).call(this);
|
997
|
+
|
998
|
+
};require['./model'] = new function() {
|
999
|
+
var exports = this;
|
1000
|
+
(function() {
|
1001
|
+
var Associations, Cache, Model, Properties, extend, _ref,
|
1002
|
+
__hasProp = {}.hasOwnProperty,
|
1003
|
+
__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; };
|
1004
|
+
|
1005
|
+
Cache = require('./cache').Cache;
|
1006
|
+
|
1007
|
+
_ref = require('./properties'), Associations = _ref.Associations, Properties = _ref.Properties;
|
1008
|
+
|
1009
|
+
extend = require('./helpers').extend;
|
1010
|
+
|
1011
|
+
Model = (function() {
|
1012
|
+
|
1013
|
+
extend(Model.prototype, Properties);
|
1014
|
+
|
1015
|
+
extend(Model.prototype, Associations);
|
1016
|
+
|
1017
|
+
Model.property = function() {
|
1018
|
+
var _ref1;
|
1019
|
+
return (_ref1 = this.prototype).property.apply(_ref1, arguments);
|
1020
|
+
};
|
1021
|
+
|
1022
|
+
Model.collection = function() {
|
1023
|
+
var _ref1;
|
1024
|
+
return (_ref1 = this.prototype).collection.apply(_ref1, arguments);
|
1025
|
+
};
|
1026
|
+
|
1027
|
+
Model.belongsTo = function() {
|
1028
|
+
var _ref1;
|
1029
|
+
return (_ref1 = this.prototype).belongsTo.apply(_ref1, arguments);
|
1030
|
+
};
|
1031
|
+
|
1032
|
+
Model.hasMany = function() {
|
1033
|
+
var _ref1;
|
1034
|
+
return (_ref1 = this.prototype).hasMany.apply(_ref1, arguments);
|
1035
|
+
};
|
1036
|
+
|
1037
|
+
Model.find = function(id) {
|
1038
|
+
return Cache.get(this, id) || new this({
|
1039
|
+
id: id
|
1040
|
+
});
|
1041
|
+
};
|
1042
|
+
|
1043
|
+
Model.property('id', {
|
1044
|
+
serialize: true
|
1045
|
+
});
|
1046
|
+
|
1047
|
+
Model.extend = function(name, ctor) {
|
1048
|
+
var New;
|
1049
|
+
return New = (function(_super) {
|
1050
|
+
|
1051
|
+
__extends(New, _super);
|
1052
|
+
|
1053
|
+
New.modelName = name;
|
1054
|
+
|
1055
|
+
function New() {
|
1056
|
+
New.__super__.constructor.apply(this, arguments);
|
1057
|
+
if (ctor) {
|
1058
|
+
ctor.apply(this, arguments);
|
1059
|
+
}
|
1060
|
+
}
|
1061
|
+
|
1062
|
+
return New;
|
1063
|
+
|
1064
|
+
})(this);
|
1065
|
+
};
|
1066
|
+
|
1067
|
+
function Model(attributes, bypassCache) {
|
1068
|
+
var fromCache,
|
1069
|
+
_this = this;
|
1070
|
+
if (bypassCache == null) {
|
1071
|
+
bypassCache = false;
|
1072
|
+
}
|
1073
|
+
if (!bypassCache) {
|
1074
|
+
if (attributes != null ? attributes.id : void 0) {
|
1075
|
+
fromCache = Cache.get(this.constructor, attributes.id);
|
1076
|
+
if (fromCache) {
|
1077
|
+
fromCache.set(attributes);
|
1078
|
+
return fromCache;
|
1079
|
+
} else {
|
1080
|
+
Cache.set(this.constructor, attributes.id, this);
|
1081
|
+
}
|
1082
|
+
}
|
1083
|
+
}
|
1084
|
+
if (this.constructor.localStorage) {
|
1085
|
+
this.bind('saved', function() {
|
1086
|
+
return Cache.store(_this.constructor, _this.get('id'), _this);
|
1087
|
+
});
|
1088
|
+
if (this.constructor.localStorage !== 'save') {
|
1089
|
+
this.bind('change', function() {
|
1090
|
+
return Cache.store(_this.constructor, _this.get('id'), _this);
|
1091
|
+
});
|
1092
|
+
}
|
1093
|
+
}
|
1094
|
+
this.set(attributes);
|
1095
|
+
}
|
1096
|
+
|
1097
|
+
Model.prototype.save = function() {
|
1098
|
+
return this.trigger('saved');
|
1099
|
+
};
|
1100
|
+
|
1101
|
+
return Model;
|
1102
|
+
|
1103
|
+
})();
|
1104
|
+
|
1105
|
+
exports.Model = Model;
|
1106
|
+
|
1107
|
+
}).call(this);
|
1108
|
+
|
1109
|
+
};require['./serenade'] = new function() {
|
1110
|
+
var exports = this;
|
1111
|
+
(function() {
|
1112
|
+
var Cache, Properties, Serenade, extend, globalDependencies, _ref;
|
1113
|
+
|
1114
|
+
Cache = require('./cache').Cache;
|
1115
|
+
|
1116
|
+
extend = require('./helpers').extend;
|
1117
|
+
|
1118
|
+
_ref = require("./properties"), Properties = _ref.Properties, globalDependencies = _ref.globalDependencies;
|
1119
|
+
|
1120
|
+
Serenade = function(attributes) {
|
1121
|
+
if (this === root) {
|
1122
|
+
return new Serenade(attributes);
|
1123
|
+
}
|
1124
|
+
this.set(attributes);
|
1125
|
+
return this;
|
1126
|
+
};
|
1127
|
+
|
1128
|
+
extend(Serenade.prototype, Properties);
|
1129
|
+
|
1130
|
+
extend(Serenade, {
|
1131
|
+
VERSION: '0.2.0',
|
1132
|
+
_views: {},
|
1133
|
+
_controllers: {},
|
1134
|
+
document: typeof window !== "undefined" && window !== null ? window.document : void 0,
|
1135
|
+
view: function(nameOrTemplate, template) {
|
1136
|
+
var View;
|
1137
|
+
View = require('./view').View;
|
1138
|
+
if (template) {
|
1139
|
+
return this._views[nameOrTemplate] = new View(nameOrTemplate, template);
|
1140
|
+
} else {
|
1141
|
+
return new View(void 0, nameOrTemplate);
|
1142
|
+
}
|
1143
|
+
},
|
1144
|
+
render: function(name, model, controller, parent) {
|
1145
|
+
return this._views[name].render(model, controller, parent);
|
1146
|
+
},
|
1147
|
+
controller: function(name, klass) {
|
1148
|
+
return this._controllers[name] = klass;
|
1149
|
+
},
|
1150
|
+
controllerFor: function(name) {
|
1151
|
+
return this._controllers[name];
|
1152
|
+
},
|
1153
|
+
clearIdentityMap: function() {
|
1154
|
+
return Cache._identityMap = {};
|
1155
|
+
},
|
1156
|
+
clearLocalStorage: function() {
|
1157
|
+
return Cache._storage.clear();
|
1158
|
+
},
|
1159
|
+
clearCache: function() {
|
1160
|
+
var key, value, _i, _len, _results;
|
1161
|
+
Serenade.clearIdentityMap();
|
1162
|
+
Serenade.clearLocalStorage();
|
1163
|
+
_results = [];
|
1164
|
+
for (key = _i = 0, _len = globalDependencies.length; _i < _len; key = ++_i) {
|
1165
|
+
value = globalDependencies[key];
|
1166
|
+
_results.push(delete globalDependencies[key]);
|
1167
|
+
}
|
1168
|
+
return _results;
|
1169
|
+
},
|
1170
|
+
unregisterAll: function() {
|
1171
|
+
Serenade._views = {};
|
1172
|
+
return Serenade._controllers = {};
|
1173
|
+
},
|
1174
|
+
bindEvent: function(element, event, callback) {
|
1175
|
+
if (typeof element.addEventListener === 'function') {
|
1176
|
+
return element.addEventListener(event, callback, false);
|
1177
|
+
} else {
|
1178
|
+
return element.attachEvent('on' + event, callback);
|
1179
|
+
}
|
1180
|
+
},
|
1181
|
+
useJQuery: function() {
|
1182
|
+
return this.bindEvent = function(element, event, callback) {
|
1183
|
+
return jQuery(element).bind(event, callback);
|
1184
|
+
};
|
1185
|
+
},
|
1186
|
+
Events: require('./events').Events,
|
1187
|
+
Model: require('./model').Model,
|
1188
|
+
Collection: require('./collection').Collection,
|
1189
|
+
Helpers: {}
|
1190
|
+
});
|
1191
|
+
|
1192
|
+
exports.Serenade = Serenade;
|
1193
|
+
|
1194
|
+
exports.compile = function() {
|
1195
|
+
var document, fs, window;
|
1196
|
+
document = require("jsdom").jsdom(null, null, {});
|
1197
|
+
fs = require("fs");
|
1198
|
+
window = document.createWindow();
|
1199
|
+
Serenade.document = document;
|
1200
|
+
return function(env) {
|
1201
|
+
var element, html, model, viewName;
|
1202
|
+
model = env.model;
|
1203
|
+
viewName = env.filename.split('/').reverse()[0].replace(/\.serenade$/, '');
|
1204
|
+
Serenade.view(viewName, fs.readFileSync(env.filename).toString());
|
1205
|
+
element = Serenade.render(viewName, model, {});
|
1206
|
+
document.body.appendChild(element);
|
1207
|
+
html = document.body.innerHTML;
|
1208
|
+
if (env.doctype !== false) {
|
1209
|
+
html = "<!DOCTYPE html>\n" + html;
|
1210
|
+
}
|
1211
|
+
return html;
|
1212
|
+
};
|
1213
|
+
};
|
1214
|
+
|
1215
|
+
}).call(this);
|
1216
|
+
|
1217
|
+
};require['./lexer'] = new function() {
|
1218
|
+
var exports = this;
|
1219
|
+
(function() {
|
1220
|
+
var IDENTIFIER, KEYWORDS, LITERAL, Lexer, MULTI_DENT, STRING, WHITESPACE,
|
1221
|
+
__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; };
|
1222
|
+
|
1223
|
+
IDENTIFIER = /^[a-zA-Z][a-zA-Z0-9\-_]*/;
|
1224
|
+
|
1225
|
+
LITERAL = /^[\[\]=\:\-!#\.@]/;
|
1226
|
+
|
1227
|
+
STRING = /^"((?:\\.|[^"])*)"/;
|
1228
|
+
|
1229
|
+
MULTI_DENT = /^(?:\r?\n[^\r\n\S]*)+/;
|
1230
|
+
|
1231
|
+
WHITESPACE = /^[^\r\n\S]+/;
|
1232
|
+
|
1233
|
+
KEYWORDS = ["IF", "COLLECTION", "IN", "VIEW", "UNLESS"];
|
1234
|
+
|
1235
|
+
Lexer = (function() {
|
1236
|
+
|
1237
|
+
function Lexer() {}
|
1238
|
+
|
1239
|
+
Lexer.prototype.tokenize = function(code, opts) {
|
1240
|
+
var i, tag;
|
1241
|
+
if (opts == null) {
|
1242
|
+
opts = {};
|
1243
|
+
}
|
1244
|
+
this.code = code.replace(/^\s*/, '').replace(/\s*$/, '');
|
1245
|
+
this.line = opts.line || 0;
|
1246
|
+
this.indent = 0;
|
1247
|
+
this.indents = [];
|
1248
|
+
this.ends = [];
|
1249
|
+
this.tokens = [];
|
1250
|
+
i = 0;
|
1251
|
+
while (this.chunk = this.code.slice(i)) {
|
1252
|
+
i += this.identifierToken() || this.whitespaceToken() || this.lineToken() || this.stringToken() || this.literalToken();
|
1253
|
+
}
|
1254
|
+
while (tag = this.ends.pop()) {
|
1255
|
+
if (tag === 'OUTDENT') {
|
1256
|
+
this.token('OUTDENT');
|
1257
|
+
} else {
|
1258
|
+
this.error("missing " + tag);
|
1259
|
+
}
|
1260
|
+
}
|
1261
|
+
return this.tokens;
|
1262
|
+
};
|
1263
|
+
|
1264
|
+
Lexer.prototype.whitespaceToken = function() {
|
1265
|
+
var match;
|
1266
|
+
if (match = WHITESPACE.exec(this.chunk)) {
|
1267
|
+
this.token('WHITESPACE', match[0].length);
|
1268
|
+
return match[0].length;
|
1269
|
+
} else {
|
1270
|
+
return 0;
|
1271
|
+
}
|
1272
|
+
};
|
1273
|
+
|
1274
|
+
Lexer.prototype.token = function(tag, value) {
|
1275
|
+
return this.tokens.push([tag, value, this.line]);
|
1276
|
+
};
|
1277
|
+
|
1278
|
+
Lexer.prototype.identifierToken = function() {
|
1279
|
+
var match, name;
|
1280
|
+
if (match = IDENTIFIER.exec(this.chunk)) {
|
1281
|
+
name = match[0].toUpperCase();
|
1282
|
+
if (__indexOf.call(KEYWORDS, name) >= 0) {
|
1283
|
+
this.token(name, match[0]);
|
1284
|
+
} else {
|
1285
|
+
this.token('IDENTIFIER', match[0]);
|
1286
|
+
}
|
1287
|
+
return match[0].length;
|
1288
|
+
} else {
|
1289
|
+
return 0;
|
1290
|
+
}
|
1291
|
+
};
|
1292
|
+
|
1293
|
+
Lexer.prototype.stringToken = function() {
|
1294
|
+
var match;
|
1295
|
+
if (match = STRING.exec(this.chunk)) {
|
1296
|
+
this.token('STRING_LITERAL', match[1]);
|
1297
|
+
return match[0].length;
|
1298
|
+
} else {
|
1299
|
+
return 0;
|
1300
|
+
}
|
1301
|
+
};
|
1302
|
+
|
1303
|
+
Lexer.prototype.lineToken = function() {
|
1304
|
+
var diff, indent, match, prev, size;
|
1305
|
+
if (!(match = MULTI_DENT.exec(this.chunk))) {
|
1306
|
+
return 0;
|
1307
|
+
}
|
1308
|
+
indent = match[0];
|
1309
|
+
this.line += this.count(indent, '\n');
|
1310
|
+
prev = this.last(this.tokens, 1);
|
1311
|
+
size = indent.length - 1 - indent.lastIndexOf('\n');
|
1312
|
+
diff = size - this.indent;
|
1313
|
+
if (size === this.indent) {
|
1314
|
+
this.newlineToken();
|
1315
|
+
} else if (size > this.indent) {
|
1316
|
+
this.token('INDENT');
|
1317
|
+
this.indents.push(diff);
|
1318
|
+
this.ends.push('OUTDENT');
|
1319
|
+
} else {
|
1320
|
+
while (diff < 0) {
|
1321
|
+
if (this.last(this.ends) !== 'OUTDENT') {
|
1322
|
+
this.error('Should be an OUTDENT, yo');
|
1323
|
+
}
|
1324
|
+
this.ends.pop();
|
1325
|
+
diff += this.indents.pop();
|
1326
|
+
this.token('OUTDENT');
|
1327
|
+
}
|
1328
|
+
this.token('TERMINATOR', '\n');
|
1329
|
+
}
|
1330
|
+
this.indent = size;
|
1331
|
+
return indent.length;
|
1332
|
+
};
|
1333
|
+
|
1334
|
+
Lexer.prototype.literalToken = function() {
|
1335
|
+
var match;
|
1336
|
+
if (match = LITERAL.exec(this.chunk)) {
|
1337
|
+
this.token(match[0]);
|
1338
|
+
return 1;
|
1339
|
+
} else {
|
1340
|
+
return this.error("WUT??? is '" + (this.chunk.charAt(0)) + "'");
|
1341
|
+
}
|
1342
|
+
};
|
1343
|
+
|
1344
|
+
Lexer.prototype.newlineToken = function() {
|
1345
|
+
if (this.tag() !== 'TERMINATOR') {
|
1346
|
+
return this.token('TERMINATOR', '\n');
|
1347
|
+
}
|
1348
|
+
};
|
1349
|
+
|
1350
|
+
Lexer.prototype.tag = function(index, tag) {
|
1351
|
+
var tok;
|
1352
|
+
return (tok = this.last(this.tokens, index)) && (tag ? tok[0] = tag : tok[0]);
|
1353
|
+
};
|
1354
|
+
|
1355
|
+
Lexer.prototype.value = function(index, val) {
|
1356
|
+
var tok;
|
1357
|
+
return (tok = this.last(this.tokens, index)) && (val ? tok[1] = val : tok[1]);
|
1358
|
+
};
|
1359
|
+
|
1360
|
+
Lexer.prototype.error = function(message) {
|
1361
|
+
throw SyntaxError("" + message + " on line " + (this.line + 1));
|
1362
|
+
};
|
1363
|
+
|
1364
|
+
Lexer.prototype.count = function(string, substr) {
|
1365
|
+
var num, pos;
|
1366
|
+
num = pos = 0;
|
1367
|
+
if (!substr.length) {
|
1368
|
+
return 1 / 0;
|
1369
|
+
}
|
1370
|
+
while (pos = 1 + string.indexOf(substr, pos)) {
|
1371
|
+
num++;
|
1372
|
+
}
|
1373
|
+
return num;
|
1374
|
+
};
|
1375
|
+
|
1376
|
+
Lexer.prototype.last = function(array, back) {
|
1377
|
+
return array[array.length - (back || 0) - 1];
|
1378
|
+
};
|
1379
|
+
|
1380
|
+
return Lexer;
|
1381
|
+
|
1382
|
+
})();
|
1383
|
+
|
1384
|
+
exports.Lexer = Lexer;
|
1385
|
+
|
1386
|
+
}).call(this);
|
1387
|
+
|
1388
|
+
};require['./node'] = new function() {
|
1389
|
+
var exports = this;
|
1390
|
+
(function() {
|
1391
|
+
var Node, Serenade;
|
1392
|
+
|
1393
|
+
Serenade = require('./serenade').Serenade;
|
1394
|
+
|
1395
|
+
Node = (function() {
|
1396
|
+
|
1397
|
+
function Node(ast, element) {
|
1398
|
+
this.ast = ast;
|
1399
|
+
this.element = element;
|
1400
|
+
}
|
1401
|
+
|
1402
|
+
Node.prototype.append = function(inside) {
|
1403
|
+
return inside.appendChild(this.element);
|
1404
|
+
};
|
1405
|
+
|
1406
|
+
Node.prototype.insertAfter = function(after) {
|
1407
|
+
return after.parentNode.insertBefore(this.element, after.nextSibling);
|
1408
|
+
};
|
1409
|
+
|
1410
|
+
Node.prototype.remove = function() {
|
1411
|
+
var _ref;
|
1412
|
+
return (_ref = this.element.parentNode) != null ? _ref.removeChild(this.element) : void 0;
|
1413
|
+
};
|
1414
|
+
|
1415
|
+
Node.prototype.lastElement = function() {
|
1416
|
+
return this.element;
|
1417
|
+
};
|
1418
|
+
|
1419
|
+
return Node;
|
1420
|
+
|
1421
|
+
})();
|
1422
|
+
|
1423
|
+
exports.Node = Node;
|
1424
|
+
|
1425
|
+
}).call(this);
|
1426
|
+
|
1427
|
+
};require['./dynamic_node'] = new function() {
|
1428
|
+
var exports = this;
|
1429
|
+
(function() {
|
1430
|
+
var Collection, DynamicNode, Serenade;
|
1431
|
+
|
1432
|
+
Serenade = require('./serenade').Serenade;
|
1433
|
+
|
1434
|
+
Collection = require('./collection').Collection;
|
1435
|
+
|
1436
|
+
DynamicNode = (function() {
|
1437
|
+
|
1438
|
+
function DynamicNode(ast) {
|
1439
|
+
this.ast = ast;
|
1440
|
+
this.anchor = Serenade.document.createTextNode('');
|
1441
|
+
this.nodeSets = new Collection([]);
|
1442
|
+
}
|
1443
|
+
|
1444
|
+
DynamicNode.prototype.eachNode = function(fun) {
|
1445
|
+
var node, set, _i, _len, _ref, _results;
|
1446
|
+
_ref = this.nodeSets;
|
1447
|
+
_results = [];
|
1448
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1449
|
+
set = _ref[_i];
|
1450
|
+
_results.push((function() {
|
1451
|
+
var _j, _len1, _results1;
|
1452
|
+
_results1 = [];
|
1453
|
+
for (_j = 0, _len1 = set.length; _j < _len1; _j++) {
|
1454
|
+
node = set[_j];
|
1455
|
+
_results1.push(fun(node));
|
1456
|
+
}
|
1457
|
+
return _results1;
|
1458
|
+
})());
|
1459
|
+
}
|
1460
|
+
return _results;
|
1461
|
+
};
|
1462
|
+
|
1463
|
+
DynamicNode.prototype.rebuild = function() {
|
1464
|
+
var last;
|
1465
|
+
if (this.anchor.parentNode) {
|
1466
|
+
last = this.anchor;
|
1467
|
+
return this.eachNode(function(node) {
|
1468
|
+
node.insertAfter(last);
|
1469
|
+
return last = node.lastElement();
|
1470
|
+
});
|
1471
|
+
}
|
1472
|
+
};
|
1473
|
+
|
1474
|
+
DynamicNode.prototype.replace = function(sets) {
|
1475
|
+
var set;
|
1476
|
+
this.clear();
|
1477
|
+
this.nodeSets.update((function() {
|
1478
|
+
var _i, _len, _results;
|
1479
|
+
_results = [];
|
1480
|
+
for (_i = 0, _len = sets.length; _i < _len; _i++) {
|
1481
|
+
set = sets[_i];
|
1482
|
+
_results.push(new Collection(set));
|
1483
|
+
}
|
1484
|
+
return _results;
|
1485
|
+
})());
|
1486
|
+
return this.rebuild();
|
1487
|
+
};
|
1488
|
+
|
1489
|
+
DynamicNode.prototype.appendNodeSet = function(nodes) {
|
1490
|
+
return this.insertNodeSet(this.nodeSets.length, nodes);
|
1491
|
+
};
|
1492
|
+
|
1493
|
+
DynamicNode.prototype.deleteNodeSet = function(index) {
|
1494
|
+
var node, _i, _len, _ref;
|
1495
|
+
_ref = this.nodeSets[index];
|
1496
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1497
|
+
node = _ref[_i];
|
1498
|
+
node.remove();
|
1499
|
+
}
|
1500
|
+
return this.nodeSets.deleteAt(index);
|
1501
|
+
};
|
1502
|
+
|
1503
|
+
DynamicNode.prototype.insertNodeSet = function(index, nodes) {
|
1504
|
+
var last, node, _i, _len, _ref, _ref1;
|
1505
|
+
last = ((_ref = this.nodeSets[index - 1]) != null ? (_ref1 = _ref.last()) != null ? _ref1.lastElement() : void 0 : void 0) || this.anchor;
|
1506
|
+
for (_i = 0, _len = nodes.length; _i < _len; _i++) {
|
1507
|
+
node = nodes[_i];
|
1508
|
+
node.insertAfter(last);
|
1509
|
+
last = node.lastElement();
|
1510
|
+
}
|
1511
|
+
return this.nodeSets.insertAt(index, new Collection(nodes));
|
1512
|
+
};
|
1513
|
+
|
1514
|
+
DynamicNode.prototype.clear = function() {
|
1515
|
+
return this.eachNode(function(node) {
|
1516
|
+
return node.remove();
|
1517
|
+
});
|
1518
|
+
};
|
1519
|
+
|
1520
|
+
DynamicNode.prototype.remove = function() {
|
1521
|
+
this.clear();
|
1522
|
+
return this.anchor.parentNode.removeChild(this.anchor);
|
1523
|
+
};
|
1524
|
+
|
1525
|
+
DynamicNode.prototype.append = function(inside) {
|
1526
|
+
inside.appendChild(this.anchor);
|
1527
|
+
return this.rebuild();
|
1528
|
+
};
|
1529
|
+
|
1530
|
+
DynamicNode.prototype.insertAfter = function(after) {
|
1531
|
+
after.parentNode.insertBefore(this.anchor, after.nextSibling);
|
1532
|
+
return this.rebuild();
|
1533
|
+
};
|
1534
|
+
|
1535
|
+
DynamicNode.prototype.lastElement = function() {
|
1536
|
+
var _ref, _ref1;
|
1537
|
+
return ((_ref = this.nodeSets.last()) != null ? (_ref1 = _ref.last()) != null ? _ref1.lastElement() : void 0 : void 0) || this.anchor;
|
1538
|
+
};
|
1539
|
+
|
1540
|
+
return DynamicNode;
|
1541
|
+
|
1542
|
+
})();
|
1543
|
+
|
1544
|
+
exports.DynamicNode = DynamicNode;
|
1545
|
+
|
1546
|
+
}).call(this);
|
1547
|
+
|
1548
|
+
};require['./compile'] = new function() {
|
1549
|
+
var exports = this;
|
1550
|
+
(function() {
|
1551
|
+
var Collection, Compile, DynamicNode, Node, Property, Serenade, compile, get, getValue, preventDefault, set, _ref;
|
1552
|
+
|
1553
|
+
Serenade = require('./serenade').Serenade;
|
1554
|
+
|
1555
|
+
Collection = require('./collection').Collection;
|
1556
|
+
|
1557
|
+
Node = require('./node').Node;
|
1558
|
+
|
1559
|
+
DynamicNode = require('./dynamic_node').DynamicNode;
|
1560
|
+
|
1561
|
+
_ref = require('./helpers'), get = _ref.get, set = _ref.set, preventDefault = _ref.preventDefault;
|
1562
|
+
|
1563
|
+
getValue = function(ast, model) {
|
1564
|
+
if (ast.bound && ast.value) {
|
1565
|
+
return get(model, ast.value, true);
|
1566
|
+
} else if (ast.value) {
|
1567
|
+
return ast.value;
|
1568
|
+
} else {
|
1569
|
+
return model;
|
1570
|
+
}
|
1571
|
+
};
|
1572
|
+
|
1573
|
+
Property = {
|
1574
|
+
style: function(ast, node, model, controller) {
|
1575
|
+
var update;
|
1576
|
+
update = function() {
|
1577
|
+
return node.element.style[ast.name] = getValue(ast, model);
|
1578
|
+
};
|
1579
|
+
update();
|
1580
|
+
if (ast.bound) {
|
1581
|
+
return typeof model.bind === "function" ? model.bind("change:" + ast.value, update) : void 0;
|
1582
|
+
}
|
1583
|
+
},
|
1584
|
+
event: function(ast, node, model, controller) {
|
1585
|
+
var _this = this;
|
1586
|
+
return Serenade.bindEvent(node.element, ast.name, function(e) {
|
1587
|
+
if (ast.preventDefault) {
|
1588
|
+
preventDefault(e);
|
1589
|
+
}
|
1590
|
+
return controller[ast.value](model, node.element, e);
|
1591
|
+
});
|
1592
|
+
},
|
1593
|
+
binding: function(ast, node, model, controller) {
|
1594
|
+
var domUpdated, element, modelUpdated, _ref1,
|
1595
|
+
_this = this;
|
1596
|
+
element = node.element;
|
1597
|
+
((_ref1 = node.ast.name) === "input" || _ref1 === "textarea" || _ref1 === "select") || (function() {
|
1598
|
+
throw SyntaxError("invalid node type " + node.ast.name + " for two way binding");
|
1599
|
+
})();
|
1600
|
+
ast.value || (function() {
|
1601
|
+
throw SyntaxError("cannot bind to whole model, please specify an attribute to bind to");
|
1602
|
+
})();
|
1603
|
+
domUpdated = function() {
|
1604
|
+
if (element.type === "checkbox") {
|
1605
|
+
return set(model, ast.value, element.checked);
|
1606
|
+
} else if (element.type === "radio") {
|
1607
|
+
if (element.checked) {
|
1608
|
+
return set(model, ast.value, element.getAttribute("value"));
|
1609
|
+
}
|
1610
|
+
} else {
|
1611
|
+
return set(model, ast.value, element.value);
|
1612
|
+
}
|
1613
|
+
};
|
1614
|
+
modelUpdated = function() {
|
1615
|
+
var val;
|
1616
|
+
if (element.type === "checkbox") {
|
1617
|
+
val = get(model, ast.value);
|
1618
|
+
return element.checked = !!val;
|
1619
|
+
} else if (element.type === "radio") {
|
1620
|
+
val = get(model, ast.value);
|
1621
|
+
if (val === element.getAttribute("value")) {
|
1622
|
+
return element.checked = true;
|
1623
|
+
}
|
1624
|
+
} else {
|
1625
|
+
val = get(model, ast.value);
|
1626
|
+
if (val === void 0) {
|
1627
|
+
val = "";
|
1628
|
+
}
|
1629
|
+
return element.value = val;
|
1630
|
+
}
|
1631
|
+
};
|
1632
|
+
modelUpdated();
|
1633
|
+
if (typeof model.bind === "function") {
|
1634
|
+
model.bind("change:" + ast.value, modelUpdated);
|
1635
|
+
}
|
1636
|
+
if (ast.name === "binding") {
|
1637
|
+
return Serenade.bindEvent(Serenade.document, "submit", function(e) {
|
1638
|
+
if (element.form === (e.target || e.srcElement)) {
|
1639
|
+
return domUpdated();
|
1640
|
+
}
|
1641
|
+
});
|
1642
|
+
} else {
|
1643
|
+
return Serenade.bindEvent(element, ast.name, domUpdated);
|
1644
|
+
}
|
1645
|
+
},
|
1646
|
+
attribute: function(ast, node, model, controller) {
|
1647
|
+
var element, update;
|
1648
|
+
if (ast.name === "binding") {
|
1649
|
+
return Property.binding(ast, node, model, controller);
|
1650
|
+
}
|
1651
|
+
element = node.element;
|
1652
|
+
update = function() {
|
1653
|
+
var classes, value;
|
1654
|
+
value = getValue(ast, model);
|
1655
|
+
if (ast.name === 'value') {
|
1656
|
+
return element.value = value || '';
|
1657
|
+
} else if (node.ast.name === 'input' && ast.name === 'checked') {
|
1658
|
+
return element.checked = !!value;
|
1659
|
+
} else if (ast.name === 'class') {
|
1660
|
+
classes = node.ast.classes;
|
1661
|
+
if (value !== void 0) {
|
1662
|
+
classes = classes.concat(value);
|
1663
|
+
}
|
1664
|
+
if (classes.length) {
|
1665
|
+
return element.setAttribute(ast.name, classes.join(' '));
|
1666
|
+
} else {
|
1667
|
+
return element.removeAttribute(ast.name);
|
1668
|
+
}
|
1669
|
+
} else if (value === void 0) {
|
1670
|
+
return element.removeAttribute(ast.name);
|
1671
|
+
} else {
|
1672
|
+
if (value === 0) {
|
1673
|
+
value = "0";
|
1674
|
+
}
|
1675
|
+
return element.setAttribute(ast.name, value);
|
1676
|
+
}
|
1677
|
+
};
|
1678
|
+
if (ast.bound) {
|
1679
|
+
if (typeof model.bind === "function") {
|
1680
|
+
model.bind("change:" + ast.value, update);
|
1681
|
+
}
|
1682
|
+
}
|
1683
|
+
return update();
|
1684
|
+
}
|
1685
|
+
};
|
1686
|
+
|
1687
|
+
Compile = {
|
1688
|
+
element: function(ast, model, controller) {
|
1689
|
+
var action, child, element, node, property, _i, _j, _len, _len1, _ref1, _ref2, _ref3;
|
1690
|
+
element = Serenade.document.createElement(ast.name);
|
1691
|
+
node = new Node(ast, element);
|
1692
|
+
if (ast.id) {
|
1693
|
+
element.setAttribute('id', ast.id);
|
1694
|
+
}
|
1695
|
+
if ((_ref1 = ast.classes) != null ? _ref1.length : void 0) {
|
1696
|
+
element.setAttribute('class', ast.classes.join(' '));
|
1697
|
+
}
|
1698
|
+
_ref2 = ast.properties;
|
1699
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
1700
|
+
property = _ref2[_i];
|
1701
|
+
action = Property[property.scope];
|
1702
|
+
if (action) {
|
1703
|
+
action(property, node, model, controller);
|
1704
|
+
} else {
|
1705
|
+
throw SyntaxError("" + property.scope + " is not a valid scope");
|
1706
|
+
}
|
1707
|
+
}
|
1708
|
+
_ref3 = ast.children;
|
1709
|
+
for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
|
1710
|
+
child = _ref3[_j];
|
1711
|
+
compile(child, model, controller).append(element);
|
1712
|
+
}
|
1713
|
+
return node;
|
1714
|
+
},
|
1715
|
+
view: function(ast, model, parent) {
|
1716
|
+
var controller, element;
|
1717
|
+
controller = Serenade.controllerFor(ast["arguments"][0]) || parent;
|
1718
|
+
element = Serenade.render(ast["arguments"][0], model, controller, parent);
|
1719
|
+
return new Node(ast, element);
|
1720
|
+
},
|
1721
|
+
helper: function(ast, model, controller) {
|
1722
|
+
var context, element, helperFunction, render;
|
1723
|
+
render = function(model, controller) {
|
1724
|
+
var child, fragment, node, _i, _len, _ref1;
|
1725
|
+
if (model == null) {
|
1726
|
+
model = model;
|
1727
|
+
}
|
1728
|
+
if (controller == null) {
|
1729
|
+
controller = controller;
|
1730
|
+
}
|
1731
|
+
fragment = Serenade.document.createDocumentFragment();
|
1732
|
+
_ref1 = ast.children;
|
1733
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
1734
|
+
child = _ref1[_i];
|
1735
|
+
node = compile(child, model, controller);
|
1736
|
+
node.append(fragment);
|
1737
|
+
}
|
1738
|
+
return fragment;
|
1739
|
+
};
|
1740
|
+
helperFunction = Serenade.Helpers[ast.command] || (function() {
|
1741
|
+
throw SyntaxError("no helper " + ast.command + " defined");
|
1742
|
+
})();
|
1743
|
+
context = {
|
1744
|
+
render: render,
|
1745
|
+
model: model,
|
1746
|
+
controller: controller
|
1747
|
+
};
|
1748
|
+
element = helperFunction.apply(context, ast["arguments"]);
|
1749
|
+
return new Node(ast, element);
|
1750
|
+
},
|
1751
|
+
text: function(ast, model, controller) {
|
1752
|
+
var getText, textNode;
|
1753
|
+
getText = function() {
|
1754
|
+
var value;
|
1755
|
+
value = getValue(ast, model);
|
1756
|
+
if (value === 0) {
|
1757
|
+
value = "0";
|
1758
|
+
}
|
1759
|
+
return value || "";
|
1760
|
+
};
|
1761
|
+
textNode = Serenade.document.createTextNode(getText());
|
1762
|
+
if (ast.bound) {
|
1763
|
+
if (typeof model.bind === "function") {
|
1764
|
+
model.bind("change:" + ast.value, function() {
|
1765
|
+
return textNode.nodeValue = getText();
|
1766
|
+
});
|
1767
|
+
}
|
1768
|
+
}
|
1769
|
+
return new Node(ast, textNode);
|
1770
|
+
},
|
1771
|
+
collection: function(ast, model, controller) {
|
1772
|
+
var collection, compileItem, dynamic, item,
|
1773
|
+
_this = this;
|
1774
|
+
compileItem = function(item) {
|
1775
|
+
var child, _i, _len, _ref1, _results;
|
1776
|
+
_ref1 = ast.children;
|
1777
|
+
_results = [];
|
1778
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
1779
|
+
child = _ref1[_i];
|
1780
|
+
_results.push(compile(child, item, controller));
|
1781
|
+
}
|
1782
|
+
return _results;
|
1783
|
+
};
|
1784
|
+
dynamic = new DynamicNode(ast);
|
1785
|
+
collection = get(model, ast["arguments"][0]);
|
1786
|
+
if (typeof collection.bind === "function") {
|
1787
|
+
collection.bind('set', function() {
|
1788
|
+
var item;
|
1789
|
+
return dynamic.replace((function() {
|
1790
|
+
var _i, _len, _results;
|
1791
|
+
_results = [];
|
1792
|
+
for (_i = 0, _len = collection.length; _i < _len; _i++) {
|
1793
|
+
item = collection[_i];
|
1794
|
+
_results.push(compileItem(item));
|
1795
|
+
}
|
1796
|
+
return _results;
|
1797
|
+
})());
|
1798
|
+
});
|
1799
|
+
collection.bind('update', function() {
|
1800
|
+
var item;
|
1801
|
+
return dynamic.replace((function() {
|
1802
|
+
var _i, _len, _results;
|
1803
|
+
_results = [];
|
1804
|
+
for (_i = 0, _len = collection.length; _i < _len; _i++) {
|
1805
|
+
item = collection[_i];
|
1806
|
+
_results.push(compileItem(item));
|
1807
|
+
}
|
1808
|
+
return _results;
|
1809
|
+
})());
|
1810
|
+
});
|
1811
|
+
collection.bind('add', function(item) {
|
1812
|
+
return dynamic.appendNodeSet(compileItem(item));
|
1813
|
+
});
|
1814
|
+
collection.bind('insert', function(index, item) {
|
1815
|
+
return dynamic.insertNodeSet(index, compileItem(item));
|
1816
|
+
});
|
1817
|
+
collection.bind('delete', function(index) {
|
1818
|
+
return dynamic.deleteNodeSet(index);
|
1819
|
+
});
|
1820
|
+
}
|
1821
|
+
dynamic.replace((function() {
|
1822
|
+
var _i, _len, _results;
|
1823
|
+
_results = [];
|
1824
|
+
for (_i = 0, _len = collection.length; _i < _len; _i++) {
|
1825
|
+
item = collection[_i];
|
1826
|
+
_results.push(compileItem(item));
|
1827
|
+
}
|
1828
|
+
return _results;
|
1829
|
+
})());
|
1830
|
+
return dynamic;
|
1831
|
+
},
|
1832
|
+
"in": function(ast, model, controller) {
|
1833
|
+
var dynamic, update;
|
1834
|
+
dynamic = new DynamicNode(ast);
|
1835
|
+
update = function() {
|
1836
|
+
var child, nodes, value;
|
1837
|
+
value = get(model, ast["arguments"][0]);
|
1838
|
+
if (value) {
|
1839
|
+
nodes = (function() {
|
1840
|
+
var _i, _len, _ref1, _results;
|
1841
|
+
_ref1 = ast.children;
|
1842
|
+
_results = [];
|
1843
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
1844
|
+
child = _ref1[_i];
|
1845
|
+
_results.push(compile(child, value, controller));
|
1846
|
+
}
|
1847
|
+
return _results;
|
1848
|
+
})();
|
1849
|
+
return dynamic.replace([nodes]);
|
1850
|
+
} else {
|
1851
|
+
return dynamic.clear();
|
1852
|
+
}
|
1853
|
+
};
|
1854
|
+
update();
|
1855
|
+
if (typeof model.bind === "function") {
|
1856
|
+
model.bind("change:" + ast["arguments"][0], update);
|
1857
|
+
}
|
1858
|
+
return dynamic;
|
1859
|
+
},
|
1860
|
+
"if": function(ast, model, controller) {
|
1861
|
+
var dynamic, update;
|
1862
|
+
dynamic = new DynamicNode(ast);
|
1863
|
+
update = function() {
|
1864
|
+
var child, nodes, value;
|
1865
|
+
value = get(model, ast["arguments"][0]);
|
1866
|
+
if (value) {
|
1867
|
+
nodes = (function() {
|
1868
|
+
var _i, _len, _ref1, _results;
|
1869
|
+
_ref1 = ast.children;
|
1870
|
+
_results = [];
|
1871
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
1872
|
+
child = _ref1[_i];
|
1873
|
+
_results.push(compile(child, model, controller));
|
1874
|
+
}
|
1875
|
+
return _results;
|
1876
|
+
})();
|
1877
|
+
return dynamic.replace([nodes]);
|
1878
|
+
} else {
|
1879
|
+
return dynamic.clear();
|
1880
|
+
}
|
1881
|
+
};
|
1882
|
+
update();
|
1883
|
+
if (typeof model.bind === "function") {
|
1884
|
+
model.bind("change:" + ast["arguments"][0], update);
|
1885
|
+
}
|
1886
|
+
return dynamic;
|
1887
|
+
},
|
1888
|
+
unless: function(ast, model, controller) {
|
1889
|
+
var dynamic, update;
|
1890
|
+
dynamic = new DynamicNode(ast);
|
1891
|
+
update = function() {
|
1892
|
+
var child, nodes, value;
|
1893
|
+
value = get(model, ast["arguments"][0]);
|
1894
|
+
if (value) {
|
1895
|
+
return dynamic.clear();
|
1896
|
+
} else {
|
1897
|
+
nodes = (function() {
|
1898
|
+
var _i, _len, _ref1, _results;
|
1899
|
+
_ref1 = ast.children;
|
1900
|
+
_results = [];
|
1901
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
1902
|
+
child = _ref1[_i];
|
1903
|
+
_results.push(compile(child, model, controller));
|
1904
|
+
}
|
1905
|
+
return _results;
|
1906
|
+
})();
|
1907
|
+
return dynamic.replace([nodes]);
|
1908
|
+
}
|
1909
|
+
};
|
1910
|
+
update();
|
1911
|
+
if (typeof model.bind === "function") {
|
1912
|
+
model.bind("change:" + ast["arguments"][0], update);
|
1913
|
+
}
|
1914
|
+
return dynamic;
|
1915
|
+
}
|
1916
|
+
};
|
1917
|
+
|
1918
|
+
compile = function(ast, model, controller) {
|
1919
|
+
var action;
|
1920
|
+
action = Compile[ast.type];
|
1921
|
+
if (action) {
|
1922
|
+
return action(ast, model, controller);
|
1923
|
+
} else {
|
1924
|
+
throw SyntaxError("unknown type '" + ast.type + "'");
|
1925
|
+
}
|
1926
|
+
};
|
1927
|
+
|
1928
|
+
exports.compile = compile;
|
1929
|
+
|
1930
|
+
}).call(this);
|
1931
|
+
|
1932
|
+
};require['./parser'] = new function() {
|
1933
|
+
var exports = this;
|
1934
|
+
/* Jison generated parser */
|
1935
|
+
var parser = (function(){
|
1936
|
+
var parser = {trace: function trace() { },
|
1937
|
+
yy: {},
|
1938
|
+
symbols_: {"error":2,"Root":3,"Element":4,"ElementIdentifier":5,"AnyIdentifier":6,"#":7,".":8,"[":9,"]":10,"PropertyList":11,"WHITESPACE":12,"Text":13,"INDENT":14,"ChildList":15,"OUTDENT":16,"TextList":17,"Bound":18,"STRING_LITERAL":19,"Child":20,"TERMINATOR":21,"Instruction":22,"Property":23,"=":24,"!":25,":":26,"-":27,"VIEW":28,"COLLECTION":29,"IF":30,"UNLESS":31,"IN":32,"IDENTIFIER":33,"@":34,"$accept":0,"$end":1},
|
1939
|
+
terminals_: {2:"error",7:"#",8:".",9:"[",10:"]",12:"WHITESPACE",14:"INDENT",16:"OUTDENT",19:"STRING_LITERAL",21:"TERMINATOR",24:"=",25:"!",26:":",27:"-",28:"VIEW",29:"COLLECTION",30:"IF",31:"UNLESS",32:"IN",33:"IDENTIFIER",34:"@"},
|
1940
|
+
productions_: [0,[3,0],[3,1],[5,1],[5,3],[5,2],[5,2],[5,3],[4,1],[4,3],[4,4],[4,3],[4,4],[17,1],[17,3],[13,1],[13,1],[15,1],[15,3],[20,1],[20,1],[20,1],[11,1],[11,3],[23,3],[23,3],[23,4],[23,4],[23,3],[23,3],[22,3],[22,3],[22,3],[22,3],[22,3],[22,3],[22,3],[22,4],[6,1],[6,1],[6,1],[6,1],[6,1],[6,1],[18,2],[18,1]],
|
1941
|
+
performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
|
1942
|
+
|
1943
|
+
var $0 = $$.length - 1;
|
1944
|
+
switch (yystate) {
|
1945
|
+
case 1:this.$ = null;
|
1946
|
+
break;
|
1947
|
+
case 2:return this.$
|
1948
|
+
break;
|
1949
|
+
case 3:this.$ = {
|
1950
|
+
name: $$[$0],
|
1951
|
+
classes: []
|
1952
|
+
};
|
1953
|
+
break;
|
1954
|
+
case 4:this.$ = {
|
1955
|
+
name: $$[$0-2],
|
1956
|
+
id: $$[$0],
|
1957
|
+
classes: []
|
1958
|
+
};
|
1959
|
+
break;
|
1960
|
+
case 5:this.$ = {
|
1961
|
+
name: 'div',
|
1962
|
+
id: $$[$0],
|
1963
|
+
classes: []
|
1964
|
+
};
|
1965
|
+
break;
|
1966
|
+
case 6:this.$ = {
|
1967
|
+
name: 'div',
|
1968
|
+
classes: [$$[$0]]
|
1969
|
+
};
|
1970
|
+
break;
|
1971
|
+
case 7:this.$ = (function () {
|
1972
|
+
$$[$0-2].classes.push($$[$0]);
|
1973
|
+
return $$[$0-2];
|
1974
|
+
}());
|
1975
|
+
break;
|
1976
|
+
case 8:this.$ = {
|
1977
|
+
name: $$[$0].name,
|
1978
|
+
id: $$[$0].id,
|
1979
|
+
classes: $$[$0].classes,
|
1980
|
+
properties: [],
|
1981
|
+
children: [],
|
1982
|
+
type: 'element'
|
1983
|
+
};
|
1984
|
+
break;
|
1985
|
+
case 9:this.$ = $$[$0-2];
|
1986
|
+
break;
|
1987
|
+
case 10:this.$ = (function () {
|
1988
|
+
$$[$0-3].properties = $$[$0-1];
|
1989
|
+
return $$[$0-3];
|
1990
|
+
}());
|
1991
|
+
break;
|
1992
|
+
case 11:this.$ = (function () {
|
1993
|
+
$$[$0-2].children = $$[$0-2].children.concat($$[$0]);
|
1994
|
+
return $$[$0-2];
|
1995
|
+
}());
|
1996
|
+
break;
|
1997
|
+
case 12:this.$ = (function () {
|
1998
|
+
$$[$0-3].children = $$[$0-3].children.concat($$[$0-1]);
|
1999
|
+
return $$[$0-3];
|
2000
|
+
}());
|
2001
|
+
break;
|
2002
|
+
case 13:this.$ = [$$[$0]];
|
2003
|
+
break;
|
2004
|
+
case 14:this.$ = $$[$0-2].concat($$[$0]);
|
2005
|
+
break;
|
2006
|
+
case 15:this.$ = {
|
2007
|
+
type: 'text',
|
2008
|
+
value: $$[$0],
|
2009
|
+
bound: true
|
2010
|
+
};
|
2011
|
+
break;
|
2012
|
+
case 16:this.$ = {
|
2013
|
+
type: 'text',
|
2014
|
+
value: $$[$0],
|
2015
|
+
bound: false
|
2016
|
+
};
|
2017
|
+
break;
|
2018
|
+
case 17:this.$ = [].concat($$[$0]);
|
2019
|
+
break;
|
2020
|
+
case 18:this.$ = $$[$0-2].concat($$[$0]);
|
2021
|
+
break;
|
2022
|
+
case 19:this.$ = $$[$0];
|
2023
|
+
break;
|
2024
|
+
case 20:this.$ = $$[$0];
|
2025
|
+
break;
|
2026
|
+
case 21:this.$ = $$[$0];
|
2027
|
+
break;
|
2028
|
+
case 22:this.$ = [$$[$0]];
|
2029
|
+
break;
|
2030
|
+
case 23:this.$ = $$[$0-2].concat($$[$0]);
|
2031
|
+
break;
|
2032
|
+
case 24:this.$ = {
|
2033
|
+
name: $$[$0-2],
|
2034
|
+
value: $$[$0],
|
2035
|
+
bound: true,
|
2036
|
+
scope: 'attribute'
|
2037
|
+
};
|
2038
|
+
break;
|
2039
|
+
case 25:this.$ = {
|
2040
|
+
name: $$[$0-2],
|
2041
|
+
value: $$[$0],
|
2042
|
+
bound: true,
|
2043
|
+
scope: 'attribute'
|
2044
|
+
};
|
2045
|
+
break;
|
2046
|
+
case 26:this.$ = {
|
2047
|
+
name: $$[$0-3],
|
2048
|
+
value: $$[$0-1],
|
2049
|
+
bound: true,
|
2050
|
+
scope: 'attribute',
|
2051
|
+
preventDefault: true
|
2052
|
+
};
|
2053
|
+
break;
|
2054
|
+
case 27:this.$ = {
|
2055
|
+
name: $$[$0-3],
|
2056
|
+
value: $$[$0-1],
|
2057
|
+
bound: true,
|
2058
|
+
scope: 'attribute',
|
2059
|
+
preventDefault: true
|
2060
|
+
};
|
2061
|
+
break;
|
2062
|
+
case 28:this.$ = {
|
2063
|
+
name: $$[$0-2],
|
2064
|
+
value: $$[$0],
|
2065
|
+
bound: false,
|
2066
|
+
scope: 'attribute'
|
2067
|
+
};
|
2068
|
+
break;
|
2069
|
+
case 29:this.$ = (function () {
|
2070
|
+
$$[$0].scope = $$[$0-2];
|
2071
|
+
return $$[$0];
|
2072
|
+
}());
|
2073
|
+
break;
|
2074
|
+
case 30:this.$ = {
|
2075
|
+
"arguments": [],
|
2076
|
+
children: [],
|
2077
|
+
type: 'view'
|
2078
|
+
};
|
2079
|
+
break;
|
2080
|
+
case 31:this.$ = {
|
2081
|
+
"arguments": [],
|
2082
|
+
children: [],
|
2083
|
+
type: 'collection'
|
2084
|
+
};
|
2085
|
+
break;
|
2086
|
+
case 32:this.$ = {
|
2087
|
+
"arguments": [],
|
2088
|
+
children: [],
|
2089
|
+
type: 'if'
|
2090
|
+
};
|
2091
|
+
break;
|
2092
|
+
case 33:this.$ = {
|
2093
|
+
"arguments": [],
|
2094
|
+
children: [],
|
2095
|
+
type: 'unless'
|
2096
|
+
};
|
2097
|
+
break;
|
2098
|
+
case 34:this.$ = {
|
2099
|
+
"arguments": [],
|
2100
|
+
children: [],
|
2101
|
+
type: 'in'
|
2102
|
+
};
|
2103
|
+
break;
|
2104
|
+
case 35:this.$ = {
|
2105
|
+
command: $$[$0],
|
2106
|
+
"arguments": [],
|
2107
|
+
children: [],
|
2108
|
+
type: 'helper'
|
2109
|
+
};
|
2110
|
+
break;
|
2111
|
+
case 36:this.$ = (function () {
|
2112
|
+
$$[$0-2]["arguments"].push($$[$0].value);
|
2113
|
+
return $$[$0-2];
|
2114
|
+
}());
|
2115
|
+
break;
|
2116
|
+
case 37:this.$ = (function () {
|
2117
|
+
$$[$0-3].children = $$[$0-1];
|
2118
|
+
return $$[$0-3];
|
2119
|
+
}());
|
2120
|
+
break;
|
2121
|
+
case 38:this.$ = $$[$0];
|
2122
|
+
break;
|
2123
|
+
case 39:this.$ = $$[$0];
|
2124
|
+
break;
|
2125
|
+
case 40:this.$ = $$[$0];
|
2126
|
+
break;
|
2127
|
+
case 41:this.$ = $$[$0];
|
2128
|
+
break;
|
2129
|
+
case 42:this.$ = $$[$0];
|
2130
|
+
break;
|
2131
|
+
case 43:this.$ = $$[$0];
|
2132
|
+
break;
|
2133
|
+
case 44:this.$ = $$[$0];
|
2134
|
+
break;
|
2135
|
+
case 45:this.$ = (function () {}());
|
2136
|
+
break;
|
2137
|
+
}
|
2138
|
+
},
|
2139
|
+
table: [{1:[2,1],3:1,4:2,5:3,6:4,7:[1,5],8:[1,6],28:[1,7],29:[1,8],30:[1,9],31:[1,10],32:[1,11],33:[1,12]},{1:[3]},{1:[2,2],9:[1,13],12:[1,14],14:[1,15]},{1:[2,8],8:[1,16],9:[2,8],12:[2,8],14:[2,8],16:[2,8],21:[2,8]},{1:[2,3],7:[1,17],8:[2,3],9:[2,3],12:[2,3],14:[2,3],16:[2,3],21:[2,3]},{6:18,28:[1,7],29:[1,8],30:[1,9],31:[1,10],32:[1,11],33:[1,12]},{6:19,28:[1,7],29:[1,8],30:[1,9],31:[1,10],32:[1,11],33:[1,12]},{1:[2,38],7:[2,38],8:[2,38],9:[2,38],10:[2,38],12:[2,38],14:[2,38],16:[2,38],21:[2,38],24:[2,38],25:[2,38],26:[2,38]},{1:[2,39],7:[2,39],8:[2,39],9:[2,39],10:[2,39],12:[2,39],14:[2,39],16:[2,39],21:[2,39],24:[2,39],25:[2,39],26:[2,39]},{1:[2,40],7:[2,40],8:[2,40],9:[2,40],10:[2,40],12:[2,40],14:[2,40],16:[2,40],21:[2,40],24:[2,40],25:[2,40],26:[2,40]},{1:[2,41],7:[2,41],8:[2,41],9:[2,41],10:[2,41],12:[2,41],14:[2,41],16:[2,41],21:[2,41],24:[2,41],25:[2,41],26:[2,41]},{1:[2,42],7:[2,42],8:[2,42],9:[2,42],10:[2,42],12:[2,42],14:[2,42],16:[2,42],21:[2,42],24:[2,42],25:[2,42],26:[2,42]},{1:[2,43],7:[2,43],8:[2,43],9:[2,43],10:[2,43],12:[2,43],14:[2,43],16:[2,43],21:[2,43],24:[2,43],25:[2,43],26:[2,43]},{6:23,10:[1,20],11:21,23:22,28:[1,7],29:[1,8],30:[1,9],31:[1,10],32:[1,11],33:[1,12]},{13:24,18:25,19:[1,26],34:[1,27]},{4:30,5:3,6:4,7:[1,5],8:[1,6],13:34,15:28,17:32,18:25,19:[1,26],20:29,22:31,27:[1,33],28:[1,7],29:[1,8],30:[1,9],31:[1,10],32:[1,11],33:[1,12],34:[1,27]},{6:35,28:[1,7],29:[1,8],30:[1,9],31:[1,10],32:[1,11],33:[1,12]},{6:36,28:[1,7],29:[1,8],30:[1,9],31:[1,10],32:[1,11],33:[1,12]},{1:[2,5],8:[2,5],9:[2,5],12:[2,5],14:[2,5],16:[2,5],21:[2,5]},{1:[2,6],8:[2,6],9:[2,6],12:[2,6],14:[2,6],16:[2,6],21:[2,6]},{1:[2,9],9:[2,9],12:[2,9],14:[2,9],16:[2,9],21:[2,9]},{10:[1,37],12:[1,38]},{10:[2,22],12:[2,22]},{24:[1,39],26:[1,40]},{1:[2,11],9:[2,11],12:[2,11],14:[2,11],16:[2,11],21:[2,11]},{1:[2,15],9:[2,15],12:[2,15],14:[2,15],16:[2,15],21:[2,15]},{1:[2,16],9:[2,16],12:[2,16],14:[2,16],16:[2,16],21:[2,16]},{1:[2,45],6:41,9:[2,45],10:[2,45],12:[2,45],14:[2,45],16:[2,45],21:[2,45],25:[2,45],28:[1,7],29:[1,8],30:[1,9],31:[1,10],32:[1,11],33:[1,12]},{16:[1,42],21:[1,43]},{16:[2,17],21:[2,17]},{9:[1,13],12:[1,14],14:[1,15],16:[2,19],21:[2,19]},{12:[1,44],14:[1,45],16:[2,20],21:[2,20]},{12:[1,46],16:[2,21],21:[2,21]},{12:[1,47]},{12:[2,13],16:[2,13],21:[2,13]},{1:[2,7],8:[2,7],9:[2,7],12:[2,7],14:[2,7],16:[2,7],21:[2,7]},{1:[2,4],8:[2,4],9:[2,4],12:[2,4],14:[2,4],16:[2,4],21:[2,4]},{1:[2,10],9:[2,10],12:[2,10],14:[2,10],16:[2,10],21:[2,10]},{6:23,23:48,28:[1,7],29:[1,8],30:[1,9],31:[1,10],32:[1,11],33:[1,12]},{6:49,18:50,19:[1,51],28:[1,7],29:[1,8],30:[1,9],31:[1,10],32:[1,11],33:[1,12],34:[1,27]},{6:23,23:52,28:[1,7],29:[1,8],30:[1,9],31:[1,10],32:[1,11],33:[1,12]},{1:[2,44],9:[2,44],10:[2,44],12:[2,44],14:[2,44],16:[2,44],21:[2,44],25:[2,44]},{1:[2,12],9:[2,12],12:[2,12],14:[2,12],16:[2,12],21:[2,12]},{4:30,5:3,6:4,7:[1,5],8:[1,6],13:34,17:32,18:25,19:[1,26],20:53,22:31,27:[1,33],28:[1,7],29:[1,8],30:[1,9],31:[1,10],32:[1,11],33:[1,12],34:[1,27]},{13:54,18:25,19:[1,26],34:[1,27]},{4:30,5:3,6:4,7:[1,5],8:[1,6],13:34,15:55,17:32,18:25,19:[1,26],20:29,22:31,27:[1,33],28:[1,7],29:[1,8],30:[1,9],31:[1,10],32:[1,11],33:[1,12],34:[1,27]},{13:56,18:25,19:[1,26],34:[1,27]},{28:[1,57],29:[1,58],30:[1,59],31:[1,60],32:[1,61],33:[1,62]},{10:[2,23],12:[2,23]},{10:[2,24],12:[2,24],25:[1,63]},{10:[2,25],12:[2,25],25:[1,64]},{10:[2,28],12:[2,28]},{10:[2,29],12:[2,29]},{16:[2,18],21:[2,18]},{12:[2,36],14:[2,36],16:[2,36],21:[2,36]},{16:[1,65],21:[1,43]},{12:[2,14],16:[2,14],21:[2,14]},{12:[2,30],14:[2,30],16:[2,30],21:[2,30]},{12:[2,31],14:[2,31],16:[2,31],21:[2,31]},{12:[2,32],14:[2,32],16:[2,32],21:[2,32]},{12:[2,33],14:[2,33],16:[2,33],21:[2,33]},{12:[2,34],14:[2,34],16:[2,34],21:[2,34]},{12:[2,35],14:[2,35],16:[2,35],21:[2,35]},{10:[2,26],12:[2,26]},{10:[2,27],12:[2,27]},{12:[2,37],14:[2,37],16:[2,37],21:[2,37]}],
|
2140
|
+
defaultActions: {},
|
2141
|
+
parseError: function parseError(str, hash) {
|
2142
|
+
throw new Error(str);
|
2143
|
+
},
|
2144
|
+
parse: function parse(input) {
|
2145
|
+
var self = this, stack = [0], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
|
2146
|
+
this.lexer.setInput(input);
|
2147
|
+
this.lexer.yy = this.yy;
|
2148
|
+
this.yy.lexer = this.lexer;
|
2149
|
+
this.yy.parser = this;
|
2150
|
+
if (typeof this.lexer.yylloc == "undefined")
|
2151
|
+
this.lexer.yylloc = {};
|
2152
|
+
var yyloc = this.lexer.yylloc;
|
2153
|
+
lstack.push(yyloc);
|
2154
|
+
var ranges = this.lexer.options && this.lexer.options.ranges;
|
2155
|
+
if (typeof this.yy.parseError === "function")
|
2156
|
+
this.parseError = this.yy.parseError;
|
2157
|
+
function popStack(n) {
|
2158
|
+
stack.length = stack.length - 2 * n;
|
2159
|
+
vstack.length = vstack.length - n;
|
2160
|
+
lstack.length = lstack.length - n;
|
2161
|
+
}
|
2162
|
+
function lex() {
|
2163
|
+
var token;
|
2164
|
+
token = self.lexer.lex() || 1;
|
2165
|
+
if (typeof token !== "number") {
|
2166
|
+
token = self.symbols_[token] || token;
|
2167
|
+
}
|
2168
|
+
return token;
|
2169
|
+
}
|
2170
|
+
var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
|
2171
|
+
while (true) {
|
2172
|
+
state = stack[stack.length - 1];
|
2173
|
+
if (this.defaultActions[state]) {
|
2174
|
+
action = this.defaultActions[state];
|
2175
|
+
} else {
|
2176
|
+
if (symbol === null || typeof symbol == "undefined") {
|
2177
|
+
symbol = lex();
|
2178
|
+
}
|
2179
|
+
action = table[state] && table[state][symbol];
|
2180
|
+
}
|
2181
|
+
if (typeof action === "undefined" || !action.length || !action[0]) {
|
2182
|
+
var errStr = "";
|
2183
|
+
}
|
2184
|
+
if (action[0] instanceof Array && action.length > 1) {
|
2185
|
+
throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
|
2186
|
+
}
|
2187
|
+
switch (action[0]) {
|
2188
|
+
case 1:
|
2189
|
+
stack.push(symbol);
|
2190
|
+
vstack.push(this.lexer.yytext);
|
2191
|
+
lstack.push(this.lexer.yylloc);
|
2192
|
+
stack.push(action[1]);
|
2193
|
+
symbol = null;
|
2194
|
+
if (!preErrorSymbol) {
|
2195
|
+
yyleng = this.lexer.yyleng;
|
2196
|
+
yytext = this.lexer.yytext;
|
2197
|
+
yylineno = this.lexer.yylineno;
|
2198
|
+
yyloc = this.lexer.yylloc;
|
2199
|
+
if (recovering > 0)
|
2200
|
+
recovering--;
|
2201
|
+
} else {
|
2202
|
+
symbol = preErrorSymbol;
|
2203
|
+
preErrorSymbol = null;
|
2204
|
+
}
|
2205
|
+
break;
|
2206
|
+
case 2:
|
2207
|
+
len = this.productions_[action[1]][1];
|
2208
|
+
yyval.$ = vstack[vstack.length - len];
|
2209
|
+
yyval._$ = {first_line: lstack[lstack.length - (len || 1)].first_line, last_line: lstack[lstack.length - 1].last_line, first_column: lstack[lstack.length - (len || 1)].first_column, last_column: lstack[lstack.length - 1].last_column};
|
2210
|
+
if (ranges) {
|
2211
|
+
yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
|
2212
|
+
}
|
2213
|
+
r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
|
2214
|
+
if (typeof r !== "undefined") {
|
2215
|
+
return r;
|
2216
|
+
}
|
2217
|
+
if (len) {
|
2218
|
+
stack = stack.slice(0, -1 * len * 2);
|
2219
|
+
vstack = vstack.slice(0, -1 * len);
|
2220
|
+
lstack = lstack.slice(0, -1 * len);
|
2221
|
+
}
|
2222
|
+
stack.push(this.productions_[action[1]][0]);
|
2223
|
+
vstack.push(yyval.$);
|
2224
|
+
lstack.push(yyval._$);
|
2225
|
+
newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
|
2226
|
+
stack.push(newState);
|
2227
|
+
break;
|
2228
|
+
case 3:
|
2229
|
+
return true;
|
2230
|
+
}
|
2231
|
+
}
|
2232
|
+
return true;
|
2233
|
+
}
|
2234
|
+
};
|
2235
|
+
undefined/* Jison generated lexer */
|
2236
|
+
var lexer = (function(){
|
2237
|
+
var lexer = ({EOF:1,
|
2238
|
+
parseError:function parseError(str, hash) {
|
2239
|
+
if (this.yy.parser) {
|
2240
|
+
this.yy.parser.parseError(str, hash);
|
2241
|
+
} else {
|
2242
|
+
throw new Error(str);
|
2243
|
+
}
|
2244
|
+
},
|
2245
|
+
setInput:function (input) {
|
2246
|
+
this._input = input;
|
2247
|
+
this._more = this._less = this.done = false;
|
2248
|
+
this.yylineno = this.yyleng = 0;
|
2249
|
+
this.yytext = this.matched = this.match = '';
|
2250
|
+
this.conditionStack = ['INITIAL'];
|
2251
|
+
this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0};
|
2252
|
+
if (this.options.ranges) this.yylloc.range = [0,0];
|
2253
|
+
this.offset = 0;
|
2254
|
+
return this;
|
2255
|
+
},
|
2256
|
+
input:function () {
|
2257
|
+
var ch = this._input[0];
|
2258
|
+
this.yytext += ch;
|
2259
|
+
this.yyleng++;
|
2260
|
+
this.offset++;
|
2261
|
+
this.match += ch;
|
2262
|
+
this.matched += ch;
|
2263
|
+
var lines = ch.match(/(?:\r\n?|\n).*/g);
|
2264
|
+
if (lines) {
|
2265
|
+
this.yylineno++;
|
2266
|
+
this.yylloc.last_line++;
|
2267
|
+
} else {
|
2268
|
+
this.yylloc.last_column++;
|
2269
|
+
}
|
2270
|
+
if (this.options.ranges) this.yylloc.range[1]++;
|
2271
|
+
|
2272
|
+
this._input = this._input.slice(1);
|
2273
|
+
return ch;
|
2274
|
+
},
|
2275
|
+
unput:function (ch) {
|
2276
|
+
var len = ch.length;
|
2277
|
+
var lines = ch.split(/(?:\r\n?|\n)/g);
|
2278
|
+
|
2279
|
+
this._input = ch + this._input;
|
2280
|
+
this.yytext = this.yytext.substr(0, this.yytext.length-len-1);
|
2281
|
+
//this.yyleng -= len;
|
2282
|
+
this.offset -= len;
|
2283
|
+
var oldLines = this.match.split(/(?:\r\n?|\n)/g);
|
2284
|
+
this.match = this.match.substr(0, this.match.length-1);
|
2285
|
+
this.matched = this.matched.substr(0, this.matched.length-1);
|
2286
|
+
|
2287
|
+
if (lines.length-1) this.yylineno -= lines.length-1;
|
2288
|
+
var r = this.yylloc.range;
|
2289
|
+
|
2290
|
+
this.yylloc = {first_line: this.yylloc.first_line,
|
2291
|
+
last_line: this.yylineno+1,
|
2292
|
+
first_column: this.yylloc.first_column,
|
2293
|
+
last_column: lines ?
|
2294
|
+
(lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length:
|
2295
|
+
this.yylloc.first_column - len
|
2296
|
+
};
|
2297
|
+
|
2298
|
+
if (this.options.ranges) {
|
2299
|
+
this.yylloc.range = [r[0], r[0] + this.yyleng - len];
|
2300
|
+
}
|
2301
|
+
return this;
|
2302
|
+
},
|
2303
|
+
more:function () {
|
2304
|
+
this._more = true;
|
2305
|
+
return this;
|
2306
|
+
},
|
2307
|
+
less:function (n) {
|
2308
|
+
this.unput(this.match.slice(n));
|
2309
|
+
},
|
2310
|
+
pastInput:function () {
|
2311
|
+
var past = this.matched.substr(0, this.matched.length - this.match.length);
|
2312
|
+
return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
|
2313
|
+
},
|
2314
|
+
upcomingInput:function () {
|
2315
|
+
var next = this.match;
|
2316
|
+
if (next.length < 20) {
|
2317
|
+
next += this._input.substr(0, 20-next.length);
|
2318
|
+
}
|
2319
|
+
return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, "");
|
2320
|
+
},
|
2321
|
+
showPosition:function () {
|
2322
|
+
var pre = this.pastInput();
|
2323
|
+
var c = new Array(pre.length + 1).join("-");
|
2324
|
+
return pre + this.upcomingInput() + "\n" + c+"^";
|
2325
|
+
},
|
2326
|
+
next:function () {
|
2327
|
+
if (this.done) {
|
2328
|
+
return this.EOF;
|
2329
|
+
}
|
2330
|
+
if (!this._input) this.done = true;
|
2331
|
+
|
2332
|
+
var token,
|
2333
|
+
match,
|
2334
|
+
tempMatch,
|
2335
|
+
index,
|
2336
|
+
col,
|
2337
|
+
lines;
|
2338
|
+
if (!this._more) {
|
2339
|
+
this.yytext = '';
|
2340
|
+
this.match = '';
|
2341
|
+
}
|
2342
|
+
var rules = this._currentRules();
|
2343
|
+
for (var i=0;i < rules.length; i++) {
|
2344
|
+
tempMatch = this._input.match(this.rules[rules[i]]);
|
2345
|
+
if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
|
2346
|
+
match = tempMatch;
|
2347
|
+
index = i;
|
2348
|
+
if (!this.options.flex) break;
|
2349
|
+
}
|
2350
|
+
}
|
2351
|
+
if (match) {
|
2352
|
+
lines = match[0].match(/(?:\r\n?|\n).*/g);
|
2353
|
+
if (lines) this.yylineno += lines.length;
|
2354
|
+
this.yylloc = {first_line: this.yylloc.last_line,
|
2355
|
+
last_line: this.yylineno+1,
|
2356
|
+
first_column: this.yylloc.last_column,
|
2357
|
+
last_column: lines ? lines[lines.length-1].length-lines[lines.length-1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length};
|
2358
|
+
this.yytext += match[0];
|
2359
|
+
this.match += match[0];
|
2360
|
+
this.matches = match;
|
2361
|
+
this.yyleng = this.yytext.length;
|
2362
|
+
if (this.options.ranges) {
|
2363
|
+
this.yylloc.range = [this.offset, this.offset += this.yyleng];
|
2364
|
+
}
|
2365
|
+
this._more = false;
|
2366
|
+
this._input = this._input.slice(match[0].length);
|
2367
|
+
this.matched += match[0];
|
2368
|
+
token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]);
|
2369
|
+
if (this.done && this._input) this.done = false;
|
2370
|
+
if (token) return token;
|
2371
|
+
else return;
|
2372
|
+
}
|
2373
|
+
if (this._input === "") {
|
2374
|
+
return this.EOF;
|
2375
|
+
} else {
|
2376
|
+
return this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(),
|
2377
|
+
{text: "", token: null, line: this.yylineno});
|
2378
|
+
}
|
2379
|
+
},
|
2380
|
+
lex:function lex() {
|
2381
|
+
var r = this.next();
|
2382
|
+
if (typeof r !== 'undefined') {
|
2383
|
+
return r;
|
2384
|
+
} else {
|
2385
|
+
return this.lex();
|
2386
|
+
}
|
2387
|
+
},
|
2388
|
+
begin:function begin(condition) {
|
2389
|
+
this.conditionStack.push(condition);
|
2390
|
+
},
|
2391
|
+
popState:function popState() {
|
2392
|
+
return this.conditionStack.pop();
|
2393
|
+
},
|
2394
|
+
_currentRules:function _currentRules() {
|
2395
|
+
return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules;
|
2396
|
+
},
|
2397
|
+
topState:function () {
|
2398
|
+
return this.conditionStack[this.conditionStack.length-2];
|
2399
|
+
},
|
2400
|
+
pushState:function begin(condition) {
|
2401
|
+
this.begin(condition);
|
2402
|
+
}});
|
2403
|
+
lexer.options = {};
|
2404
|
+
lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
|
2405
|
+
|
2406
|
+
var YYSTATE=YY_START
|
2407
|
+
switch($avoiding_name_collisions) {
|
2408
|
+
}
|
2409
|
+
};
|
2410
|
+
lexer.rules = [];
|
2411
|
+
lexer.conditions = {"INITIAL":{"rules":[],"inclusive":true}};
|
2412
|
+
return lexer;})()
|
2413
|
+
parser.lexer = lexer;function Parser () { this.yy = {}; }Parser.prototype = parser;parser.Parser = Parser;
|
2414
|
+
return new Parser;
|
2415
|
+
})();
|
2416
|
+
if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
|
2417
|
+
exports.parser = parser;
|
2418
|
+
exports.Parser = parser.Parser;
|
2419
|
+
exports.parse = function () { return parser.parse.apply(parser, arguments); }
|
2420
|
+
exports.main = function commonjsMain(args) {
|
2421
|
+
if (!args[1])
|
2422
|
+
throw new Error('Usage: '+args[0]+' FILE');
|
2423
|
+
var source, cwd;
|
2424
|
+
if (typeof process !== 'undefined') {
|
2425
|
+
source = require('fs').readFileSync(require('path').resolve(args[1]), "utf8");
|
2426
|
+
} else {
|
2427
|
+
source = require("file").path(require("file").cwd()).join(args[1]).read({charset: "utf-8"});
|
2428
|
+
}
|
2429
|
+
return exports.parser.parse(source);
|
2430
|
+
}
|
2431
|
+
if (typeof module !== 'undefined' && require.main === module) {
|
2432
|
+
exports.main(typeof process !== 'undefined' ? process.argv.slice(1) : require("system").args);
|
2433
|
+
}
|
2434
|
+
}
|
2435
|
+
};require['./view'] = new function() {
|
2436
|
+
var exports = this;
|
2437
|
+
(function() {
|
2438
|
+
var Lexer, Serenade, View, compile, parser;
|
2439
|
+
|
2440
|
+
parser = require('./parser').parser;
|
2441
|
+
|
2442
|
+
Lexer = require('./lexer').Lexer;
|
2443
|
+
|
2444
|
+
compile = require('./compile').compile;
|
2445
|
+
|
2446
|
+
Serenade = require('./serenade').Serenade;
|
2447
|
+
|
2448
|
+
parser.lexer = {
|
2449
|
+
lex: function() {
|
2450
|
+
var tag, _ref;
|
2451
|
+
_ref = this.tokens[this.pos++] || [''], tag = _ref[0], this.yytext = _ref[1], this.yylineno = _ref[2];
|
2452
|
+
return tag;
|
2453
|
+
},
|
2454
|
+
setInput: function(tokens) {
|
2455
|
+
this.tokens = tokens;
|
2456
|
+
return this.pos = 0;
|
2457
|
+
},
|
2458
|
+
upcomingInput: function() {
|
2459
|
+
return "";
|
2460
|
+
}
|
2461
|
+
};
|
2462
|
+
|
2463
|
+
View = (function() {
|
2464
|
+
|
2465
|
+
function View(name, view) {
|
2466
|
+
this.name = name;
|
2467
|
+
this.view = view;
|
2468
|
+
}
|
2469
|
+
|
2470
|
+
View.prototype.parse = function() {
|
2471
|
+
if (typeof this.view === 'string') {
|
2472
|
+
return parser.parse(new Lexer().tokenize(this.view));
|
2473
|
+
} else {
|
2474
|
+
return this.view;
|
2475
|
+
}
|
2476
|
+
};
|
2477
|
+
|
2478
|
+
View.prototype.render = function(model, controller, parent) {
|
2479
|
+
var node;
|
2480
|
+
if (this.name) {
|
2481
|
+
controller || (controller = Serenade.controllerFor(this.name, model));
|
2482
|
+
}
|
2483
|
+
controller || (controller = {});
|
2484
|
+
if (typeof controller === "function") {
|
2485
|
+
controller = new controller(model, parent);
|
2486
|
+
}
|
2487
|
+
node = compile(this.parse(), model, controller);
|
2488
|
+
if (typeof controller.loaded === "function") {
|
2489
|
+
controller.loaded(model, node.element);
|
2490
|
+
}
|
2491
|
+
return node.element;
|
2492
|
+
};
|
2493
|
+
|
2494
|
+
return View;
|
2495
|
+
|
2496
|
+
})();
|
2497
|
+
|
2498
|
+
exports.View = View;
|
2499
|
+
|
2500
|
+
}).call(this);
|
2501
|
+
|
2502
|
+
};
|
2503
|
+
return require['./serenade'].Serenade
|
2504
|
+
}();
|
2505
|
+
|
2506
|
+
if(typeof define === 'function' && define.amd) {
|
2507
|
+
define(function() { return Serenade });
|
2508
|
+
} else { root.Serenade = Serenade }
|
2509
|
+
}(this));
|