active_leonardo 0.1.0 → 0.2.0

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 (40) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +44 -0
  3. data/LICENSE +19 -19
  4. data/README.md +173 -0
  5. data/active_template.rb +141 -137
  6. data/lib/generators/active_leonardo.rb +7 -1
  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 -400
  10. data/lib/generators/leolay/templates/app/admin/users.rb +87 -87
  11. data/lib/generators/leolay/templates/config/locales/it.yml +7 -0
  12. data/lib/generators/leolay/templates/spec/helpers/application_helpers.rb +13 -13
  13. data/lib/generators/leolay/templates/spec/support/devise.rb +4 -4
  14. data/lib/generators/leolay/templates/styles/active/stylesheets/app/custom_active_admin.css.scss +27 -27
  15. data/lib/generators/leosca/USAGE +23 -23
  16. data/lib/generators/rails/leosca/USAGE +39 -39
  17. data/lib/generators/rails/leosca/leosca_generator.rb +55 -55
  18. data/lib/generators/rails/leosca/templates/leosca.css +56 -56
  19. data/lib/generators/rails/leosca_controller/USAGE +23 -23
  20. data/lib/generators/rails/leosca_controller/leosca_controller_generator.rb +192 -188
  21. data/lib/generators/rails/leosca_controller/templates/controller.rb +3 -3
  22. data/lib/generators/rspec/leointegration/leointegration_generator.rb +35 -35
  23. data/lib/generators/rspec/leointegration/templates/admin/feature.rb +67 -67
  24. data/lib/generators/rspec/leointegration/templates/feature.rb +9 -9
  25. data/lib/generators/rspec/leosca/leosca_generator.rb +57 -57
  26. data/lib/generators/rspec/leosca/templates/admin/controller_spec.rb +181 -181
  27. data/lib/generators/rspec/leosca/templates/admin/edit_spec.rb +31 -31
  28. data/lib/generators/rspec/leosca/templates/admin/index_spec.rb +32 -32
  29. data/lib/generators/rspec/leosca/templates/admin/new_spec.rb +30 -30
  30. data/lib/generators/rspec/leosca/templates/admin/routing_spec.rb +39 -39
  31. data/lib/generators/rspec/leosca/templates/admin/show_spec.rb +28 -28
  32. data/lib/generators/rspec/leosca/templates/controller_spec.rb +168 -168
  33. data/lib/generators/rspec/leosca/templates/edit_spec.rb +31 -31
  34. data/lib/generators/rspec/leosca/templates/index_spec.rb +32 -32
  35. data/lib/generators/rspec/leosca/templates/new_spec.rb +30 -30
  36. data/lib/generators/rspec/leosca/templates/routing_spec.rb +39 -39
  37. data/lib/generators/rspec/leosca/templates/show_spec.rb +28 -28
  38. metadata +55 -124
  39. data/CHANGELOG +0 -28
  40. data/README.rdoc +0 -159
@@ -49,7 +49,7 @@ module ActiveLeonardo
49
49
  when :boolean then "true"
50
50
  when :integer then "#"
51
51
  when :float, :decimal then "#.46"
52
- when :references, :belongs_to then "#"
52
+ when :references, :belongs_to then "rand(#{attribute.name}_from..#{attribute.name}_to)"
53
53
  when :date then "#{Time.now.strftime("%Y-%m-%d 00:00:00.000")}".inspect
54
54
  when :datetime then "#{Time.now.strftime("%Y-%m-%d %H:%M:%S.000")}".inspect
55
55
  when :time, :timestamp then "#{Time.now.strftime("%H:%M:%S.000")}".inspect
@@ -57,6 +57,12 @@ module ActiveLeonardo
57
57
  end
58
58
  " #{name} => #{value}"
59
59
  end
60
+ def attribute_to_range(attribute)
61
+ case attribute.type
62
+ when :references, :belongs_to then "#{attribute.name}_from = #{attribute.name.classify}.first.id; #{attribute.name}_to = #{attribute.name.classify}.last.id#{CRLF}"
63
+ else ""
64
+ end
65
+ end
60
66
  def attribute_to_factories(attribute)
61
67
  spaces = 34
62
68
  space_association = " " * (spaces-11).abs
@@ -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,400 +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
- application do
109
- <<-FILE.gsub(/^ /, '')
110
- config.generators do |g|
111
- g.stylesheets false
112
- g.javascripts true
113
- g.leosca_controller :leosca_controller
114
- end
115
-
116
- config.autoload_paths += %W(\#{config.root}/lib/extras)
117
- FILE
118
- end
119
-
120
- file = "app/controllers/application_controller.rb"
121
- if File.exists?(file)
122
- inject_into_class file, ApplicationController do
123
- <<-FILE.gsub(/^ /, '')
124
- rescue_from CanCan::AccessDenied do |exception|
125
- redirect_to root_url, :alert => exception.message
126
- end
127
- def current_ability
128
- @current_ability ||= Ability.new(current_#{options[:auth_class].downcase})
129
- end
130
- FILE
131
- end if options.authorization?
132
-
133
- inject_into_class file, ApplicationController do
134
- <<-FILE.gsub(/^ /, '')
135
- before_filter :localizate
136
-
137
- def localizate
138
- if params[:lang]
139
- session[:lang] = params[:lang]
140
- else
141
- session[:lang] ||= I18n.default_locale
142
- end
143
- I18n.locale = session[:lang]
144
- end
145
- FILE
146
- end
147
- end
148
-
149
- #file = "app/helpers/application_helper.rb"
150
- #if File.exists?(file)
151
- # inject_into_file file, :after => "module ApplicationHelper" do
152
- # <<-FILE.gsub(/^ /, '')
153
- #
154
- # def sortable(column, title = nil, remote = nil, path = nil, *params)
155
- # column = column.to_s
156
- # title ||= column.titleize
157
- # css_class = (column == sort_column) ? "sorted \#{sort_direction}" : nil
158
- # direction = (column == sort_column && sort_direction == "asc") ? "desc" : "asc"
159
- # params << "{:sort => column, :direction => direction}"
160
- # path = path ? eval("#\{path}(\#{params.join(',')})") : {:sort => column, :direction => direction}
161
- # link_to(title, path, :remote => true, :disable_with => t(:loading), :class => css_class)
162
- # end
163
- # FILE
164
- # end
165
- #end
166
- end
167
-
168
- def setup_authentication
169
- file = "app/models/#{options[:auth_class].downcase}.rb"
170
- #puts "File #{file} #{File.exists?(file) ? "" : "does not"} exists!"
171
- return unless options.authentication? and File.exists?(file)
172
-
173
- inject_into_class file, auth_class do
174
- <<-FILE.gsub(/^ /, '')
175
- ROLES = %w[admin manager user guest]
176
- scope :with_role, lambda { |role| {:conditions => "roles_mask & \#{2**ROLES.index(role.to_s)} > 0 "} }
177
-
178
- def roles=(roles)
179
- self.roles_mask = (roles & ROLES).map { |r| 2**ROLES.index(r) }.sum
180
- end
181
- def roles
182
- ROLES.reject { |r| ((roles_mask || 0) & 2**ROLES.index(r)).zero? }
183
- end
184
- def role_symbols
185
- roles.map(&:to_sym)
186
- end
187
- def role?(role)
188
- roles.include? role.to_s
189
- end
190
- def roles?(*roles)
191
- roles.each do |role|
192
- return true if role? role
193
- end
194
- nil
195
- end
196
- def admin?
197
- self.role? 'admin'
198
- end
199
- attr_accessible :roles
200
- FILE
201
- end
202
-
203
- end
204
-
205
- def setup_authorization
206
- file = "app/models/ability.rb"
207
- return unless File.exists?(file)
208
- gsub_file file, /initialize(\s|\()user(.|)/, "initialize(#{options[:auth_class].downcase})"
209
- inject_into_file file, :before => " end\nend" do
210
- <<-FILE.gsub(/^ /, '')
211
- #{options[:auth_class].downcase} ||= #{auth_class}.new
212
- can :manage, :all if #{options[:auth_class].downcase}.role? :admin
213
- alias_action :batch_action, :to => :update
214
- FILE
215
- end
216
- end
217
-
218
- def create_users_for_development
219
- return unless options.authentication?
220
- file = "db/seeds.rb"
221
- append_file file do
222
- <<-FILE.gsub(/^ /, '')
223
- user=#{auth_class}.new :email => 'admin@#{app_name}.com', :password => 'abcd1234', :password_confirmation => 'abcd1234'
224
- #{"user.roles=['admin']" if options.authorization?}
225
- user.save
226
- user=#{auth_class}.new :email => 'manager@#{app_name}.com', :password => 'abcd1234', :password_confirmation => 'abcd1234'
227
- #{"user.roles=['manager']" if options.authorization?}
228
- user.save
229
- user=#{auth_class}.new :email => 'user@#{app_name}.com', :password => 'abcd1234', :password_confirmation => 'abcd1234'
230
- #{"user.roles=['user']" if options.authorization?}
231
- user.save
232
- FILE
233
- end if File.exists?(file)
234
- end
235
-
236
- #def setup_formtastic
237
- # return unless options.formtastic?
238
- #
239
- # path = "styles/#{style_name}/stylesheets/vendor/formtastic"
240
- # dest_path = "vendor/assets/stylesheets/formtastic"
241
- #
242
- # path = dest_path unless File.exists?(path)
243
- #
244
- # file = "#{path}/formtastic.css"
245
- # copy_file file, file unless File.exists?(file)
246
- # file = "#{path}/formtastic_changes.css"
247
- # copy_file file, file
248
- #
249
- # file = "config/initializers/formtastic.rb"
250
- # inject_into_file file, :after => "# Formtastic::FormBuilder.i18n_lookups_by_default = false" do
251
- # <<-FILE.gsub(/^ /, '')
252
- #
253
- # Formtastic::FormBuilder.i18n_lookups_by_default = true
254
- # FILE
255
- # end if File.exists?(file)
256
- #
257
- # path = "lib/templates/erb/"
258
- # remove_file path if File.exists?(path)
259
- #end
260
-
261
- def setup_javascript
262
- app_path = "app/assets/javascripts"
263
-
264
- file = "#{app_path}/custom.js.coffee"
265
- copy_file file, file
266
-
267
- file = "#{app_path}/active_admin.js"
268
- gsub_file file, "//= require active_admin/base" do
269
- <<-FILE.gsub(/^ /, '')
270
- //= require jquery
271
- //= require jquery-ui
272
- //= require jquery_ujs
273
- //= require turbolinks
274
- //= require jquery.turbolinks
275
-
276
- //= require active_admin/base
277
- FILE
278
- end
279
- inject_into_file file, :before => "\n//= require active_admin/base" do
280
- <<-FILE.gsub(/^ /, '')
281
- #{options[:auth_class].downcase} ||= #{auth_class}.new
282
- can :manage, :all if #{options[:auth_class].downcase}.role? :admin
283
-
284
- FILE
285
- end
286
- append_file file do
287
- <<-FILE.gsub(/^ /, '')
288
-
289
- //= require custom
290
- FILE
291
- end
292
- end
293
-
294
- #def setup_stylesheets
295
- # app_path = "app/assets/stylesheets"
296
- # vendor_path = "vendor/assets/stylesheets"
297
- #
298
- # file = "#{vendor_path}/vendor.css"
299
- # copy_file file, file
300
- #
301
- # if options.jquery_ui?
302
- # directory "styles/#{style_name}/stylesheets/vendor/jquery-ui", "vendor/assets/stylesheets/jquery-ui"
303
- #
304
- # file = "#{app_path}/application.css"
305
- # inject_into_file file, :before => "*/" do
306
- # <<-FILE.gsub(/^ /, '')
307
- # *= require vendor
308
- # FILE
309
- # end
310
- #
311
- # file = "#{vendor_path}/vendor.css"
312
- # inject_into_file file, :before => "*/" do
313
- # <<-FILE.gsub(/^ /, '')
314
- # *= require_tree ./jquery-ui
315
- # FILE
316
- # end
317
- # end
318
- #
319
- # file = "#{vendor_path}/vendor.css"
320
- # inject_into_file file, :before => "*/" do
321
- # <<-FILE.gsub(/^ /, '')
322
- # *= require_tree ./formtastic
323
- # FILE
324
- # end if options.formtastic?
325
- #end
326
-
327
- def setup_rspec
328
- file = "spec/spec_helper.rb"
329
- return unless File.exists?(file) && options.rspec?
330
- inject_into_file file, :after => "require 'rspec/rails'" do
331
- <<-FILE.gsub(/^ /, '')
332
-
333
- require 'capybara/rspec'
334
- require 'helpers/application_helpers'
335
-
336
- Capybara.default_wait_time = 10 #default=2
337
- FILE
338
- end
339
-
340
- gsub_file file, 'config.fixture_path = "#{::Rails.root}/spec/fixtures"', '#config.fixture_path = "#{::Rails.root}/spec/fixtures"'
341
- #inject_into_file file, "#", :before => 'config.fixture_path = "#{::Rails.root}/spec/fixtures"'
342
-
343
- gsub_file file, "config.use_transactional_fixtures = true" do
344
- <<-FILE.gsub(/^ /, '')
345
- config.use_transactional_fixtures = false
346
-
347
- config.before(:suite) do
348
- DatabaseCleaner.strategy = :truncation
349
- end
350
-
351
- config.before(:each) do
352
- DatabaseCleaner.start
353
- end
354
-
355
- config.after(:each) do
356
- DatabaseCleaner.clean
357
- end
358
-
359
- config.include ApplicationHelpers
360
- FILE
361
- end
362
-
363
- file = "spec/factories.rb"
364
- copy_file file, file
365
- file = "spec/support/devise.rb"
366
- copy_file file, file
367
- file = "spec/helpers/application_helpers.rb"
368
- copy_file file, file
369
-
370
- end
371
-
372
- def setup_extras
373
- copy_file "lib/upd_array.rb", "lib/extras/upd_array.rb"
374
- end
375
-
376
- def setup_activeadmin
377
- return unless options.activeadmin? and activeadmin?
378
- template "config/initializers/activeadmin_leonardo.rb", "config/initializers/activeadmin_leonardo.rb"
379
- #copy_file "config/initializers/activeadmin_cancan.rb", "config/initializers/activeadmin_cancan.rb" if options.authorization?
380
- template "app/admin/users.rb", "app/admin/#{options[:auth_class].downcase.pluralize}.rb"
381
-
382
- file = "app/assets/stylesheets/active_admin.css.scss"
383
- append_file file do
384
- <<-FILE.gsub(/^ /, '')
385
-
386
- @import "custom_active_admin";
387
- FILE
388
- end if File.exists?(file)
389
- end
390
-
391
- private
392
- def style_name
393
- style.underscore
394
- end
395
-
396
- def app_name
397
- File.basename(Dir.pwd)
398
- end
399
-
400
- 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
+
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