cream 0.6.4 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_DISABLE_SHARED_GEMS: "1"
data/Gemfile CHANGED
@@ -4,12 +4,12 @@ source 'http://gems.github.com/'
4
4
  group :default do
5
5
  gem "devise-links", "~> 0.1.4"
6
6
  gem "cancan-rest-links", "~> 0.1.3"
7
- gem "cancan-permits", "~> 0.1.3"
7
+ gem "cancan-permits", "~> 0.2.3"
8
8
 
9
9
  gem "require_all", "~> 1.2.0"
10
10
 
11
11
  gem "devise", ">= 1.1.2"
12
- gem "cancan", "~> 1.3.4"
12
+ gem "cancan", "~> 1.4.0"
13
13
  gem "rails", "~> 3.0.0"
14
14
 
15
15
  gem "rails3_artifactor", "~> 0.2.5"
@@ -19,7 +19,8 @@ group :default do
19
19
  gem "sugar-high", "~> 0.2.10"
20
20
  end
21
21
 
22
- group :test do
22
+ group :test do
23
+ gem 'ffaker', '~> 0.4.0', :git => 'http://github.com/kematzy/ffaker.git'
23
24
  gem "rspec", ">= 2.0.0.rc"
24
25
  gem "generator-spec", "~> 0.6.5"
25
26
  gem "rspec-action_view", "~> 0.3.1"
@@ -128,17 +128,24 @@ Currently CanCan is supported as the permission system. I have added the concept
128
128
 
129
129
  Check out [Cancan permits](http://github.com/kristianmandrup/cancan-permits) for more info for how to use Permits.
130
130
 
131
- _Note_: In the future I will add the ability for a given role to have multiple Permits in a PermitSet, so that Permits are stand-alone and not linked to a given role, which
132
- allows permits to be reused for multiple roles. Stay tuned or join in the effort!
131
+ Cream has ben updated to support my latest version of *Cancan permits*, which now support all the ORMs which cream aims to support and which Roles Generic supports.
132
+ The various players are starting to play together nice!
133
133
 
134
134
  ## Generators
135
135
 
136
136
  The following generators are currently available
137
137
 
138
- * config - Configure Rails 3 application with devise Session strategies, a Role strategy, valid roles, and Permits
139
- * views - Generate partials to display menu items for Session actions such as logout, login etc.
138
+ * cream:config - Configure Rails 3 application with Cream
139
+ * cream:users - Configure Rails 3 application with Cream
140
+ * cream:views - Generate partials for menu items
140
141
 
141
- The *config* generator should automatically setup up your project with Devise, a Roles strategy of choice a Permission system of choice and all using an ORM of your choice!
142
+ * permits:config - Configures app with CanCan Permits
143
+ * cancan:config - Configures app with CanCan
144
+ * roles:config - Configures app with Roles
145
+
146
+ All the above generators now have specs to show how to use them.
147
+ Note: They have still not been tested in all scenarios with all ORMs, role strategies etc.
148
+ I am sure there are still some issues... so please help uncover these!
142
149
 
143
150
  Cream will support these ORMs:
144
151
 
@@ -147,18 +154,11 @@ Cream will support these ORMs:
147
154
  * Mongo Mapper
148
155
  * Mongoid
149
156
 
150
- Status 17 sept, 2010:
151
- The latest *generator-spec* and other supporting generator utils I've created (such as rails3_artifactor) should facilitate finishing this generator...
152
-
153
- The goal is to make the generator:
154
- * Configure the Rails 3 app with appropriate gems for the sub-systems
155
- * Run various other generators
156
-
157
- The result should be a full (or nearly full) integration of all the sub-systems mentioned for a given Rails 3 app with the ORM of choice.
157
+ ### Config Generator ###
158
158
 
159
- See [Cream rails 3 app](http://github.com/kristianmandrup/cream-rails3-app) to get an idea of the end goal.
159
+ *Deprecated*
160
160
 
161
- ### Config Generator ###
161
+ In the future this should be a master generator which calls the other generators in turn.
162
162
 
163
163
  <code>rails g cream::config --strategy ROLE_STRATEGY [--init-devise] [--admin_user] [--orm] [--roles]</code>
164
164
 
data/Rakefile CHANGED
@@ -16,11 +16,11 @@ begin
16
16
  gem.add_dependency "require_all", "~> 1.2.0"
17
17
 
18
18
  gem.add_dependency "devise-links", "~> 0.1.4"
19
- gem.add_dependency "cancan-rest-links", "~> 0.1.3"
20
- gem.add_dependency "cancan-permits", "~> 0.1.3"
19
+ gem.add_dependency "cancan-rest-links", "~> 0.1.4"
20
+ gem.add_dependency "cancan-permits", "~> 0.2.4"
21
21
 
22
22
  gem.add_dependency "devise", ">= 1.1.2"
23
- gem.add_dependency "cancan", "~> 1.3.4"
23
+ gem.add_dependency "cancan", "~> 1.4.0"
24
24
  gem.add_dependency "rails", "~> 3.0.0"
25
25
 
26
26
  gem.add_dependency "rails3_artifactor", "~> 0.2.5"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.4
1
+ 0.7.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cream}
8
- s.version = "0.6.4"
8
+ s.version = "0.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
12
- s.date = %q{2010-10-07}
12
+ s.date = %q{2010-10-16}
13
13
  s.description = %q{Provides assistance for setting up Session, Role and Permission systems for a Rails 3 app. Support for multiple ORMs}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -17,7 +17,8 @@ Gem::Specification.new do |s|
17
17
  "README.markdown"
18
18
  ]
19
19
  s.files = [
20
- ".document",
20
+ ".bundle/config",
21
+ ".document",
21
22
  ".gitignore",
22
23
  ".rspec",
23
24
  "Changelog.txt",
@@ -50,6 +51,8 @@ Gem::Specification.new do |s|
50
51
  "lib/cream/view/host_area.rb",
51
52
  "lib/cream/view/role_area.rb",
52
53
  "lib/cream/view/user_action_menu.rb",
54
+ "lib/generators/cancan/config/config_generator.rb",
55
+ "lib/generators/cream/app/app_generator.rb",
53
56
  "lib/generators/cream/config/DESIGN NOTES.markdown",
54
57
  "lib/generators/cream/config/config_generator.rb",
55
58
  "lib/generators/cream/config/modules/app_config.rb",
@@ -63,6 +66,10 @@ Gem::Specification.new do |s|
63
66
  "lib/generators/cream/views/haml_util.rb",
64
67
  "lib/generators/cream/views/views_generator.rb",
65
68
  "lib/generators/cream_refactor.rb",
69
+ "lib/generators/devise/config/config_generator.rb",
70
+ "lib/generators/devise/users/users_generator.rb",
71
+ "lib/generators/permits/config/config_generator.rb",
72
+ "lib/generators/roles/config/config_generator.rb",
66
73
  "log/development.log",
67
74
  "sandbox/test.rb",
68
75
  "spec/configure_helper.rb",
@@ -75,6 +82,8 @@ Gem::Specification.new do |s|
75
82
  "spec/cream/view/host_area_spec.rb",
76
83
  "spec/cream/view/role_area_spec.rb",
77
84
  "spec/generator_spec_helper.rb",
85
+ "spec/generators/cancan/config/cancan_config_generator_spec.rb",
86
+ "spec/generators/cream/app/app_generator_spec.rb",
78
87
  "spec/generators/cream/config/CONFIG_GENERATOR_SPEC.markdown",
79
88
  "spec/generators/cream/config/devise/existing_devise_users.rb",
80
89
  "spec/generators/cream/config/empty_app/default_args_spec.rb",
@@ -84,6 +93,10 @@ Gem::Specification.new do |s|
84
93
  "spec/generators/cream/config/roles/roles_spec.rb",
85
94
  "spec/generators/cream/shared_examples.rb",
86
95
  "spec/generators/cream/views_generator_spec.rb",
96
+ "spec/generators/devise/config/devise_config_generator_spec.rb",
97
+ "spec/generators/devise/users/devise_users_generator_spec.rb",
98
+ "spec/generators/permits/config/permits_config_generator_spec.rb",
99
+ "spec/generators/roles/config/roles_config_generator_spec.rb",
87
100
  "spec/spec_helper.rb",
88
101
  "wiki/CONFIG_GENERATOR.txt",
89
102
  "wiki/DESIGN.txt",
@@ -110,6 +123,8 @@ Gem::Specification.new do |s|
110
123
  "spec/cream/view/host_area_spec.rb",
111
124
  "spec/cream/view/role_area_spec.rb",
112
125
  "spec/generator_spec_helper.rb",
126
+ "spec/generators/cancan/config/cancan_config_generator_spec.rb",
127
+ "spec/generators/cream/app/app_generator_spec.rb",
113
128
  "spec/generators/cream/config/devise/existing_devise_users.rb",
114
129
  "spec/generators/cream/config/empty_app/default_args_spec.rb",
115
130
  "spec/generators/cream/config/permits/existing_permits_spec.rb",
@@ -118,6 +133,10 @@ Gem::Specification.new do |s|
118
133
  "spec/generators/cream/config/roles/roles_spec.rb",
119
134
  "spec/generators/cream/shared_examples.rb",
120
135
  "spec/generators/cream/views_generator_spec.rb",
136
+ "spec/generators/devise/config/devise_config_generator_spec.rb",
137
+ "spec/generators/devise/users/devise_users_generator_spec.rb",
138
+ "spec/generators/permits/config/permits_config_generator_spec.rb",
139
+ "spec/generators/roles/config/roles_config_generator_spec.rb",
121
140
  "spec/spec_helper.rb"
122
141
  ]
123
142
 
@@ -132,10 +151,10 @@ Gem::Specification.new do |s|
132
151
  s.add_development_dependency(%q<rails-app-spec>, ["~> 0.2.14"])
133
152
  s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
134
153
  s.add_runtime_dependency(%q<devise-links>, ["~> 0.1.4"])
135
- s.add_runtime_dependency(%q<cancan-rest-links>, ["~> 0.1.3"])
136
- s.add_runtime_dependency(%q<cancan-permits>, ["~> 0.1.3"])
154
+ s.add_runtime_dependency(%q<cancan-rest-links>, ["~> 0.1.4"])
155
+ s.add_runtime_dependency(%q<cancan-permits>, ["~> 0.2.4"])
137
156
  s.add_runtime_dependency(%q<devise>, [">= 1.1.2"])
138
- s.add_runtime_dependency(%q<cancan>, ["~> 1.3.4"])
157
+ s.add_runtime_dependency(%q<cancan>, ["~> 1.4.0"])
139
158
  s.add_runtime_dependency(%q<rails>, ["~> 3.0.0"])
140
159
  s.add_runtime_dependency(%q<rails3_artifactor>, ["~> 0.2.5"])
141
160
  s.add_runtime_dependency(%q<logging_assist>, ["~> 0.1.3"])
@@ -148,10 +167,10 @@ Gem::Specification.new do |s|
148
167
  s.add_dependency(%q<rails-app-spec>, ["~> 0.2.14"])
149
168
  s.add_dependency(%q<require_all>, ["~> 1.2.0"])
150
169
  s.add_dependency(%q<devise-links>, ["~> 0.1.4"])
151
- s.add_dependency(%q<cancan-rest-links>, ["~> 0.1.3"])
152
- s.add_dependency(%q<cancan-permits>, ["~> 0.1.3"])
170
+ s.add_dependency(%q<cancan-rest-links>, ["~> 0.1.4"])
171
+ s.add_dependency(%q<cancan-permits>, ["~> 0.2.4"])
153
172
  s.add_dependency(%q<devise>, [">= 1.1.2"])
154
- s.add_dependency(%q<cancan>, ["~> 1.3.4"])
173
+ s.add_dependency(%q<cancan>, ["~> 1.4.0"])
155
174
  s.add_dependency(%q<rails>, ["~> 3.0.0"])
156
175
  s.add_dependency(%q<rails3_artifactor>, ["~> 0.2.5"])
157
176
  s.add_dependency(%q<logging_assist>, ["~> 0.1.3"])
@@ -165,10 +184,10 @@ Gem::Specification.new do |s|
165
184
  s.add_dependency(%q<rails-app-spec>, ["~> 0.2.14"])
166
185
  s.add_dependency(%q<require_all>, ["~> 1.2.0"])
167
186
  s.add_dependency(%q<devise-links>, ["~> 0.1.4"])
168
- s.add_dependency(%q<cancan-rest-links>, ["~> 0.1.3"])
169
- s.add_dependency(%q<cancan-permits>, ["~> 0.1.3"])
187
+ s.add_dependency(%q<cancan-rest-links>, ["~> 0.1.4"])
188
+ s.add_dependency(%q<cancan-permits>, ["~> 0.2.4"])
170
189
  s.add_dependency(%q<devise>, [">= 1.1.2"])
171
- s.add_dependency(%q<cancan>, ["~> 1.3.4"])
190
+ s.add_dependency(%q<cancan>, ["~> 1.4.0"])
172
191
  s.add_dependency(%q<rails>, ["~> 3.0.0"])
173
192
  s.add_dependency(%q<rails3_artifactor>, ["~> 0.2.5"])
174
193
  s.add_dependency(%q<logging_assist>, ["~> 0.1.3"])
@@ -19,9 +19,12 @@ Rails3::Plugin::Extender.new do
19
19
  after :initialize do
20
20
  require_all File.dirname(__FILE__) + '/after_init'
21
21
 
22
- Rails3.with_configuration do
23
- autoload_paths += %W(#{Rails.root}/app/permits)
24
- end
22
+ # Rails3.with_configuration do
23
+ # autoload_paths += %W(#{Rails.root}/app/permits)
24
+ # load_paths += %W( #{RAILS_ROOT}/extras )
25
+ # end
26
+
27
+ ActiveSupport::Dependencies.load_paths << %W(#{Rails.root}/app/permits)
25
28
 
26
29
  # set cream config object
27
30
  # Rails3.with_configuration do
@@ -0,0 +1,57 @@
1
+ require 'sugar-high/file'
2
+ require 'sugar-high/module'
3
+ require 'cream'
4
+ require 'rails3_artifactor'
5
+ require 'logging_assist'
6
+
7
+ module CanCan
8
+ module Generators
9
+ class ConfigGenerator < Rails::Generators::Base
10
+ desc "Configure CanCan"
11
+
12
+ class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
13
+
14
+ def cancan_configure
15
+ logger.add_logfile :logfile => logfile if logfile
16
+ cancan_gems
17
+ cancan_exception_handling
18
+ end
19
+
20
+ protected
21
+
22
+ include Rails3::Assist::BasicLogger
23
+ extend Rails3::Assist::UseMacro
24
+
25
+ use_helpers :controller, :app
26
+
27
+ def logfile
28
+ options[:logfile]
29
+ end
30
+
31
+ def cancan_gems
32
+ gem 'cancan'
33
+ gem 'cancan-rest-links'
34
+ end
35
+
36
+ # CanCan access denied exception handling
37
+ def cancan_exception_handling
38
+ logger.debug "Rescue exists? #{rescue_exists?}"
39
+ return if rescue_exists?
40
+
41
+ logger.debug "Insert rescue into application controller"
42
+ insert_into_controller :application, :after => "ActionController::Base\n" do
43
+ %{
44
+ rescue_from CanCan::AccessDenied do |exception|
45
+ flash[:error] = exception.message
46
+ redirect_to root_url
47
+ end
48
+ }
49
+ end
50
+ end
51
+
52
+ def rescue_exists?
53
+ File.read(controller_file :application) =~ /rescue_from CanCan::AccessDenied/
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,64 @@
1
+ require 'sugar-high/file'
2
+ require 'sugar-high/module'
3
+ require 'cream'
4
+ require 'rails3_artifactor'
5
+ require 'logging_assist'
6
+
7
+ module Roles
8
+ module Generators
9
+ class ConfigGenerator < Rails::Generators::Base
10
+ extend Rails3::Assist::UseMacro
11
+
12
+ desc "Configure Permits"
13
+
14
+ # ORM to use
15
+ class_option :orm, :type => :string, :default => 'active_record', :desc => "ORM to use"
16
+
17
+ class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
18
+
19
+ def configure_application
20
+ app_orm
21
+ app_routes
22
+ app_layout
23
+ end
24
+
25
+ protected
26
+
27
+ def app_orm
28
+ return if orm == 'active_record'
29
+ File.replace_content_from config_file(:application), :where => "require 'rails/all'" do
30
+ %q{
31
+ require "action_controller/railtie"
32
+ require "action_mailer/railtie"
33
+ require "active_resource/railtie"
34
+ require "rails/test_unit/railtie"
35
+ }
36
+ end
37
+
38
+ def app_routes
39
+ routes = read_from config_file(:routes)
40
+ # if no :welcome controller
41
+ if !(routes =~ /root\s+:/)
42
+ # create one with an 'index' view.
43
+ insert_into config_file(:routes) :after => 'do', :content => 'root :to => "welcome#index"'
44
+ execute "rails g controller Welcome index"
45
+ end
46
+ end
47
+
48
+ # in 'app/views/layouts/application.html.erb'
49
+ # insert special flash msg displayers after opening <body> element
50
+ def app_layout
51
+ layout_content = read_view :application, :folder => 'layouts' #, :type => :erb
52
+
53
+ [:alert, :notice].each{|name| insert_flash_displayer name}
54
+ end
55
+
56
+ def insert_flash_displayer name
57
+ return if layout_content =~ /<%=\s+#{name}\s+%>/
58
+ insert_into_view :application, :folder => 'layouts', :after => '<body>' do
59
+ '<p class="alert"><%= alert %></p>'
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,5 +1,5 @@
1
1
  require 'sugar-high/file'
2
- require 'sugar-high/modules'
2
+ require 'sugar-high/module'
3
3
  require 'cream'
4
4
  require 'rails3_artifactor'
5
5
  require 'logging_assist'
@@ -71,7 +71,7 @@ module Cream::Generators
71
71
  use_helpers :model, :controller, :permit, :application
72
72
 
73
73
  def configure_logger
74
- logger.add_logfile :logfile => logfile
74
+ logger.add_logfile :logfile => logfile if logfile
75
75
  logger.debug 'main flow'
76
76
  end
77
77
 
@@ -23,7 +23,7 @@ require "rails/test_unit/railtie"
23
23
  # if no :welcome controller
24
24
  if !(routes =~ /root\s+:/)
25
25
  # create one with an 'index' view.
26
- insert_into config_file(:routes) :after => 'do', :content => 'root :to => "welcome#index"'
26
+ insert_into config_file(:routes), :after => 'do', :content => 'root :to => "welcome#index"'
27
27
  execute "rails g controller Welcome index"
28
28
  end
29
29
  end
@@ -2,7 +2,7 @@ module Cream::Generators
2
2
  module Config
3
3
  module CanCan
4
4
  def cancan_configure
5
- configure_cancan_gems
5
+ cancan_gems
6
6
  cancan_exception_handling
7
7
  end
8
8
 
@@ -49,7 +49,7 @@ module Cream::Generators
49
49
  end
50
50
 
51
51
  def devise_users?
52
- has_user?(:user) && has_user?(:admin)
52
+ has_devise_user?(:user) && has_devise_user?(:admin)
53
53
  end
54
54
 
55
55
  def has_devise_user? user
@@ -57,7 +57,7 @@ module Cream::Generators
57
57
  begin
58
58
  read_model(user) =~ /devise/
59
59
  rescue Exception => e
60
- logger.info "Exception for has_user? #{user}: #{e.message}"
60
+ logger.info "Exception for #has_devise_user? #{user}: #{e.message}"
61
61
  false
62
62
  end
63
63
  end
@@ -68,18 +68,23 @@ module Cream::Generators
68
68
  end
69
69
  end
70
70
 
71
- module Inherit
72
- def self.remove_inheritance user
73
- File.remove_from model_file user, :content => /<\s*ActiveRecord::Base/
74
- end
71
+ module Inherit
72
+ self << class
73
+ extend Rails3::Assist::UseMacro
74
+ use_helpers :model
75
+
76
+ def remove_inheritance user
77
+ File.remove_from model_file user, :content => /<\s*ActiveRecord::Base/
78
+ end
75
79
 
76
- def self.inherit_model hash
77
- subclass = hash.keys.first
78
- superclass = hash.values.first.to_s.camelize
79
- File.replace_content_from model_file subclass, :where => /class Admin/, :with => "class Admin < #{superclass}"
80
+ def inherit_model hash
81
+ subclass = hash.keys.first
82
+ superclass = hash.values.first.to_s.camelize
83
+ File.replace_content_from model_file subclass, :where => /class Admin/, :with => "class Admin < #{superclass}"
84
+ end
80
85
  end
81
86
  end
82
-
87
+
83
88
  module Strategy
84
89
  self << class
85
90
  extend Rails3::Assist::UseMacro
@@ -91,8 +96,8 @@ module Cream::Generators
91
96
  "devise #{*names}"
92
97
  end
93
98
  end
94
-
95
- def self.devise_default_strategies
99
+
100
+ def devise_default_strategies
96
101
  [:database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable]
97
102
  end
98
103
  end