cream 0.8.9.2 → 0.8.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ module Cream
7
7
  end
8
8
 
9
9
  def execute command
10
- logger.debug command
10
+ debug! command
11
11
  run command
12
12
  end
13
13
 
@@ -3,10 +3,10 @@ module Cream
3
3
  module Gemfile
4
4
  def add_gem_version name, version
5
5
  if !has_gem? name
6
- logger.debug "Adding gem: #{name}, #{version}"
6
+ debug! "Adding gem: #{name}, #{version}"
7
7
  gem name, :version => version
8
8
  else
9
- logger.debug "gem: #{name}, #{version} already in Gemfile"
9
+ debug! "gem: #{name}, #{version} already in Gemfile"
10
10
  end
11
11
  end
12
12
 
@@ -17,10 +17,10 @@ module Cream
17
17
  end
18
18
 
19
19
  if !has_gem? name
20
- logger.debug "Adding gem: #{name}"
20
+ debug! "Adding gem: #{name}"
21
21
  gem name
22
22
  else
23
- logger.debug "gem: #{name} already in Gemfile"
23
+ debug! "gem: #{name} already in Gemfile"
24
24
  end
25
25
  end
26
26
  end
@@ -1,7 +1,7 @@
1
1
  module DeviseConfigGenerator
2
2
  module AppHelper
3
3
  def protection_configure!
4
- logger.debug "Configuring: devise authentication filter"
4
+ debug! "Configuring: devise authentication filter"
5
5
  ## Add Devise protection to Application controller:
6
6
  insert_into_controller :application do
7
7
  "before_filter :authenticate_user!"
@@ -12,7 +12,7 @@ module DeviseConfigGenerator
12
12
  # require 'devise/orm/mongo_mapper'
13
13
  def orm_configure!
14
14
  return if orm == :active_record
15
- logger.debug "Configuring orm: [#{orm}]"
15
+ debug! "Configuring orm: [#{orm}]"
16
16
 
17
17
  if !devise_initializer?
18
18
  say "WARNING: initializer/devise.rb not found", :yellow
@@ -20,7 +20,7 @@ module DeviseConfigGenerator
20
20
  end
21
21
 
22
22
  if !has_statement?(orm_replacement)
23
- logger.debug "require 'devise/orm/#{orm}' already in devise.rb initializer"
23
+ debug! "require 'devise/orm/#{orm}' already in devise.rb initializer"
24
24
  return
25
25
  end
26
26
 
@@ -33,7 +33,7 @@ module DeviseConfigGenerator
33
33
  end
34
34
 
35
35
  def mailer_configure!
36
- logger.debug "Configuring: devise mailer"
36
+ debug! "Configuring: devise mailer"
37
37
  insert_application_config "action_mailer.default_url_options = { :host => 'localhost:3000' }"
38
38
  end
39
39
 
@@ -2,7 +2,6 @@ require 'sugar-high/file'
2
2
  require 'sugar-high/module'
3
3
  require 'cream'
4
4
  require 'rails3_artifactor'
5
- require 'logging_assist'
6
5
  require 'generators/cream/helpers/all'
7
6
 
8
7
  # include helpers
@@ -17,11 +16,12 @@ module Devise
17
16
 
18
17
  # ORM to use
19
18
  class_option :orm, :type => :string, :default => 'active_record', :desc => "ORM to use"
19
+ class_option :logging, :type => :boolean, :default => false, :desc => "Logging on?"
20
20
  class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
21
21
  class_option :gems, :type => :boolean, :default => true, :desc => "Add gems to gemfile?"
22
22
 
23
23
  def configure_devise
24
- logger.add_logfile :logfile => logfile if logfile
24
+ logit!
25
25
  devise_gems if gems?
26
26
  say "WARNING: Not configuring devise gems for #{orm}", :yellow if !gems?
27
27
 
@@ -43,10 +43,10 @@ module Devise
43
43
 
44
44
  def devise_install
45
45
  if devise_initializer?
46
- logger.debug "initializers/devise.rb was found so devise:install will not be run"
46
+ debug! "initializers/devise.rb was found so devise:install will not be run"
47
47
  return
48
48
  end
49
- logger.debug "initializers/devise.rb was NOT found so devise:install will now be run"
49
+ debug! "initializers/devise.rb was NOT found so devise:install will now be run"
50
50
  rgen 'devise:install'
51
51
  end
52
52
 
@@ -2,7 +2,6 @@ require 'sugar-high/file'
2
2
  require 'sugar-high/module'
3
3
  require 'cream'
4
4
  require 'rails3_artifactor'
5
- require 'logging_assist'
6
5
  require 'generators/cream/helpers/all'
7
6
 
8
7
  require_all File.dirname(__FILE__) # + '/helpers'
@@ -16,14 +15,15 @@ module Devise
16
15
 
17
16
  # ORM to use
18
17
  class_option :orm, :type => :string, :default => 'active_record', :desc => "ORM to use"
18
+ class_option :logging, :type => :boolean, :default => false, :desc => "Logging on?"
19
19
  class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
20
20
 
21
21
  class_option :user_name, :type => :boolean, :default => true, :desc => "Add username as login option"
22
22
  class_option :login_type, :type => :string, :default => 'generic', :desc => "How to login: 'email', 'username', 'generic' (i.e 'username' or 'email')"
23
23
 
24
24
  def main_flow
25
- logger.add_logfile :logfile => logfile if logfile
26
- logger.debug 'customizing devise...'
25
+ logit!
26
+ debug! 'customizing devise...'
27
27
 
28
28
  Devise::Customizers::UserName.new(orm, user_class, login_attribute).add_to_user_class if add_user_name?
29
29
  end
@@ -17,9 +17,9 @@ module Devise
17
17
  end
18
18
 
19
19
  def add_to_user_class
20
- logger.debug 'add_to_user_class'
20
+ debug! 'add_to_user_class'
21
21
  if active_record? && !has_migration_file?(:add_username_to_users)
22
- logger.debug 'create migration: add_username_to_users'
22
+ debug! 'create migration: add_username_to_users'
23
23
  %x[rails g migration add_username_to_users username:string]
24
24
  %x[rake db:migrate]
25
25
  end
@@ -54,7 +54,7 @@ module Devise
54
54
  end
55
55
 
56
56
  def configure_generic_login
57
- logger.debug 'configure generic login'
57
+ debug! 'configure generic login'
58
58
  add_virtual_login_accessor
59
59
  override_user_auth
60
60
  modify_retrieve_password
@@ -126,7 +126,7 @@ module Devise
126
126
  end
127
127
 
128
128
  def modify_initializer
129
- logger.debug 'modify devise initializer'
129
+ debug! 'modify devise initializer'
130
130
  return if devise_init_content? keys_stmt_replacement(login_attribute)
131
131
 
132
132
  replace_initializer_content :devise, :where => default_keys_stmt, :with => keys_stmt_replacement(login_attribute)
@@ -42,7 +42,7 @@ module DeviseUserGenerator
42
42
  begin
43
43
  read_model(user.as_filename) =~ /devise/
44
44
  rescue Exception => e
45
- logger.info "Exception for #has_devise_user? #{user}: #{e.message}"
45
+ info! "Exception for #has_devise_user? #{user}: #{e.message}"
46
46
  false
47
47
  end
48
48
  end
@@ -2,69 +2,74 @@ module DeviseUserGenerator
2
2
  module RoutesHelper
3
3
  def model_routes
4
4
  arg = "#{user_class.pluralize.underscore}"
5
- arg << ", :admins" if admin_user?
5
+ # arg << ", :admins" if admin_user?
6
6
  arg
7
7
  end
8
8
 
9
9
  def routes_configure!
10
- routes_content = routes_for_roles
10
+ routes_content = default_signin_routes << user_type_routes
11
11
  puts "Insert into routes: #{routes_content}"
12
12
  insert_into_routes do
13
13
  routes_content
14
14
  end
15
15
  end
16
-
17
- def routes_for_roles
18
- say customize_note, :green
19
16
 
20
- routes_customize_comment << roles_routes
17
+ def user_types_to_route
18
+ @user_types_to_route ||= user_types_except(:guest).delete_if do |user_type|
19
+ name_user_types = user_type.pluralize
20
+ is_there = !(read_routes_file =~ /devise_for :#{name_user_types}, :class_name =>/).nil?
21
+ debug! "not doing devise routing for #{name_user_types} as it is already there" if is_there
22
+ is_there
23
+ end
21
24
  end
22
25
 
23
- def roles_except *names
24
- roles.reject {|r| names.include? r.to_sym }
25
- end
26
+ def default_signin_routes
27
+ name_default_users = user_class.underscore.gsub('/', '_').pluralize
28
+ default_user_class = user_class.classify
29
+ %Q{
30
+ match '/sign_in' => 'main#index'
31
+ match '/log_in' => 'main#index'
26
32
 
27
- def roles_routes
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
+ devise_scope do
34
+ get '/sign_in' => 'main#index', :as => :new_user_session
35
+ end
36
+
37
+ devise_for :#{name_default_users}, :class_name => '#{default_user_class}', :controllers => {:sessions => 'main'} do
38
+ get '/sign_in' => 'main#index', :as => :new_user_session
39
+ end}
40
+ end
33
41
 
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}/
42
+ def user_type_routes
43
+ user_types_to_route.each do |user_type|
44
+ name_user_types = user_type.pluralize
45
+ if read_routes_file =~ /devise_for :#{name_user_types}/
46
+ debug! "removing old devise routing for: #{name_user_types}"
47
+ File.remove_content_from routes_file, :where => /devise_for :#{name_user_types}/
38
48
  end
39
49
  end
40
50
 
41
- logger.debug "performing devise role routing for: #{roles_to_route}"
42
- roles_to_route.map do |role|
43
- %Q{
44
- devise_for :#{role.pluralize}, :class_name => '#{role.classify}'
45
- as :#{role} do
46
- match "/#{role.pluralize}/sign_up" => "devise/registrations#new", :as => :#{role}_signup
51
+ debug! "performing devise role routing for: #{user_types_to_route}"
52
+
53
+ user_types_to_route.map do |user_type|
54
+ name_user_types = user_type.pluralize
55
+ name_user_type = user_type.underscore.gsub('/', '_')
56
+ %Q{
57
+ devise_for :#{name_user_types}, :class_name => '#{user_type.classify}', :controllers => {:registrations => 'devise/registrations', :sessions => 'main'} do
58
+ match "/#{name_user_types}/sign_in" => "devise/sessions#new", :as => :#{name_user_type}_signin
59
+ match "/#{name_user_types}/sign_up" => "devise/registrations#new", :as => :#{name_user_type}_signup
47
60
  end
48
61
  }
49
62
  end.join("\n")
50
- end
63
+ end
51
64
 
52
-
53
- def routes_customize_comment
54
- return "" if read_routes_file =~ /customize controller action/
55
- %q{
56
- # customize controller action if needed to render individual registration form for each role
57
- # Example:
58
- # match "/editors/sign_up" => "user_registrations#new_editor", :as => :editor_signup
59
-
60
- # 'user_registrations_controller.rb' with the action #new_editor
61
- # def new_editor
62
- # build_resource({})
63
- # end
64
- #
65
- # and the registration form in 'views/user_registrations/new_editor.html.erb'
66
- #
67
- }
65
+ protected
66
+
67
+ def roles_except *names
68
+ roles.reject {|r| names.include? r.to_sym }
68
69
  end
70
+
71
+ def user_types_except *names
72
+ user_types.reject {|r| user_types.include? r.to_sym }
73
+ end
69
74
  end
70
75
  end
@@ -2,7 +2,6 @@ require 'sugar-high/file'
2
2
  require 'sugar-high/module'
3
3
  require 'cream'
4
4
  require 'rails3_artifactor'
5
- require 'logging_assist'
6
5
  require 'generators/cream/helpers/all'
7
6
 
8
7
  # include helpers
@@ -18,19 +17,22 @@ module Devise
18
17
 
19
18
  class_option :user_class, :type => :string, :default => 'User', :desc => "User class"
20
19
 
20
+ class_option :registrations_for, :type => :array, :default => [], :desc => "User types individual registrations"
21
+
21
22
  # ORM to use
22
23
  class_option :orm, :type => :string, :default => 'active_record', :desc => "ORM to use"
23
24
  class_option :roles, :type => :array, :default => [], :desc => "Roles"
24
- class_option :default_roles, :type => :boolean, :default => true, :desc => "Create default roles :admin and :guest"
25
+ # class_option :default_roles, :type => :boolean, :default => true, :desc => "Create default roles :admin and :guest"
25
26
 
26
27
  class_option :user_types, :type => :array, :default => ['admin'], :desc => "Devise Users to create that override the generic base User", :aliases => '-ut'
27
28
 
29
+ class_option :logging, :type => :boolean, :default => false, :desc => "Logging on?"
28
30
  class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
29
31
  class_option :gems, :type => :boolean, :default => false, :desc => "Add gems to gemfile?"
30
32
 
31
33
  def configure_devise_users
32
- logger.add_logfile :logfile => logfile if logfile
33
- logger.debug "Configure Devise Users"
34
+ logit!
35
+ debug! "Configure Devise Users"
34
36
 
35
37
  self.class.use_orm orm.to_sym
36
38
 
@@ -48,6 +50,17 @@ module Devise
48
50
  end
49
51
 
50
52
  routes_configure!
53
+
54
+ registrations.each do |reg|
55
+ if user_type? reg
56
+ # create controller
57
+ controller = "#{reg}::Registrations".camelcase
58
+ rgen "controller #{controller} new"
59
+ rgen "view #{controller} new"
60
+
61
+ # make controller a devise controller
62
+ replace_controller_inheritance controller.underscore, 'Devise::RegistrationsController'
63
+ end
51
64
  end
52
65
 
53
66
  protected
@@ -62,12 +75,24 @@ module Devise
62
75
 
63
76
  use_helpers :model, :app, :special, :file
64
77
 
78
+ def remove_controller_inheritance name
79
+ File.remove_content_from controller_file_name(name.as_filename), :where => /<\s*ApplicationController/
80
+ end
81
+
82
+ def replace_controller_inheritance name, replace_controller
83
+ File.replace_content_from controller_file_name(name.as_filename), :where => /<\s*ApplicationController/, :with => replace_controller
84
+ end
85
+
86
+ def registrations
87
+ options[:registrations_for]
88
+ end
89
+
65
90
  # creates a new user model of a given name without devise strategies, instead inheriting from the base User
66
91
  # Never create a Guest user model as this should always be a "fake" (suggestions!?)
67
92
  def create_user name
68
93
  return if name.to_sym == :guest
69
94
 
70
- logger.debug "create devise user: #{name}"
95
+ debug! "create devise user: #{name}"
71
96
  create_user_model name
72
97
  # remove any current inheritance
73
98
  remove_inheritance name
@@ -102,30 +127,6 @@ module Devise
102
127
  def devise_base_user
103
128
  create_devise_model user_class
104
129
  end
105
-
106
- private
107
-
108
- def customize_note
109
- %q{
110
- Customize controller action if needed to render an individual registration form for each devise User type
111
-
112
- Example:
113
-
114
- - routes.rb:
115
-
116
- match "/editors/sign_up" => "user_registrations#new_editor", :as => :editor_signup
117
-
118
- - user_registrations_controller.rb:
119
-
120
- def new_editor
121
- build_resource({})
122
- end
123
-
124
- Then create the registration form (view) for the :editor user in 'views/user_registrations/new_editor.html.erb'
125
- See comments in routes.rb for more info. There is also a page on the wiki about advanced routes customization.
126
- }
127
- end
128
-
129
130
  end
130
131
  end
131
132
  end
@@ -2,7 +2,6 @@ require 'sugar-high/file'
2
2
  require 'sugar-high/module'
3
3
  require 'cream'
4
4
  require 'rails3_artifactor'
5
- require 'logging_assist'
6
5
  require 'generators/cream/helpers/all'
7
6
 
8
7
  module Permits
@@ -15,12 +14,13 @@ module Permits
15
14
  class_option :roles, :type => :array, :desc => "Roles for permits"
16
15
  class_option :default_roles, :type => :boolean, :default => true, :desc => "Create default roles :admin and :guest"
17
16
 
17
+ class_option :logging, :type => :boolean, :default => false, :desc => "Logging on?"
18
18
  class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
19
19
  class_option :gems, :type => :boolean, :default => false, :desc => "Add gems to gemfile?"
20
20
 
21
21
  def configure_permits
22
- logger.add_logfile :logfile => logfile if logfile
23
- logger.debug "Configure Permits"
22
+ logit!
23
+ debug! "Configure Permits"
24
24
 
25
25
  permits_gems if gems?
26
26
 
@@ -2,7 +2,6 @@ require 'sugar-high/file'
2
2
  require 'sugar-high/module'
3
3
  require 'cream'
4
4
  require 'rails3_artifactor'
5
- require 'logging_assist'
6
5
  require 'generators/cream/helpers/all'
7
6
 
8
7
  module Roles
@@ -20,12 +19,16 @@ module Roles
20
19
  class_option :role_class, :type => :string, :aliases => "-rc", :default => 'Role', :desc => "Role class name", :optional => true
21
20
  class_option :user_role_class, :type => :string, :aliases => "-urc", :default => 'UserRole', :desc => "User-Role (join table) class name", :optional => true
22
21
 
22
+ class_option :logging, :type => :boolean, :default => false, :desc => "Logging on?"
23
23
  class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
24
24
  class_option :default_roles, :type => :boolean, :default => true, :desc => "Create default roles :admin and :guest"
25
25
  class_option :gems, :type => :boolean, :default => true, :desc => "Add gems to gemfile?"
26
26
 
27
27
  def configure_roles
28
- logger.add_logfile :logfile => logfile if logfile
28
+ if logging_on?
29
+ require 'logging_assist'
30
+
31
+ end
29
32
 
30
33
  # make the artifactor model methods behave according to selected orm! - this is a macro
31
34
  set_orm
@@ -55,7 +58,8 @@ module Roles
55
58
  end
56
59
 
57
60
  def create_roles
58
- rgen "#{roles_generator} #{user_class} --strategy #{strategy} --roles #{roles_list} #{default_roles_option} #{class_options}"
61
+ # #{default_roles_option}
62
+ rgen "#{roles_generator} #{user_class} --strategy #{strategy} --roles #{roles_list} #{class_options}"
59
63
  end
60
64
 
61
65
  def set_valid_roles_cream
@@ -106,9 +110,9 @@ module Roles
106
110
  "valid_roles_are Cream::Role.available"
107
111
  end
108
112
 
109
- def default_roles_option
110
- default_roles? ? '--default-roles' : '--no-default-roles'
111
- end
113
+ # def default_user_types_option
114
+ # default_user_types? ? '--default-user-types' : '--no-default-user-types'
115
+ # end
112
116
  end
113
117
  end
114
118
  end