active_leonardo 0.0.3 → 0.0.4

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.
data/CHANGELOG CHANGED
@@ -1,4 +1,7 @@
1
- 0.0.3 (May 23th, 2012) Marco Mastrodonato
1
+ 0.0.4 (August 13th, 2012) Marco Mastrodonato
2
+ * Now you can use any name instead of *User*
3
+
4
+ 0.0.3 (August 10th, 2012) Marco Mastrodonato
2
5
  * Improved cancan integration
3
6
  * Localization yaml file cleaned from some previous leonardo stuff
4
7
 
data/README.rdoc CHANGED
@@ -139,7 +139,7 @@ PS: Of course, these options are in addition to those provided by the original s
139
139
 
140
140
  == Tutorial
141
141
 
142
- That what do you think is??? :)
142
+ On my blog you can find some other info.
143
143
 
144
144
 
145
145
 
data/active_template.rb CHANGED
@@ -48,8 +48,20 @@ authentication = yes?("Authentication ?")
48
48
  model_name = authorization = nil
49
49
  if authentication
50
50
  default_model_name = "User"
51
- model_name = ask(" Insert model name: [#{default_model_name}] (Other names are not tested yet)")
52
- model_name = default_model_name if model_name.empty?
51
+ model_name = ask(" Insert model name: [#{default_model_name}]")
52
+ if model_name.empty? || model_name == 'y'
53
+ model_name = default_model_name
54
+ else
55
+ model_name = model_name.classify
56
+ stdout = <<-REMEM.gsub(/^ /, '')
57
+ *************************************************************************
58
+ Remember to add your auth class when you use active leonardo's generator.
59
+ For example:
60
+ rails g leosca Product name price:decimal --auth_class=#{model_name}
61
+ *************************************************************************
62
+ REMEM
63
+ p stdout
64
+ end
53
65
 
54
66
  authorization = yes?("Authorization ?")
55
67
  gem 'cancan' if authorization
@@ -60,7 +72,7 @@ home = yes?("Ok. Would you create home controller as root ?") unless dashboard_r
60
72
 
61
73
  if yes?("Bundle install ?")
62
74
  dir = ask(" Insert folder name to install locally: [blank=default gems path]")
63
- run "bundle install #{"--path=#{dir}" unless dir.empty?}"
75
+ run "bundle install #{"--path=#{dir}" unless dir.empty? || dir=='y'}"
64
76
  end
65
77
 
66
78
  generate "active_admin:install #{authentication ? model_name : "--skip-users"}"
@@ -20,6 +20,10 @@ module ActiveLeonardo
20
20
  def activeadmin?
21
21
  File.exists? activeadmin_file
22
22
  end
23
+ def auth_class
24
+ return unless options[:auth_class]
25
+ options[:auth_class].classify
26
+ end
23
27
  #def formtastic?
24
28
  # return false unless options.formtastic?
25
29
  # File.exists? "config/initializers/formtastic.rb"
@@ -114,6 +114,9 @@ class LeolayGenerator < Rails::Generators::Base
114
114
  rescue_from CanCan::AccessDenied do |exception|
115
115
  redirect_to root_url, :alert => exception.message
116
116
  end
117
+ def current_ability
118
+ @current_ability ||= Ability.new(current_#{options[:auth_class].downcase})
119
+ end
117
120
  FILE
118
121
  end if options.authorization?
119
122
 
@@ -153,11 +156,11 @@ class LeolayGenerator < Rails::Generators::Base
153
156
  end
154
157
 
155
158
  def setup_authentication
156
- file = "app/models/#{options.auth_class}.rb"
159
+ file = "app/models/#{options[:auth_class].downcase}.rb"
157
160
  #puts "File #{file} #{File.exists?(file) ? "" : "does not"} exists!"
158
161
  return unless options.authentication? and File.exists?(file)
159
162
 
160
- inject_into_class file, options[:auth_class] do
163
+ inject_into_class file, auth_class do
161
164
  <<-FILE.gsub(/^ /, '')
162
165
  ROLES = %w[admin manager user guest]
163
166
  scope :with_role, lambda { |role| {:conditions => "roles_mask & \#{2**ROLES.index(role.to_s)} > 0 "} }
@@ -186,9 +189,10 @@ class LeolayGenerator < Rails::Generators::Base
186
189
  def setup_authorization
187
190
  file = "app/models/ability.rb"
188
191
  return unless File.exists?(file)
192
+ gsub_file file, /initialize(\s|\()user(.|)/, "initialize(#{options[:auth_class].downcase})"
189
193
  inject_into_file file, :before => " end\nend" do
190
194
  <<-FILE.gsub(/^ /, '')
191
- #{options[:auth_class].downcase} ||= #{options[:auth_class].classify}.new
195
+ #{options[:auth_class].downcase} ||= #{auth_class}.new
192
196
  can :manage, :all if #{options[:auth_class].downcase}.role? :admin
193
197
 
194
198
  FILE
@@ -200,13 +204,13 @@ class LeolayGenerator < Rails::Generators::Base
200
204
  file = "db/seeds.rb"
201
205
  append_file file do
202
206
  <<-FILE.gsub(/^ /, '')
203
- user=#{options[:auth_class]}.new :email => 'admin@#{app_name}.com', :password => 'abcd1234', :password_confirmation => 'abcd1234'
207
+ user=#{auth_class}.new :email => 'admin@#{app_name}.com', :password => 'abcd1234', :password_confirmation => 'abcd1234'
204
208
  #{"user.roles=['admin']" if options.authorization?}
205
209
  user.save
206
- user=#{options[:auth_class]}.new :email => 'manager@#{app_name}.com', :password => 'abcd1234', :password_confirmation => 'abcd1234'
210
+ user=#{auth_class}.new :email => 'manager@#{app_name}.com', :password => 'abcd1234', :password_confirmation => 'abcd1234'
207
211
  #{"user.roles=['manager']" if options.authorization?}
208
212
  user.save
209
- user=#{options[:auth_class]}.new :email => 'user@#{app_name}.com', :password => 'abcd1234', :password_confirmation => 'abcd1234'
213
+ user=#{auth_class}.new :email => 'user@#{app_name}.com', :password => 'abcd1234', :password_confirmation => 'abcd1234'
210
214
  #{"user.roles=['user']" if options.authorization?}
211
215
  user.save
212
216
  FILE
@@ -1,11 +1,14 @@
1
1
  ActiveAdmin.register <%= options[:auth_class] %> do
2
+ <%- if options.authorization? -%>
2
3
  menu :if => proc{ can?(:manage, <%= options[:auth_class] %>) }
3
-
4
+ <%- end -%>
4
5
  config.sort_order = 'email_asc'
5
6
 
6
7
  controller do
8
+ <%- if options.authorization? -%>
7
9
  load_resource :except => :index
8
10
  authorize_resource
11
+ <%- end -%>
9
12
  def update
10
13
  unless params[:<%= options[:auth_class].downcase %>]['password'] && params[:<%= options[:auth_class].downcase %>]['password'].size > 0
11
14
  params[:<%= options[:auth_class].downcase %>].delete 'password'
@@ -21,9 +24,11 @@ ActiveAdmin.register <%= options[:auth_class] %> do
21
24
  id_column
22
25
  column :email
23
26
  #column :group, :sortable => :group_id
24
- column :roles do |user|
25
- user.roles.join ", "
27
+ <%- if options.authorization? -%>
28
+ column :roles do |<%= options[:auth_class].downcase %>|
29
+ <%= options[:auth_class].downcase %>.roles.join ", "
26
30
  end
31
+ <%- end -%>
27
32
  column :current_sign_in_at
28
33
  column :current_sign_in_ip
29
34
  column :created_at
@@ -31,16 +36,18 @@ ActiveAdmin.register <%= options[:auth_class] %> do
31
36
  end
32
37
 
33
38
  form do |f|
39
+ <%- if options.authorization? -%>
34
40
  input_roles = "<li>" <<
35
41
  f.label(:roles) <<
36
42
  <%= options[:auth_class] %>::ROLES.map{|role| check_box_tag("<%= options[:auth_class].downcase %>[roles][]", role, f.object.roles.include?(role)) << ' ' << role.humanize.html_safe }.join(" ") <<
37
43
  hidden_field_tag("<%= options[:auth_class].downcase %>[roles][]") <<
38
44
  "</li>"
45
+ <%- end -%>
39
46
  f.inputs "Account" do
40
47
  f.input :email
41
48
  f.input :password
42
- f.input(:password_confirmation) <<
43
- input_roles.html_safe
49
+ f.input(:password_confirmation) <%= "<< input_roles.html_safe" if options.authorization? %>
50
+
44
51
  end
45
52
  f.buttons
46
53
  end
@@ -53,9 +60,11 @@ ActiveAdmin.register <%= options[:auth_class] %> do
53
60
  row :last_sign_in_at
54
61
  row :sign_in_count
55
62
  row :current_sign_in_ip
56
- row :roles do |user|
57
- user.roles.join ", "
63
+ <%- if options.authorization? -%>
64
+ row :roles do |<%= options[:auth_class].downcase %>|
65
+ <%= options[:auth_class].downcase %>.roles.join ", "
58
66
  end
67
+ <%- end -%>
59
68
  row :created_at
60
69
  row :updated_at
61
70
  end
@@ -65,7 +74,9 @@ ActiveAdmin.register <%= options[:auth_class] %> do
65
74
  column :email
66
75
  #column("Name") { |<%= options[:auth_class].downcase %>| <%= options[:auth_class].downcase %>.name }
67
76
  #column("Group") { |<%= options[:auth_class].downcase %>| <%= options[:auth_class].downcase %>.group.try(:name) }
77
+ <%- if options.authorization? -%>
68
78
  column(I18n.t('attributes.<%= options[:auth_class].downcase %>.roles')) { |<%= options[:auth_class].downcase %>| <%= options[:auth_class].downcase %>.roles.join ", " }
79
+ <%- end -%>
69
80
  column(I18n.t('attributes.created_at')) { |<%= options[:auth_class].downcase %>| <%= options[:auth_class].downcase %>.created_at.strftime("%d/%m/%Y") }
70
81
  column(I18n.t('attributes.<%= options[:auth_class].downcase %>.last_sign_in_at')) { |<%= options[:auth_class].downcase %>| <%= options[:auth_class].downcase %>.last_sign_in_at.strftime("%d/%m/%Y") if <%= options[:auth_class].downcase %>.last_sign_in_at }
71
82
  end
metadata CHANGED
@@ -1,80 +1,73 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: active_leonardo
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 3
10
- version: 0.0.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Marco Mastrodonato
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-08-10 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-08-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rails
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 3
31
- - 1
32
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
33
21
  version: 3.1.0
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: activeadmin
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: activeadmin
32
+ requirement: !ruby/object:Gem::Requirement
40
33
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 15
45
- segments:
46
- - 0
47
- - 4
48
- - 0
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
49
37
  version: 0.4.0
50
38
  type: :runtime
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- name: cancan
54
39
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
56
41
  none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 3
61
- segments:
62
- - 1
63
- - 5
64
- - 0
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.4.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: cancan
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
65
53
  version: 1.5.0
66
54
  type: :runtime
67
- version_requirements: *id003
68
- description: This generator help you to create new Rails applications to combine with active admin gem. It generates application structure to easily get the internationalization and authorization.
69
- email:
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.5.0
62
+ description: This generator help you to create new Rails applications to combine with
63
+ active admin gem. It generates application structure to easily get the internationalization
64
+ and authorization.
65
+ email:
70
66
  - m.mastrodonato@gmail.com
71
67
  executables: []
72
-
73
68
  extensions: []
74
-
75
69
  extra_rdoc_files: []
76
-
77
- files:
70
+ files:
78
71
  - lib/generators/active_leonardo.rb
79
72
  - lib/generators/erb/leosca/leosca_generator.rb
80
73
  - lib/generators/leolay/install_generator.rb
@@ -115,36 +108,28 @@ files:
115
108
  - active_template.rb
116
109
  homepage: https://github.com/marcomd/Active_Leonardo
117
110
  licenses: []
118
-
119
111
  post_install_message:
120
112
  rdoc_options: []
121
-
122
- require_paths:
113
+ require_paths:
123
114
  - lib
124
- required_ruby_version: !ruby/object:Gem::Requirement
115
+ required_ruby_version: !ruby/object:Gem::Requirement
125
116
  none: false
126
- requirements:
127
- - - ">="
128
- - !ruby/object:Gem::Version
129
- hash: 3
130
- segments:
131
- - 0
132
- version: "0"
133
- required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
122
  none: false
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- hash: 3
139
- segments:
140
- - 0
141
- version: "0"
142
- requirements:
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements:
143
128
  - Start a new app with the template.rb inside root folder
144
129
  rubyforge_project:
145
130
  rubygems_version: 1.8.24
146
131
  signing_key:
147
132
  specification_version: 3
148
- summary: This gem provides a new customized scaffold generator to combine with active admin
133
+ summary: This gem provides a new customized scaffold generator to combine with active
134
+ admin
149
135
  test_files: []
150
-