spine-rails 0.0.1 → 0.0.2

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.
@@ -1,9 +0,0 @@
1
- (function(i){var n=function(){var f=function(){};f.prototype={otag:"{{",ctag:"}}",pragmas:{},buffer:[],pragmas_implemented:{"IMPLICIT-ITERATOR":true},context:{},render:function(a,b,c,d){if(!d){this.context=b;this.buffer=[]}if(!this.includes("",a))if(d)return a;else{this.send(a);return}a=this.render_pragmas(a);a=this.render_section(a,b,c);if(d)return this.render_tags(a,b,c,d);this.render_tags(a,b,c,d)},send:function(a){a!=""&&this.buffer.push(a)},render_pragmas:function(a){if(!this.includes("%",a))return a;
2
- var b=this;return a.replace(RegExp(this.otag+"%([\\w-]+) ?([\\w]+=[\\w]+)?"+this.ctag),function(c,d,e){if(!b.pragmas_implemented[d])throw{message:"This implementation of mustache doesn't understand the '"+d+"' pragma"};b.pragmas[d]={};if(e){c=e.split("=");b.pragmas[d][c[0]]=c[1]}return""})},render_partial:function(a,b,c){a=this.trim(a);if(!c||c[a]===undefined)throw{message:"unknown_partial '"+a+"'"};if(typeof b[a]!="object")return this.render(c[a],b,c,true);return this.render(c[a],b[a],c,true)},render_section:function(a,
3
- b,c){if(!this.includes("#",a)&&!this.includes("^",a))return a;var d=this;return a.replace(RegExp(this.otag+"(\\^|\\#)\\s*(.+)\\s*"+this.ctag+"\n*([\\s\\S]+?)"+this.otag+"\\/\\s*\\2\\s*"+this.ctag+"\\s*","mg"),function(e,j,k,h){e=d.find(k,b);if(j=="^")return!e||d.is_array(e)&&e.length===0?d.render(h,b,c,true):"";else if(j=="#")return d.is_array(e)?d.map(e,function(g){return d.render(h,d.create_context(g),c,true)}).join(""):d.is_object(e)?d.render(h,d.create_context(e),c,true):typeof e==="function"?
4
- e.call(b,h,function(g){return d.render(g,b,c,true)}):e?d.render(h,b,c,true):""})},render_tags:function(a,b,c,d){var e=this,j=function(){return RegExp(e.otag+"(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?"+e.ctag+"+","g")},k=j(),h=function(o,m,l){switch(m){case "!":return"";case "=":e.set_delimiters(l);k=j();return"";case ">":return e.render_partial(l,b,c);case "{":return e.find(l,b);default:return e.escape(e.find(l,b))}};a=a.split("\n");for(var g=0;g<a.length;g++){a[g]=a[g].replace(k,h,this);d||this.send(a[g])}if(d)return a.join("\n")},
5
- set_delimiters:function(a){a=a.split(" ");this.otag=this.escape_regex(a[0]);this.ctag=this.escape_regex(a[1])},escape_regex:function(a){if(!arguments.callee.sRE)arguments.callee.sRE=RegExp("(\\/|\\.|\\*|\\+|\\?|\\||\\(|\\)|\\[|\\]|\\{|\\}|\\\\)","g");return a.replace(arguments.callee.sRE,"\\$1")},find:function(a,b){a=this.trim(a);var c;if(b[a]===false||b[a]===0||b[a])c=b[a];else if(this.context[a]===false||this.context[a]===0||this.context[a])c=this.context[a];if(typeof c==="function")return c.apply(b);
6
- if(c!==undefined)return c;return""},includes:function(a,b){return b.indexOf(this.otag+a)!=-1},escape:function(a){a=String(a===null?"":a);return a.replace(/&(?!\w+;)|["<>\\]/g,function(b){switch(b){case "&":return"&amp;";case "\\":return"\\\\";case '"':return'"';case "<":return"&lt;";case ">":return"&gt;";default:return b}})},create_context:function(a){if(this.is_object(a))return a;else{var b=".";if(this.pragmas["IMPLICIT-ITERATOR"])b=this.pragmas["IMPLICIT-ITERATOR"].iterator;var c={};c[b]=a;return c}},
7
- is_object:function(a){return a&&typeof a=="object"},is_array:function(a){return Object.prototype.toString.call(a)==="[object Array]"},trim:function(a){return a.replace(/^\s*|\s*$/g,"")},map:function(a,b){if(typeof a.map=="function")return a.map(b);else{for(var c=[],d=a.length,e=0;e<d;e++)c.push(b(a[e]));return c}}};return{name:"mustache.js",version:"0.3.0",to_html:function(a,b,c,d){var e=new f;if(d)e.send=d;e.render(a,b,c);if(!d)return e.buffer.join("\n")}}}();window.ich=new function(){var f=this;
8
- f.VERSION="0.9";f.templates={};f.partials={};f.addTemplate=function(a,b){if(f[a])throw"Invalid name: "+a+".";if(f.templates[a])throw'Template " + name + " exists';f.templates[a]=b;f[a]=function(c,d){c=c||{};var e=n.to_html(f.templates[a],c,f.partials);return d?e:i(e)}};f.addPartial=function(a,b){if(f.partials[a])throw'Partial " + name + " exists';else f.partials[a]=b};f.grabTemplates=function(){i('script[type="text/html"]').each(function(a,b){var c=i(typeof a==="number"?b:a),d="".trim?c.html().trim():
9
- i.trim(c.html());f[c.hasClass("partial")?"addPartial":"addTemplate"](c.attr("id"),d);c.remove()})};f.clearAll=function(){for(var a in f.templates)delete f[a];f.templates={};f.partials={}};f.refresh=function(){f.clearAll();f.grabTemplates()}};i(function(){ich.grabTemplates()})})(window.jQuery||window.Zepto);
@@ -1,534 +0,0 @@
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
- })();