active_leonardo 0.2.0 → 0.2.1

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +48 -43
  3. data/LICENSE +19 -19
  4. data/README.md +173 -173
  5. data/active_template.rb +157 -141
  6. data/lib/generators/active_leonardo.rb +383 -383
  7. data/lib/generators/erb/leosca/leosca_generator.rb +122 -122
  8. data/lib/generators/leolay/USAGE +21 -21
  9. data/lib/generators/leolay/leolay_generator.rb +420 -420
  10. data/lib/generators/leolay/templates/app/admin/users.rb +87 -87
  11. data/lib/generators/leolay/templates/spec/helpers/application_helpers.rb +13 -13
  12. data/lib/generators/leolay/templates/spec/support/devise.rb +4 -4
  13. data/lib/generators/leolay/templates/styles/active/stylesheets/app/custom_active_admin.css.scss +27 -27
  14. data/lib/generators/leosca/USAGE +23 -23
  15. data/lib/generators/rails/leosca/USAGE +39 -39
  16. data/lib/generators/rails/leosca/leosca_generator.rb +55 -55
  17. data/lib/generators/rails/leosca/templates/leosca.css +56 -56
  18. data/lib/generators/rails/leosca_controller/USAGE +23 -23
  19. data/lib/generators/rails/leosca_controller/leosca_controller_generator.rb +192 -192
  20. data/lib/generators/rails/leosca_controller/templates/controller.rb +3 -3
  21. data/lib/generators/rspec/leointegration/leointegration_generator.rb +35 -35
  22. data/lib/generators/rspec/leointegration/templates/admin/feature.rb +67 -67
  23. data/lib/generators/rspec/leointegration/templates/feature.rb +9 -9
  24. data/lib/generators/rspec/leosca/leosca_generator.rb +57 -57
  25. data/lib/generators/rspec/leosca/templates/admin/controller_spec.rb +181 -181
  26. data/lib/generators/rspec/leosca/templates/admin/edit_spec.rb +31 -31
  27. data/lib/generators/rspec/leosca/templates/admin/index_spec.rb +32 -32
  28. data/lib/generators/rspec/leosca/templates/admin/new_spec.rb +30 -30
  29. data/lib/generators/rspec/leosca/templates/admin/routing_spec.rb +39 -39
  30. data/lib/generators/rspec/leosca/templates/admin/show_spec.rb +28 -28
  31. data/lib/generators/rspec/leosca/templates/controller_spec.rb +168 -168
  32. data/lib/generators/rspec/leosca/templates/edit_spec.rb +31 -31
  33. data/lib/generators/rspec/leosca/templates/index_spec.rb +32 -32
  34. data/lib/generators/rspec/leosca/templates/new_spec.rb +30 -30
  35. data/lib/generators/rspec/leosca/templates/routing_spec.rb +39 -39
  36. data/lib/generators/rspec/leosca/templates/show_spec.rb +28 -28
  37. metadata +3 -3
@@ -1,122 +1,122 @@
1
- require 'rails/generators/erb/scaffold/scaffold_generator'
2
- require File.join(File.dirname(__FILE__), '../../active_leonardo')
3
-
4
- module Erb
5
- module Generators
6
- class LeoscaGenerator < ::Erb::Generators::ScaffoldGenerator
7
- include ::ActiveLeonardo::Base
8
- include ::ActiveLeonardo::Leosca
9
- #include ::ActiveLeonardo::Nested
10
- #puts 'erb:leosca'
11
-
12
- source_root File.expand_path('../templates', __FILE__)
13
- class_option :authorization, :type => :boolean, :default => true, :description => "Add code to manage authorization with cancan"
14
- #class_option :remote, :type => :boolean, :default => true, :description => "Enable ajax. You can also do later set remote to true into index view."
15
- #class_option :formtastic, :type => :boolean, :default => true, :description => "Create forms to manage with formtastic gem"
16
- #class_option :under, :type => :string, :default => "", :banner => "brand/category", :desc => "To nest a resource under another(s)"
17
- #class_option :leospace, :type => :string, :default => "", :banner => ":admin", :desc => "To nest a resource under namespace(s)"
18
- class_option :auth_class, :type => :boolean, :default => 'user', :desc => "Set the authentication class name"
19
-
20
- #override
21
- #def copy_view_files
22
- # available_views.each do |view|
23
- # filenames = filenames_all_formats(view, source_paths)
24
- # filenames.each do |filename|
25
- # #Looking for custom filename into subfolder
26
- # filename_source = "#{"formtastic/" if formtastic?}#{filename}"
27
- # search_into_subfolder = nil
28
- # source_paths.each do |path|
29
- # if File.exists?(File.join(path,filename_source))
30
- # search_into_subfolder = true
31
- # break
32
- # end
33
- # end
34
- # filename_source = filename unless search_into_subfolder
35
- #
36
- # template filename_source, File.join("app/views", base_namespaces, controller_file_path, filename)
37
- # end
38
- # end
39
- #end
40
-
41
- #def update_layout_html
42
- # file = "app/views/layouts/_#{CONFIG[:default_style]}.html.erb"
43
- # if nested?
44
- # inject_into_file file, :before => " <!-- Insert above here other #{last_parent} elements -->" do
45
- # <<-FILE.gsub(/^ /, '')
46
- # #{"<% if can?(:read, #{class_name}) && controller.controller_path == '#{controller_name}' -%>" if authorization?}
47
- # <li class="active"><%= t('models.#{plural_table_name}') %></li>
48
- # <!-- Insert above here other #{singular_table_name} elements -->
49
- # #{"<% end -%>" if authorization?}
50
- # FILE
51
- # end if File.exists?(file)
52
- # else
53
- # inject_into_file file, :before => " <!-- Insert above other elements -->" do
54
- # <<-FILE.gsub(/^ /, '')
55
- # #{"<% if can?(:read, #{class_name}) -%>" if authorization?}
56
- # <li class="<%= controller.controller_path == '#{formatted_namespace_path}#{controller_name}' ? 'active' : '' %>"><a href="<%= #{list_resources_path} %>"><%= t('models.#{plural_table_name}') %></a></li>
57
- # <!-- Insert above here other #{singular_table_name} elements -->
58
- # #{"<% end -%>" if authorization?}
59
- # FILE
60
- # end if File.exists?(file)
61
- # end
62
- #end
63
-
64
- #def update_parent_views
65
- # return unless nested?
66
- # file = "app/views/#{plural_last_parent}/_row_index.html.erb"
67
- # inject_into_file file, :before => "<!-- Manage section, do not remove this tag -->" do
68
- # <<-FILE.gsub(/^ /, '')
69
- # <td><%= link_to t('models.#{plural_table_name}'), #{list_resources_path_back} %><%= link_to "", #{last_parent}_with_#{plural_table_name}_path(#{last_parent}), :id => "a_#{singular_table_name[0..5]}_\#{#{last_parent}.id}", :class =>"toggle_#{plural_table_name} desc", :remote => true %></td>
70
- #
71
- # FILE
72
- # end if File.exists?(file)
73
- # available_nested_views.each do |view|
74
- # filenames = filenames_all_formats(view, source_paths)
75
- # filenames.each do |filename|
76
- # #Looking for custom filename into subfolder
77
- # filename_source = "#{"formtastic/" if formtastic?}#{filename}"
78
- # search_into_subfolder = nil
79
- # source_paths.each do |path|
80
- # if File.exists?(File.join(path,filename_source))
81
- # search_into_subfolder = true
82
- # break
83
- # end
84
- # end
85
- # filename_source = filename unless search_into_subfolder
86
- #
87
- # template filename_source, File.join("app/views", base_namespaces, plural_last_parent, filename.sub('nested', plural_table_name))
88
- # end
89
- # end
90
- #end
91
-
92
- protected
93
-
94
- #Override
95
- #def available_views
96
- # %w(index edit edit_multiple copy show new _form _form_multiple _fields destroy _show _list _row_index select)
97
- #end
98
- #
99
- #def available_nested_views
100
- # %w(_nested with_nested)
101
- #end
102
- #
103
- #def filenames_all_formats(name, paths=[], formats=[:html, :js, nil])
104
- # filenames = []
105
- # paths.each do |path|
106
- # formats.each do |format|
107
- # filename = filename_with_extensions(format, name)
108
- # if File.exists?(File.join(path, filename))
109
- # filenames << filename
110
- # end
111
- # end
112
- # break if filenames.any?
113
- # end
114
- # filenames
115
- #end
116
- #def filename_with_extensions(format, name, parser=:erb)
117
- # [name, format, parser].compact.join(".")
118
- #end
119
-
120
- end
121
- end
122
- end
1
+ require 'rails/generators/erb/scaffold/scaffold_generator'
2
+ require File.join(File.dirname(__FILE__), '../../active_leonardo')
3
+
4
+ module Erb
5
+ module Generators
6
+ class LeoscaGenerator < ::Erb::Generators::ScaffoldGenerator
7
+ include ::ActiveLeonardo::Base
8
+ include ::ActiveLeonardo::Leosca
9
+ #include ::ActiveLeonardo::Nested
10
+ #puts 'erb:leosca'
11
+
12
+ source_root File.expand_path('../templates', __FILE__)
13
+ class_option :authorization, :type => :boolean, :default => true, :description => "Add code to manage authorization with cancan"
14
+ #class_option :remote, :type => :boolean, :default => true, :description => "Enable ajax. You can also do later set remote to true into index view."
15
+ #class_option :formtastic, :type => :boolean, :default => true, :description => "Create forms to manage with formtastic gem"
16
+ #class_option :under, :type => :string, :default => "", :banner => "brand/category", :desc => "To nest a resource under another(s)"
17
+ #class_option :leospace, :type => :string, :default => "", :banner => ":admin", :desc => "To nest a resource under namespace(s)"
18
+ class_option :auth_class, :type => :boolean, :default => 'user', :desc => "Set the authentication class name"
19
+
20
+ #override
21
+ #def copy_view_files
22
+ # available_views.each do |view|
23
+ # filenames = filenames_all_formats(view, source_paths)
24
+ # filenames.each do |filename|
25
+ # #Looking for custom filename into subfolder
26
+ # filename_source = "#{"formtastic/" if formtastic?}#{filename}"
27
+ # search_into_subfolder = nil
28
+ # source_paths.each do |path|
29
+ # if File.exists?(File.join(path,filename_source))
30
+ # search_into_subfolder = true
31
+ # break
32
+ # end
33
+ # end
34
+ # filename_source = filename unless search_into_subfolder
35
+ #
36
+ # template filename_source, File.join("app/views", base_namespaces, controller_file_path, filename)
37
+ # end
38
+ # end
39
+ #end
40
+
41
+ #def update_layout_html
42
+ # file = "app/views/layouts/_#{CONFIG[:default_style]}.html.erb"
43
+ # if nested?
44
+ # inject_into_file file, :before => " <!-- Insert above here other #{last_parent} elements -->" do
45
+ # <<-FILE.gsub(/^ /, '')
46
+ # #{"<% if can?(:read, #{class_name}) && controller.controller_path == '#{controller_name}' -%>" if authorization?}
47
+ # <li class="active"><%= t('models.#{plural_table_name}') %></li>
48
+ # <!-- Insert above here other #{singular_table_name} elements -->
49
+ # #{"<% end -%>" if authorization?}
50
+ # FILE
51
+ # end if File.exists?(file)
52
+ # else
53
+ # inject_into_file file, :before => " <!-- Insert above other elements -->" do
54
+ # <<-FILE.gsub(/^ /, '')
55
+ # #{"<% if can?(:read, #{class_name}) -%>" if authorization?}
56
+ # <li class="<%= controller.controller_path == '#{formatted_namespace_path}#{controller_name}' ? 'active' : '' %>"><a href="<%= #{list_resources_path} %>"><%= t('models.#{plural_table_name}') %></a></li>
57
+ # <!-- Insert above here other #{singular_table_name} elements -->
58
+ # #{"<% end -%>" if authorization?}
59
+ # FILE
60
+ # end if File.exists?(file)
61
+ # end
62
+ #end
63
+
64
+ #def update_parent_views
65
+ # return unless nested?
66
+ # file = "app/views/#{plural_last_parent}/_row_index.html.erb"
67
+ # inject_into_file file, :before => "<!-- Manage section, do not remove this tag -->" do
68
+ # <<-FILE.gsub(/^ /, '')
69
+ # <td><%= link_to t('models.#{plural_table_name}'), #{list_resources_path_back} %><%= link_to "", #{last_parent}_with_#{plural_table_name}_path(#{last_parent}), :id => "a_#{singular_table_name[0..5]}_\#{#{last_parent}.id}", :class =>"toggle_#{plural_table_name} desc", :remote => true %></td>
70
+ #
71
+ # FILE
72
+ # end if File.exists?(file)
73
+ # available_nested_views.each do |view|
74
+ # filenames = filenames_all_formats(view, source_paths)
75
+ # filenames.each do |filename|
76
+ # #Looking for custom filename into subfolder
77
+ # filename_source = "#{"formtastic/" if formtastic?}#{filename}"
78
+ # search_into_subfolder = nil
79
+ # source_paths.each do |path|
80
+ # if File.exists?(File.join(path,filename_source))
81
+ # search_into_subfolder = true
82
+ # break
83
+ # end
84
+ # end
85
+ # filename_source = filename unless search_into_subfolder
86
+ #
87
+ # template filename_source, File.join("app/views", base_namespaces, plural_last_parent, filename.sub('nested', plural_table_name))
88
+ # end
89
+ # end
90
+ #end
91
+
92
+ protected
93
+
94
+ #Override
95
+ #def available_views
96
+ # %w(index edit edit_multiple copy show new _form _form_multiple _fields destroy _show _list _row_index select)
97
+ #end
98
+ #
99
+ #def available_nested_views
100
+ # %w(_nested with_nested)
101
+ #end
102
+ #
103
+ #def filenames_all_formats(name, paths=[], formats=[:html, :js, nil])
104
+ # filenames = []
105
+ # paths.each do |path|
106
+ # formats.each do |format|
107
+ # filename = filename_with_extensions(format, name)
108
+ # if File.exists?(File.join(path, filename))
109
+ # filenames << filename
110
+ # end
111
+ # end
112
+ # break if filenames.any?
113
+ # end
114
+ # filenames
115
+ #end
116
+ #def filename_with_extensions(format, name, parser=:erb)
117
+ # [name, format, parser].compact.join(".")
118
+ #end
119
+
120
+ end
121
+ end
122
+ end
@@ -1,21 +1,21 @@
1
- Description:
2
- A layout and customized scaffold generator for Rails 3.1
3
-
4
- Rails version supported:
5
- 3.1
6
-
7
- Available layout:
8
- cloudy [default]
9
-
10
- Example:
11
- rails generate leolay
12
- rails generate leolay --main_color=#c8c8c8
13
- rails generate leolay layout1 --main_color=rgb(200,150,200) --second-color=yellow
14
- rails generate leolay layout2 --skip-pagination --skip-authentication --skip-authorization
15
-
16
- Will be:
17
- Created an application layout with a nice and dynamic stylesheet based on sass
18
- Customized views (only erb atm) and controller ajax ready and filters based on attributes, i18n messages ecc.
19
- Customized application.rb to exclude javascript and stylesheet for every resource you will create
20
- Customized application controller to manage i18n and others stuff like authentication, authorization ecc [optionals]
21
- Created customized partials for pagination with kaminari [optional]
1
+ Description:
2
+ A layout and customized scaffold generator for Rails 3.1
3
+
4
+ Rails version supported:
5
+ 3.1
6
+
7
+ Available layout:
8
+ cloudy [default]
9
+
10
+ Example:
11
+ rails generate leolay
12
+ rails generate leolay --main_color=#c8c8c8
13
+ rails generate leolay layout1 --main_color=rgb(200,150,200) --second-color=yellow
14
+ rails generate leolay layout2 --skip-pagination --skip-authentication --skip-authorization
15
+
16
+ Will be:
17
+ Created an application layout with a nice and dynamic stylesheet based on sass
18
+ Customized views (only erb atm) and controller ajax ready and filters based on attributes, i18n messages ecc.
19
+ Customized application.rb to exclude javascript and stylesheet for every resource you will create
20
+ Customized application controller to manage i18n and others stuff like authentication, authorization ecc [optionals]
21
+ Created customized partials for pagination with kaminari [optional]
@@ -1,420 +1,420 @@
1
- require File.join(File.dirname(__FILE__), '../active_leonardo')
2
-
3
- class LeolayGenerator < Rails::Generators::Base
4
- include ::ActiveLeonardo::Base
5
-
6
- source_root File.expand_path('../templates', __FILE__)
7
- argument :style, :type => :string, :default => "active"
8
- #class_option :pagination, :type => :boolean, :default => true, :desc => "Include pagination files"
9
- class_option :main_color, :type => :string, :default => nil, :desc => "Force a main color for the stylesheet"
10
- class_option :second_color, :type => :string, :default => nil, :desc => "Force a secondary color for the stylesheet"
11
- class_option :authentication, :type => :boolean, :default => true, :desc => "Add code to manage authentication with devise"
12
- class_option :authorization, :type => :boolean, :default => true, :desc => "Add code to manage authorization with cancan"
13
- class_option :activeadmin, :type => :boolean, :default => true, :desc => "Add code to manage activeadmin gem"
14
- class_option :auth_class, :type => :string, :default => 'User', :desc => "Set the authentication class name"
15
- #class_option :formtastic, :type => :boolean, :default => true, :desc => "Copy formtastic files into leosca custom folder (inside project)"
16
- #class_option :jquery_ui, :type => :boolean, :default => true, :desc => "To use jQuery ui improvement"
17
- class_option :rspec, :type => :boolean, :default => true, :desc => "Include custom rspec generator and custom templates"
18
- #class_option :old_views, :type => :boolean, :default => false, :desc => "Include old management"
19
-
20
- #def generate_layout
21
- # template "config.rb", "config/initializers/config.rb"
22
- #
23
- # template "styles/#{style_name}/stylesheets/app/stylesheet.sass", "app/assets/stylesheets/#{style_name}.sass"
24
- # copy_file "styles/#{style_name}/stylesheets/app/states.sass", "app/assets/stylesheets/states.sass"
25
- #
26
- # copy_file "app/helpers/layout_helper.rb", "app/helpers/layout_helper.rb"
27
- #
28
- # copy_file "styles/#{style_name}/views/layout/application.html.erb", "app/views/layouts/application.html.erb", :force => true
29
- # template "styles/#{style_name}/views/layout/_layout.html.erb", "app/views/layouts/_#{style_name}.html.erb"
30
- # copy_file "styles/#{style_name}/views/layout/_message.html.erb", "app/views/application/_message.html.erb"
31
- # copy_file "styles/#{style_name}/views/layout/_session.html.erb", "app/views/application/_session.html.erb" if options.authentication?
32
- #
33
- # locale_path = "config/locales"
34
- # source_paths.each do |source_path|
35
- # files = Dir["#{source_path}/#{locale_path}/??.yml"]
36
- # files.each do |f|
37
- # copy_file f, "#{locale_path}/#{File.basename(f)}"
38
- # end
39
- # break if files.any?
40
- # end
41
- #
42
- # copy_file "lib/utility.rb", "lib/extras/utility.rb"
43
- #
44
- # if options.pagination?
45
- # source_paths.each do |source_path|
46
- # files = Dir["#{source_path}/#{locale_path}/kaminari.??.yml"]
47
- # files.each do |f|
48
- # copy_file f, "#{locale_path}/#{File.basename(f)}"
49
- # end
50
- # break if files.any?
51
- # end
52
- #
53
- # directory "styles/#{style_name}/views/kaminari", "app/views/kaminari"
54
- #
55
- # directory "styles/#{style_name}/images/kaminari", "app/assets/images/styles/#{style_name}/kaminari"
56
- # end
57
- #
58
- # directory "styles/#{style_name}/images/style", "app/assets/images/styles/#{style_name}"
59
- #
60
- # directory "styles/#{style_name}/images/jquery-ui", "app/assets/images/styles/#{style_name}/jquery-ui" if options.jquery_ui?
61
- #
62
- # if options.authentication?
63
- # source_paths.each do |source_path|
64
- # files = Dir["#{source_path}/#{locale_path}/devise.??.yml"]
65
- # files.each do |f|
66
- # copy_file f, "#{locale_path}/#{File.basename(f)}"
67
- # end
68
- # break if files.any?
69
- # end
70
- # directory "app/views/devise", "app/views/devise"
71
- # end
72
- #end
73
- def generate_layout
74
- template "styles/#{style_name}/stylesheets/app/stylesheet.css.scss", "app/assets/stylesheets/#{style_name}.css.scss"
75
- template "styles/#{style_name}/stylesheets/app/custom_active_admin.css.scss", "app/assets/stylesheets/custom_active_admin.css.scss"
76
- template "styles/#{style_name}/stylesheets/app/_enviroment.css.scss", "app/assets/stylesheets/_enviroment.css.scss"
77
-
78
- copy_file "app/helpers/layout_helper.rb", "app/helpers/layout_helper.rb"
79
- directory "styles/#{style_name}/images", "app/assets/images/styles/#{style_name}"
80
- copy_file "styles/#{style_name}/favicon.ico", "app/assets/images/favicon.ico"
81
-
82
- copy_file "styles/#{style_name}/views/layout/application.html.erb", "app/views/layouts/application.html.erb", :force => true
83
- copy_file "styles/#{style_name}/views/layout/_message.html.erb", "app/views/application/_message.html.erb"
84
- copy_file "styles/#{style_name}/views/layout/_session.html.erb", "app/views/application/_session.html.erb" if options.authentication?
85
-
86
- copy_file "config/initializers/config.rb", "config/initializers/config.rb"
87
- template "config/config.yml", "config/config.yml"
88
- locale_path = "config/locales"
89
- source_paths.each do |source_path|
90
- files = Dir["#{source_path}/#{locale_path}/??.yml"]
91
- files.each do |f|
92
- copy_file f, "#{locale_path}/#{File.basename(f)}"
93
- end
94
- break if files.any?
95
- end
96
- if options.authentication?
97
- source_paths.each do |source_path|
98
- files = Dir["#{source_path}/#{locale_path}/devise.??.yml"]
99
- files.each do |f|
100
- copy_file f, "#{locale_path}/#{File.basename(f)}"
101
- end
102
- break if files.any?
103
- end
104
- end
105
- end
106
-
107
- def setup_application
108
-
109
- application do
110
- <<-FILE.gsub(/^ /, '')
111
- config.generators do |g|
112
- g.stylesheets false
113
- g.javascripts true
114
- g.leosca_controller :leosca_controller
115
- end
116
-
117
- config.autoload_paths += %W(\#{config.root}/lib/extras)
118
- I18n.enforce_available_locales = false
119
- FILE
120
- end
121
-
122
- file = "app/controllers/application_controller.rb"
123
- if File.exists?(file)
124
- inject_into_class file, ApplicationController do
125
- <<-FILE.gsub(/^ /, '')
126
- rescue_from CanCan::AccessDenied do |exception|
127
- redirect_to root_url, :alert => exception.message
128
- end
129
- def current_ability
130
- @current_ability ||= Ability.new(current_#{options[:auth_class].downcase})
131
- end
132
- FILE
133
- end if options.authorization?
134
-
135
- inject_into_class file, ApplicationController do
136
- <<-FILE.gsub(/^ /, '')
137
- before_filter :localizate
138
-
139
- def localizate
140
- if params[:lang]
141
- session[:lang] = params[:lang]
142
- else
143
- session[:lang] ||= I18n.default_locale
144
- end
145
- I18n.locale = session[:lang]
146
- end
147
- FILE
148
- end
149
- end
150
-
151
- #file = "app/helpers/application_helper.rb"
152
- #if File.exists?(file)
153
- # inject_into_file file, :after => "module ApplicationHelper" do
154
- # <<-FILE.gsub(/^ /, '')
155
- #
156
- # def sortable(column, title = nil, remote = nil, path = nil, *params)
157
- # column = column.to_s
158
- # title ||= column.titleize
159
- # css_class = (column == sort_column) ? "sorted \#{sort_direction}" : nil
160
- # direction = (column == sort_column && sort_direction == "asc") ? "desc" : "asc"
161
- # params << "{:sort => column, :direction => direction}"
162
- # path = path ? eval("#\{path}(\#{params.join(',')})") : {:sort => column, :direction => direction}
163
- # link_to(title, path, :remote => true, :disable_with => t(:loading), :class => css_class)
164
- # end
165
- # FILE
166
- # end
167
- #end
168
- end
169
-
170
- def setup_authentication
171
- file = "app/models/#{options[:auth_class].downcase}.rb"
172
- #puts "File #{file} #{File.exists?(file) ? "" : "does not"} exists!"
173
- return unless options.authentication? and File.exists?(file)
174
-
175
- inject_into_class file, auth_class do
176
- <<-FILE.gsub(/^ /, '')
177
- ROLES = %w[admin manager user guest]
178
- scope :with_role, lambda { |role| {:conditions => "roles_mask & \#{2**ROLES.index(role.to_s)} > 0 "} }
179
-
180
- def roles=(roles)
181
- self.roles_mask = (roles & ROLES).map { |r| 2**ROLES.index(r) }.sum
182
- end
183
- def roles
184
- ROLES.reject { |r| ((roles_mask || 0) & 2**ROLES.index(r)).zero? }
185
- end
186
- def role_symbols
187
- roles.map(&:to_sym)
188
- end
189
- def role?(role)
190
- roles.include? role.to_s
191
- end
192
- def roles?(*roles)
193
- roles.each do |role|
194
- return true if role? role
195
- end
196
- nil
197
- end
198
- def admin?
199
- self.role? 'admin'
200
- end
201
- FILE
202
- end
203
-
204
- end
205
-
206
- def setup_authorization
207
- file = "app/models/ability.rb"
208
- return unless File.exists?(file)
209
- gsub_file file, /initialize(\s|\()user(.|)/, "initialize(#{options[:auth_class].downcase})"
210
- inject_into_file file, :before => " end\nend" do
211
- <<-FILE.gsub(/^ /, '')
212
- #{options[:auth_class].downcase} ||= #{auth_class}.new
213
- can :manage, :all if #{options[:auth_class].downcase}.role? :admin
214
- alias_action :batch_action, :to => :update
215
- can :read, ActiveAdmin::Page, :name => "Dashboard"
216
- FILE
217
- end
218
- end
219
-
220
- def create_users_for_development
221
- return unless options.authentication?
222
- file = "db/seeds.rb"
223
- append_file file do
224
- <<-FILE.gsub(/^ /, '')
225
- #{auth_class}.delete_all if #{auth_class}.count == 1
226
- user=#{auth_class}.new :email => 'admin@#{app_name}.com', :password => 'abcd1234', :password_confirmation => 'abcd1234'
227
- #{"user.roles=['admin']" if options.authorization?}
228
- user.save
229
- user=#{auth_class}.new :email => 'manager@#{app_name}.com', :password => 'abcd1234', :password_confirmation => 'abcd1234'
230
- #{"user.roles=['manager']" if options.authorization?}
231
- user.save
232
- user=#{auth_class}.new :email => 'user@#{app_name}.com', :password => 'abcd1234', :password_confirmation => 'abcd1234'
233
- #{"user.roles=['user']" if options.authorization?}
234
- user.save
235
- FILE
236
- end if File.exists?(file)
237
- end
238
-
239
- #def setup_formtastic
240
- # return unless options.formtastic?
241
- #
242
- # path = "styles/#{style_name}/stylesheets/vendor/formtastic"
243
- # dest_path = "vendor/assets/stylesheets/formtastic"
244
- #
245
- # path = dest_path unless File.exists?(path)
246
- #
247
- # file = "#{path}/formtastic.css"
248
- # copy_file file, file unless File.exists?(file)
249
- # file = "#{path}/formtastic_changes.css"
250
- # copy_file file, file
251
- #
252
- # file = "config/initializers/formtastic.rb"
253
- # inject_into_file file, :after => "# Formtastic::FormBuilder.i18n_lookups_by_default = false" do
254
- # <<-FILE.gsub(/^ /, '')
255
- #
256
- # Formtastic::FormBuilder.i18n_lookups_by_default = true
257
- # FILE
258
- # end if File.exists?(file)
259
- #
260
- # path = "lib/templates/erb/"
261
- # remove_file path if File.exists?(path)
262
- #end
263
-
264
- def setup_javascript
265
- app_path = "app/assets/javascripts"
266
-
267
- file = "#{app_path}/custom.js.coffee"
268
- copy_file file, file
269
-
270
- file = "#{app_path}/active_admin.js.coffee"
271
- #gsub_file file, "#= require active_admin/base" do
272
- # <<-FILE.gsub(/^ /, '')
273
- # #= require jquery.turbolinks
274
- #
275
- # #= require active_admin/base
276
- #FILE
277
- #end
278
- append_file file do
279
- <<-FILE.gsub(/^ /, '')
280
-
281
- #= require custom
282
- FILE
283
- end
284
- end
285
-
286
- #def setup_stylesheets
287
- # app_path = "app/assets/stylesheets"
288
- # vendor_path = "vendor/assets/stylesheets"
289
- #
290
- # file = "#{vendor_path}/vendor.css"
291
- # copy_file file, file
292
- #
293
- # if options.jquery_ui?
294
- # directory "styles/#{style_name}/stylesheets/vendor/jquery-ui", "vendor/assets/stylesheets/jquery-ui"
295
- #
296
- # file = "#{app_path}/application.css"
297
- # inject_into_file file, :before => "*/" do
298
- # <<-FILE.gsub(/^ /, '')
299
- # *= require vendor
300
- # FILE
301
- # end
302
- #
303
- # file = "#{vendor_path}/vendor.css"
304
- # inject_into_file file, :before => "*/" do
305
- # <<-FILE.gsub(/^ /, '')
306
- # *= require_tree ./jquery-ui
307
- # FILE
308
- # end
309
- # end
310
- #
311
- # file = "#{vendor_path}/vendor.css"
312
- # inject_into_file file, :before => "*/" do
313
- # <<-FILE.gsub(/^ /, '')
314
- # *= require_tree ./formtastic
315
- # FILE
316
- # end if options.formtastic?
317
- #end
318
-
319
- def setup_rspec
320
- file = "spec/spec_helper.rb"
321
- return unless File.exists?(file) && options.rspec?
322
- inject_into_file file, :after => "require 'rspec/rails'" do
323
- <<-FILE.gsub(/^ /, '')
324
-
325
- require 'capybara/rspec'
326
- require 'helpers/application_helpers'
327
-
328
- Capybara.default_wait_time = 10 #default=2
329
- FILE
330
- end
331
-
332
- gsub_file file, 'config.fixture_path = "#{::Rails.root}/spec/fixtures"', '#config.fixture_path = "#{::Rails.root}/spec/fixtures"'
333
- #inject_into_file file, "#", :before => 'config.fixture_path = "#{::Rails.root}/spec/fixtures"'
334
-
335
- gsub_file file, "config.use_transactional_fixtures = true" do
336
- <<-FILE.gsub(/^ /, '')
337
- config.use_transactional_fixtures = false
338
-
339
- config.before(:suite) do
340
- DatabaseCleaner.strategy = :truncation
341
- end
342
-
343
- config.before(:each) do
344
- DatabaseCleaner.start
345
- end
346
-
347
- config.after(:each) do
348
- DatabaseCleaner.clean
349
- end
350
-
351
- config.include ApplicationHelpers
352
- FILE
353
- end
354
-
355
- file = "spec/factories.rb"
356
- copy_file file, file
357
- file = "spec/support/devise.rb"
358
- copy_file file, file
359
- file = "spec/helpers/application_helpers.rb"
360
- copy_file file, file
361
-
362
- end
363
-
364
- def setup_extras
365
- copy_file "lib/upd_array.rb", "lib/extras/upd_array.rb"
366
- end
367
-
368
- def setup_activeadmin
369
- return unless options.activeadmin? and activeadmin?
370
- template "config/initializers/activeadmin_leonardo.rb", "config/initializers/activeadmin_leonardo.rb"
371
- #copy_file "config/initializers/activeadmin_cancan.rb", "config/initializers/activeadmin_cancan.rb" if options.authorization?
372
- #template "app/admin/users.rb", "app/admin/#{options[:auth_class].downcase.pluralize}.rb"
373
- file = "app/admin/#{options[:auth_class].downcase}.rb"
374
- inject_into_file file, :after => "ActiveAdmin.register #{options[:auth_class]} do" do
375
- <<-FILE.gsub(/^ /, '')
376
-
377
- controller do
378
- def update
379
- unless params[:user]['password'] && params[:user]['password'].size > 0
380
- params[:user].delete 'password'
381
- params[:user].delete 'password_confirmation'
382
- end
383
- super do
384
- #do something
385
- end
386
- end
387
- end
388
- FILE
389
- end
390
-
391
-
392
- file = "app/assets/stylesheets/active_admin.css.scss"
393
- append_file file do
394
- <<-FILE.gsub(/^ /, '')
395
-
396
- @import "custom_active_admin";
397
- FILE
398
- end if File.exists?(file)
399
-
400
- file = "config/initializers/active_admin.rb"
401
- gsub_file file, 'config.fixture_path = "#{::Rails.root}/spec/fixtures"', '#config.fixture_path = "#{::Rails.root}/spec/fixtures"'
402
- #inject_into_file file, "#", :before => 'config.fixture_path = "#{::Rails.root}/spec/fixtures"'
403
-
404
- gsub_file file, "# config.authorization_adapter = ActiveAdmin::CanCanAdapter" do
405
- <<-FILE.gsub(/^ /, '')
406
- config.authorization_adapter = ActiveAdmin::CanCanAdapter
407
- FILE
408
- end if File.exists?(file)
409
- end
410
-
411
- private
412
- def style_name
413
- style.underscore
414
- end
415
-
416
- def app_name
417
- File.basename(Dir.pwd)
418
- end
419
-
420
- end
1
+ require File.join(File.dirname(__FILE__), '../active_leonardo')
2
+
3
+ class LeolayGenerator < Rails::Generators::Base
4
+ include ::ActiveLeonardo::Base
5
+
6
+ source_root File.expand_path('../templates', __FILE__)
7
+ argument :style, :type => :string, :default => "active"
8
+ #class_option :pagination, :type => :boolean, :default => true, :desc => "Include pagination files"
9
+ class_option :main_color, :type => :string, :default => nil, :desc => "Force a main color for the stylesheet"
10
+ class_option :second_color, :type => :string, :default => nil, :desc => "Force a secondary color for the stylesheet"
11
+ class_option :authentication, :type => :boolean, :default => true, :desc => "Add code to manage authentication with devise"
12
+ class_option :authorization, :type => :boolean, :default => true, :desc => "Add code to manage authorization with cancan"
13
+ class_option :activeadmin, :type => :boolean, :default => true, :desc => "Add code to manage activeadmin gem"
14
+ class_option :auth_class, :type => :string, :default => 'User', :desc => "Set the authentication class name"
15
+ #class_option :formtastic, :type => :boolean, :default => true, :desc => "Copy formtastic files into leosca custom folder (inside project)"
16
+ #class_option :jquery_ui, :type => :boolean, :default => true, :desc => "To use jQuery ui improvement"
17
+ class_option :rspec, :type => :boolean, :default => true, :desc => "Include custom rspec generator and custom templates"
18
+ #class_option :old_views, :type => :boolean, :default => false, :desc => "Include old management"
19
+
20
+ #def generate_layout
21
+ # template "config.rb", "config/initializers/config.rb"
22
+ #
23
+ # template "styles/#{style_name}/stylesheets/app/stylesheet.sass", "app/assets/stylesheets/#{style_name}.sass"
24
+ # copy_file "styles/#{style_name}/stylesheets/app/states.sass", "app/assets/stylesheets/states.sass"
25
+ #
26
+ # copy_file "app/helpers/layout_helper.rb", "app/helpers/layout_helper.rb"
27
+ #
28
+ # copy_file "styles/#{style_name}/views/layout/application.html.erb", "app/views/layouts/application.html.erb", :force => true
29
+ # template "styles/#{style_name}/views/layout/_layout.html.erb", "app/views/layouts/_#{style_name}.html.erb"
30
+ # copy_file "styles/#{style_name}/views/layout/_message.html.erb", "app/views/application/_message.html.erb"
31
+ # copy_file "styles/#{style_name}/views/layout/_session.html.erb", "app/views/application/_session.html.erb" if options.authentication?
32
+ #
33
+ # locale_path = "config/locales"
34
+ # source_paths.each do |source_path|
35
+ # files = Dir["#{source_path}/#{locale_path}/??.yml"]
36
+ # files.each do |f|
37
+ # copy_file f, "#{locale_path}/#{File.basename(f)}"
38
+ # end
39
+ # break if files.any?
40
+ # end
41
+ #
42
+ # copy_file "lib/utility.rb", "lib/extras/utility.rb"
43
+ #
44
+ # if options.pagination?
45
+ # source_paths.each do |source_path|
46
+ # files = Dir["#{source_path}/#{locale_path}/kaminari.??.yml"]
47
+ # files.each do |f|
48
+ # copy_file f, "#{locale_path}/#{File.basename(f)}"
49
+ # end
50
+ # break if files.any?
51
+ # end
52
+ #
53
+ # directory "styles/#{style_name}/views/kaminari", "app/views/kaminari"
54
+ #
55
+ # directory "styles/#{style_name}/images/kaminari", "app/assets/images/styles/#{style_name}/kaminari"
56
+ # end
57
+ #
58
+ # directory "styles/#{style_name}/images/style", "app/assets/images/styles/#{style_name}"
59
+ #
60
+ # directory "styles/#{style_name}/images/jquery-ui", "app/assets/images/styles/#{style_name}/jquery-ui" if options.jquery_ui?
61
+ #
62
+ # if options.authentication?
63
+ # source_paths.each do |source_path|
64
+ # files = Dir["#{source_path}/#{locale_path}/devise.??.yml"]
65
+ # files.each do |f|
66
+ # copy_file f, "#{locale_path}/#{File.basename(f)}"
67
+ # end
68
+ # break if files.any?
69
+ # end
70
+ # directory "app/views/devise", "app/views/devise"
71
+ # end
72
+ #end
73
+ def generate_layout
74
+ template "styles/#{style_name}/stylesheets/app/stylesheet.css.scss", "app/assets/stylesheets/#{style_name}.css.scss"
75
+ template "styles/#{style_name}/stylesheets/app/custom_active_admin.css.scss", "app/assets/stylesheets/custom_active_admin.css.scss"
76
+ template "styles/#{style_name}/stylesheets/app/_enviroment.css.scss", "app/assets/stylesheets/_enviroment.css.scss"
77
+
78
+ copy_file "app/helpers/layout_helper.rb", "app/helpers/layout_helper.rb"
79
+ directory "styles/#{style_name}/images", "app/assets/images/styles/#{style_name}"
80
+ copy_file "styles/#{style_name}/favicon.ico", "app/assets/images/favicon.ico"
81
+
82
+ copy_file "styles/#{style_name}/views/layout/application.html.erb", "app/views/layouts/application.html.erb", :force => true
83
+ copy_file "styles/#{style_name}/views/layout/_message.html.erb", "app/views/application/_message.html.erb"
84
+ copy_file "styles/#{style_name}/views/layout/_session.html.erb", "app/views/application/_session.html.erb" if options.authentication?
85
+
86
+ copy_file "config/initializers/config.rb", "config/initializers/config.rb"
87
+ template "config/config.yml", "config/config.yml"
88
+ locale_path = "config/locales"
89
+ source_paths.each do |source_path|
90
+ files = Dir["#{source_path}/#{locale_path}/??.yml"]
91
+ files.each do |f|
92
+ copy_file f, "#{locale_path}/#{File.basename(f)}"
93
+ end
94
+ break if files.any?
95
+ end
96
+ if options.authentication?
97
+ source_paths.each do |source_path|
98
+ files = Dir["#{source_path}/#{locale_path}/devise.??.yml"]
99
+ files.each do |f|
100
+ copy_file f, "#{locale_path}/#{File.basename(f)}"
101
+ end
102
+ break if files.any?
103
+ end
104
+ end
105
+ end
106
+
107
+ def setup_application
108
+
109
+ application do
110
+ <<-FILE.gsub(/^ /, '')
111
+ config.generators do |g|
112
+ g.stylesheets false
113
+ g.javascripts true
114
+ g.leosca_controller :leosca_controller
115
+ end
116
+
117
+ config.autoload_paths += %W(\#{config.root}/lib/extras)
118
+ I18n.enforce_available_locales = false
119
+ FILE
120
+ end
121
+
122
+ file = "app/controllers/application_controller.rb"
123
+ if File.exists?(file)
124
+ inject_into_class file, ApplicationController do
125
+ <<-FILE.gsub(/^ /, '')
126
+ rescue_from CanCan::AccessDenied do |exception|
127
+ redirect_to root_url, :alert => exception.message
128
+ end
129
+ def current_ability
130
+ @current_ability ||= Ability.new(current_#{options[:auth_class].downcase})
131
+ end
132
+ FILE
133
+ end if options.authorization?
134
+
135
+ inject_into_class file, ApplicationController do
136
+ <<-FILE.gsub(/^ /, '')
137
+ before_filter :localizate
138
+
139
+ def localizate
140
+ if params[:lang]
141
+ session[:lang] = params[:lang]
142
+ else
143
+ session[:lang] ||= I18n.default_locale
144
+ end
145
+ I18n.locale = session[:lang]
146
+ end
147
+ FILE
148
+ end
149
+ end
150
+
151
+ #file = "app/helpers/application_helper.rb"
152
+ #if File.exists?(file)
153
+ # inject_into_file file, :after => "module ApplicationHelper" do
154
+ # <<-FILE.gsub(/^ /, '')
155
+ #
156
+ # def sortable(column, title = nil, remote = nil, path = nil, *params)
157
+ # column = column.to_s
158
+ # title ||= column.titleize
159
+ # css_class = (column == sort_column) ? "sorted \#{sort_direction}" : nil
160
+ # direction = (column == sort_column && sort_direction == "asc") ? "desc" : "asc"
161
+ # params << "{:sort => column, :direction => direction}"
162
+ # path = path ? eval("#\{path}(\#{params.join(',')})") : {:sort => column, :direction => direction}
163
+ # link_to(title, path, :remote => true, :disable_with => t(:loading), :class => css_class)
164
+ # end
165
+ # FILE
166
+ # end
167
+ #end
168
+ end
169
+
170
+ def setup_authentication
171
+ file = "app/models/#{options[:auth_class].downcase}.rb"
172
+ #puts "File #{file} #{File.exists?(file) ? "" : "does not"} exists!"
173
+ return unless options.authentication? and File.exists?(file)
174
+
175
+ inject_into_class file, auth_class do
176
+ <<-FILE.gsub(/^ /, '')
177
+ ROLES = %w[admin manager user guest]
178
+ scope :with_role, lambda { |role| {:conditions => "roles_mask & \#{2**ROLES.index(role.to_s)} > 0 "} }
179
+
180
+ def roles=(roles)
181
+ self.roles_mask = (roles & ROLES).map { |r| 2**ROLES.index(r) }.sum
182
+ end
183
+ def roles
184
+ ROLES.reject { |r| ((roles_mask || 0) & 2**ROLES.index(r)).zero? }
185
+ end
186
+ def role_symbols
187
+ roles.map(&:to_sym)
188
+ end
189
+ def role?(role)
190
+ roles.include? role.to_s
191
+ end
192
+ def roles?(*roles)
193
+ roles.each do |role|
194
+ return true if role? role
195
+ end
196
+ nil
197
+ end
198
+ def admin?
199
+ self.role? 'admin'
200
+ end
201
+ FILE
202
+ end
203
+
204
+ end
205
+
206
+ def setup_authorization
207
+ file = "app/models/ability.rb"
208
+ return unless File.exists?(file)
209
+ gsub_file file, /initialize(\s|\()user(.|)/, "initialize(#{options[:auth_class].downcase})"
210
+ inject_into_file file, :before => " end\nend" do
211
+ <<-FILE.gsub(/^ /, '')
212
+ #{options[:auth_class].downcase} ||= #{auth_class}.new
213
+ can :manage, :all if #{options[:auth_class].downcase}.role? :admin
214
+ alias_action :batch_action, :to => :update
215
+ can :read, ActiveAdmin::Page, :name => "Dashboard"
216
+ FILE
217
+ end
218
+ end
219
+
220
+ def create_users_for_development
221
+ return unless options.authentication?
222
+ file = "db/seeds.rb"
223
+ append_file file do
224
+ <<-FILE.gsub(/^ /, '')
225
+ #{auth_class}.delete_all if #{auth_class}.count == 1
226
+ user=#{auth_class}.new :email => 'admin@#{app_name}.com', :password => 'abcd1234', :password_confirmation => 'abcd1234'
227
+ #{"user.roles=['admin']" if options.authorization?}
228
+ user.save
229
+ user=#{auth_class}.new :email => 'manager@#{app_name}.com', :password => 'abcd1234', :password_confirmation => 'abcd1234'
230
+ #{"user.roles=['manager']" if options.authorization?}
231
+ user.save
232
+ user=#{auth_class}.new :email => 'user@#{app_name}.com', :password => 'abcd1234', :password_confirmation => 'abcd1234'
233
+ #{"user.roles=['user']" if options.authorization?}
234
+ user.save
235
+ FILE
236
+ end if File.exists?(file)
237
+ end
238
+
239
+ #def setup_formtastic
240
+ # return unless options.formtastic?
241
+ #
242
+ # path = "styles/#{style_name}/stylesheets/vendor/formtastic"
243
+ # dest_path = "vendor/assets/stylesheets/formtastic"
244
+ #
245
+ # path = dest_path unless File.exists?(path)
246
+ #
247
+ # file = "#{path}/formtastic.css"
248
+ # copy_file file, file unless File.exists?(file)
249
+ # file = "#{path}/formtastic_changes.css"
250
+ # copy_file file, file
251
+ #
252
+ # file = "config/initializers/formtastic.rb"
253
+ # inject_into_file file, :after => "# Formtastic::FormBuilder.i18n_lookups_by_default = false" do
254
+ # <<-FILE.gsub(/^ /, '')
255
+ #
256
+ # Formtastic::FormBuilder.i18n_lookups_by_default = true
257
+ # FILE
258
+ # end if File.exists?(file)
259
+ #
260
+ # path = "lib/templates/erb/"
261
+ # remove_file path if File.exists?(path)
262
+ #end
263
+
264
+ def setup_javascript
265
+ app_path = "app/assets/javascripts"
266
+
267
+ file = "#{app_path}/custom.js.coffee"
268
+ copy_file file, file
269
+
270
+ file = "#{app_path}/active_admin.js.coffee"
271
+ #gsub_file file, "#= require active_admin/base" do
272
+ # <<-FILE.gsub(/^ /, '')
273
+ # #= require jquery.turbolinks
274
+ #
275
+ # #= require active_admin/base
276
+ #FILE
277
+ #end
278
+ append_file file do
279
+ <<-FILE.gsub(/^ /, '')
280
+ #= require turbolinks
281
+ #= require custom
282
+ FILE
283
+ end
284
+ end
285
+
286
+ #def setup_stylesheets
287
+ # app_path = "app/assets/stylesheets"
288
+ # vendor_path = "vendor/assets/stylesheets"
289
+ #
290
+ # file = "#{vendor_path}/vendor.css"
291
+ # copy_file file, file
292
+ #
293
+ # if options.jquery_ui?
294
+ # directory "styles/#{style_name}/stylesheets/vendor/jquery-ui", "vendor/assets/stylesheets/jquery-ui"
295
+ #
296
+ # file = "#{app_path}/application.css"
297
+ # inject_into_file file, :before => "*/" do
298
+ # <<-FILE.gsub(/^ /, '')
299
+ # *= require vendor
300
+ # FILE
301
+ # end
302
+ #
303
+ # file = "#{vendor_path}/vendor.css"
304
+ # inject_into_file file, :before => "*/" do
305
+ # <<-FILE.gsub(/^ /, '')
306
+ # *= require_tree ./jquery-ui
307
+ # FILE
308
+ # end
309
+ # end
310
+ #
311
+ # file = "#{vendor_path}/vendor.css"
312
+ # inject_into_file file, :before => "*/" do
313
+ # <<-FILE.gsub(/^ /, '')
314
+ # *= require_tree ./formtastic
315
+ # FILE
316
+ # end if options.formtastic?
317
+ #end
318
+
319
+ def setup_rspec
320
+ file = "spec/spec_helper.rb"
321
+ return unless File.exists?(file) && options.rspec?
322
+ inject_into_file file, :after => "require 'rspec/rails'" do
323
+ <<-FILE.gsub(/^ /, '')
324
+
325
+ require 'capybara/rspec'
326
+ require 'helpers/application_helpers'
327
+
328
+ Capybara.default_wait_time = 10 #default=2
329
+ FILE
330
+ end
331
+
332
+ gsub_file file, 'config.fixture_path = "#{::Rails.root}/spec/fixtures"', '#config.fixture_path = "#{::Rails.root}/spec/fixtures"'
333
+ #inject_into_file file, "#", :before => 'config.fixture_path = "#{::Rails.root}/spec/fixtures"'
334
+
335
+ gsub_file file, "config.use_transactional_fixtures = true" do
336
+ <<-FILE.gsub(/^ /, '')
337
+ config.use_transactional_fixtures = false
338
+
339
+ config.before(:suite) do
340
+ DatabaseCleaner.strategy = :truncation
341
+ end
342
+
343
+ config.before(:each) do
344
+ DatabaseCleaner.start
345
+ end
346
+
347
+ config.after(:each) do
348
+ DatabaseCleaner.clean
349
+ end
350
+
351
+ config.include ApplicationHelpers
352
+ FILE
353
+ end
354
+
355
+ file = "spec/factories.rb"
356
+ copy_file file, file
357
+ file = "spec/support/devise.rb"
358
+ copy_file file, file
359
+ file = "spec/helpers/application_helpers.rb"
360
+ copy_file file, file
361
+
362
+ end
363
+
364
+ def setup_extras
365
+ copy_file "lib/upd_array.rb", "lib/extras/upd_array.rb"
366
+ end
367
+
368
+ def setup_activeadmin
369
+ return unless options.activeadmin? and activeadmin?
370
+ template "config/initializers/activeadmin_leonardo.rb", "config/initializers/activeadmin_leonardo.rb"
371
+ #copy_file "config/initializers/activeadmin_cancan.rb", "config/initializers/activeadmin_cancan.rb" if options.authorization?
372
+ #template "app/admin/users.rb", "app/admin/#{options[:auth_class].downcase.pluralize}.rb"
373
+ file = "app/admin/#{options[:auth_class].downcase}.rb"
374
+ inject_into_file file, :after => "ActiveAdmin.register #{options[:auth_class]} do" do
375
+ <<-FILE.gsub(/^ /, '')
376
+
377
+ controller do
378
+ def update
379
+ unless params[:user]['password'] && params[:user]['password'].size > 0
380
+ params[:user].delete 'password'
381
+ params[:user].delete 'password_confirmation'
382
+ end
383
+ super do
384
+ #do something
385
+ end
386
+ end
387
+ end
388
+ FILE
389
+ end
390
+
391
+
392
+ file = "app/assets/stylesheets/active_admin.css.scss"
393
+ append_file file do
394
+ <<-FILE.gsub(/^ /, '')
395
+
396
+ @import "custom_active_admin";
397
+ FILE
398
+ end if File.exists?(file)
399
+
400
+ file = "config/initializers/active_admin.rb"
401
+ gsub_file file, 'config.fixture_path = "#{::Rails.root}/spec/fixtures"', '#config.fixture_path = "#{::Rails.root}/spec/fixtures"'
402
+ #inject_into_file file, "#", :before => 'config.fixture_path = "#{::Rails.root}/spec/fixtures"'
403
+
404
+ gsub_file file, "# config.authorization_adapter = ActiveAdmin::CanCanAdapter" do
405
+ <<-FILE.gsub(/^ /, '')
406
+ config.authorization_adapter = ActiveAdmin::CanCanAdapter
407
+ FILE
408
+ end if File.exists?(file)
409
+ end
410
+
411
+ private
412
+ def style_name
413
+ style.underscore
414
+ end
415
+
416
+ def app_name
417
+ File.basename(Dir.pwd)
418
+ end
419
+
420
+ end