cream 0.8.7 → 0.8.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ 0.8.7 - Jan 9, 2011
2
+ -----
3
+ Added devise:customize generator, cleaned up design and fixed some bugs!
4
+
1
5
  0.8.6 - Jan 4, 2011
2
6
  -----
3
7
  Completed major refactoring to streamline generators and DRY things up!
data/Gemfile CHANGED
@@ -14,7 +14,7 @@ group :default do
14
14
  gem "rails", ">= 3.0.1"
15
15
 
16
16
  gem "rails3_artifactor", ">= 0.3.2"
17
- gem 'logging_assist', "~> 0.1.6"
17
+ gem 'logging_assist', ">= 0.2.0"
18
18
 
19
19
  gem "r3_plugin_toolbox", ">= 0.4.0"
20
20
  gem "sugar-high", "~> 0.3.1"
@@ -59,8 +59,6 @@ Cream edge (directly from trunk or a feature branch), might have some extra good
59
59
 
60
60
  <code>gem 'cream', :git => 'https://github.com/kristianmandrup/cream.git'</code>
61
61
 
62
- Note: As a bonus you currently get access to a new *devise:customize* generator under development (Jan 7, 2011)
63
-
64
62
  There is also a _:branch_ option to use a specific branch, fx a feature branch.
65
63
 
66
64
  If you want to develop on Cream: <code>git clone https://github.com/kristianmandrup/cream.git</code>
data/Rakefile CHANGED
@@ -27,10 +27,10 @@ begin
27
27
  gem.add_dependency "rails", ">= 3.0.1"
28
28
 
29
29
  gem.add_dependency "rails3_artifactor", "~> 0.3.2"
30
- gem.add_dependency 'logging_assist', "~> 0.1.6"
30
+ gem.add_dependency 'logging_assist', ">= 0.1.6"
31
31
 
32
32
  gem.add_dependency "r3_plugin_toolbox", ">= 0.4.0"
33
- gem.add_dependency "sugar-high", "~> 0.3.1"
33
+ gem.add_dependency "sugar-high", ">= 0.3.1"
34
34
 
35
35
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
36
36
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.7
1
+ 0.8.8
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cream}
8
- s.version = "0.8.7"
8
+ s.version = "0.8.8"
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"]
@@ -54,6 +54,7 @@ Gem::Specification.new do |s|
54
54
  "lib/cream/view/user_action_menu.rb",
55
55
  "lib/generators/cancan/config/config_generator.rb",
56
56
  "lib/generators/cream/app/app_generator.rb",
57
+ "lib/generators/cream/core_ext.rb",
57
58
  "lib/generators/cream/full_config/full_config_generator.rb",
58
59
  "lib/generators/cream/helpers/all.rb",
59
60
  "lib/generators/cream/helpers/args_helper.rb",
@@ -141,7 +142,7 @@ Gem::Specification.new do |s|
141
142
  s.add_runtime_dependency(%q<cancan>, [">= 1.4.0"])
142
143
  s.add_runtime_dependency(%q<rails>, [">= 3.0.1"])
143
144
  s.add_runtime_dependency(%q<rails3_artifactor>, [">= 0.3.2"])
144
- s.add_runtime_dependency(%q<logging_assist>, ["~> 0.1.6"])
145
+ s.add_runtime_dependency(%q<logging_assist>, [">= 0.2.0"])
145
146
  s.add_runtime_dependency(%q<r3_plugin_toolbox>, [">= 0.4.0"])
146
147
  s.add_runtime_dependency(%q<sugar-high>, ["~> 0.3.1"])
147
148
  s.add_development_dependency(%q<rspec>, [">= 2.0.1"])
@@ -159,9 +160,9 @@ Gem::Specification.new do |s|
159
160
  s.add_runtime_dependency(%q<cancan>, [">= 1.4.0"])
160
161
  s.add_runtime_dependency(%q<rails>, [">= 3.0.1"])
161
162
  s.add_runtime_dependency(%q<rails3_artifactor>, ["~> 0.3.2"])
162
- s.add_runtime_dependency(%q<logging_assist>, ["~> 0.1.6"])
163
+ s.add_runtime_dependency(%q<logging_assist>, [">= 0.1.6"])
163
164
  s.add_runtime_dependency(%q<r3_plugin_toolbox>, [">= 0.4.0"])
164
- s.add_runtime_dependency(%q<sugar-high>, ["~> 0.3.1"])
165
+ s.add_runtime_dependency(%q<sugar-high>, [">= 0.3.1"])
165
166
  else
166
167
  s.add_dependency(%q<devise-links>, [">= 0.2.0"])
167
168
  s.add_dependency(%q<cancan-rest-links>, [">= 0.2.0"])
@@ -172,7 +173,7 @@ Gem::Specification.new do |s|
172
173
  s.add_dependency(%q<cancan>, [">= 1.4.0"])
173
174
  s.add_dependency(%q<rails>, [">= 3.0.1"])
174
175
  s.add_dependency(%q<rails3_artifactor>, [">= 0.3.2"])
175
- s.add_dependency(%q<logging_assist>, ["~> 0.1.6"])
176
+ s.add_dependency(%q<logging_assist>, [">= 0.2.0"])
176
177
  s.add_dependency(%q<r3_plugin_toolbox>, [">= 0.4.0"])
177
178
  s.add_dependency(%q<sugar-high>, ["~> 0.3.1"])
178
179
  s.add_dependency(%q<rspec>, [">= 2.0.1"])
@@ -190,9 +191,9 @@ Gem::Specification.new do |s|
190
191
  s.add_dependency(%q<cancan>, [">= 1.4.0"])
191
192
  s.add_dependency(%q<rails>, [">= 3.0.1"])
192
193
  s.add_dependency(%q<rails3_artifactor>, ["~> 0.3.2"])
193
- s.add_dependency(%q<logging_assist>, ["~> 0.1.6"])
194
+ s.add_dependency(%q<logging_assist>, [">= 0.1.6"])
194
195
  s.add_dependency(%q<r3_plugin_toolbox>, [">= 0.4.0"])
195
- s.add_dependency(%q<sugar-high>, ["~> 0.3.1"])
196
+ s.add_dependency(%q<sugar-high>, [">= 0.3.1"])
196
197
  end
197
198
  else
198
199
  s.add_dependency(%q<devise-links>, [">= 0.2.0"])
@@ -204,7 +205,7 @@ Gem::Specification.new do |s|
204
205
  s.add_dependency(%q<cancan>, [">= 1.4.0"])
205
206
  s.add_dependency(%q<rails>, [">= 3.0.1"])
206
207
  s.add_dependency(%q<rails3_artifactor>, [">= 0.3.2"])
207
- s.add_dependency(%q<logging_assist>, ["~> 0.1.6"])
208
+ s.add_dependency(%q<logging_assist>, [">= 0.2.0"])
208
209
  s.add_dependency(%q<r3_plugin_toolbox>, [">= 0.4.0"])
209
210
  s.add_dependency(%q<sugar-high>, ["~> 0.3.1"])
210
211
  s.add_dependency(%q<rspec>, [">= 2.0.1"])
@@ -222,9 +223,9 @@ Gem::Specification.new do |s|
222
223
  s.add_dependency(%q<cancan>, [">= 1.4.0"])
223
224
  s.add_dependency(%q<rails>, [">= 3.0.1"])
224
225
  s.add_dependency(%q<rails3_artifactor>, ["~> 0.3.2"])
225
- s.add_dependency(%q<logging_assist>, ["~> 0.1.6"])
226
+ s.add_dependency(%q<logging_assist>, [">= 0.1.6"])
226
227
  s.add_dependency(%q<r3_plugin_toolbox>, [">= 0.4.0"])
227
- s.add_dependency(%q<sugar-high>, ["~> 0.3.1"])
228
+ s.add_dependency(%q<sugar-high>, [">= 0.3.1"])
228
229
  end
229
230
  end
230
231
 
@@ -17,12 +17,18 @@ module Cream::Helper
17
17
  return if Labels.state_check Labels.extract(options), current_user
18
18
  yield
19
19
  end
20
-
20
+
21
21
  # does the user have ANY of the given roles?
22
22
  # Uses generic roles API
23
23
  def has_role? user_role
24
24
  current_user && current_user.has_role?(user_role)
25
25
  end
26
+
27
+ # does the user have ANY of the given roles?
28
+ # Uses generic roles API
29
+ def has_any_role? user_role
30
+ current_user && current_user.has_any_role?(user_role)
31
+ end
26
32
 
27
33
  # does the user have ALL of the given roles?
28
34
  # Uses generic roles API
@@ -30,6 +36,20 @@ module Cream::Helper
30
36
  current_user && current_user.has_roles?(roles.flat_uniq)
31
37
  end
32
38
 
39
+ # using group membership as guard
40
+
41
+ def for_user_in_group name, &block
42
+ yield if current_user && current_user.is_in_group?(name)
43
+ end
44
+
45
+ def for_user_in_groups *names, &block
46
+ yield if current_user && current_user.is_in_group?(names.flat_uniq)
47
+ end
48
+
49
+ def for_user_in_any_group *names, &block
50
+ yield if current_user && current_user.is_in_any_groups?(names.flat_uniq)
51
+ end
52
+
33
53
  # returns true if the current user owns the object
34
54
  # tries default 'owner' relations if none given as an argument
35
55
  def owner? obj, relation=nil
@@ -44,14 +64,16 @@ module Cream::Helper
44
64
 
45
65
  # execute block if user DOES have any of the given roles
46
66
  def for_roles *user_roles, &block
47
- user_roles = user_roles.flatten
67
+ user_roles = user_roles.flat_uniq
48
68
  yield if has_roles?(user_roles) && block
49
69
  end
70
+ alias_method :when_user_is, :for_roles
50
71
 
51
72
  def for_any_role *user_roles, &block
52
- user_roles = user_roles.flatten
53
- yield if has_role?(user_roles) && block
73
+ user_roles = user_roles.flat_uniq
74
+ yield if has_any_role?(user_roles) && block
54
75
  end
76
+ alias_method :when_user_is_any_of, :for_any_role
55
77
 
56
78
  def for_role user_role, &block
57
79
  if is_negation_role?(user_role)
@@ -61,9 +83,10 @@ module Cream::Helper
61
83
  yield if has_role?(user_role) && block
62
84
  end
63
85
 
86
+
64
87
  # execute block if user DOES NOT have any of the given roles
65
88
  def not_for_roles(*user_roles, &block)
66
- user_roles = user_roles.flatten
89
+ user_roles = user_roles.flat_uniq
67
90
  yield if !has_roles?(user_roles) && block
68
91
  end
69
92
 
@@ -73,7 +96,8 @@ module Cream::Helper
73
96
  return
74
97
  end
75
98
  yield if !has_role?(user_role) && block
76
- end
99
+ end
100
+ alias_method :when_user_is_not, :not_for_roles
77
101
 
78
102
  protected
79
103
 
@@ -0,0 +1,14 @@
1
+ # TODO:
2
+ # model_file_name and similar methods in rails3_assist and rails3_artifaftor should be fixed to always call underscore on filenames
3
+
4
+ class String
5
+ def as_filename
6
+ self.underscore
7
+ end
8
+ end
9
+
10
+ class Symbol
11
+ def as_filename
12
+ self.to_s.underscore
13
+ end
14
+ end
@@ -35,6 +35,8 @@ module Cream
35
35
  class_option :migrations, :type => :boolean, :default => false, :desc => "Autorun database migrations?", :aliases => '-m'
36
36
 
37
37
  # Devise customize
38
+ class_option :customize, :type => :array, :default => [], :desc => "Which elements of devise to customize (customize generator)"
39
+
38
40
  class_option :user_name, :type => :boolean, :default => true, :desc => "Add username as login option"
39
41
  class_option :login_type, :type => :string, :default => 'generic', :desc => "How to login: 'email', 'username', 'generic' (i.e 'username' or 'email')"
40
42
 
@@ -80,7 +82,8 @@ module Cream
80
82
  end
81
83
 
82
84
  def run_migrations
83
- return if orm != 'active_record'
85
+ return if orm != :active_record
86
+ logger.debug "Running DB migrations"
84
87
  execute "rake db:migrate"
85
88
  end
86
89
 
@@ -91,7 +94,10 @@ module Cream
91
94
  def run_devise
92
95
  rgen "devise:config #{user_class} --orm #{orm} #{admin_user_option}"
93
96
  rgen "devise:users --orm #{orm} --roles #{roles_list} #{admin_user_option} --no-gems"
94
- rgen "devise:customize #{user_class} --orm #{orm} --login-type #{login_type} #{user_name_option}"
97
+
98
+ say("Devise credentials not customized since --customize option was not used to say so!", :green) if !customize_credentials?
99
+
100
+ rgen "devise:customize #{user_class} --orm #{orm} --login-type #{login_type} #{user_name_option}" if customize_credentials?
95
101
  end
96
102
 
97
103
  def run_cancan
@@ -117,6 +123,14 @@ require 'cream/configure/rails'
117
123
  end
118
124
  end
119
125
 
126
+ def customize_credentials?
127
+ customize.include? 'credentials'
128
+ end
129
+
130
+ def customize
131
+ options[:customize]
132
+ end
133
+
120
134
  def login_type
121
135
  options[:login_type]
122
136
  end
@@ -1,3 +1,4 @@
1
+ require 'generators/cream/core_ext'
1
2
  require_all File.dirname(__FILE__)
2
3
 
3
4
  module Cream
@@ -15,7 +15,7 @@ module Cream
15
15
  end
16
16
 
17
17
  def has_user_model?
18
- model_file?(user_class)
18
+ model_file?(user_class.as_filename)
19
19
  end
20
20
 
21
21
  def set_orm
@@ -7,8 +7,10 @@ module DeviseUserGenerator
7
7
  }
8
8
  end
9
9
 
10
- def inherit_model hash
11
- File.replace_content_from model_file_name(subclass hash), :where => /class #{admin_class_name}/, :with => "class #{admin_class_name} < #{superclass hash}"
10
+ def inherit_model hash
11
+ class_name = subclass(hash)
12
+ superclass_name = superclass(hash)
13
+ File.replace_content_from model_file_name(class_name.as_filename), :where => /class #{class_name}/, :with => "class #{class_name} < #{superclass_name}"
12
14
  end
13
15
 
14
16
  def superclass hash
@@ -20,15 +22,15 @@ module DeviseUserGenerator
20
22
  end
21
23
 
22
24
  def remove_inheritance user
23
- File.remove_content_from model_file_name(user), :where => /<\s*ActiveRecord::Base/
25
+ File.remove_content_from model_file_name(user.as_filename), :where => /<\s*ActiveRecord::Base/
24
26
  end
25
27
 
26
28
  def has_admin_model?
27
- has_model? admin_class
29
+ has_model? admin_class.as_filename
28
30
  end
29
31
 
30
32
  def has_user_model?
31
- has_model? user_class
33
+ has_model? user_class.as_filename
32
34
  end
33
35
 
34
36
  def user_generator
@@ -38,7 +40,7 @@ module DeviseUserGenerator
38
40
  def has_devise_user? user
39
41
  return true if is_admin?(user) && !admin_class
40
42
  begin
41
- read_model(user) =~ /devise/
43
+ read_model(user.as_filename) =~ /devise/
42
44
  rescue Exception => e
43
45
  logger.info "Exception for #has_devise_user? #{user}: #{e.message}"
44
46
  false
@@ -7,8 +7,10 @@ module DeviseUserGenerator
7
7
  end
8
8
 
9
9
  def routes_configure!
10
+ routes_content = routes_for_roles
11
+ puts "Insert into routes: #{routes_content}"
10
12
  insert_into_routes do
11
- routes_for_roles
13
+ routes_content
12
14
  end
13
15
  end
14
16
 
@@ -23,9 +25,22 @@ module DeviseUserGenerator
23
25
  end
24
26
 
25
27
  def roles_routes
26
- roles_except(:guest).map do |role|
27
- next if read_routes_file =~ /devise_for :#{role.pluralize}/
28
- %Q{
28
+ roles_to_route = roles_except(:guest).delete_if do |role|
29
+ is_there = !(read_routes_file =~ /devise_for :#{role.pluralize}, :class_name =>/).nil?
30
+ logger.debug "not doing devise routing for #{role.pluralize} as it is already there" if is_there
31
+ is_there
32
+ end
33
+
34
+ roles_to_route.each do |role|
35
+ if read_routes_file =~ /devise_for :#{role.pluralize}/
36
+ logger.debug "removing old devise routing for: #{role}"
37
+ File.remove_content_from routes_file, :where => /devise_for :#{role.pluralize}/
38
+ end
39
+ end
40
+
41
+ logger.debug "performing devise role routing for: #{roles_to_route}"
42
+ roles_to_route.map do |role|
43
+ %Q{
29
44
  devise_for :#{role.pluralize}, :class_name => '#{role.classify}'
30
45
  as :#{role} do
31
46
  match "/#{role.pluralize}/sign_up" => "devise/registrations#new", :as => :#{role}_signup
@@ -113,18 +113,22 @@ module Devise
113
113
 
114
114
  def customize_note
115
115
  %q{
116
- Customize controller action if needed to render individual registration form for each role
117
- Example:
116
+ Customize controller action if needed to render individual registration form for each role
118
117
 
119
- routes.rb
120
- match "/editors/sign_up" => "user_registrations#new_editor", :as => :editor_signup
118
+ Example:
121
119
 
122
- user_registrations_controller.rb
123
- def new_editor
124
- build_resource({})
125
- end
120
+ - routes.rb:
121
+
122
+ match "/editors/sign_up" => "user_registrations#new_editor", :as => :editor_signup
123
+
124
+ - user_registrations_controller.rb:
125
+
126
+ def new_editor
127
+ build_resource({})
128
+ end
126
129
 
127
- Create the registration form for the editor user in 'views/user_registrations/new_editor.html.erb'
130
+ Then create the registration form (view) for the :editor user in 'views/user_registrations/new_editor.html.erb'
131
+ See comments in routes.rb for more info. There is also a page on the wiki about advanced routes customization.
128
132
  }
129
133
  end
130
134
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 8
8
- - 7
9
- version: 0.8.7
8
+ - 8
9
+ version: 0.8.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -157,13 +157,13 @@ dependencies:
157
157
  requirement: &id010 !ruby/object:Gem::Requirement
158
158
  none: false
159
159
  requirements:
160
- - - ~>
160
+ - - ">="
161
161
  - !ruby/object:Gem::Version
162
162
  segments:
163
163
  - 0
164
- - 1
165
- - 6
166
- version: 0.1.6
164
+ - 2
165
+ - 0
166
+ version: 0.2.0
167
167
  type: :runtime
168
168
  prerelease: false
169
169
  version_requirements: *id010
@@ -427,7 +427,7 @@ dependencies:
427
427
  requirement: &id028 !ruby/object:Gem::Requirement
428
428
  none: false
429
429
  requirements:
430
- - - ~>
430
+ - - ">="
431
431
  - !ruby/object:Gem::Version
432
432
  segments:
433
433
  - 0
@@ -457,7 +457,7 @@ dependencies:
457
457
  requirement: &id030 !ruby/object:Gem::Requirement
458
458
  none: false
459
459
  requirements:
460
- - - ~>
460
+ - - ">="
461
461
  - !ruby/object:Gem::Version
462
462
  segments:
463
463
  - 0
@@ -514,6 +514,7 @@ files:
514
514
  - lib/cream/view/user_action_menu.rb
515
515
  - lib/generators/cancan/config/config_generator.rb
516
516
  - lib/generators/cream/app/app_generator.rb
517
+ - lib/generators/cream/core_ext.rb
517
518
  - lib/generators/cream/full_config/full_config_generator.rb
518
519
  - lib/generators/cream/helpers/all.rb
519
520
  - lib/generators/cream/helpers/args_helper.rb