angular_velocity 0.0.2alpha

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.
Files changed (27) hide show
  1. data/.gitignore +25 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +8 -0
  4. data/lib/generators/angular_velocity/angular_config.rb +23 -0
  5. data/lib/generators/angular_velocity/controller/controller_generator.rb +22 -0
  6. data/lib/generators/angular_velocity/controller/templates/controller.coffee +4 -0
  7. data/lib/generators/angular_velocity/install/install_generator.rb +60 -0
  8. data/lib/generators/angular_velocity/install/templates/AppLoader.js +3 -0
  9. data/lib/generators/angular_velocity/install/templates/angular-cookies.js +183 -0
  10. data/lib/generators/angular_velocity/install/templates/angular-mocks.js +1764 -0
  11. data/lib/generators/angular_velocity/install/templates/angular-resource.js +445 -0
  12. data/lib/generators/angular_velocity/install/templates/angular-sanitize.js +535 -0
  13. data/lib/generators/angular_velocity/install/templates/angular-scenario.js +26195 -0
  14. data/lib/generators/angular_velocity/install/templates/angular.js +14733 -0
  15. data/lib/generators/angular_velocity/install/templates/app.coffee +3 -0
  16. data/lib/generators/angular_velocity/install/templates/index.html.erb +9 -0
  17. data/lib/generators/angular_velocity/install/templates/jasmine.yml +24 -0
  18. data/lib/generators/angular_velocity/install/templates/main_control.html +9 -0
  19. data/lib/generators/angular_velocity/install/templates/main_controller.coffee +4 -0
  20. data/lib/generators/angular_velocity/install/templates/main_controller.rb +11 -0
  21. data/lib/generators/angular_velocity/install/templates/main_controller_spec.coffee +19 -0
  22. data/lib/generators/angular_velocity/install/templates/templates_controller.rb +11 -0
  23. data/spec/controller/controller_generator_spec.rb +25 -0
  24. data/spec/install/install_generator_spec.rb +82 -0
  25. data/spec/spec_helper.rb +50 -0
  26. data/spec/support/generator_matcher.rb +45 -0
  27. metadata +143 -0
@@ -0,0 +1,445 @@
1
+ /**
2
+ * @license AngularJS v1.0.5
3
+ * (c) 2010-2012 Google, Inc. http://angularjs.org
4
+ * License: MIT
5
+ */
6
+ (function(window, angular, undefined) {
7
+ 'use strict';
8
+
9
+ /**
10
+ * @ngdoc overview
11
+ * @name ngResource
12
+ * @description
13
+ */
14
+
15
+ /**
16
+ * @ngdoc object
17
+ * @name ngResource.$resource
18
+ * @requires $http
19
+ *
20
+ * @description
21
+ * A factory which creates a resource object that lets you interact with
22
+ * [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer) server-side data sources.
23
+ *
24
+ * The returned resource object has action methods which provide high-level behaviors without
25
+ * the need to interact with the low level {@link ng.$http $http} service.
26
+ *
27
+ * @param {string} url A parameterized URL template with parameters prefixed by `:` as in
28
+ * `/user/:username`. If you are using a URL with a port number (e.g.
29
+ * `http://example.com:8080/api`), you'll need to escape the colon character before the port
30
+ * number, like this: `$resource('http://example.com\\:8080/api')`.
31
+ *
32
+ * @param {Object=} paramDefaults Default values for `url` parameters. These can be overridden in
33
+ * `actions` methods.
34
+ *
35
+ * Each key value in the parameter object is first bound to url template if present and then any
36
+ * excess keys are appended to the url search query after the `?`.
37
+ *
38
+ * Given a template `/path/:verb` and parameter `{verb:'greet', salutation:'Hello'}` results in
39
+ * URL `/path/greet?salutation=Hello`.
40
+ *
41
+ * If the parameter value is prefixed with `@` then the value of that parameter is extracted from
42
+ * the data object (useful for non-GET operations).
43
+ *
44
+ * @param {Object.<Object>=} actions Hash with declaration of custom action that should extend the
45
+ * default set of resource actions. The declaration should be created in the following format:
46
+ *
47
+ * {action1: {method:?, params:?, isArray:?},
48
+ * action2: {method:?, params:?, isArray:?},
49
+ * ...}
50
+ *
51
+ * Where:
52
+ *
53
+ * - `action` – {string} – The name of action. This name becomes the name of the method on your
54
+ * resource object.
55
+ * - `method` – {string} – HTTP request method. Valid methods are: `GET`, `POST`, `PUT`, `DELETE`,
56
+ * and `JSONP`
57
+ * - `params` – {object=} – Optional set of pre-bound parameters for this action.
58
+ * - isArray – {boolean=} – If true then the returned object for this action is an array, see
59
+ * `returns` section.
60
+ *
61
+ * @returns {Object} A resource "class" object with methods for the default set of resource actions
62
+ * optionally extended with custom `actions`. The default set contains these actions:
63
+ *
64
+ * { 'get': {method:'GET'},
65
+ * 'save': {method:'POST'},
66
+ * 'query': {method:'GET', isArray:true},
67
+ * 'remove': {method:'DELETE'},
68
+ * 'delete': {method:'DELETE'} };
69
+ *
70
+ * Calling these methods invoke an {@link ng.$http} with the specified http method,
71
+ * destination and parameters. When the data is returned from the server then the object is an
72
+ * instance of the resource class. The actions `save`, `remove` and `delete` are available on it
73
+ * as methods with the `$` prefix. This allows you to easily perform CRUD operations (create,
74
+ * read, update, delete) on server-side data like this:
75
+ * <pre>
76
+ var User = $resource('/user/:userId', {userId:'@id'});
77
+ var user = User.get({userId:123}, function() {
78
+ user.abc = true;
79
+ user.$save();
80
+ });
81
+ </pre>
82
+ *
83
+ * It is important to realize that invoking a $resource object method immediately returns an
84
+ * empty reference (object or array depending on `isArray`). Once the data is returned from the
85
+ * server the existing reference is populated with the actual data. This is a useful trick since
86
+ * usually the resource is assigned to a model which is then rendered by the view. Having an empty
87
+ * object results in no rendering, once the data arrives from the server then the object is
88
+ * populated with the data and the view automatically re-renders itself showing the new data. This
89
+ * means that in most case one never has to write a callback function for the action methods.
90
+ *
91
+ * The action methods on the class object or instance object can be invoked with the following
92
+ * parameters:
93
+ *
94
+ * - HTTP GET "class" actions: `Resource.action([parameters], [success], [error])`
95
+ * - non-GET "class" actions: `Resource.action([parameters], postData, [success], [error])`
96
+ * - non-GET instance actions: `instance.$action([parameters], [success], [error])`
97
+ *
98
+ *
99
+ * @example
100
+ *
101
+ * # Credit card resource
102
+ *
103
+ * <pre>
104
+ // Define CreditCard class
105
+ var CreditCard = $resource('/user/:userId/card/:cardId',
106
+ {userId:123, cardId:'@id'}, {
107
+ charge: {method:'POST', params:{charge:true}}
108
+ });
109
+
110
+ // We can retrieve a collection from the server
111
+ var cards = CreditCard.query(function() {
112
+ // GET: /user/123/card
113
+ // server returns: [ {id:456, number:'1234', name:'Smith'} ];
114
+
115
+ var card = cards[0];
116
+ // each item is an instance of CreditCard
117
+ expect(card instanceof CreditCard).toEqual(true);
118
+ card.name = "J. Smith";
119
+ // non GET methods are mapped onto the instances
120
+ card.$save();
121
+ // POST: /user/123/card/456 {id:456, number:'1234', name:'J. Smith'}
122
+ // server returns: {id:456, number:'1234', name: 'J. Smith'};
123
+
124
+ // our custom method is mapped as well.
125
+ card.$charge({amount:9.99});
126
+ // POST: /user/123/card/456?amount=9.99&charge=true {id:456, number:'1234', name:'J. Smith'}
127
+ });
128
+
129
+ // we can create an instance as well
130
+ var newCard = new CreditCard({number:'0123'});
131
+ newCard.name = "Mike Smith";
132
+ newCard.$save();
133
+ // POST: /user/123/card {number:'0123', name:'Mike Smith'}
134
+ // server returns: {id:789, number:'01234', name: 'Mike Smith'};
135
+ expect(newCard.id).toEqual(789);
136
+ * </pre>
137
+ *
138
+ * The object returned from this function execution is a resource "class" which has "static" method
139
+ * for each action in the definition.
140
+ *
141
+ * Calling these methods invoke `$http` on the `url` template with the given `method` and `params`.
142
+ * When the data is returned from the server then the object is an instance of the resource type and
143
+ * all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD
144
+ * operations (create, read, update, delete) on server-side data.
145
+
146
+ <pre>
147
+ var User = $resource('/user/:userId', {userId:'@id'});
148
+ var user = User.get({userId:123}, function() {
149
+ user.abc = true;
150
+ user.$save();
151
+ });
152
+ </pre>
153
+ *
154
+ * It's worth noting that the success callback for `get`, `query` and other method gets passed
155
+ * in the response that came from the server as well as $http header getter function, so one
156
+ * could rewrite the above example and get access to http headers as:
157
+ *
158
+ <pre>
159
+ var User = $resource('/user/:userId', {userId:'@id'});
160
+ User.get({userId:123}, function(u, getResponseHeaders){
161
+ u.abc = true;
162
+ u.$save(function(u, putResponseHeaders) {
163
+ //u => saved user object
164
+ //putResponseHeaders => $http header getter
165
+ });
166
+ });
167
+ </pre>
168
+
169
+ * # Buzz client
170
+
171
+ Let's look at what a buzz client created with the `$resource` service looks like:
172
+ <doc:example>
173
+ <doc:source jsfiddle="false">
174
+ <script>
175
+ function BuzzController($resource) {
176
+ this.userId = 'googlebuzz';
177
+ this.Activity = $resource(
178
+ 'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments',
179
+ {alt:'json', callback:'JSON_CALLBACK'},
180
+ {get:{method:'JSONP', params:{visibility:'@self'}}, replies: {method:'JSONP', params:{visibility:'@self', comments:'@comments'}}}
181
+ );
182
+ }
183
+
184
+ BuzzController.prototype = {
185
+ fetch: function() {
186
+ this.activities = this.Activity.get({userId:this.userId});
187
+ },
188
+ expandReplies: function(activity) {
189
+ activity.replies = this.Activity.replies({userId:this.userId, activityId:activity.id});
190
+ }
191
+ };
192
+ BuzzController.$inject = ['$resource'];
193
+ </script>
194
+
195
+ <div ng-controller="BuzzController">
196
+ <input ng-model="userId"/>
197
+ <button ng-click="fetch()">fetch</button>
198
+ <hr/>
199
+ <div ng-repeat="item in activities.data.items">
200
+ <h1 style="font-size: 15px;">
201
+ <img src="{{item.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
202
+ <a href="{{item.actor.profileUrl}}">{{item.actor.name}}</a>
203
+ <a href ng-click="expandReplies(item)" style="float: right;">Expand replies: {{item.links.replies[0].count}}</a>
204
+ </h1>
205
+ {{item.object.content | html}}
206
+ <div ng-repeat="reply in item.replies.data.items" style="margin-left: 20px;">
207
+ <img src="{{reply.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
208
+ <a href="{{reply.actor.profileUrl}}">{{reply.actor.name}}</a>: {{reply.content | html}}
209
+ </div>
210
+ </div>
211
+ </div>
212
+ </doc:source>
213
+ <doc:scenario>
214
+ </doc:scenario>
215
+ </doc:example>
216
+ */
217
+ angular.module('ngResource', ['ng']).
218
+ factory('$resource', ['$http', '$parse', function($http, $parse) {
219
+ var DEFAULT_ACTIONS = {
220
+ 'get': {method:'GET'},
221
+ 'save': {method:'POST'},
222
+ 'query': {method:'GET', isArray:true},
223
+ 'remove': {method:'DELETE'},
224
+ 'delete': {method:'DELETE'}
225
+ };
226
+ var noop = angular.noop,
227
+ forEach = angular.forEach,
228
+ extend = angular.extend,
229
+ copy = angular.copy,
230
+ isFunction = angular.isFunction,
231
+ getter = function(obj, path) {
232
+ return $parse(path)(obj);
233
+ };
234
+
235
+ /**
236
+ * We need our custom method because encodeURIComponent is too aggressive and doesn't follow
237
+ * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
238
+ * segments:
239
+ * segment = *pchar
240
+ * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
241
+ * pct-encoded = "%" HEXDIG HEXDIG
242
+ * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
243
+ * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
244
+ * / "*" / "+" / "," / ";" / "="
245
+ */
246
+ function encodeUriSegment(val) {
247
+ return encodeUriQuery(val, true).
248
+ replace(/%26/gi, '&').
249
+ replace(/%3D/gi, '=').
250
+ replace(/%2B/gi, '+');
251
+ }
252
+
253
+
254
+ /**
255
+ * This method is intended for encoding *key* or *value* parts of query component. We need a custom
256
+ * method becuase encodeURIComponent is too agressive and encodes stuff that doesn't have to be
257
+ * encoded per http://tools.ietf.org/html/rfc3986:
258
+ * query = *( pchar / "/" / "?" )
259
+ * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
260
+ * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
261
+ * pct-encoded = "%" HEXDIG HEXDIG
262
+ * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
263
+ * / "*" / "+" / "," / ";" / "="
264
+ */
265
+ function encodeUriQuery(val, pctEncodeSpaces) {
266
+ return encodeURIComponent(val).
267
+ replace(/%40/gi, '@').
268
+ replace(/%3A/gi, ':').
269
+ replace(/%24/g, '$').
270
+ replace(/%2C/gi, ',').
271
+ replace((pctEncodeSpaces ? null : /%20/g), '+');
272
+ }
273
+
274
+ function Route(template, defaults) {
275
+ this.template = template = template + '#';
276
+ this.defaults = defaults || {};
277
+ var urlParams = this.urlParams = {};
278
+ forEach(template.split(/\W/), function(param){
279
+ if (param && (new RegExp("(^|[^\\\\]):" + param + "\\W").test(template))) {
280
+ urlParams[param] = true;
281
+ }
282
+ });
283
+ this.template = template.replace(/\\:/g, ':');
284
+ }
285
+
286
+ Route.prototype = {
287
+ url: function(params) {
288
+ var self = this,
289
+ url = this.template,
290
+ val,
291
+ encodedVal;
292
+
293
+ params = params || {};
294
+ forEach(this.urlParams, function(_, urlParam){
295
+ val = params.hasOwnProperty(urlParam) ? params[urlParam] : self.defaults[urlParam];
296
+ if (angular.isDefined(val) && val !== null) {
297
+ encodedVal = encodeUriSegment(val);
298
+ url = url.replace(new RegExp(":" + urlParam + "(\\W)", "g"), encodedVal + "$1");
299
+ } else {
300
+ url = url.replace(new RegExp("(\/?):" + urlParam + "(\\W)", "g"), function(match,
301
+ leadingSlashes, tail) {
302
+ if (tail.charAt(0) == '/') {
303
+ return tail;
304
+ } else {
305
+ return leadingSlashes + tail;
306
+ }
307
+ });
308
+ }
309
+ });
310
+ url = url.replace(/\/?#$/, '');
311
+ var query = [];
312
+ forEach(params, function(value, key){
313
+ if (!self.urlParams[key]) {
314
+ query.push(encodeUriQuery(key) + '=' + encodeUriQuery(value));
315
+ }
316
+ });
317
+ query.sort();
318
+ url = url.replace(/\/*$/, '');
319
+ return url + (query.length ? '?' + query.join('&') : '');
320
+ }
321
+ };
322
+
323
+
324
+ function ResourceFactory(url, paramDefaults, actions) {
325
+ var route = new Route(url);
326
+
327
+ actions = extend({}, DEFAULT_ACTIONS, actions);
328
+
329
+ function extractParams(data, actionParams){
330
+ var ids = {};
331
+ actionParams = extend({}, paramDefaults, actionParams);
332
+ forEach(actionParams, function(value, key){
333
+ ids[key] = value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
334
+ });
335
+ return ids;
336
+ }
337
+
338
+ function Resource(value){
339
+ copy(value || {}, this);
340
+ }
341
+
342
+ forEach(actions, function(action, name) {
343
+ action.method = angular.uppercase(action.method);
344
+ var hasBody = action.method == 'POST' || action.method == 'PUT' || action.method == 'PATCH';
345
+ Resource[name] = function(a1, a2, a3, a4) {
346
+ var params = {};
347
+ var data;
348
+ var success = noop;
349
+ var error = null;
350
+ switch(arguments.length) {
351
+ case 4:
352
+ error = a4;
353
+ success = a3;
354
+ //fallthrough
355
+ case 3:
356
+ case 2:
357
+ if (isFunction(a2)) {
358
+ if (isFunction(a1)) {
359
+ success = a1;
360
+ error = a2;
361
+ break;
362
+ }
363
+
364
+ success = a2;
365
+ error = a3;
366
+ //fallthrough
367
+ } else {
368
+ params = a1;
369
+ data = a2;
370
+ success = a3;
371
+ break;
372
+ }
373
+ case 1:
374
+ if (isFunction(a1)) success = a1;
375
+ else if (hasBody) data = a1;
376
+ else params = a1;
377
+ break;
378
+ case 0: break;
379
+ default:
380
+ throw "Expected between 0-4 arguments [params, data, success, error], got " +
381
+ arguments.length + " arguments.";
382
+ }
383
+
384
+ var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data));
385
+ $http({
386
+ method: action.method,
387
+ url: route.url(extend({}, extractParams(data, action.params || {}), params)),
388
+ data: data
389
+ }).then(function(response) {
390
+ var data = response.data;
391
+
392
+ if (data) {
393
+ if (action.isArray) {
394
+ value.length = 0;
395
+ forEach(data, function(item) {
396
+ value.push(new Resource(item));
397
+ });
398
+ } else {
399
+ copy(data, value);
400
+ }
401
+ }
402
+ (success||noop)(value, response.headers);
403
+ }, error);
404
+
405
+ return value;
406
+ };
407
+
408
+
409
+ Resource.prototype['$' + name] = function(a1, a2, a3) {
410
+ var params = extractParams(this),
411
+ success = noop,
412
+ error;
413
+
414
+ switch(arguments.length) {
415
+ case 3: params = a1; success = a2; error = a3; break;
416
+ case 2:
417
+ case 1:
418
+ if (isFunction(a1)) {
419
+ success = a1;
420
+ error = a2;
421
+ } else {
422
+ params = a1;
423
+ success = a2 || noop;
424
+ }
425
+ case 0: break;
426
+ default:
427
+ throw "Expected between 1-3 arguments [params, success, error], got " +
428
+ arguments.length + " arguments.";
429
+ }
430
+ var data = hasBody ? this : undefined;
431
+ Resource[name].call(this, params, data, success, error);
432
+ };
433
+ });
434
+
435
+ Resource.bind = function(additionalParamDefaults){
436
+ return ResourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions);
437
+ };
438
+
439
+ return Resource;
440
+ }
441
+
442
+ return ResourceFactory;
443
+ }]);
444
+
445
+ })(window, window.angular);