angular_velocity 0.0.2alpha

Sign up to get free protection for your applications and to get access to all the features.
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
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+
13
+ # Ignore all logfiles and tempfiles.
14
+ /log/*.log
15
+ *.gem
16
+ #because is a generator
17
+ /spec/tmp
18
+ /tmp
19
+ /app
20
+ /config
21
+ /db
22
+ /log
23
+ /public
24
+ /tmp
25
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '3.2.13'
4
+ gem 'rspec'
5
+ #needed to use testunit generator cases with rspec
6
+ gem "generator_spec"
7
+
8
+ gem 'rspec-rails'
@@ -0,0 +1,23 @@
1
+ module AngularVelocity
2
+ module Generators
3
+ module AngularConfig
4
+
5
+ def application_name
6
+ if defined?(Rails) && Rails.application
7
+ "#{Rails.application.class.name.split('::').first}App"
8
+ else
9
+ "App"
10
+ end
11
+ end
12
+
13
+ def angular_path
14
+ "app/assets/javascripts/#{application_name}"
15
+ end
16
+
17
+ def angular_spec_path
18
+ "spec/javascripts/#{application_name}"
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ require 'generators/angular_velocity/angular_config'
2
+
3
+ #Rails.root.join('public','images','logo.png')
4
+
5
+ module AngularVelocity
6
+ module Generators
7
+
8
+ class ControllerGenerator < Rails::Generators::NamedBase
9
+ include AngularVelocity::Generators::AngularConfig
10
+ source_root File.expand_path('../templates', __FILE__)
11
+ desc "This generator creates an angular controller"
12
+
13
+ def create_angular_controller
14
+ template "controller.coffee", "#{angular_path}/controllers/#{file_name}_controller.coffee"
15
+ end
16
+
17
+
18
+ end
19
+
20
+ end
21
+ end
22
+
@@ -0,0 +1,4 @@
1
+ <%=file_name.camelize %>Controller = ($scope) ->
2
+ $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma' ]
3
+
4
+ angular.module('<%= application_name %>').controller( '<%=file_name.camelize %>Ctrl', [ '$scope', <%=file_name.camelize %>Controller ])
@@ -0,0 +1,60 @@
1
+ require 'generators/angular_velocity/angular_config'
2
+
3
+ module AngularVelocity
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ include AngularVelocity::Generators::AngularConfig
7
+ source_root File.expand_path("../templates", __FILE__)
8
+
9
+ desc "This generator installs angular.js with a default folder layout in app/assets/javascripts/"
10
+
11
+ def create_angular_application
12
+ template "app.coffee", "#{angular_path}/app.coffee"
13
+ %W{controllers services models views}.each do |dir|
14
+ empty_directory "#{angular_path}/#{dir}"
15
+ end
16
+ %W{angular angular-cookies angular-mocks angular-resource angular-sanitize angular-scenario}.each do |file|
17
+ copy_file "#{file}.js", "#{angular_path}/#{file}.js"
18
+ end
19
+ insert_into_file "app/assets/javascripts/application.js", :after =>"//= require jquery_ujs" do
20
+ "\n//= require ./#{application_name}/angular.js"
21
+ end
22
+ end
23
+
24
+ def create_main_angular_controller
25
+ template "main_controller.coffee", "#{angular_path}/controllers/main_controller.coffee"
26
+ copy_file("main_control.html", "#{angular_path}/views/main_control.html")
27
+ template "main_controller_spec.coffee", "#{angular_spec_path}/controllers/main_controller_spec.coffee"
28
+ end
29
+
30
+ def create_main_rails_controller
31
+ empty_directory "app/views/main"
32
+ template "index.html.erb", "app/views/main/index.html.erb"
33
+ copy_file "AppLoader.js", "#{angular_path}/#{application_name}Loader.js"
34
+ copy_file "main_controller.rb", "app/controllers/main_controller.rb"
35
+ insert_into_file "config/routes.rb", :after => "Application.routes.draw do" do
36
+ "\n" + %{ get "main/index"\n root to: "main#index"\n}
37
+ end
38
+ end
39
+
40
+ def create_templates_serving_rails_controller
41
+ #http://stackoverflow.com/questions/12116476/rails-static-html-template-files-in-the-asset-pipeline-and-caching-in-developmen
42
+ template "templates_controller.rb", "app/controllers/templates_controller.rb"
43
+ insert_into_file "config/routes.rb", :after => "Application.routes.draw do" do
44
+ "\n" + %{ get "/templates/:path.html" => "templates#file", :constraints => { :path => /.+/ }}
45
+ end
46
+ end
47
+
48
+ def create_angular_jasmine_link
49
+ template "jasmine.yml", "spec/javascripts/support/jasmine.yml"
50
+ insert_into_file "config/routes.rb", :after => "Application.routes.draw do" do
51
+ "\n" + %{ mount JasmineRails::Engine => "/specs" unless Rails.env.production?}
52
+ end
53
+ end
54
+
55
+
56
+
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ //= require ./app
2
+ //= require_directory ./services
3
+ //= require_directory ./controllers
@@ -0,0 +1,183 @@
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 ngCookies
12
+ */
13
+
14
+
15
+ angular.module('ngCookies', ['ng']).
16
+ /**
17
+ * @ngdoc object
18
+ * @name ngCookies.$cookies
19
+ * @requires $browser
20
+ *
21
+ * @description
22
+ * Provides read/write access to browser's cookies.
23
+ *
24
+ * Only a simple Object is exposed and by adding or removing properties to/from
25
+ * this object, new cookies are created/deleted at the end of current $eval.
26
+ *
27
+ * @example
28
+ <doc:example>
29
+ <doc:source>
30
+ <script>
31
+ function ExampleController($cookies) {
32
+ // Retrieving a cookie
33
+ var favoriteCookie = $cookies.myFavorite;
34
+ // Setting a cookie
35
+ $cookies.myFavorite = 'oatmeal';
36
+ }
37
+ </script>
38
+ </doc:source>
39
+ </doc:example>
40
+ */
41
+ factory('$cookies', ['$rootScope', '$browser', function ($rootScope, $browser) {
42
+ var cookies = {},
43
+ lastCookies = {},
44
+ lastBrowserCookies,
45
+ runEval = false,
46
+ copy = angular.copy,
47
+ isUndefined = angular.isUndefined;
48
+
49
+ //creates a poller fn that copies all cookies from the $browser to service & inits the service
50
+ $browser.addPollFn(function() {
51
+ var currentCookies = $browser.cookies();
52
+ if (lastBrowserCookies != currentCookies) { //relies on browser.cookies() impl
53
+ lastBrowserCookies = currentCookies;
54
+ copy(currentCookies, lastCookies);
55
+ copy(currentCookies, cookies);
56
+ if (runEval) $rootScope.$apply();
57
+ }
58
+ })();
59
+
60
+ runEval = true;
61
+
62
+ //at the end of each eval, push cookies
63
+ //TODO: this should happen before the "delayed" watches fire, because if some cookies are not
64
+ // strings or browser refuses to store some cookies, we update the model in the push fn.
65
+ $rootScope.$watch(push);
66
+
67
+ return cookies;
68
+
69
+
70
+ /**
71
+ * Pushes all the cookies from the service to the browser and verifies if all cookies were stored.
72
+ */
73
+ function push() {
74
+ var name,
75
+ value,
76
+ browserCookies,
77
+ updated;
78
+
79
+ //delete any cookies deleted in $cookies
80
+ for (name in lastCookies) {
81
+ if (isUndefined(cookies[name])) {
82
+ $browser.cookies(name, undefined);
83
+ }
84
+ }
85
+
86
+ //update all cookies updated in $cookies
87
+ for(name in cookies) {
88
+ value = cookies[name];
89
+ if (!angular.isString(value)) {
90
+ if (angular.isDefined(lastCookies[name])) {
91
+ cookies[name] = lastCookies[name];
92
+ } else {
93
+ delete cookies[name];
94
+ }
95
+ } else if (value !== lastCookies[name]) {
96
+ $browser.cookies(name, value);
97
+ updated = true;
98
+ }
99
+ }
100
+
101
+ //verify what was actually stored
102
+ if (updated){
103
+ updated = false;
104
+ browserCookies = $browser.cookies();
105
+
106
+ for (name in cookies) {
107
+ if (cookies[name] !== browserCookies[name]) {
108
+ //delete or reset all cookies that the browser dropped from $cookies
109
+ if (isUndefined(browserCookies[name])) {
110
+ delete cookies[name];
111
+ } else {
112
+ cookies[name] = browserCookies[name];
113
+ }
114
+ updated = true;
115
+ }
116
+ }
117
+ }
118
+ }
119
+ }]).
120
+
121
+
122
+ /**
123
+ * @ngdoc object
124
+ * @name ngCookies.$cookieStore
125
+ * @requires $cookies
126
+ *
127
+ * @description
128
+ * Provides a key-value (string-object) storage, that is backed by session cookies.
129
+ * Objects put or retrieved from this storage are automatically serialized or
130
+ * deserialized by angular's toJson/fromJson.
131
+ * @example
132
+ */
133
+ factory('$cookieStore', ['$cookies', function($cookies) {
134
+
135
+ return {
136
+ /**
137
+ * @ngdoc method
138
+ * @name ngCookies.$cookieStore#get
139
+ * @methodOf ngCookies.$cookieStore
140
+ *
141
+ * @description
142
+ * Returns the value of given cookie key
143
+ *
144
+ * @param {string} key Id to use for lookup.
145
+ * @returns {Object} Deserialized cookie value.
146
+ */
147
+ get: function(key) {
148
+ return angular.fromJson($cookies[key]);
149
+ },
150
+
151
+ /**
152
+ * @ngdoc method
153
+ * @name ngCookies.$cookieStore#put
154
+ * @methodOf ngCookies.$cookieStore
155
+ *
156
+ * @description
157
+ * Sets a value for given cookie key
158
+ *
159
+ * @param {string} key Id for the `value`.
160
+ * @param {Object} value Value to be stored.
161
+ */
162
+ put: function(key, value) {
163
+ $cookies[key] = angular.toJson(value);
164
+ },
165
+
166
+ /**
167
+ * @ngdoc method
168
+ * @name ngCookies.$cookieStore#remove
169
+ * @methodOf ngCookies.$cookieStore
170
+ *
171
+ * @description
172
+ * Remove given cookie
173
+ *
174
+ * @param {string} key Id of the key-value pair to delete.
175
+ */
176
+ remove: function(key) {
177
+ delete $cookies[key];
178
+ }
179
+ };
180
+
181
+ }]);
182
+
183
+ })(window, window.angular);