eyeballs 0.3.7 → 0.4.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/CHANGELOG +6 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +47 -0
- data/README.md +62 -17
- data/Rakefile +1 -1
- data/dist/{jquery-1.4.2.min.js → jquery/jquery-1.4.2.min.js} +0 -0
- data/dist/jquery/jquery.ba-hashchange.js +244 -0
- data/dist/{jquery.livequery.js → jquery/jquery.livequery.js} +0 -0
- data/dist/{mustache.js → mustache/mustache.0.2.3.js} +27 -50
- data/eyeballs.gemspec +23 -14
- data/lib/eyeballs/app_generator.rb +3 -3
- data/spec/app_generator_spec.rb +7 -1
- data/spec/spec_helper.rb +1 -2
- data/src/{o_O.localstorage.js → adapters/o_O.localstorage.js} +0 -0
- data/src/{jquery.o_O.couchdb.js → drivers/jquery/adapters/o_O.couchdb.js} +0 -0
- data/src/{jquery.o_O.dom.js → drivers/jquery/adapters/o_O.dom.js} +0 -0
- data/src/{jquery.o_O.rails.js → drivers/jquery/adapters/o_O.rest.js} +1 -1
- data/src/{jquery.o_O.js → drivers/jquery/modules/o_O.controller.js} +3 -65
- data/src/drivers/jquery/modules/o_O.routes.js +45 -0
- data/src/drivers/jquery/modules/o_O.support.js +69 -0
- data/src/modules/o_O.model.js +188 -0
- data/src/modules/o_O.validations.js +45 -0
- data/src/o_O.js +0 -235
- data/templates/app_root/config/initializer.js +3 -0
- data/templates/app_root/config/routes.js +7 -0
- data/test/unit/test_controller.html +7 -7
- data/test/unit/test_dom.html +7 -4
- data/test/unit/test_dom_with_callbacks.html +7 -3
- data/test/unit/test_form.html +7 -2
- data/test/unit/test_localstorage.html +7 -4
- data/test/unit/test_model.html +7 -3
- data/test/unit/test_model_with_callbacks.html +7 -3
- data/test/unit/{test_rails.html → test_rest.html} +9 -6
- data/test/unit/test_routing.html +76 -0
- metadata +39 -15
- data/eyeballs.js.gemspec +0 -83
@@ -0,0 +1,188 @@
|
|
1
|
+
o_O.model = {
|
2
|
+
adapter: false,
|
3
|
+
initialize: function(model_name, callback){
|
4
|
+
var callback = callback;
|
5
|
+
var class_methods, instance_methods, initializer_methods;
|
6
|
+
var validates_presence_of, validates_length_of;
|
7
|
+
var table_name = model_name.toLowerCase() + 's';
|
8
|
+
|
9
|
+
class_methods = {
|
10
|
+
validations: {presence: [], lengthliness: [], custom: []},
|
11
|
+
methods: {},
|
12
|
+
validates_presence_of: function(field){
|
13
|
+
this.validations.presence.push({field: field});
|
14
|
+
},
|
15
|
+
validates_length_of: function(field, options){
|
16
|
+
options.field = field;
|
17
|
+
this.validations.lengthliness.push(options);
|
18
|
+
},
|
19
|
+
validates: function(validation){
|
20
|
+
this.validations.custom.push(validation)
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
var run_callback = function(callback, method, args){
|
25
|
+
try{
|
26
|
+
if(typeof callback === 'function' && method === 'success')
|
27
|
+
{
|
28
|
+
callback(args);
|
29
|
+
}
|
30
|
+
if(typeof callback === 'object' && typeof callback[method] === 'function')
|
31
|
+
{
|
32
|
+
callback[method](args);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
catch(e)
|
36
|
+
{
|
37
|
+
if(typeof console === 'object')
|
38
|
+
{
|
39
|
+
console.log(e);
|
40
|
+
}
|
41
|
+
else
|
42
|
+
{
|
43
|
+
alert(e);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
var config = callback(class_methods);
|
49
|
+
instance_methods = {
|
50
|
+
adapter: o_O.model.adapter,
|
51
|
+
destroy: function(callback){
|
52
|
+
run_callback(callback, 'loading', this)
|
53
|
+
if(this.adapter)
|
54
|
+
{
|
55
|
+
this.adapter.destroy(this, function(returned_object){
|
56
|
+
run_callback(callback, 'success', returned_object);
|
57
|
+
});
|
58
|
+
}
|
59
|
+
else
|
60
|
+
{
|
61
|
+
run_callback(callback, 'success', this)
|
62
|
+
}
|
63
|
+
return this;
|
64
|
+
},
|
65
|
+
model_name: model_name,
|
66
|
+
save: function(callback){
|
67
|
+
if(this.valid())
|
68
|
+
{
|
69
|
+
run_callback(callback, 'loading', this);
|
70
|
+
if(this.adapter)
|
71
|
+
{
|
72
|
+
var model = this;
|
73
|
+
this.adapter.save(this, function(returned_object){
|
74
|
+
var initialized_object = o_O.models[model.model_name].initialize(returned_object);
|
75
|
+
initialized_object.new_record = false;
|
76
|
+
run_callback(callback, 'success', initialized_object);
|
77
|
+
});
|
78
|
+
}
|
79
|
+
else
|
80
|
+
{
|
81
|
+
run_callback(callback, 'success', this);
|
82
|
+
}
|
83
|
+
return this;
|
84
|
+
}
|
85
|
+
else
|
86
|
+
{
|
87
|
+
run_callback(callback, 'invalid', this);
|
88
|
+
}
|
89
|
+
},
|
90
|
+
table_name: table_name,
|
91
|
+
to_json: function(){
|
92
|
+
var serialized_object = {};
|
93
|
+
for(var i = 0; i < this.attributes.length; i++);
|
94
|
+
{
|
95
|
+
var index = i - 1;
|
96
|
+
var attribute_name = this.attributes[index];
|
97
|
+
serialized_object[this.attributes[index]] = this[this.attributes[index]];
|
98
|
+
}
|
99
|
+
serialized_object._model_name = this.model_name;
|
100
|
+
return JSON.stringify(serialized_object);
|
101
|
+
},
|
102
|
+
update_attributes: function(attributes, callback){
|
103
|
+
for(var attribute in attributes)
|
104
|
+
{
|
105
|
+
this[attribute] = attributes[attribute];
|
106
|
+
}
|
107
|
+
this.save(callback);
|
108
|
+
},
|
109
|
+
valid: function(){
|
110
|
+
this.errors = [];
|
111
|
+
|
112
|
+
o_O.validations.run(this);
|
113
|
+
|
114
|
+
if(this.errors.length == 0)
|
115
|
+
{
|
116
|
+
return true;
|
117
|
+
}
|
118
|
+
else
|
119
|
+
{
|
120
|
+
return false;
|
121
|
+
}
|
122
|
+
},
|
123
|
+
errors: [],
|
124
|
+
validations: class_methods.validations
|
125
|
+
}
|
126
|
+
for(method in class_methods.methods)
|
127
|
+
{
|
128
|
+
instance_methods[method] = class_methods.methods[method]
|
129
|
+
}
|
130
|
+
|
131
|
+
initializer_methods = {
|
132
|
+
adapter: o_O.model.adapter,
|
133
|
+
all: function(callback){
|
134
|
+
if(this.adapter)
|
135
|
+
{
|
136
|
+
return this.adapter.all(this, callback);
|
137
|
+
}
|
138
|
+
},
|
139
|
+
initialize: function(attributes){
|
140
|
+
if(!attributes) { var attributes = {}; };
|
141
|
+
var initialized_attributes = [];
|
142
|
+
for( var attribute in attributes )
|
143
|
+
{
|
144
|
+
initialized_attributes.push(attribute);
|
145
|
+
}
|
146
|
+
attributes['attributes'] = initialized_attributes;
|
147
|
+
for ( var method in instance_methods ) {
|
148
|
+
attributes[method] = instance_methods[method];
|
149
|
+
}
|
150
|
+
if(!attributes['id'])
|
151
|
+
{
|
152
|
+
attributes['id'] = o_O.uuid();
|
153
|
+
}
|
154
|
+
if(!attributes['new_record'])
|
155
|
+
{
|
156
|
+
attributes['new_record'] = true;
|
157
|
+
}
|
158
|
+
return attributes;
|
159
|
+
},
|
160
|
+
find: function(id, callback){
|
161
|
+
if(this.adapter)
|
162
|
+
{
|
163
|
+
run_callback(callback, 'loading', this)
|
164
|
+
var model = this;
|
165
|
+
return this.adapter.find(this, id, function(returned_object){
|
166
|
+
found_object = model.initialize(returned_object);
|
167
|
+
if(!found_object['new_record'])
|
168
|
+
{
|
169
|
+
found_object['new_record'] = false;
|
170
|
+
}
|
171
|
+
if(found_object.id)
|
172
|
+
{
|
173
|
+
run_callback(callback, 'success', found_object);
|
174
|
+
}
|
175
|
+
else
|
176
|
+
{
|
177
|
+
run_callback(callback, 'failure', found_object);
|
178
|
+
}
|
179
|
+
}, callback);
|
180
|
+
}
|
181
|
+
},
|
182
|
+
model_name: model_name,
|
183
|
+
table_name: table_name
|
184
|
+
}
|
185
|
+
|
186
|
+
return initializer_methods;
|
187
|
+
}
|
188
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
o_O.validations = {
|
2
|
+
run: function(object){
|
3
|
+
this.run_custom_validations(object);
|
4
|
+
this.run_length_validations(object);
|
5
|
+
this.run_presence_validations(object);
|
6
|
+
},
|
7
|
+
run_custom_validations: function(object){
|
8
|
+
for(var i = 0; i < object.validations.custom.length; i++)
|
9
|
+
{
|
10
|
+
object.validations.custom[i](object);
|
11
|
+
}
|
12
|
+
},
|
13
|
+
run_length_validations: function(object){
|
14
|
+
for(var i = 0; i < object.validations.lengthliness.length; i++)
|
15
|
+
{
|
16
|
+
var field = object.validations.lengthliness[i].field;
|
17
|
+
var max = object.validations.lengthliness[i].max
|
18
|
+
var min = object.validations.lengthliness[i].min
|
19
|
+
if(object[field])
|
20
|
+
{
|
21
|
+
if(max && object[field].length > max)
|
22
|
+
{
|
23
|
+
var message = field + ' should be less than ' + max + ' characters';
|
24
|
+
object.errors.push({field: field, type: 'length', message: message});
|
25
|
+
}
|
26
|
+
if(min && object[field].length < min)
|
27
|
+
{
|
28
|
+
var message = field + ' should be greater than ' + min + ' characters';
|
29
|
+
object.errors.push({field: field, type: 'length', message: message});
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
},
|
34
|
+
run_presence_validations: function(object){
|
35
|
+
for(var i = 0; i < object.validations.presence.length; i++)
|
36
|
+
{
|
37
|
+
var field = object.validations.presence[i].field;
|
38
|
+
if(object[field] == '' || object[field] == null)
|
39
|
+
{
|
40
|
+
var message = field + ' should be present';
|
41
|
+
object.errors.push({field: field, type: 'presence', message: message})
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
data/src/o_O.js
CHANGED
@@ -28,241 +28,6 @@ var o_O = function(){
|
|
28
28
|
}
|
29
29
|
}
|
30
30
|
|
31
|
-
o_O.model = {
|
32
|
-
adapter: false,
|
33
|
-
initialize: function(model_name, callback){
|
34
|
-
var callback = callback;
|
35
|
-
var class_methods, instance_methods, initializer_methods;
|
36
|
-
var validates_presence_of, validates_length_of;
|
37
|
-
var table_name = model_name.toLowerCase() + 's';
|
38
|
-
|
39
|
-
class_methods = {
|
40
|
-
validations: {presence: [], lengthliness: [], custom: []},
|
41
|
-
methods: {},
|
42
|
-
validates_presence_of: function(field){
|
43
|
-
this.validations.presence.push({field: field});
|
44
|
-
},
|
45
|
-
validates_length_of: function(field, options){
|
46
|
-
options.field = field;
|
47
|
-
this.validations.lengthliness.push(options);
|
48
|
-
},
|
49
|
-
validates: function(validation){
|
50
|
-
this.validations.custom.push(validation)
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
var run_callback = function(callback, method, args){
|
55
|
-
try{
|
56
|
-
if(typeof callback === 'function' && method === 'success')
|
57
|
-
{
|
58
|
-
callback(args);
|
59
|
-
}
|
60
|
-
if(typeof callback === 'object' && typeof callback[method] === 'function')
|
61
|
-
{
|
62
|
-
callback[method](args);
|
63
|
-
}
|
64
|
-
}
|
65
|
-
catch(e)
|
66
|
-
{
|
67
|
-
if(typeof console === 'object')
|
68
|
-
{
|
69
|
-
console.log(e);
|
70
|
-
}
|
71
|
-
else
|
72
|
-
{
|
73
|
-
alert(e);
|
74
|
-
}
|
75
|
-
}
|
76
|
-
}
|
77
|
-
|
78
|
-
var config = callback(class_methods);
|
79
|
-
instance_methods = {
|
80
|
-
adapter: o_O.model.adapter,
|
81
|
-
destroy: function(callback){
|
82
|
-
run_callback(callback, 'loading', this)
|
83
|
-
if(this.adapter)
|
84
|
-
{
|
85
|
-
this.adapter.destroy(this, function(returned_object){
|
86
|
-
run_callback(callback, 'success', returned_object);
|
87
|
-
});
|
88
|
-
}
|
89
|
-
else
|
90
|
-
{
|
91
|
-
run_callback(callback, 'success', this)
|
92
|
-
}
|
93
|
-
return this;
|
94
|
-
},
|
95
|
-
model_name: model_name,
|
96
|
-
save: function(callback){
|
97
|
-
if(this.valid())
|
98
|
-
{
|
99
|
-
run_callback(callback, 'loading', this);
|
100
|
-
if(this.adapter)
|
101
|
-
{
|
102
|
-
var model = this;
|
103
|
-
this.adapter.save(this, function(returned_object){
|
104
|
-
var initialized_object = o_O.models[model.model_name].initialize(returned_object);
|
105
|
-
initialized_object.new_record = false;
|
106
|
-
run_callback(callback, 'success', initialized_object);
|
107
|
-
});
|
108
|
-
}
|
109
|
-
else
|
110
|
-
{
|
111
|
-
run_callback(callback, 'success', this);
|
112
|
-
}
|
113
|
-
return this;
|
114
|
-
}
|
115
|
-
else
|
116
|
-
{
|
117
|
-
run_callback(callback, 'invalid', this);
|
118
|
-
}
|
119
|
-
},
|
120
|
-
table_name: table_name,
|
121
|
-
to_json: function(){
|
122
|
-
var serialized_object = {};
|
123
|
-
for(var i = 0; i < this.attributes.length; i++);
|
124
|
-
{
|
125
|
-
var index = i - 1;
|
126
|
-
var attribute_name = this.attributes[index];
|
127
|
-
serialized_object[this.attributes[index]] = this[this.attributes[index]];
|
128
|
-
}
|
129
|
-
serialized_object._model_name = this.model_name;
|
130
|
-
return JSON.stringify(serialized_object);
|
131
|
-
},
|
132
|
-
update_attributes: function(attributes, callback){
|
133
|
-
for(var attribute in attributes)
|
134
|
-
{
|
135
|
-
this[attribute] = attributes[attribute];
|
136
|
-
}
|
137
|
-
this.save(callback);
|
138
|
-
},
|
139
|
-
valid: function(){
|
140
|
-
this.errors = [];
|
141
|
-
|
142
|
-
o_O.validations.run(this);
|
143
|
-
|
144
|
-
if(this.errors.length == 0)
|
145
|
-
{
|
146
|
-
return true;
|
147
|
-
}
|
148
|
-
else
|
149
|
-
{
|
150
|
-
return false;
|
151
|
-
}
|
152
|
-
},
|
153
|
-
errors: [],
|
154
|
-
validations: class_methods.validations
|
155
|
-
}
|
156
|
-
for(method in class_methods.methods)
|
157
|
-
{
|
158
|
-
instance_methods[method] = class_methods.methods[method]
|
159
|
-
}
|
160
|
-
|
161
|
-
initializer_methods = {
|
162
|
-
adapter: o_O.model.adapter,
|
163
|
-
all: function(callback){
|
164
|
-
if(this.adapter)
|
165
|
-
{
|
166
|
-
return this.adapter.all(this, callback);
|
167
|
-
}
|
168
|
-
},
|
169
|
-
initialize: function(attributes){
|
170
|
-
if(!attributes) { var attributes = {}; };
|
171
|
-
var initialized_attributes = [];
|
172
|
-
for( var attribute in attributes )
|
173
|
-
{
|
174
|
-
initialized_attributes.push(attribute);
|
175
|
-
}
|
176
|
-
attributes['attributes'] = initialized_attributes;
|
177
|
-
for ( var method in instance_methods ) {
|
178
|
-
attributes[method] = instance_methods[method];
|
179
|
-
}
|
180
|
-
if(!attributes['id'])
|
181
|
-
{
|
182
|
-
attributes['id'] = o_O.uuid();
|
183
|
-
}
|
184
|
-
if(!attributes['new_record'])
|
185
|
-
{
|
186
|
-
attributes['new_record'] = true;
|
187
|
-
}
|
188
|
-
return attributes;
|
189
|
-
},
|
190
|
-
find: function(id, callback){
|
191
|
-
if(this.adapter)
|
192
|
-
{
|
193
|
-
run_callback(callback, 'loading', this)
|
194
|
-
var model = this;
|
195
|
-
return this.adapter.find(this, id, function(returned_object){
|
196
|
-
found_object = model.initialize(returned_object);
|
197
|
-
if(!found_object['new_record'])
|
198
|
-
{
|
199
|
-
found_object['new_record'] = false;
|
200
|
-
}
|
201
|
-
if(found_object.id)
|
202
|
-
{
|
203
|
-
run_callback(callback, 'success', found_object);
|
204
|
-
}
|
205
|
-
else
|
206
|
-
{
|
207
|
-
run_callback(callback, 'failure', found_object);
|
208
|
-
}
|
209
|
-
}, callback);
|
210
|
-
}
|
211
|
-
},
|
212
|
-
model_name: model_name,
|
213
|
-
table_name: table_name
|
214
|
-
}
|
215
|
-
|
216
|
-
return initializer_methods;
|
217
|
-
}
|
218
|
-
}
|
219
|
-
|
220
|
-
o_O.validations = {
|
221
|
-
run: function(object){
|
222
|
-
this.run_custom_validations(object);
|
223
|
-
this.run_length_validations(object);
|
224
|
-
this.run_presence_validations(object);
|
225
|
-
},
|
226
|
-
run_custom_validations: function(object){
|
227
|
-
for(var i = 0; i < object.validations.custom.length; i++)
|
228
|
-
{
|
229
|
-
object.validations.custom[i](object);
|
230
|
-
}
|
231
|
-
},
|
232
|
-
run_length_validations: function(object){
|
233
|
-
for(var i = 0; i < object.validations.lengthliness.length; i++)
|
234
|
-
{
|
235
|
-
var field = object.validations.lengthliness[i].field;
|
236
|
-
var max = object.validations.lengthliness[i].max
|
237
|
-
var min = object.validations.lengthliness[i].min
|
238
|
-
if(object[field])
|
239
|
-
{
|
240
|
-
if(max && object[field].length > max)
|
241
|
-
{
|
242
|
-
var message = field + ' should be less than ' + max + ' characters';
|
243
|
-
object.errors.push({field: field, type: 'length', message: message});
|
244
|
-
}
|
245
|
-
if(min && object[field].length < min)
|
246
|
-
{
|
247
|
-
var message = field + ' should be greater than ' + min + ' characters';
|
248
|
-
object.errors.push({field: field, type: 'length', message: message});
|
249
|
-
}
|
250
|
-
}
|
251
|
-
}
|
252
|
-
},
|
253
|
-
run_presence_validations: function(object){
|
254
|
-
for(var i = 0; i < object.validations.presence.length; i++)
|
255
|
-
{
|
256
|
-
var field = object.validations.presence[i].field;
|
257
|
-
if(object[field] == '' || object[field] == null)
|
258
|
-
{
|
259
|
-
var message = field + ' should be present';
|
260
|
-
object.errors.push({field: field, type: 'presence', message: message})
|
261
|
-
}
|
262
|
-
}
|
263
|
-
}
|
264
|
-
}
|
265
|
-
|
266
31
|
o_O.config = {}
|
267
32
|
o_O.templates = {}
|
268
33
|
|