spine-rails 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
 - data/Gemfile +4 -0
 - data/Rakefile +2 -0
 - data/lib/generators/spinejs/install/install_generator.rb +84 -0
 - data/lib/spine-rails/railtie.rb +18 -0
 - data/lib/spine-rails/version.rb +5 -0
 - data/lib/spine-rails.rb +12 -0
 - data/lib/tasks/get_js.rake +52 -0
 - data/spine-rails.gemspec +27 -0
 - data/tasks/get_js.rake +52 -0
 - data/vendor/assets/javascripts/icanhaz.js +401 -0
 - data/vendor/assets/javascripts/icanhaz.min.js +9 -0
 - data/vendor/assets/javascripts/json2.js +480 -0
 - data/vendor/assets/javascripts/spine.js +534 -0
 - data/vendor/assets/javascripts/spine.min.js +1 -0
 - metadata +125 -0
 
| 
         @@ -0,0 +1,534 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            (function(){
         
     | 
| 
      
 2 
     | 
    
         
            +
              
         
     | 
| 
      
 3 
     | 
    
         
            +
              var Spine;
         
     | 
| 
      
 4 
     | 
    
         
            +
              if (typeof exports !== "undefined") {
         
     | 
| 
      
 5 
     | 
    
         
            +
                Spine = exports;
         
     | 
| 
      
 6 
     | 
    
         
            +
              } else {
         
     | 
| 
      
 7 
     | 
    
         
            +
                Spine = this.Spine = {};
         
     | 
| 
      
 8 
     | 
    
         
            +
              }
         
     | 
| 
      
 9 
     | 
    
         
            +
              
         
     | 
| 
      
 10 
     | 
    
         
            +
              Spine.version = "0.0.4";
         
     | 
| 
      
 11 
     | 
    
         
            +
              
         
     | 
| 
      
 12 
     | 
    
         
            +
              var $ = Spine.$ = this.jQuery || this.Zepto || function(){ return arguments[0]; };
         
     | 
| 
      
 13 
     | 
    
         
            +
              
         
     | 
| 
      
 14 
     | 
    
         
            +
              var makeArray = Spine.makeArray = function(args){
         
     | 
| 
      
 15 
     | 
    
         
            +
                return Array.prototype.slice.call(args, 0);
         
     | 
| 
      
 16 
     | 
    
         
            +
              };
         
     | 
| 
      
 17 
     | 
    
         
            +
              
         
     | 
| 
      
 18 
     | 
    
         
            +
              // Shim Array, as these functions aren't in IE
         
     | 
| 
      
 19 
     | 
    
         
            +
              if (typeof Array.prototype.indexOf === "undefined")
         
     | 
| 
      
 20 
     | 
    
         
            +
                Array.prototype.indexOf = function(value){
         
     | 
| 
      
 21 
     | 
    
         
            +
                  for ( var i = 0; i < this.length; i++ )
         
     | 
| 
      
 22 
     | 
    
         
            +
                		if ( this[ i ] === value )
         
     | 
| 
      
 23 
     | 
    
         
            +
                			return i;
         
     | 
| 
      
 24 
     | 
    
         
            +
                	return -1;
         
     | 
| 
      
 25 
     | 
    
         
            +
                };
         
     | 
| 
      
 26 
     | 
    
         
            +
              
         
     | 
| 
      
 27 
     | 
    
         
            +
              var Events = Spine.Events = {
         
     | 
| 
      
 28 
     | 
    
         
            +
                bind: function(ev, callback) {
         
     | 
| 
      
 29 
     | 
    
         
            +
                  var evs   = ev.split(" ");
         
     | 
| 
      
 30 
     | 
    
         
            +
                  var calls = this._callbacks || (this._callbacks = {});
         
     | 
| 
      
 31 
     | 
    
         
            +
                  
         
     | 
| 
      
 32 
     | 
    
         
            +
                  for (var i=0; i < evs.length; i++)
         
     | 
| 
      
 33 
     | 
    
         
            +
                    (this._callbacks[evs[i]] || (this._callbacks[evs[i]] = [])).push(callback);
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  return this;
         
     | 
| 
      
 36 
     | 
    
         
            +
                },
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                trigger: function() {
         
     | 
| 
      
 39 
     | 
    
         
            +
                  var args = makeArray(arguments);
         
     | 
| 
      
 40 
     | 
    
         
            +
                  var ev   = args.shift();
         
     | 
| 
      
 41 
     | 
    
         
            +
                        
         
     | 
| 
      
 42 
     | 
    
         
            +
                  var list, calls, i, l;
         
     | 
| 
      
 43 
     | 
    
         
            +
                  if (!(calls = this._callbacks)) return false;
         
     | 
| 
      
 44 
     | 
    
         
            +
                  if (!(list  = this._callbacks[ev])) return false;
         
     | 
| 
      
 45 
     | 
    
         
            +
                  
         
     | 
| 
      
 46 
     | 
    
         
            +
                  for (i = 0, l = list.length; i < l; i++)
         
     | 
| 
      
 47 
     | 
    
         
            +
                    if (list[i].apply(this, args) === false)
         
     | 
| 
      
 48 
     | 
    
         
            +
                      break;
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                  return true;
         
     | 
| 
      
 51 
     | 
    
         
            +
                },
         
     | 
| 
      
 52 
     | 
    
         
            +
                
         
     | 
| 
      
 53 
     | 
    
         
            +
                unbind: function(ev, callback){
         
     | 
| 
      
 54 
     | 
    
         
            +
                  if ( !ev ) {
         
     | 
| 
      
 55 
     | 
    
         
            +
                    this._callbacks = {};
         
     | 
| 
      
 56 
     | 
    
         
            +
                    return this;
         
     | 
| 
      
 57 
     | 
    
         
            +
                  }
         
     | 
| 
      
 58 
     | 
    
         
            +
                  
         
     | 
| 
      
 59 
     | 
    
         
            +
                  var list, calls, i, l;
         
     | 
| 
      
 60 
     | 
    
         
            +
                  if (!(calls = this._callbacks)) return this;
         
     | 
| 
      
 61 
     | 
    
         
            +
                  if (!(list  = this._callbacks[ev])) return this;
         
     | 
| 
      
 62 
     | 
    
         
            +
                  
         
     | 
| 
      
 63 
     | 
    
         
            +
                  if ( !callback ) {
         
     | 
| 
      
 64 
     | 
    
         
            +
                    delete this._callbacks[ev];
         
     | 
| 
      
 65 
     | 
    
         
            +
                    return this;
         
     | 
| 
      
 66 
     | 
    
         
            +
                  }
         
     | 
| 
      
 67 
     | 
    
         
            +
                  
         
     | 
| 
      
 68 
     | 
    
         
            +
                  for (i = 0, l = list.length; i < l; i++)
         
     | 
| 
      
 69 
     | 
    
         
            +
                    if (callback === list[i]) {
         
     | 
| 
      
 70 
     | 
    
         
            +
                      list.splice(i, 1);
         
     | 
| 
      
 71 
     | 
    
         
            +
                      break;
         
     | 
| 
      
 72 
     | 
    
         
            +
                    }
         
     | 
| 
      
 73 
     | 
    
         
            +
                    
         
     | 
| 
      
 74 
     | 
    
         
            +
                  return this;
         
     | 
| 
      
 75 
     | 
    
         
            +
                }
         
     | 
| 
      
 76 
     | 
    
         
            +
              };
         
     | 
| 
      
 77 
     | 
    
         
            +
              
         
     | 
| 
      
 78 
     | 
    
         
            +
              var Log = Spine.Log = {
         
     | 
| 
      
 79 
     | 
    
         
            +
                trace: true,
         
     | 
| 
      
 80 
     | 
    
         
            +
                
         
     | 
| 
      
 81 
     | 
    
         
            +
                logPrefix: "(App)",
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                log: function(){
         
     | 
| 
      
 84 
     | 
    
         
            +
                  if ( !this.trace ) return;
         
     | 
| 
      
 85 
     | 
    
         
            +
                  if (typeof console == "undefined") return;
         
     | 
| 
      
 86 
     | 
    
         
            +
                  var args = makeArray(arguments);
         
     | 
| 
      
 87 
     | 
    
         
            +
                  if (this.logPrefix) args.unshift(this.logPrefix);
         
     | 
| 
      
 88 
     | 
    
         
            +
                  console.log.apply(console, args);
         
     | 
| 
      
 89 
     | 
    
         
            +
                  return this;
         
     | 
| 
      
 90 
     | 
    
         
            +
                }
         
     | 
| 
      
 91 
     | 
    
         
            +
              };
         
     | 
| 
      
 92 
     | 
    
         
            +
              
         
     | 
| 
      
 93 
     | 
    
         
            +
              // Classes (or prototypial inheritors)
         
     | 
| 
      
 94 
     | 
    
         
            +
              
         
     | 
| 
      
 95 
     | 
    
         
            +
              if (typeof Object.create !== "function")
         
     | 
| 
      
 96 
     | 
    
         
            +
                  Object.create = function(o) {
         
     | 
| 
      
 97 
     | 
    
         
            +
                    function F() {}
         
     | 
| 
      
 98 
     | 
    
         
            +
                    F.prototype = o;
         
     | 
| 
      
 99 
     | 
    
         
            +
                    return new F();
         
     | 
| 
      
 100 
     | 
    
         
            +
                  };
         
     | 
| 
      
 101 
     | 
    
         
            +
                  
         
     | 
| 
      
 102 
     | 
    
         
            +
              var moduleKeywords = ["included", "extended"];
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
              var Class = Spine.Class = {
         
     | 
| 
      
 105 
     | 
    
         
            +
                inherited: function(){},
         
     | 
| 
      
 106 
     | 
    
         
            +
                created: function(){},
         
     | 
| 
      
 107 
     | 
    
         
            +
                
         
     | 
| 
      
 108 
     | 
    
         
            +
                prototype: {
         
     | 
| 
      
 109 
     | 
    
         
            +
                  initialize: function(){},
         
     | 
| 
      
 110 
     | 
    
         
            +
                  init: function(){}
         
     | 
| 
      
 111 
     | 
    
         
            +
                },
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                create: function(include, extend){
         
     | 
| 
      
 114 
     | 
    
         
            +
                  var object = Object.create(this);
         
     | 
| 
      
 115 
     | 
    
         
            +
                  object.parent    = this;
         
     | 
| 
      
 116 
     | 
    
         
            +
                  object.prototype = object.fn = Object.create(this.prototype);
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
                  if (include) object.include(include);
         
     | 
| 
      
 119 
     | 
    
         
            +
                  if (extend)  object.extend(extend);
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
                  object.created();
         
     | 
| 
      
 122 
     | 
    
         
            +
                  this.inherited(object);
         
     | 
| 
      
 123 
     | 
    
         
            +
                  return object;
         
     | 
| 
      
 124 
     | 
    
         
            +
                },
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                init: function(){
         
     | 
| 
      
 127 
     | 
    
         
            +
                  var instance = Object.create(this.prototype);
         
     | 
| 
      
 128 
     | 
    
         
            +
                  instance.parent = this;
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
                  instance.initialize.apply(instance, arguments);
         
     | 
| 
      
 131 
     | 
    
         
            +
                  instance.init.apply(instance, arguments);
         
     | 
| 
      
 132 
     | 
    
         
            +
                  return instance;
         
     | 
| 
      
 133 
     | 
    
         
            +
                },
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
                proxy: function(func){
         
     | 
| 
      
 136 
     | 
    
         
            +
                  var thisObject = this;
         
     | 
| 
      
 137 
     | 
    
         
            +
                  return(function(){ 
         
     | 
| 
      
 138 
     | 
    
         
            +
                    return func.apply(thisObject, arguments); 
         
     | 
| 
      
 139 
     | 
    
         
            +
                  });
         
     | 
| 
      
 140 
     | 
    
         
            +
                },
         
     | 
| 
      
 141 
     | 
    
         
            +
                
         
     | 
| 
      
 142 
     | 
    
         
            +
                proxyAll: function(){
         
     | 
| 
      
 143 
     | 
    
         
            +
                  var functions = makeArray(arguments);
         
     | 
| 
      
 144 
     | 
    
         
            +
                  for (var i=0; i < functions.length; i++)
         
     | 
| 
      
 145 
     | 
    
         
            +
                    this[functions[i]] = this.proxy(this[functions[i]]);
         
     | 
| 
      
 146 
     | 
    
         
            +
                },
         
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
                include: function(obj){
         
     | 
| 
      
 149 
     | 
    
         
            +
                  for(var key in obj)
         
     | 
| 
      
 150 
     | 
    
         
            +
                    if (moduleKeywords.indexOf(key) == -1)
         
     | 
| 
      
 151 
     | 
    
         
            +
                      this.fn[key] = obj[key];
         
     | 
| 
      
 152 
     | 
    
         
            +
                  
         
     | 
| 
      
 153 
     | 
    
         
            +
                  var included = obj.included;
         
     | 
| 
      
 154 
     | 
    
         
            +
                  if (included) included.apply(this);
         
     | 
| 
      
 155 
     | 
    
         
            +
                  return this;
         
     | 
| 
      
 156 
     | 
    
         
            +
                },
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
                extend: function(obj){
         
     | 
| 
      
 159 
     | 
    
         
            +
                  for(var key in obj)
         
     | 
| 
      
 160 
     | 
    
         
            +
                    if (moduleKeywords.indexOf(key) == -1)
         
     | 
| 
      
 161 
     | 
    
         
            +
                      this[key] = obj[key];
         
     | 
| 
      
 162 
     | 
    
         
            +
                  
         
     | 
| 
      
 163 
     | 
    
         
            +
                  var extended = obj.extended;
         
     | 
| 
      
 164 
     | 
    
         
            +
                  if (extended) extended.apply(this);
         
     | 
| 
      
 165 
     | 
    
         
            +
                  return this;
         
     | 
| 
      
 166 
     | 
    
         
            +
                }
         
     | 
| 
      
 167 
     | 
    
         
            +
              };
         
     | 
| 
      
 168 
     | 
    
         
            +
              
         
     | 
| 
      
 169 
     | 
    
         
            +
              Class.prototype.proxy    = Class.proxy;
         
     | 
| 
      
 170 
     | 
    
         
            +
              Class.prototype.proxyAll = Class.proxyAll;
         
     | 
| 
      
 171 
     | 
    
         
            +
              Class.inst               = Class.init;
         
     | 
| 
      
 172 
     | 
    
         
            +
              Class.sub                = Class.create;
         
     | 
| 
      
 173 
     | 
    
         
            +
             
     | 
| 
      
 174 
     | 
    
         
            +
              // Models
         
     | 
| 
      
 175 
     | 
    
         
            +
              
         
     | 
| 
      
 176 
     | 
    
         
            +
              Spine.guid = function(){
         
     | 
| 
      
 177 
     | 
    
         
            +
                return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
         
     | 
| 
      
 178 
     | 
    
         
            +
                  var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
         
     | 
| 
      
 179 
     | 
    
         
            +
                  return v.toString(16);
         
     | 
| 
      
 180 
     | 
    
         
            +
                }).toUpperCase();      
         
     | 
| 
      
 181 
     | 
    
         
            +
              };
         
     | 
| 
      
 182 
     | 
    
         
            +
             
     | 
| 
      
 183 
     | 
    
         
            +
              var Model = Spine.Model = Class.create();
         
     | 
| 
      
 184 
     | 
    
         
            +
              
         
     | 
| 
      
 185 
     | 
    
         
            +
              Model.extend(Events);
         
     | 
| 
      
 186 
     | 
    
         
            +
             
     | 
| 
      
 187 
     | 
    
         
            +
              Model.extend({
         
     | 
| 
      
 188 
     | 
    
         
            +
                setup: function(name, atts){
         
     | 
| 
      
 189 
     | 
    
         
            +
                  var model = Model.sub();
         
     | 
| 
      
 190 
     | 
    
         
            +
                  if (name) model.name = name;
         
     | 
| 
      
 191 
     | 
    
         
            +
                  if (atts) model.attributes = atts;
         
     | 
| 
      
 192 
     | 
    
         
            +
                  return model;
         
     | 
| 
      
 193 
     | 
    
         
            +
                },
         
     | 
| 
      
 194 
     | 
    
         
            +
                
         
     | 
| 
      
 195 
     | 
    
         
            +
                created: function(sub){
         
     | 
| 
      
 196 
     | 
    
         
            +
                  this.records = {};
         
     | 
| 
      
 197 
     | 
    
         
            +
                  this.attributes = this.attributes ? 
         
     | 
| 
      
 198 
     | 
    
         
            +
                    makeArray(this.attributes) : [];
         
     | 
| 
      
 199 
     | 
    
         
            +
                },
         
     | 
| 
      
 200 
     | 
    
         
            +
             
     | 
| 
      
 201 
     | 
    
         
            +
                find: function(id){
         
     | 
| 
      
 202 
     | 
    
         
            +
                  var record = this.records[id];
         
     | 
| 
      
 203 
     | 
    
         
            +
                  if ( !record ) throw("Unknown record");
         
     | 
| 
      
 204 
     | 
    
         
            +
                  return record.clone();
         
     | 
| 
      
 205 
     | 
    
         
            +
                },
         
     | 
| 
      
 206 
     | 
    
         
            +
             
     | 
| 
      
 207 
     | 
    
         
            +
                exists: function(id){
         
     | 
| 
      
 208 
     | 
    
         
            +
                  try {
         
     | 
| 
      
 209 
     | 
    
         
            +
                    return this.find(id);
         
     | 
| 
      
 210 
     | 
    
         
            +
                  } catch (e) {
         
     | 
| 
      
 211 
     | 
    
         
            +
                    return false;
         
     | 
| 
      
 212 
     | 
    
         
            +
                  }
         
     | 
| 
      
 213 
     | 
    
         
            +
                },
         
     | 
| 
      
 214 
     | 
    
         
            +
             
     | 
| 
      
 215 
     | 
    
         
            +
                refresh: function(values){
         
     | 
| 
      
 216 
     | 
    
         
            +
                  if(Model.ajaxPrefix && this.prefix) {
         
     | 
| 
      
 217 
     | 
    
         
            +
                    values = values[this.prefix];
         
     | 
| 
      
 218 
     | 
    
         
            +
                  }
         
     | 
| 
      
 219 
     | 
    
         
            +
                  values = this.fromJSON(values);
         
     | 
| 
      
 220 
     | 
    
         
            +
                  this.records = {};
         
     | 
| 
      
 221 
     | 
    
         
            +
             
     | 
| 
      
 222 
     | 
    
         
            +
                  for (var i=0, il = values.length; i < il; i++) {    
         
     | 
| 
      
 223 
     | 
    
         
            +
                    var record = values[i];
         
     | 
| 
      
 224 
     | 
    
         
            +
                    record.newRecord = false;
         
     | 
| 
      
 225 
     | 
    
         
            +
                    this.records[record.id] = record;
         
     | 
| 
      
 226 
     | 
    
         
            +
                  }
         
     | 
| 
      
 227 
     | 
    
         
            +
             
     | 
| 
      
 228 
     | 
    
         
            +
                  this.trigger("refresh");
         
     | 
| 
      
 229 
     | 
    
         
            +
                  return this;
         
     | 
| 
      
 230 
     | 
    
         
            +
                },
         
     | 
| 
      
 231 
     | 
    
         
            +
             
     | 
| 
      
 232 
     | 
    
         
            +
                select: function(callback){
         
     | 
| 
      
 233 
     | 
    
         
            +
                  var result = [];
         
     | 
| 
      
 234 
     | 
    
         
            +
             
     | 
| 
      
 235 
     | 
    
         
            +
                  for (var key in this.records)
         
     | 
| 
      
 236 
     | 
    
         
            +
                    if (callback(this.records[key]))
         
     | 
| 
      
 237 
     | 
    
         
            +
                      result.push(this.records[key]);
         
     | 
| 
      
 238 
     | 
    
         
            +
             
     | 
| 
      
 239 
     | 
    
         
            +
                  return this.cloneArray(result);
         
     | 
| 
      
 240 
     | 
    
         
            +
                },
         
     | 
| 
      
 241 
     | 
    
         
            +
             
     | 
| 
      
 242 
     | 
    
         
            +
                findByAttribute: function(name, value){
         
     | 
| 
      
 243 
     | 
    
         
            +
                  for (var key in this.records)
         
     | 
| 
      
 244 
     | 
    
         
            +
                    if (this.records[key][name] == value)
         
     | 
| 
      
 245 
     | 
    
         
            +
                      return this.records[key].clone();
         
     | 
| 
      
 246 
     | 
    
         
            +
                },
         
     | 
| 
      
 247 
     | 
    
         
            +
             
     | 
| 
      
 248 
     | 
    
         
            +
                findAllByAttribute: function(name, value){
         
     | 
| 
      
 249 
     | 
    
         
            +
                  return(this.select(function(item){
         
     | 
| 
      
 250 
     | 
    
         
            +
                    return(item[name] == value);
         
     | 
| 
      
 251 
     | 
    
         
            +
                  }));
         
     | 
| 
      
 252 
     | 
    
         
            +
                },
         
     | 
| 
      
 253 
     | 
    
         
            +
             
     | 
| 
      
 254 
     | 
    
         
            +
                each: function(callback){
         
     | 
| 
      
 255 
     | 
    
         
            +
                  for (var key in this.records)
         
     | 
| 
      
 256 
     | 
    
         
            +
                    callback(this.records[key]);
         
     | 
| 
      
 257 
     | 
    
         
            +
                },
         
     | 
| 
      
 258 
     | 
    
         
            +
             
     | 
| 
      
 259 
     | 
    
         
            +
                all: function(){
         
     | 
| 
      
 260 
     | 
    
         
            +
                  return this.cloneArray(this.recordsValues());
         
     | 
| 
      
 261 
     | 
    
         
            +
                },
         
     | 
| 
      
 262 
     | 
    
         
            +
             
     | 
| 
      
 263 
     | 
    
         
            +
                first: function(){
         
     | 
| 
      
 264 
     | 
    
         
            +
                  var record = this.recordsValues()[0];
         
     | 
| 
      
 265 
     | 
    
         
            +
                  return(record && record.clone());
         
     | 
| 
      
 266 
     | 
    
         
            +
                },
         
     | 
| 
      
 267 
     | 
    
         
            +
             
     | 
| 
      
 268 
     | 
    
         
            +
                last: function(){
         
     | 
| 
      
 269 
     | 
    
         
            +
                  var values = this.recordsValues()
         
     | 
| 
      
 270 
     | 
    
         
            +
                  var record = values[values.length - 1];
         
     | 
| 
      
 271 
     | 
    
         
            +
                  return(record && record.clone());
         
     | 
| 
      
 272 
     | 
    
         
            +
                },
         
     | 
| 
      
 273 
     | 
    
         
            +
             
     | 
| 
      
 274 
     | 
    
         
            +
                count: function(){
         
     | 
| 
      
 275 
     | 
    
         
            +
                  return this.recordsValues().length;
         
     | 
| 
      
 276 
     | 
    
         
            +
                },
         
     | 
| 
      
 277 
     | 
    
         
            +
             
     | 
| 
      
 278 
     | 
    
         
            +
                deleteAll: function(){
         
     | 
| 
      
 279 
     | 
    
         
            +
                  for (var key in this.records)
         
     | 
| 
      
 280 
     | 
    
         
            +
                    delete this.records[key];
         
     | 
| 
      
 281 
     | 
    
         
            +
                },
         
     | 
| 
      
 282 
     | 
    
         
            +
             
     | 
| 
      
 283 
     | 
    
         
            +
                destroyAll: function(){
         
     | 
| 
      
 284 
     | 
    
         
            +
                  for (var key in this.records)
         
     | 
| 
      
 285 
     | 
    
         
            +
                    this.records[key].destroy();
         
     | 
| 
      
 286 
     | 
    
         
            +
                },
         
     | 
| 
      
 287 
     | 
    
         
            +
             
     | 
| 
      
 288 
     | 
    
         
            +
                update: function(id, atts){
         
     | 
| 
      
 289 
     | 
    
         
            +
                  this.find(id).updateAttributes(atts);
         
     | 
| 
      
 290 
     | 
    
         
            +
                },
         
     | 
| 
      
 291 
     | 
    
         
            +
             
     | 
| 
      
 292 
     | 
    
         
            +
                create: function(atts){
         
     | 
| 
      
 293 
     | 
    
         
            +
                  var record = this.init(atts);
         
     | 
| 
      
 294 
     | 
    
         
            +
                  return record.save();
         
     | 
| 
      
 295 
     | 
    
         
            +
                },
         
     | 
| 
      
 296 
     | 
    
         
            +
             
     | 
| 
      
 297 
     | 
    
         
            +
                destroy: function(id){
         
     | 
| 
      
 298 
     | 
    
         
            +
                  this.find(id).destroy();
         
     | 
| 
      
 299 
     | 
    
         
            +
                },
         
     | 
| 
      
 300 
     | 
    
         
            +
             
     | 
| 
      
 301 
     | 
    
         
            +
                sync: function(callback){
         
     | 
| 
      
 302 
     | 
    
         
            +
                  this.bind("change", callback);
         
     | 
| 
      
 303 
     | 
    
         
            +
                },
         
     | 
| 
      
 304 
     | 
    
         
            +
             
     | 
| 
      
 305 
     | 
    
         
            +
                fetch: function(callbackOrParams){
         
     | 
| 
      
 306 
     | 
    
         
            +
                  typeof(callbackOrParams) == 'function' ? this.bind("fetch", callbackOrParams) : this.trigger("fetch", callbackOrParams);
         
     | 
| 
      
 307 
     | 
    
         
            +
                },
         
     | 
| 
      
 308 
     | 
    
         
            +
             
     | 
| 
      
 309 
     | 
    
         
            +
                toJSON: function(){
         
     | 
| 
      
 310 
     | 
    
         
            +
                  return this.recordsValues();
         
     | 
| 
      
 311 
     | 
    
         
            +
                },
         
     | 
| 
      
 312 
     | 
    
         
            +
                
         
     | 
| 
      
 313 
     | 
    
         
            +
                fromJSON: function(objects){
         
     | 
| 
      
 314 
     | 
    
         
            +
                  if ( !objects ) return;
         
     | 
| 
      
 315 
     | 
    
         
            +
                  if (typeof objects == "string")
         
     | 
| 
      
 316 
     | 
    
         
            +
                    objects = JSON.parse(objects)
         
     | 
| 
      
 317 
     | 
    
         
            +
                  if (typeof objects.length == "number") {
         
     | 
| 
      
 318 
     | 
    
         
            +
                    var results = [];
         
     | 
| 
      
 319 
     | 
    
         
            +
                    for (var i=0; i < objects.length; i++)
         
     | 
| 
      
 320 
     | 
    
         
            +
                      results.push(this.init(objects[i]));
         
     | 
| 
      
 321 
     | 
    
         
            +
                    return results;
         
     | 
| 
      
 322 
     | 
    
         
            +
                  } else {
         
     | 
| 
      
 323 
     | 
    
         
            +
                    return this.init(objects);
         
     | 
| 
      
 324 
     | 
    
         
            +
                  }
         
     | 
| 
      
 325 
     | 
    
         
            +
                },
         
     | 
| 
      
 326 
     | 
    
         
            +
             
     | 
| 
      
 327 
     | 
    
         
            +
                // Private
         
     | 
| 
      
 328 
     | 
    
         
            +
             
     | 
| 
      
 329 
     | 
    
         
            +
                recordsValues: function(){
         
     | 
| 
      
 330 
     | 
    
         
            +
                  var result = [];
         
     | 
| 
      
 331 
     | 
    
         
            +
                  for (var key in this.records)
         
     | 
| 
      
 332 
     | 
    
         
            +
                    result.push(this.records[key]);
         
     | 
| 
      
 333 
     | 
    
         
            +
                  return result;
         
     | 
| 
      
 334 
     | 
    
         
            +
                },
         
     | 
| 
      
 335 
     | 
    
         
            +
             
     | 
| 
      
 336 
     | 
    
         
            +
                cloneArray: function(array){
         
     | 
| 
      
 337 
     | 
    
         
            +
                  var result = [];
         
     | 
| 
      
 338 
     | 
    
         
            +
                  for (var i=0; i < array.length; i++)
         
     | 
| 
      
 339 
     | 
    
         
            +
                    result.push(array[i].clone());
         
     | 
| 
      
 340 
     | 
    
         
            +
                  return result;
         
     | 
| 
      
 341 
     | 
    
         
            +
                }
         
     | 
| 
      
 342 
     | 
    
         
            +
              });
         
     | 
| 
      
 343 
     | 
    
         
            +
             
     | 
| 
      
 344 
     | 
    
         
            +
              Model.include({
         
     | 
| 
      
 345 
     | 
    
         
            +
                model: true,
         
     | 
| 
      
 346 
     | 
    
         
            +
                newRecord: true,
         
     | 
| 
      
 347 
     | 
    
         
            +
             
     | 
| 
      
 348 
     | 
    
         
            +
                init: function(atts){
         
     | 
| 
      
 349 
     | 
    
         
            +
                  if (atts) this.load(atts);
         
     | 
| 
      
 350 
     | 
    
         
            +
                  this.trigger("init", this);
         
     | 
| 
      
 351 
     | 
    
         
            +
                },
         
     | 
| 
      
 352 
     | 
    
         
            +
             
     | 
| 
      
 353 
     | 
    
         
            +
                isNew: function(){
         
     | 
| 
      
 354 
     | 
    
         
            +
                  return this.newRecord;
         
     | 
| 
      
 355 
     | 
    
         
            +
                },
         
     | 
| 
      
 356 
     | 
    
         
            +
                
         
     | 
| 
      
 357 
     | 
    
         
            +
                isValid: function(){
         
     | 
| 
      
 358 
     | 
    
         
            +
                  return(!this.validate());
         
     | 
| 
      
 359 
     | 
    
         
            +
                },
         
     | 
| 
      
 360 
     | 
    
         
            +
             
     | 
| 
      
 361 
     | 
    
         
            +
                validate: function(){ },
         
     | 
| 
      
 362 
     | 
    
         
            +
             
     | 
| 
      
 363 
     | 
    
         
            +
                load: function(atts){
         
     | 
| 
      
 364 
     | 
    
         
            +
                  for(var name in atts)
         
     | 
| 
      
 365 
     | 
    
         
            +
                    this[name] = atts[name];
         
     | 
| 
      
 366 
     | 
    
         
            +
                },
         
     | 
| 
      
 367 
     | 
    
         
            +
             
     | 
| 
      
 368 
     | 
    
         
            +
                attributes: function(){
         
     | 
| 
      
 369 
     | 
    
         
            +
                  var result = {};
         
     | 
| 
      
 370 
     | 
    
         
            +
                  for (var i=0; i < this.parent.attributes.length; i++) {
         
     | 
| 
      
 371 
     | 
    
         
            +
                    var attr = this.parent.attributes[i];
         
     | 
| 
      
 372 
     | 
    
         
            +
                    result[attr] = this[attr];
         
     | 
| 
      
 373 
     | 
    
         
            +
                  }
         
     | 
| 
      
 374 
     | 
    
         
            +
                  result.id = this.id;
         
     | 
| 
      
 375 
     | 
    
         
            +
                  return result;
         
     | 
| 
      
 376 
     | 
    
         
            +
                },
         
     | 
| 
      
 377 
     | 
    
         
            +
             
     | 
| 
      
 378 
     | 
    
         
            +
                eql: function(rec){
         
     | 
| 
      
 379 
     | 
    
         
            +
                  return(rec && rec.id === this.id && 
         
     | 
| 
      
 380 
     | 
    
         
            +
                         rec.parent === this.parent);
         
     | 
| 
      
 381 
     | 
    
         
            +
                },
         
     | 
| 
      
 382 
     | 
    
         
            +
             
     | 
| 
      
 383 
     | 
    
         
            +
                save: function(){
         
     | 
| 
      
 384 
     | 
    
         
            +
                  var error = this.validate();
         
     | 
| 
      
 385 
     | 
    
         
            +
                  if ( error ) {
         
     | 
| 
      
 386 
     | 
    
         
            +
                    this.trigger("error", this, error)
         
     | 
| 
      
 387 
     | 
    
         
            +
                    return false;
         
     | 
| 
      
 388 
     | 
    
         
            +
                  }
         
     | 
| 
      
 389 
     | 
    
         
            +
                  
         
     | 
| 
      
 390 
     | 
    
         
            +
                  this.trigger("beforeSave", this);
         
     | 
| 
      
 391 
     | 
    
         
            +
                  this.newRecord ? this.create() : this.update();
         
     | 
| 
      
 392 
     | 
    
         
            +
                  this.trigger("save", this);
         
     | 
| 
      
 393 
     | 
    
         
            +
                  return this;
         
     | 
| 
      
 394 
     | 
    
         
            +
                },
         
     | 
| 
      
 395 
     | 
    
         
            +
             
     | 
| 
      
 396 
     | 
    
         
            +
                updateAttribute: function(name, value){
         
     | 
| 
      
 397 
     | 
    
         
            +
                  this[name] = value;
         
     | 
| 
      
 398 
     | 
    
         
            +
                  return this.save();
         
     | 
| 
      
 399 
     | 
    
         
            +
                },
         
     | 
| 
      
 400 
     | 
    
         
            +
             
     | 
| 
      
 401 
     | 
    
         
            +
                updateAttributes: function(atts){
         
     | 
| 
      
 402 
     | 
    
         
            +
                  this.load(atts);
         
     | 
| 
      
 403 
     | 
    
         
            +
                  return this.save();
         
     | 
| 
      
 404 
     | 
    
         
            +
                },
         
     | 
| 
      
 405 
     | 
    
         
            +
                
         
     | 
| 
      
 406 
     | 
    
         
            +
                destroy: function(){
         
     | 
| 
      
 407 
     | 
    
         
            +
                  this.trigger("beforeDestroy", this);
         
     | 
| 
      
 408 
     | 
    
         
            +
                  delete this.parent.records[this.id];
         
     | 
| 
      
 409 
     | 
    
         
            +
                  this.destroyed = true;
         
     | 
| 
      
 410 
     | 
    
         
            +
                  this.trigger("destroy", this);
         
     | 
| 
      
 411 
     | 
    
         
            +
                  this.trigger("change", this, "destroy");
         
     | 
| 
      
 412 
     | 
    
         
            +
                },
         
     | 
| 
      
 413 
     | 
    
         
            +
             
     | 
| 
      
 414 
     | 
    
         
            +
                dup: function(){
         
     | 
| 
      
 415 
     | 
    
         
            +
                  var result = this.parent.init(this.attributes());
         
     | 
| 
      
 416 
     | 
    
         
            +
                  result.newRecord = this.newRecord;
         
     | 
| 
      
 417 
     | 
    
         
            +
                  return result;
         
     | 
| 
      
 418 
     | 
    
         
            +
                },
         
     | 
| 
      
 419 
     | 
    
         
            +
                
         
     | 
| 
      
 420 
     | 
    
         
            +
                clone: function(){
         
     | 
| 
      
 421 
     | 
    
         
            +
                  return Object.create(this);
         
     | 
| 
      
 422 
     | 
    
         
            +
                },
         
     | 
| 
      
 423 
     | 
    
         
            +
             
     | 
| 
      
 424 
     | 
    
         
            +
                reload: function(){
         
     | 
| 
      
 425 
     | 
    
         
            +
                  if ( this.newRecord ) return this;
         
     | 
| 
      
 426 
     | 
    
         
            +
                  var original = this.parent.find(this.id);
         
     | 
| 
      
 427 
     | 
    
         
            +
                  this.load(original.attributes());
         
     | 
| 
      
 428 
     | 
    
         
            +
                  return original;
         
     | 
| 
      
 429 
     | 
    
         
            +
                },
         
     | 
| 
      
 430 
     | 
    
         
            +
             
     | 
| 
      
 431 
     | 
    
         
            +
                toJSON: function(){
         
     | 
| 
      
 432 
     | 
    
         
            +
                  return(this.attributes());
         
     | 
| 
      
 433 
     | 
    
         
            +
                },
         
     | 
| 
      
 434 
     | 
    
         
            +
                
         
     | 
| 
      
 435 
     | 
    
         
            +
                exists: function(){
         
     | 
| 
      
 436 
     | 
    
         
            +
                  return(this.id && this.id in this.parent.records);
         
     | 
| 
      
 437 
     | 
    
         
            +
                },
         
     | 
| 
      
 438 
     | 
    
         
            +
             
     | 
| 
      
 439 
     | 
    
         
            +
                // Private
         
     | 
| 
      
 440 
     | 
    
         
            +
             
     | 
| 
      
 441 
     | 
    
         
            +
                update: function(){
         
     | 
| 
      
 442 
     | 
    
         
            +
                  this.trigger("beforeUpdate", this);
         
     | 
| 
      
 443 
     | 
    
         
            +
                  var records = this.parent.records;
         
     | 
| 
      
 444 
     | 
    
         
            +
                  records[this.id].load(this.attributes());
         
     | 
| 
      
 445 
     | 
    
         
            +
                  var clone = records[this.id].clone();
         
     | 
| 
      
 446 
     | 
    
         
            +
                  this.trigger("update", clone);
         
     | 
| 
      
 447 
     | 
    
         
            +
                  this.trigger("change", clone, "update");
         
     | 
| 
      
 448 
     | 
    
         
            +
                },
         
     | 
| 
      
 449 
     | 
    
         
            +
             
     | 
| 
      
 450 
     | 
    
         
            +
                create: function(){
         
     | 
| 
      
 451 
     | 
    
         
            +
                  this.trigger("beforeCreate", this);
         
     | 
| 
      
 452 
     | 
    
         
            +
                  if ( !this.id ) this.id = Spine.guid();
         
     | 
| 
      
 453 
     | 
    
         
            +
                  this.newRecord   = false;
         
     | 
| 
      
 454 
     | 
    
         
            +
                  var records      = this.parent.records;
         
     | 
| 
      
 455 
     | 
    
         
            +
                  records[this.id] = this.dup();
         
     | 
| 
      
 456 
     | 
    
         
            +
                  var clone        = records[this.id].clone();
         
     | 
| 
      
 457 
     | 
    
         
            +
                  this.trigger("create", clone);
         
     | 
| 
      
 458 
     | 
    
         
            +
                  this.trigger("change", clone, "create");
         
     | 
| 
      
 459 
     | 
    
         
            +
                },
         
     | 
| 
      
 460 
     | 
    
         
            +
                
         
     | 
| 
      
 461 
     | 
    
         
            +
                bind: function(events, callback){
         
     | 
| 
      
 462 
     | 
    
         
            +
                  return this.parent.bind(events, this.proxy(function(record){
         
     | 
| 
      
 463 
     | 
    
         
            +
                    if ( record && this.eql(record) )
         
     | 
| 
      
 464 
     | 
    
         
            +
                      callback.apply(this, arguments);
         
     | 
| 
      
 465 
     | 
    
         
            +
                  }));
         
     | 
| 
      
 466 
     | 
    
         
            +
                },
         
     | 
| 
      
 467 
     | 
    
         
            +
                
         
     | 
| 
      
 468 
     | 
    
         
            +
                trigger: function(){
         
     | 
| 
      
 469 
     | 
    
         
            +
                  return this.parent.trigger.apply(this.parent, arguments);
         
     | 
| 
      
 470 
     | 
    
         
            +
                }
         
     | 
| 
      
 471 
     | 
    
         
            +
              });
         
     | 
| 
      
 472 
     | 
    
         
            +
              
         
     | 
| 
      
 473 
     | 
    
         
            +
              // Controllers
         
     | 
| 
      
 474 
     | 
    
         
            +
              
         
     | 
| 
      
 475 
     | 
    
         
            +
              var eventSplitter = /^(\w+)\s*(.*)$/;
         
     | 
| 
      
 476 
     | 
    
         
            +
              
         
     | 
| 
      
 477 
     | 
    
         
            +
              var Controller = Spine.Controller = Class.create({
         
     | 
| 
      
 478 
     | 
    
         
            +
                tag: "div",
         
     | 
| 
      
 479 
     | 
    
         
            +
                
         
     | 
| 
      
 480 
     | 
    
         
            +
                initialize: function(options){
         
     | 
| 
      
 481 
     | 
    
         
            +
                  this.options = options;
         
     | 
| 
      
 482 
     | 
    
         
            +
             
     | 
| 
      
 483 
     | 
    
         
            +
                  for (var key in this.options)
         
     | 
| 
      
 484 
     | 
    
         
            +
                    this[key] = this.options[key];
         
     | 
| 
      
 485 
     | 
    
         
            +
             
     | 
| 
      
 486 
     | 
    
         
            +
                  if (!this.el) this.el = document.createElement(this.tag);
         
     | 
| 
      
 487 
     | 
    
         
            +
                  this.el = $(this.el);
         
     | 
| 
      
 488 
     | 
    
         
            +
             
     | 
| 
      
 489 
     | 
    
         
            +
                  if ( !this.events ) this.events = this.parent.events;
         
     | 
| 
      
 490 
     | 
    
         
            +
                  if ( !this.elements ) this.elements = this.parent.elements;
         
     | 
| 
      
 491 
     | 
    
         
            +
             
     | 
| 
      
 492 
     | 
    
         
            +
                  if (this.events) this.delegateEvents();
         
     | 
| 
      
 493 
     | 
    
         
            +
                  if (this.elements) this.refreshElements();
         
     | 
| 
      
 494 
     | 
    
         
            +
                  if (this.proxied) this.proxyAll.apply(this, this.proxied);
         
     | 
| 
      
 495 
     | 
    
         
            +
                },
         
     | 
| 
      
 496 
     | 
    
         
            +
                    
         
     | 
| 
      
 497 
     | 
    
         
            +
                $: function(selector){
         
     | 
| 
      
 498 
     | 
    
         
            +
                  return $(selector, this.el);
         
     | 
| 
      
 499 
     | 
    
         
            +
                },
         
     | 
| 
      
 500 
     | 
    
         
            +
                    
         
     | 
| 
      
 501 
     | 
    
         
            +
                delegateEvents: function(){
         
     | 
| 
      
 502 
     | 
    
         
            +
                  for (var key in this.events) {
         
     | 
| 
      
 503 
     | 
    
         
            +
                    var methodName = this.events[key];
         
     | 
| 
      
 504 
     | 
    
         
            +
                    var method     = this.proxy(this[methodName]);
         
     | 
| 
      
 505 
     | 
    
         
            +
             
     | 
| 
      
 506 
     | 
    
         
            +
                    var match      = key.match(eventSplitter);
         
     | 
| 
      
 507 
     | 
    
         
            +
                    var eventName  = match[1], selector = match[2];
         
     | 
| 
      
 508 
     | 
    
         
            +
             
     | 
| 
      
 509 
     | 
    
         
            +
                    if (selector === '') {
         
     | 
| 
      
 510 
     | 
    
         
            +
                      this.el.bind(eventName, method);
         
     | 
| 
      
 511 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 512 
     | 
    
         
            +
                      this.el.delegate(selector, eventName, method);
         
     | 
| 
      
 513 
     | 
    
         
            +
                    }
         
     | 
| 
      
 514 
     | 
    
         
            +
                  }
         
     | 
| 
      
 515 
     | 
    
         
            +
                },
         
     | 
| 
      
 516 
     | 
    
         
            +
                
         
     | 
| 
      
 517 
     | 
    
         
            +
                refreshElements: function(){
         
     | 
| 
      
 518 
     | 
    
         
            +
                  for (var key in this.elements) {
         
     | 
| 
      
 519 
     | 
    
         
            +
                    this[this.elements[key]] = this.$(key);
         
     | 
| 
      
 520 
     | 
    
         
            +
                  }
         
     | 
| 
      
 521 
     | 
    
         
            +
                },
         
     | 
| 
      
 522 
     | 
    
         
            +
                
         
     | 
| 
      
 523 
     | 
    
         
            +
                delay: function(func, timeout){
         
     | 
| 
      
 524 
     | 
    
         
            +
                  setTimeout(this.proxy(func), timeout || 0);
         
     | 
| 
      
 525 
     | 
    
         
            +
                }
         
     | 
| 
      
 526 
     | 
    
         
            +
              });
         
     | 
| 
      
 527 
     | 
    
         
            +
              
         
     | 
| 
      
 528 
     | 
    
         
            +
              Controller.include(Events);
         
     | 
| 
      
 529 
     | 
    
         
            +
              Controller.include(Log);
         
     | 
| 
      
 530 
     | 
    
         
            +
              
         
     | 
| 
      
 531 
     | 
    
         
            +
              Spine.App = Class.create();
         
     | 
| 
      
 532 
     | 
    
         
            +
              Spine.App.extend(Events)
         
     | 
| 
      
 533 
     | 
    
         
            +
              Controller.fn.App = Spine.App;
         
     | 
| 
      
 534 
     | 
    
         
            +
            })();
         
     | 
| 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            (function(){var g;if(typeof exports!=="undefined"){g=exports}else{g=this.Spine={}}g.version="0.0.4";var e=g.$=this.jQuery||this.Zepto||function(){return arguments[0]};var b=g.makeArray=function(k){return Array.prototype.slice.call(k,0)};if(typeof Array.prototype.indexOf==="undefined"){Array.prototype.indexOf=function(l){for(var k=0;k<this.length;k++){if(this[k]===l){return k}}return -1}}var j=g.Events={bind:function(n,o){var k=n.split(" ");var m=this._callbacks||(this._callbacks={});for(var l=0;l<k.length;l++){(this._callbacks[k[l]]||(this._callbacks[k[l]]=[])).push(o)}return this},trigger:function(){var m=b(arguments);var p=m.shift();var q,o,n,k;if(!(o=this._callbacks)){return false}if(!(q=this._callbacks[p])){return false}for(n=0,k=q.length;n<k;n++){if(q[n].apply(this,m)===false){break}}return true},unbind:function(o,q){if(!o){this._callbacks={};return this}var p,n,m,k;if(!(n=this._callbacks)){return this}if(!(p=this._callbacks[o])){return this}if(!q){delete this._callbacks[o];return this}for(m=0,k=p.length;m<k;m++){if(q===p[m]){p.splice(m,1);break}}return this}};var f=g.Log={trace:true,logPrefix:"(App)",log:function(){if(!this.trace){return}if(typeof console=="undefined"){return}var k=b(arguments);if(this.logPrefix){k.unshift(this.logPrefix)}console.log.apply(console,k);return this}};if(typeof Object.create!=="function"){Object.create=function(l){function k(){}k.prototype=l;return new k()}}var h=["included","extended"];var a=g.Class={inherited:function(){},created:function(){},prototype:{initialize:function(){},init:function(){}},create:function(k,m){var l=Object.create(this);l.parent=this;l.prototype=l.fn=Object.create(this.prototype);if(k){l.include(k)}if(m){l.extend(m)}l.created();this.inherited(l);return l},init:function(){var k=Object.create(this.prototype);k.parent=this;k.initialize.apply(k,arguments);k.init.apply(k,arguments);return k},proxy:function(l){var k=this;return(function(){return l.apply(k,arguments)})},proxyAll:function(){var l=b(arguments);for(var k=0;k<l.length;k++){this[l[k]]=this.proxy(this[l[k]])}},include:function(m){for(var k in m){if(h.indexOf(k)==-1){this.fn[k]=m[k]}}var l=m.included;if(l){l.apply(this)}return this},extend:function(m){for(var l in m){if(h.indexOf(l)==-1){this[l]=m[l]}}var k=m.extended;if(k){k.apply(this)}return this}};a.prototype.proxy=a.proxy;a.prototype.proxyAll=a.proxyAll;a.inst=a.init;a.sub=a.create;g.guid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(m){var l=Math.random()*16|0,k=m=="x"?l:(l&3|8);return k.toString(16)}).toUpperCase()};var c=g.Model=a.create();c.extend(j);c.extend({setup:function(l,m){var k=c.sub();if(l){k.name=l}if(m){k.attributes=m}return k},created:function(k){this.records={};this.attributes=this.attributes?b(this.attributes):[]},find:function(l){var k=this.records[l];if(!k){throw ("Unknown record")}return k.clone()},exists:function(l){try{return this.find(l)}catch(k){return false}},refresh:function(m){m=this.fromJSON(m);this.records={};for(var n=0,l=m.length;n<l;n++){var k=m[n];k.newRecord=false;this.records[k.id]=k}this.trigger("refresh");return this},select:function(m){var k=[];for(var l in this.records){if(m(this.records[l])){k.push(this.records[l])}}return this.cloneArray(k)},findByAttribute:function(k,m){for(var l in this.records){if(this.records[l][k]==m){return this.records[l].clone()}}},findAllByAttribute:function(k,l){return(this.select(function(m){return(m[k]==l)}))},each:function(l){for(var k in this.records){l(this.records[k])}},all:function(){return this.cloneArray(this.recordsValues())},first:function(){var k=this.recordsValues()[0];return(k&&k.clone())},last:function(){var l=this.recordsValues();var k=l[l.length-1];return(k&&k.clone())},count:function(){return this.recordsValues().length},deleteAll:function(){for(var k in this.records){delete this.records[k]}},destroyAll:function(){for(var k in this.records){this.records[k].destroy()}},update:function(l,k){this.find(l).updateAttributes(k)},create:function(l){var k=this.init(l);return k.save()},destroy:function(k){this.find(k).destroy()},sync:function(k){this.bind("change",k)},fetch:function(k){k?this.bind("fetch",k):this.trigger("fetch")},toJSON:function(){return this.recordsValues()},fromJSON:function(m){if(!m){return}if(typeof m=="string"){m=JSON.parse(m)}if(typeof m.length=="number"){var l=[];for(var k=0;k<m.length;k++){l.push(this.init(m[k]))}return l}else{return this.init(m)}},recordsValues:function(){var k=[];for(var l in this.records){k.push(this.records[l])}return k},cloneArray:function(m){var k=[];for(var l=0;l<m.length;l++){k.push(m[l].clone())}return k}});c.include({model:true,newRecord:true,init:function(k){if(k){this.load(k)}this.trigger("init",this)},isNew:function(){return this.newRecord},isValid:function(){return(!this.validate())},validate:function(){},load:function(l){for(var k in l){this[k]=l[k]}},attributes:function(){var l={};for(var m=0;m<this.parent.attributes.length;m++){var k=this.parent.attributes[m];l[k]=this[k]}l.id=this.id;return l},eql:function(k){return(k&&k.id===this.id&&k.parent===this.parent)},save:function(){var k=this.validate();if(k){this.trigger("error",this,k);return false}this.trigger("beforeSave",this);this.newRecord?this.create():this.update();this.trigger("save",this);return this},updateAttribute:function(k,l){this[k]=l;return this.save()},updateAttributes:function(k){this.load(k);return this.save()},destroy:function(){this.trigger("beforeDestroy",this);delete this.parent.records[this.id];this.destroyed=true;this.trigger("destroy",this);this.trigger("change",this,"destroy")},dup:function(){var k=this.parent.init(this.attributes());k.newRecord=this.newRecord;return k},clone:function(){return Object.create(this)},reload:function(){if(this.newRecord){return this}var k=this.parent.find(this.id);this.load(k.attributes());return k},toJSON:function(){return(this.attributes())},exists:function(){return(this.id&&this.id in this.parent.records)},update:function(){this.trigger("beforeUpdate",this);var k=this.parent.records;k[this.id].load(this.attributes());var l=k[this.id].clone();this.trigger("update",l);this.trigger("change",l,"update")},create:function(){this.trigger("beforeCreate",this);if(!this.id){this.id=g.guid()}this.newRecord=false;var k=this.parent.records;k[this.id]=this.dup();var l=k[this.id].clone();this.trigger("create",l);this.trigger("change",l,"create")},bind:function(k,l){return this.parent.bind(k,this.proxy(function(m){if(m&&this.eql(m)){l.apply(this,arguments)}}))},trigger:function(){return this.parent.trigger.apply(this.parent,arguments)}});var i=/^(\w+)\s*(.*)$/;var d=g.Controller=a.create({tag:"div",initialize:function(k){this.options=k;for(var l in this.options){this[l]=this.options[l]}if(!this.el){this.el=document.createElement(this.tag)}this.el=e(this.el);if(!this.events){this.events=this.parent.events}if(!this.elements){this.elements=this.parent.elements}if(this.events){this.delegateEvents()}if(this.elements){this.refreshElements()}if(this.proxied){this.proxyAll.apply(this,this.proxied)}},$:function(k){return e(k,this.el)},delegateEvents:function(){for(var o in this.events){var m=this.events[o];var p=this.proxy(this[m]);var n=o.match(i);var l=n[1],k=n[2];if(k===""){this.el.bind(l,p)}else{this.el.delegate(k,l,p)}}},refreshElements:function(){for(var k in this.elements){this[this.elements[k]]=this.$(k)}},delay:function(k,l){setTimeout(this.proxy(k),l||0)}});d.include(j);d.include(f);g.App=a.create();g.App.extend(j);d.fn.App=g.App})();
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,125 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification 
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: spine-rails
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version 
         
     | 
| 
      
 4 
     | 
    
         
            +
              prerelease: 
         
     | 
| 
      
 5 
     | 
    
         
            +
              version: 0.0.1
         
     | 
| 
      
 6 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 7 
     | 
    
         
            +
            authors: 
         
     | 
| 
      
 8 
     | 
    
         
            +
            - Andrew Gertig
         
     | 
| 
      
 9 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 10 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 11 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2011-05-20 00:00:00 -04:00
         
     | 
| 
      
 14 
     | 
    
         
            +
            default_executable: 
         
     | 
| 
      
 15 
     | 
    
         
            +
            dependencies: 
         
     | 
| 
      
 16 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 17 
     | 
    
         
            +
              name: railties
         
     | 
| 
      
 18 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 19 
     | 
    
         
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         
     | 
| 
      
 20 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 21 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 22 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 23 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 24 
     | 
    
         
            +
                    version: "3.0"
         
     | 
| 
      
 25 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 26 
     | 
    
         
            +
              version_requirements: *id001
         
     | 
| 
      
 27 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 28 
     | 
    
         
            +
              name: thor
         
     | 
| 
      
 29 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 30 
     | 
    
         
            +
              requirement: &id002 !ruby/object:Gem::Requirement 
         
     | 
| 
      
 31 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 32 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 33 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 34 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 35 
     | 
    
         
            +
                    version: "0.14"
         
     | 
| 
      
 36 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 37 
     | 
    
         
            +
              version_requirements: *id002
         
     | 
| 
      
 38 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 39 
     | 
    
         
            +
              name: curb
         
     | 
| 
      
 40 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 41 
     | 
    
         
            +
              requirement: &id003 !ruby/object:Gem::Requirement 
         
     | 
| 
      
 42 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 43 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 44 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 45 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 46 
     | 
    
         
            +
                    version: 0.7.15
         
     | 
| 
      
 47 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 48 
     | 
    
         
            +
              version_requirements: *id003
         
     | 
| 
      
 49 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 50 
     | 
    
         
            +
              name: bundler
         
     | 
| 
      
 51 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 52 
     | 
    
         
            +
              requirement: &id004 !ruby/object:Gem::Requirement 
         
     | 
| 
      
 53 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 54 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 55 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 56 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 57 
     | 
    
         
            +
                    version: 1.0.0
         
     | 
| 
      
 58 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 59 
     | 
    
         
            +
              version_requirements: *id004
         
     | 
| 
      
 60 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 61 
     | 
    
         
            +
              name: rails
         
     | 
| 
      
 62 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 63 
     | 
    
         
            +
              requirement: &id005 !ruby/object:Gem::Requirement 
         
     | 
| 
      
 64 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 65 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 66 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 67 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 68 
     | 
    
         
            +
                    version: "3.0"
         
     | 
| 
      
 69 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 70 
     | 
    
         
            +
              version_requirements: *id005
         
     | 
| 
      
 71 
     | 
    
         
            +
            description: A gem of convenience.
         
     | 
| 
      
 72 
     | 
    
         
            +
            email: 
         
     | 
| 
      
 73 
     | 
    
         
            +
            - andrew.gertig@gmail.com
         
     | 
| 
      
 74 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
            files: 
         
     | 
| 
      
 81 
     | 
    
         
            +
            - .gitignore
         
     | 
| 
      
 82 
     | 
    
         
            +
            - Gemfile
         
     | 
| 
      
 83 
     | 
    
         
            +
            - Rakefile
         
     | 
| 
      
 84 
     | 
    
         
            +
            - lib/generators/spinejs/install/install_generator.rb
         
     | 
| 
      
 85 
     | 
    
         
            +
            - lib/spine-rails.rb
         
     | 
| 
      
 86 
     | 
    
         
            +
            - lib/spine-rails/railtie.rb
         
     | 
| 
      
 87 
     | 
    
         
            +
            - lib/spine-rails/version.rb
         
     | 
| 
      
 88 
     | 
    
         
            +
            - lib/tasks/get_js.rake
         
     | 
| 
      
 89 
     | 
    
         
            +
            - spine-rails.gemspec
         
     | 
| 
      
 90 
     | 
    
         
            +
            - tasks/get_js.rake
         
     | 
| 
      
 91 
     | 
    
         
            +
            - vendor/assets/javascripts/icanhaz.js
         
     | 
| 
      
 92 
     | 
    
         
            +
            - vendor/assets/javascripts/icanhaz.min.js
         
     | 
| 
      
 93 
     | 
    
         
            +
            - vendor/assets/javascripts/json2.js
         
     | 
| 
      
 94 
     | 
    
         
            +
            - vendor/assets/javascripts/spine.js
         
     | 
| 
      
 95 
     | 
    
         
            +
            - vendor/assets/javascripts/spine.min.js
         
     | 
| 
      
 96 
     | 
    
         
            +
            has_rdoc: true
         
     | 
| 
      
 97 
     | 
    
         
            +
            homepage: ""
         
     | 
| 
      
 98 
     | 
    
         
            +
            licenses: []
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 101 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
            require_paths: 
         
     | 
| 
      
 104 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 105 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 106 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 107 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 108 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 109 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 110 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 111 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 112 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 113 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 114 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 115 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 116 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 117 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
            rubyforge_project: spine-rails
         
     | 
| 
      
 120 
     | 
    
         
            +
            rubygems_version: 1.6.2
         
     | 
| 
      
 121 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 122 
     | 
    
         
            +
            specification_version: 3
         
     | 
| 
      
 123 
     | 
    
         
            +
            summary: Add Spine.js, json2.js, and icanhaz.js to your Rails app.
         
     | 
| 
      
 124 
     | 
    
         
            +
            test_files: []
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     |