batman-rails 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/batman/rails/version.rb +2 -2
- data/vendor/assets/javascripts/batman/batman.jquery.js +4 -1
- data/vendor/assets/javascripts/batman/batman.js +2638 -1207
- data/vendor/assets/javascripts/batman/batman.rails.js +69 -44
- data/vendor/assets/javascripts/batman/batman.solo.js +21 -17
- metadata +40 -10
@@ -1,4 +1,5 @@
|
|
1
1
|
(function() {
|
2
|
+
var applyExtra;
|
2
3
|
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
|
3
4
|
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
|
4
5
|
function ctor() { this.constructor = child; }
|
@@ -7,52 +8,76 @@
|
|
7
8
|
child.__super__ = parent.prototype;
|
8
9
|
return child;
|
9
10
|
}, __slice = Array.prototype.slice;
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
}
|
25
|
-
return callback.call(this, err, options);
|
26
|
-
}]));
|
27
|
-
};
|
28
|
-
RailsStorage.prototype.optionsForCollection = function() {
|
29
|
-
var args, callback, _i;
|
30
|
-
args = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), callback = arguments[_i++];
|
31
|
-
return RailsStorage.__super__.optionsForCollection.apply(this, __slice.call(args).concat([function(err, options) {
|
32
|
-
if (!err) {
|
33
|
-
this._addJsonExtension(options);
|
34
|
-
}
|
35
|
-
return callback.call(this, err, options);
|
36
|
-
}]));
|
37
|
-
};
|
38
|
-
RailsStorage.prototype.after('update', 'create', function(_arg) {
|
39
|
-
var err, key, record, recordOptions, response, validationError, validationErrors, _i, _len, _ref;
|
40
|
-
err = _arg[0], record = _arg[1], response = _arg[2], recordOptions = _arg[3];
|
41
|
-
if (err) {
|
42
|
-
if (err.request.get('status') === 422) {
|
43
|
-
_ref = JSON.parse(err.request.get('response'));
|
44
|
-
for (key in _ref) {
|
45
|
-
validationErrors = _ref[key];
|
46
|
-
for (_i = 0, _len = validationErrors.length; _i < _len; _i++) {
|
47
|
-
validationError = validationErrors[_i];
|
48
|
-
record.get('errors').add(key, "" + key + " " + validationError);
|
49
|
-
}
|
11
|
+
applyExtra = function(Batman) {
|
12
|
+
Batman.mixin(Batman.Encoders, {
|
13
|
+
railsDate: {
|
14
|
+
encode: function(value) {
|
15
|
+
return value;
|
16
|
+
},
|
17
|
+
decode: function(value) {
|
18
|
+
var a;
|
19
|
+
a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
20
|
+
if (a) {
|
21
|
+
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6]));
|
22
|
+
} else {
|
23
|
+
Batman.developer.warn("Unrecognized rails date " + value + "!");
|
24
|
+
return Date.parse(value);
|
50
25
|
}
|
51
|
-
return [record.get('errors'), record, response, recordOptions];
|
52
26
|
}
|
53
27
|
}
|
54
|
-
return arguments[0];
|
55
28
|
});
|
56
|
-
return RailsStorage
|
57
|
-
|
29
|
+
return Batman.RailsStorage = (function() {
|
30
|
+
__extends(RailsStorage, Batman.RestStorage);
|
31
|
+
function RailsStorage() {
|
32
|
+
RailsStorage.__super__.constructor.apply(this, arguments);
|
33
|
+
}
|
34
|
+
RailsStorage.prototype._addJsonExtension = function(options) {
|
35
|
+
return options.url += '.json';
|
36
|
+
};
|
37
|
+
RailsStorage.prototype.optionsForRecord = function() {
|
38
|
+
var args, callback, _i;
|
39
|
+
args = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), callback = arguments[_i++];
|
40
|
+
return RailsStorage.__super__.optionsForRecord.apply(this, __slice.call(args).concat([function(err, options) {
|
41
|
+
if (!err) {
|
42
|
+
this._addJsonExtension(options);
|
43
|
+
}
|
44
|
+
return callback.call(this, err, options);
|
45
|
+
}]));
|
46
|
+
};
|
47
|
+
RailsStorage.prototype.optionsForCollection = function() {
|
48
|
+
var args, callback, _i;
|
49
|
+
args = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), callback = arguments[_i++];
|
50
|
+
return RailsStorage.__super__.optionsForCollection.apply(this, __slice.call(args).concat([function(err, options) {
|
51
|
+
if (!err) {
|
52
|
+
this._addJsonExtension(options);
|
53
|
+
}
|
54
|
+
return callback.call(this, err, options);
|
55
|
+
}]));
|
56
|
+
};
|
57
|
+
RailsStorage.prototype.after('update', 'create', function(_arg) {
|
58
|
+
var err, key, record, recordOptions, response, validationError, validationErrors, _i, _len, _ref;
|
59
|
+
err = _arg[0], record = _arg[1], response = _arg[2], recordOptions = _arg[3];
|
60
|
+
if (err) {
|
61
|
+
if (err.request.get('status') === 422) {
|
62
|
+
_ref = JSON.parse(err.request.get('response'));
|
63
|
+
for (key in _ref) {
|
64
|
+
validationErrors = _ref[key];
|
65
|
+
for (_i = 0, _len = validationErrors.length; _i < _len; _i++) {
|
66
|
+
validationError = validationErrors[_i];
|
67
|
+
record.get('errors').add(key, "" + key + " " + validationError);
|
68
|
+
}
|
69
|
+
}
|
70
|
+
return [record.get('errors'), record, response, recordOptions];
|
71
|
+
}
|
72
|
+
}
|
73
|
+
return arguments[0];
|
74
|
+
});
|
75
|
+
return RailsStorage;
|
76
|
+
})();
|
77
|
+
};
|
78
|
+
if ((typeof module !== "undefined" && module !== null) && (typeof require !== "undefined" && require !== null)) {
|
79
|
+
module.exports = applyExtra;
|
80
|
+
} else {
|
81
|
+
applyExtra(Batman);
|
82
|
+
}
|
58
83
|
}).call(this);
|
@@ -120,19 +120,19 @@ function(context, win) {
|
|
120
120
|
}
|
121
121
|
|
122
122
|
function setType(url) {
|
123
|
-
if (/\.json
|
123
|
+
if (/\.json($|\?)/.test(url)) {
|
124
124
|
return 'json'
|
125
125
|
}
|
126
|
-
if (/\.jsonp
|
126
|
+
if (/\.jsonp($|\?)/.test(url)) {
|
127
127
|
return 'jsonp'
|
128
128
|
}
|
129
|
-
if (/\.js
|
129
|
+
if (/\.js($|\?)/.test(url)) {
|
130
130
|
return 'js'
|
131
131
|
}
|
132
|
-
if (/\.html
|
132
|
+
if (/\.html?($|\?)/.test(url)) {
|
133
133
|
return 'html'
|
134
134
|
}
|
135
|
-
if (/\.xml
|
135
|
+
if (/\.xml($|\?)/.test(url)) {
|
136
136
|
return 'xml'
|
137
137
|
}
|
138
138
|
return 'js'
|
@@ -284,7 +284,9 @@ function(context, win) {
|
|
284
284
|
var add, k, name, s, v, value;
|
285
285
|
s = [];
|
286
286
|
add = function(key, value) {
|
287
|
-
|
287
|
+
if (typeof value === 'function') {
|
288
|
+
value = value();
|
289
|
+
}
|
288
290
|
return s[s.length] = encodeURIComponent(key) + "=" + encodeURIComponent(value);
|
289
291
|
};
|
290
292
|
if (Batman.typeOf(a) === 'Array') {
|
@@ -320,7 +322,10 @@ function(context, win) {
|
|
320
322
|
}
|
321
323
|
};
|
322
324
|
Batman.Request.prototype.send = function(data) {
|
323
|
-
var options, xhr, _ref;
|
325
|
+
var options, params, xhr, _ref;
|
326
|
+
if (data == null) {
|
327
|
+
data = this.get('data');
|
328
|
+
}
|
324
329
|
this.fire('loading');
|
325
330
|
options = {
|
326
331
|
url: this.get('url'),
|
@@ -329,7 +334,7 @@ function(context, win) {
|
|
329
334
|
headers: {},
|
330
335
|
success: __bind(function(response) {
|
331
336
|
this.set('response', response);
|
332
|
-
this.set('status', xhr.status);
|
337
|
+
this.set('status', (typeof xhr !== "undefined" && xhr !== null ? xhr.status : void 0) || 200);
|
333
338
|
return this.fire('success', response);
|
334
339
|
}, this),
|
335
340
|
error: __bind(function(xhr) {
|
@@ -342,18 +347,17 @@ function(context, win) {
|
|
342
347
|
return this.fire('loaded');
|
343
348
|
}, this)
|
344
349
|
};
|
350
|
+
if (!this.get('formData')) {
|
351
|
+
options.headers['Content-type'] = this.get('contentType');
|
352
|
+
}
|
345
353
|
if ((_ref = options.method) === 'PUT' || _ref === 'POST') {
|
346
|
-
if (
|
347
|
-
options.
|
348
|
-
data = data || this.get('data');
|
349
|
-
if (options.method === 'GET') {
|
350
|
-
options.url += param(data);
|
351
|
-
} else {
|
352
|
-
options.data = param(data);
|
353
|
-
}
|
354
|
+
if (this.get('formData')) {
|
355
|
+
options.data = this.constructor.objectToFormData(data);
|
354
356
|
} else {
|
355
|
-
options.data =
|
357
|
+
options.data = param(data);
|
356
358
|
}
|
359
|
+
} else if (options.method === 'GET' && (params = param(data))) {
|
360
|
+
options.url += "?" + params;
|
357
361
|
}
|
358
362
|
return xhr = (reqwest(options)).request;
|
359
363
|
};
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: batman-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- John Duff
|
@@ -10,74 +15,99 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-
|
18
|
+
date: 2011-11-28 00:00:00 -05:00
|
14
19
|
default_executable:
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
17
22
|
name: railties
|
23
|
+
prerelease: false
|
18
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
19
25
|
none: false
|
20
26
|
requirements:
|
21
27
|
- - ~>
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 1
|
33
|
+
- 0
|
23
34
|
version: 3.1.0
|
24
35
|
type: :runtime
|
25
|
-
prerelease: false
|
26
36
|
version_requirements: *id001
|
27
37
|
- !ruby/object:Gem::Dependency
|
28
38
|
name: thor
|
39
|
+
prerelease: false
|
29
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
30
41
|
none: false
|
31
42
|
requirements:
|
32
43
|
- - ~>
|
33
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 23
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 14
|
34
49
|
version: "0.14"
|
35
50
|
type: :runtime
|
36
|
-
prerelease: false
|
37
51
|
version_requirements: *id002
|
38
52
|
- !ruby/object:Gem::Dependency
|
39
53
|
name: bundler
|
54
|
+
prerelease: false
|
40
55
|
requirement: &id003 !ruby/object:Gem::Requirement
|
41
56
|
none: false
|
42
57
|
requirements:
|
43
58
|
- - ~>
|
44
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 23
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 0
|
64
|
+
- 0
|
45
65
|
version: 1.0.0
|
46
66
|
type: :development
|
47
|
-
prerelease: false
|
48
67
|
version_requirements: *id003
|
49
68
|
- !ruby/object:Gem::Dependency
|
50
69
|
name: rails
|
70
|
+
prerelease: false
|
51
71
|
requirement: &id004 !ruby/object:Gem::Requirement
|
52
72
|
none: false
|
53
73
|
requirements:
|
54
74
|
- - ~>
|
55
75
|
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 3
|
79
|
+
- 1
|
80
|
+
- 0
|
56
81
|
version: 3.1.0
|
57
82
|
type: :development
|
58
|
-
prerelease: false
|
59
83
|
version_requirements: *id004
|
60
84
|
- !ruby/object:Gem::Dependency
|
61
85
|
name: mocha
|
86
|
+
prerelease: false
|
62
87
|
requirement: &id005 !ruby/object:Gem::Requirement
|
63
88
|
none: false
|
64
89
|
requirements:
|
65
90
|
- - ">="
|
66
91
|
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
67
95
|
version: "0"
|
68
96
|
type: :development
|
69
|
-
prerelease: false
|
70
97
|
version_requirements: *id005
|
71
98
|
- !ruby/object:Gem::Dependency
|
72
99
|
name: sqlite3
|
100
|
+
prerelease: false
|
73
101
|
requirement: &id006 !ruby/object:Gem::Requirement
|
74
102
|
none: false
|
75
103
|
requirements:
|
76
104
|
- - ">="
|
77
105
|
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
78
109
|
version: "0"
|
79
110
|
type: :development
|
80
|
-
prerelease: false
|
81
111
|
version_requirements: *id006
|
82
112
|
description: Quickly get started with Batman.js in a Rails 3.1 app. Provides generators to get started and bundles in the latest version of Batman.js.
|
83
113
|
email:
|
@@ -180,7 +210,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
180
210
|
requirements:
|
181
211
|
- - ">="
|
182
212
|
- !ruby/object:Gem::Version
|
183
|
-
hash:
|
213
|
+
hash: 3
|
184
214
|
segments:
|
185
215
|
- 0
|
186
216
|
version: "0"
|
@@ -189,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
219
|
requirements:
|
190
220
|
- - ">="
|
191
221
|
- !ruby/object:Gem::Version
|
192
|
-
hash:
|
222
|
+
hash: 3
|
193
223
|
segments:
|
194
224
|
- 0
|
195
225
|
version: "0"
|