batman-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +4 -0
  3. data/README.md +73 -0
  4. data/Rakefile +18 -0
  5. data/batman-rails.gemspec +27 -0
  6. data/lib/batman-rails.rb +1 -0
  7. data/lib/batman/rails.rb +6 -0
  8. data/lib/batman/rails/engine.rb +6 -0
  9. data/lib/batman/rails/version.rb +6 -0
  10. data/lib/generators/batman/common.rb +45 -0
  11. data/lib/generators/batman/controller_generator.rb +33 -0
  12. data/lib/generators/batman/helper_generator.rb +14 -0
  13. data/lib/generators/batman/install_generator.rb +58 -0
  14. data/lib/generators/batman/model_generator.rb +29 -0
  15. data/lib/generators/batman/scaffold_generator.rb +19 -0
  16. data/lib/generators/batman/templates/batman_app.coffee +25 -0
  17. data/lib/generators/batman/templates/controller.coffee +5 -0
  18. data/lib/generators/batman/templates/helper.coffee +5 -0
  19. data/lib/generators/batman/templates/model.coffee +7 -0
  20. data/test/controller_generator_test.rb +40 -0
  21. data/test/fixtures/application.js +9 -0
  22. data/test/install_generator_test.rb +82 -0
  23. data/test/model_generator_test.rb +44 -0
  24. data/test/sample/.gitignore +5 -0
  25. data/test/sample/Gemfile +30 -0
  26. data/test/sample/README +261 -0
  27. data/test/sample/Rakefile +7 -0
  28. data/test/sample/app/assets/images/rails.png +0 -0
  29. data/test/sample/app/assets/javascripts/application.js +9 -0
  30. data/test/sample/app/assets/stylesheets/application.css +7 -0
  31. data/test/sample/app/controllers/application_controller.rb +3 -0
  32. data/test/sample/app/helpers/application_helper.rb +2 -0
  33. data/test/sample/app/mailers/.gitkeep +0 -0
  34. data/test/sample/app/models/.gitkeep +0 -0
  35. data/test/sample/app/views/layouts/application.html.erb +14 -0
  36. data/test/sample/config.ru +4 -0
  37. data/test/sample/config/application.rb +48 -0
  38. data/test/sample/config/boot.rb +6 -0
  39. data/test/sample/config/database.yml +25 -0
  40. data/test/sample/config/environment.rb +5 -0
  41. data/test/sample/config/environments/development.rb +30 -0
  42. data/test/sample/config/environments/production.rb +60 -0
  43. data/test/sample/config/environments/test.rb +42 -0
  44. data/test/sample/config/initializers/backtrace_silencers.rb +7 -0
  45. data/test/sample/config/initializers/inflections.rb +10 -0
  46. data/test/sample/config/initializers/mime_types.rb +5 -0
  47. data/test/sample/config/initializers/secret_token.rb +7 -0
  48. data/test/sample/config/initializers/session_store.rb +8 -0
  49. data/test/sample/config/initializers/wrap_parameters.rb +14 -0
  50. data/test/sample/config/locales/en.yml +5 -0
  51. data/test/sample/config/routes.rb +58 -0
  52. data/test/sample/db/seeds.rb +7 -0
  53. data/test/sample/doc/README_FOR_APP +2 -0
  54. data/test/sample/lib/assets/.gitkeep +0 -0
  55. data/test/sample/lib/tasks/.gitkeep +0 -0
  56. data/test/sample/log/.gitkeep +0 -0
  57. data/test/sample/public/404.html +26 -0
  58. data/test/sample/public/422.html +26 -0
  59. data/test/sample/public/500.html +26 -0
  60. data/test/sample/public/favicon.ico +0 -0
  61. data/test/sample/public/index.html +241 -0
  62. data/test/sample/public/robots.txt +5 -0
  63. data/test/sample/script/rails +6 -0
  64. data/test/sample/test/fixtures/.gitkeep +0 -0
  65. data/test/sample/test/functional/.gitkeep +0 -0
  66. data/test/sample/test/integration/.gitkeep +0 -0
  67. data/test/sample/test/performance/browsing_test.rb +12 -0
  68. data/test/sample/test/test_helper.rb +13 -0
  69. data/test/sample/test/unit/.gitkeep +0 -0
  70. data/test/sample/vendor/assets/stylesheets/.gitkeep +0 -0
  71. data/test/sample/vendor/plugins/.gitkeep +0 -0
  72. data/test/test_helper.rb +24 -0
  73. data/vendor/assets/javascripts/batman/batman.jquery.js +72 -0
  74. data/vendor/assets/javascripts/batman/batman.js +5193 -0
  75. data/vendor/assets/javascripts/batman/batman.rails.js +58 -0
  76. data/vendor/assets/javascripts/batman/batman.solo.js +414 -0
  77. metadata +285 -0
@@ -0,0 +1,58 @@
1
+ (function() {
2
+ var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
3
+ for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
4
+ function ctor() { this.constructor = child; }
5
+ ctor.prototype = parent.prototype;
6
+ child.prototype = new ctor;
7
+ child.__super__ = parent.prototype;
8
+ return child;
9
+ }, __slice = Array.prototype.slice;
10
+ Batman.RailsStorage = (function() {
11
+ __extends(RailsStorage, Batman.RestStorage);
12
+ function RailsStorage() {
13
+ RailsStorage.__super__.constructor.apply(this, arguments);
14
+ }
15
+ RailsStorage.prototype._addJsonExtension = function(options) {
16
+ return options.url += '.json';
17
+ };
18
+ RailsStorage.prototype.optionsForRecord = function() {
19
+ var args, callback, _i;
20
+ args = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), callback = arguments[_i++];
21
+ return RailsStorage.__super__.optionsForRecord.apply(this, __slice.call(args).concat([function(err, options) {
22
+ if (!err) {
23
+ this._addJsonExtension(options);
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
+ }
50
+ }
51
+ return [record.get('errors'), record, response, recordOptions];
52
+ }
53
+ }
54
+ return arguments[0];
55
+ });
56
+ return RailsStorage;
57
+ })();
58
+ }).call(this);
@@ -0,0 +1,414 @@
1
+ (function() {
2
+
3
+ /*!
4
+ * Reqwest! A x-browser general purpose XHR connection manager
5
+ * copyright Dustin Diaz 2011
6
+ * https://github.com/ded/reqwest
7
+ * license MIT
8
+ */
9
+ !
10
+ function(context, win) {
11
+
12
+ var twoHundo = /^20\d$/,
13
+ doc = document,
14
+ byTag = 'getElementsByTagName',
15
+ contentType = 'Content-Type',
16
+ head = doc[byTag]('head')[0],
17
+ uniqid = 0,
18
+ lastValue // data stored by the most recent JSONP callback
19
+ , xhr = ('XMLHttpRequest' in win) ?
20
+ function() {
21
+ return new XMLHttpRequest()
22
+ } : function() {
23
+ return new ActiveXObject('Microsoft.XMLHTTP')
24
+ }
25
+
26
+ function readyState(o, success, error) {
27
+ return function() {
28
+ if (o && o.readyState == 4) {
29
+ if (twoHundo.test(o.status)) {
30
+ success(o)
31
+ } else {
32
+ error(o)
33
+ }
34
+ }
35
+ }
36
+ }
37
+
38
+ function setHeaders(http, o) {
39
+ var headers = o.headers || {}
40
+ headers.Accept = headers.Accept || 'text/javascript, text/html, application/xml, text/xml, */*'
41
+
42
+ // breaks cross-origin requests with legacy browsers
43
+ if (!o.crossOrigin) {
44
+ headers['X-Requested-With'] = headers['X-Requested-With'] || 'XMLHttpRequest'
45
+ }
46
+
47
+ if (o.data) {
48
+ headers[contentType] = headers[contentType] || 'application/x-www-form-urlencoded'
49
+ }
50
+ for (var h in headers) {
51
+ headers.hasOwnProperty(h) && http.setRequestHeader(h, headers[h], false)
52
+ }
53
+ }
54
+
55
+ function getCallbackName(o) {
56
+ var callbackVar = o.jsonpCallback || "callback"
57
+ if (o.url.slice(-(callbackVar.length + 2)) == (callbackVar + "=?")) {
58
+ // Generate a guaranteed unique callback name
59
+ var callbackName = "reqwest_" + uniqid++
60
+
61
+ // Replace the ? in the URL with the generated name
62
+ o.url = o.url.substr(0, o.url.length - 1) + callbackName
63
+ return callbackName
64
+ } else {
65
+ // Find the supplied callback name
66
+ var regex = new RegExp(callbackVar + "=([\\w]+)")
67
+ return o.url.match(regex)[1]
68
+ }
69
+ }
70
+
71
+ // Store the data returned by the most recent callback
72
+
73
+
74
+ function generalCallback(data) {
75
+ lastValue = data
76
+ }
77
+
78
+ function getRequest(o, fn, err) {
79
+ function onload() {
80
+ // Call the user callback with the last value stored
81
+ // and clean up values and scripts.
82
+ o.success && o.success(lastValue)
83
+ lastValue = undefined
84
+ head.removeChild(script);
85
+ }
86
+ if (o.type == 'jsonp') {
87
+ var script = doc.createElement('script')
88
+
89
+ // Add the global callback
90
+ win[getCallbackName(o)] = generalCallback;
91
+
92
+ // Setup our script element
93
+ script.type = 'text/javascript'
94
+ script.src = o.url
95
+ script.async = true
96
+
97
+ script.onload = onload
98
+ // onload for IE
99
+ script.onreadystatechange = function() {
100
+ /^loaded|complete$/.test(script.readyState) && onload()
101
+ }
102
+
103
+ // Add the script to the DOM head
104
+ head.appendChild(script)
105
+ } else {
106
+ var http = xhr()
107
+ http.open(o.method || 'GET', typeof o == 'string' ? o : o.url, true)
108
+ setHeaders(http, o)
109
+ http.onreadystatechange = readyState(http, fn, err)
110
+ o.before && o.before(http)
111
+ http.send(o.data || null)
112
+ return http
113
+ }
114
+ }
115
+
116
+ function Reqwest(o, fn) {
117
+ this.o = o
118
+ this.fn = fn
119
+ init.apply(this, arguments)
120
+ }
121
+
122
+ function setType(url) {
123
+ if (/\.json$/.test(url)) {
124
+ return 'json'
125
+ }
126
+ if (/\.jsonp$/.test(url)) {
127
+ return 'jsonp'
128
+ }
129
+ if (/\.js$/.test(url)) {
130
+ return 'js'
131
+ }
132
+ if (/\.html?$/.test(url)) {
133
+ return 'html'
134
+ }
135
+ if (/\.xml$/.test(url)) {
136
+ return 'xml'
137
+ }
138
+ return 'js'
139
+ }
140
+
141
+ function init(o, fn) {
142
+ this.url = typeof o == 'string' ? o : o.url
143
+ this.timeout = null
144
+ var type = o.type || setType(this.url),
145
+ self = this
146
+ fn = fn ||
147
+ function() {}
148
+
149
+ if (o.timeout) {
150
+ this.timeout = setTimeout(function() {
151
+ self.abort()
152
+ error()
153
+ }, o.timeout)
154
+ }
155
+
156
+ function complete(resp) {
157
+ o.complete && o.complete(resp)
158
+ }
159
+
160
+ function success(resp) {
161
+ o.timeout && clearTimeout(self.timeout) && (self.timeout = null)
162
+ var r = resp.responseText
163
+
164
+ if (r) {
165
+ switch (type) {
166
+ case 'json':
167
+ resp = win.JSON ? win.JSON.parse(r) : eval('(' + r + ')')
168
+ break;
169
+ case 'js':
170
+ resp = eval(r)
171
+ break;
172
+ case 'html':
173
+ resp = r
174
+ break;
175
+ }
176
+ }
177
+
178
+ fn(resp)
179
+ o.success && o.success(resp)
180
+ complete(resp)
181
+ }
182
+
183
+ function error(resp) {
184
+ o.error && o.error(resp)
185
+ complete(resp)
186
+ }
187
+
188
+ this.request = getRequest(o, success, error)
189
+ }
190
+
191
+ Reqwest.prototype = {
192
+ abort: function() {
193
+ this.request.abort()
194
+ }
195
+
196
+ ,
197
+ retry: function() {
198
+ init.call(this, this.o, this.fn)
199
+ }
200
+ }
201
+
202
+ function reqwest(o, fn) {
203
+ return new Reqwest(o, fn)
204
+ }
205
+
206
+ function enc(v) {
207
+ return encodeURIComponent(v)
208
+ }
209
+
210
+ function serial(el) {
211
+ var n = el.name
212
+ // don't serialize elements that are disabled or without a name
213
+ if (el.disabled || !n) {
214
+ return ''
215
+ }
216
+ n = enc(n)
217
+ switch (el.tagName.toLowerCase()) {
218
+ case 'input':
219
+ switch (el.type) {
220
+ // silly wabbit
221
+ case 'reset':
222
+ case 'button':
223
+ case 'image':
224
+ case 'file':
225
+ return ''
226
+ case 'checkbox':
227
+ case 'radio':
228
+ return el.checked ? n + '=' + (el.value ? enc(el.value) : true) + '&' : ''
229
+ default:
230
+ // text hidden password submit
231
+ return n + '=' + (el.value ? enc(el.value) : '') + '&'
232
+ }
233
+ break;
234
+ case 'textarea':
235
+ return n + '=' + enc(el.value) + '&'
236
+ case 'select':
237
+ // @todo refactor beyond basic single selected value case
238
+ return n + '=' + enc(el.options[el.selectedIndex].value) + '&'
239
+ }
240
+ return ''
241
+ }
242
+
243
+ reqwest.serialize = function(form) {
244
+ var fields = [form[byTag]('input'), form[byTag]('select'), form[byTag]('textarea')],
245
+ serialized = []
246
+
247
+ for (var i = 0, l = fields.length; i < l; ++i) {
248
+ for (var j = 0, l2 = fields[i].length; j < l2; ++j) {
249
+ serialized.push(serial(fields[i][j]))
250
+ }
251
+ }
252
+ return serialized.join('').replace(/&$/, '')
253
+ }
254
+
255
+ reqwest.serializeArray = function(f) {
256
+ for (var pairs = this.serialize(f).split('&'), i = 0, l = pairs.length, r = [], o; i < l; i++) {
257
+ pairs[i] && (o = pairs[i].split('=')) && r.push({
258
+ name: o[0],
259
+ value: o[1]
260
+ })
261
+ }
262
+ return r
263
+ }
264
+
265
+ var old = context.reqwest
266
+ reqwest.noConflict = function() {
267
+ context.reqwest = old
268
+ return this
269
+ }
270
+
271
+ // defined as extern for Closure Compilation
272
+ if (typeof module !== 'undefined') module.exports = reqwest
273
+ context['reqwest'] = reqwest
274
+
275
+ }(this, window)
276
+
277
+ ;
278
+ var buildParams, param, prefixes, r20, rbracket;
279
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
280
+ (typeof exports !== "undefined" && exports !== null ? exports : this).reqwest = typeof window !== "undefined" && window !== null ? window.reqwest : reqwest;
281
+ rbracket = /\[\]$/;
282
+ r20 = /%20/g;
283
+ param = function(a) {
284
+ var add, k, name, s, v, value;
285
+ s = [];
286
+ add = function(key, value) {
287
+ value = (Batman.typeOf(value) === 'function' ? value() : value);
288
+ return s[s.length] = encodeURIComponent(key) + "=" + encodeURIComponent(value);
289
+ };
290
+ if (Batman.typeOf(a) === 'Array') {
291
+ for (value in a) {
292
+ name = a[value];
293
+ add(name, value);
294
+ }
295
+ } else {
296
+ for (k in a) {
297
+ v = a[k];
298
+ buildParams(k, v, add);
299
+ }
300
+ }
301
+ return s.join("&").replace(r20, "+");
302
+ };
303
+ buildParams = function(prefix, obj, add) {
304
+ var i, name, v, _len, _results, _results2;
305
+ if (Batman.typeOf(obj) === 'Array') {
306
+ _results = [];
307
+ for (i = 0, _len = obj.length; i < _len; i++) {
308
+ v = obj[i];
309
+ _results.push(rbracket.test(prefix) ? add(prefix, v) : buildParams(prefix + "[" + (typeof v === "object" || Batman.typeOf(v) === 'Array' ? i : "") + "]", v, add));
310
+ }
311
+ return _results;
312
+ } else if ((obj != null) && typeof obj === "object") {
313
+ _results2 = [];
314
+ for (name in obj) {
315
+ _results2.push(buildParams(prefix + "[" + name + "]", obj[name], add));
316
+ }
317
+ return _results2;
318
+ } else {
319
+ return add(prefix, obj);
320
+ }
321
+ };
322
+ Batman.Request.prototype.send = function(data) {
323
+ var options, xhr, _ref;
324
+ this.fire('loading');
325
+ options = {
326
+ url: this.get('url'),
327
+ method: this.get('method'),
328
+ type: this.get('type'),
329
+ headers: {},
330
+ success: __bind(function(response) {
331
+ this.set('response', response);
332
+ this.set('status', xhr.status);
333
+ return this.fire('success', response);
334
+ }, this),
335
+ error: __bind(function(xhr) {
336
+ this.set('response', xhr.responseText || xhr.content);
337
+ this.set('status', xhr.status);
338
+ xhr.request = this;
339
+ return this.fire('error', xhr);
340
+ }, this),
341
+ complete: __bind(function() {
342
+ return this.fire('loaded');
343
+ }, this)
344
+ };
345
+ if ((_ref = options.method) === 'PUT' || _ref === 'POST') {
346
+ if (!this.get('formData')) {
347
+ options.headers['Content-type'] = this.get('contentType');
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
+ } else {
355
+ options.data = this.constructor.objectToFormData(options.data);
356
+ }
357
+ }
358
+ return xhr = (reqwest(options)).request;
359
+ };
360
+ prefixes = ['Webkit', 'Moz', 'O', 'ms', ''];
361
+ Batman.mixins.animation = {
362
+ initialize: function() {
363
+ var prefix, _i, _len;
364
+ for (_i = 0, _len = prefixes.length; _i < _len; _i++) {
365
+ prefix = prefixes[_i];
366
+ this.style["" + prefix + "Transform"] = 'scale(0, 0)';
367
+ this.style.opacity = 0;
368
+ this.style["" + prefix + "TransitionProperty"] = "" + (prefix ? '-' + prefix.toLowerCase() + '-' : '') + "transform, opacity";
369
+ this.style["" + prefix + "TransitionDuration"] = "0.8s, 0.55s";
370
+ this.style["" + prefix + "TransformOrigin"] = "left top";
371
+ }
372
+ return this;
373
+ },
374
+ show: function(addToParent) {
375
+ var show, _ref, _ref2;
376
+ show = __bind(function() {
377
+ var prefix, _i, _len;
378
+ this.style.opacity = 1;
379
+ for (_i = 0, _len = prefixes.length; _i < _len; _i++) {
380
+ prefix = prefixes[_i];
381
+ this.style["" + prefix + "Transform"] = 'scale(1, 1)';
382
+ }
383
+ return this;
384
+ }, this);
385
+ if (addToParent) {
386
+ if ((_ref = addToParent.append) != null) {
387
+ _ref.appendChild(this);
388
+ }
389
+ if ((_ref2 = addToParent.before) != null) {
390
+ _ref2.parentNode.insertBefore(this, addToParent.before);
391
+ }
392
+ setTimeout(show, 0);
393
+ } else {
394
+ show();
395
+ }
396
+ return this;
397
+ },
398
+ hide: function(shouldRemove) {
399
+ var prefix, _i, _len;
400
+ this.style.opacity = 0;
401
+ for (_i = 0, _len = prefixes.length; _i < _len; _i++) {
402
+ prefix = prefixes[_i];
403
+ this.style["" + prefix + "Transform"] = 'scale(0, 0)';
404
+ }
405
+ if (shouldRemove) {
406
+ setTimeout((__bind(function() {
407
+ var _ref;
408
+ return (_ref = this.parentNode) != null ? _ref.removeChild(this) : void 0;
409
+ }, this)), 600);
410
+ }
411
+ return this;
412
+ }
413
+ };
414
+ }).call(this);