beautiful_scaffold 1.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/CHANGELOG +78 -1
- data/Gemfile +25 -9
- data/README.rdoc +45 -28
- data/Rakefile +29 -0
- data/beautiful_scaffold.gemspec +7 -7
- data/lib/beautiful_scaffold/version.rb +3 -0
- data/lib/generators/USAGE +3 -1
- data/lib/generators/beautiful_cancancan_generator.rb +51 -0
- data/lib/generators/beautiful_jointable_generator.rb +41 -8
- data/lib/generators/beautiful_locale_generator.rb +107 -104
- data/lib/generators/beautiful_migration_generator.rb +14 -20
- data/lib/generators/beautiful_scaffold_common_methods.rb +56 -26
- data/lib/generators/beautiful_scaffold_generator.rb +116 -78
- data/lib/generators/beautiful_sorcery_generator.rb +137 -0
- data/lib/generators/beautiful_storage_generator.rb +61 -0
- data/lib/generators/templates/app/assets/javascripts/application-bs.js +5 -7
- data/lib/generators/templates/app/assets/javascripts/beautiful_scaffold.js +65 -79
- data/lib/generators/templates/app/assets/javascripts/bootstrap-datetimepicker-for-beautiful-scaffold.js +26 -23
- data/lib/generators/templates/app/assets/javascripts/fixed_menu.js +3 -1
- data/lib/generators/templates/app/assets/javascripts/jstree.min.js +6 -0
- data/lib/generators/templates/app/assets/stylesheets/application-bs.css +14 -6
- data/lib/generators/templates/app/assets/stylesheets/beautiful-scaffold.css.scss +20 -3
- data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/32px.png +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/40px.png +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/style.scss +1146 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/throbber.gif +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/32px.png +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/40px.png +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/style.scss +1102 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/throbber.gif +0 -0
- data/lib/generators/templates/app/controllers/base.rb +14 -7
- data/lib/generators/templates/app/controllers/master_base.rb +19 -25
- data/lib/generators/templates/app/controllers/user_sessions_controller.rb +20 -0
- data/lib/generators/templates/app/helpers/beautiful_helper.rb +102 -66
- data/lib/generators/templates/app/initializers/link_renderer.rb +23 -18
- data/lib/generators/templates/app/locales/beautiful_scaffold.en.yml +8 -0
- data/lib/generators/templates/app/locales/beautiful_scaffold.fr.yml +9 -1
- data/lib/generators/templates/app/locales/beautiful_scaffold.ja.yml +9 -2
- data/lib/generators/templates/app/mailers/user_mailer.rb +13 -0
- data/lib/generators/templates/app/models/ability.rb +39 -0
- data/lib/generators/templates/app/models/concerns/caption_concern.rb +1 -1
- data/lib/generators/templates/app/models/user.rb +11 -0
- data/lib/generators/templates/app/views/_form.html.erb +4 -1
- data/lib/generators/templates/app/views/_form_habtm_tag.html.erb +6 -2
- data/lib/generators/templates/app/views/_mass_inserting.html.erb +38 -30
- data/lib/generators/templates/app/views/_modal_columns.html.erb +3 -3
- data/lib/generators/templates/app/views/edit.html.erb +1 -3
- data/lib/generators/templates/app/views/index.html.erb +83 -79
- data/lib/generators/templates/app/views/layout.html.erb +36 -36
- data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.en.html.erb +16 -0
- data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.en.text.erb +9 -0
- data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.fr.html.erb +16 -0
- data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.fr.text.erb +8 -0
- data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.en.html.erb +19 -0
- data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.en.text.erb +8 -0
- data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.fr.html.erb +19 -0
- data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.fr.text.erb +8 -0
- data/lib/generators/templates/app/views/login_logout/user_sessions/_form.html.erb +15 -0
- data/lib/generators/templates/app/views/login_logout/user_sessions/new.html.erb +3 -0
- data/lib/generators/templates/app/views/new.html.erb +0 -2
- data/lib/generators/templates/app/views/partials/_forget_password.html.erb +2 -2
- data/lib/generators/templates/app/views/partials/_form_field.html.erb +37 -29
- data/lib/generators/templates/app/views/partials/_index_batch.html.erb +1 -1
- data/lib/generators/templates/app/views/partials/_index_column.html.erb +6 -4
- data/lib/generators/templates/app/views/partials/_index_header.html.erb +1 -1
- data/lib/generators/templates/app/views/partials/_index_search.html.erb +1 -1
- data/lib/generators/templates/app/views/partials/_login_logout_register.html.erb +7 -0
- data/lib/generators/templates/app/views/partials/_show_field.html.erb +5 -3
- data/lib/generators/templates/app/views/show.html.erb +2 -2
- data/lib/generators/templates/app/views/treeview.html.erb +8 -5
- metadata +38 -24
- data/lib/generators/beautiful_devisecancan_generator.rb +0 -128
- data/lib/generators/templates/app/assets/javascripts/bootstrap-colorpicker.js +0 -520
- data/lib/generators/templates/app/assets/javascripts/jquery.jstree.js +0 -4551
- data/lib/generators/templates/app/assets/stylesheets/bootstrap_and_overrides.css.less +0 -40
- data/lib/generators/templates/app/assets/stylesheets/colorpicker.css +0 -127
- data/lib/generators/templates/app/assets/stylesheets/datepicker.css +0 -224
- data/lib/generators/templates/app/assets/stylesheets/reset.css +0 -48
- data/lib/generators/templates/app/assets/stylesheets/themes/default/d.gif +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/d.png +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/style.css +0 -74
- data/lib/generators/templates/app/assets/stylesheets/timepicker.css +0 -89
- data/lib/generators/templates/app/views/partials/_register_form.html.erb +0 -44
- data/lib/generators/templates/app/views/partials/_sign_in_form.html.erb +0 -18
- data/lib/generators/templates/app/views/partials/_sign_in_sign_out.html.erb +0 -19
- data/lib/generators/templates/lib/custom_failure.rb +0 -15
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding : utf-8
|
2
2
|
class BeautifulScaffoldGenerator < Rails::Generators::Base
|
3
|
-
|
3
|
+
require_relative 'beautiful_scaffold_common_methods'
|
4
4
|
include BeautifulScaffoldCommonMethods
|
5
5
|
|
6
6
|
# Resources
|
@@ -13,20 +13,20 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
|
|
13
13
|
|
14
14
|
source_root File.expand_path('../templates', __FILE__)
|
15
15
|
|
16
|
-
argument :model_opt, :
|
17
|
-
argument :myattributes, :
|
18
|
-
|
19
|
-
class_option :namespace, :
|
20
|
-
class_option :donttouchgem, :
|
21
|
-
class_option :mountable_engine, :
|
16
|
+
argument :model_opt, type: :string, desc: "Name of model singular downcase (ex: family)"
|
17
|
+
argument :myattributes, type: :array, default: [], banner: "field:type field:type"
|
18
|
+
|
19
|
+
class_option :namespace, default: nil
|
20
|
+
class_option :donttouchgem, default: nil
|
21
|
+
class_option :mountable_engine, default: nil
|
22
22
|
|
23
23
|
def install_gems
|
24
|
-
if options[:donttouchgem].blank?
|
24
|
+
if options[:donttouchgem].blank?
|
25
25
|
require_gems
|
26
26
|
end
|
27
27
|
|
28
28
|
#inside Rails.root do # Bug ?!
|
29
|
-
Bundler.
|
29
|
+
Bundler.with_unbundled_env do
|
30
30
|
run "bundle install"
|
31
31
|
end
|
32
32
|
end
|
@@ -36,7 +36,7 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
|
|
36
36
|
@fulltext_field = []
|
37
37
|
myattributes.each{ |attr|
|
38
38
|
a,t = attr.split(':')
|
39
|
-
if ['wysiwyg'].include?(t)
|
39
|
+
if ['wysiwyg'].include?(t)
|
40
40
|
# _typetext = {html|text}
|
41
41
|
# _fulltext = text without any code
|
42
42
|
@fulltext_field << [a + '_typetext', 'string'].join(':')
|
@@ -46,45 +46,61 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def mimetype
|
49
|
-
if
|
50
|
-
if File.exist?("config/initializers/mime_types.rb")
|
49
|
+
if !File.exist?("app/controllers/beautiful_controller.rb")
|
50
|
+
if File.exist?("config/initializers/mime_types.rb") # For mountable engine
|
51
51
|
inject_into_file("config/initializers/mime_types.rb", 'Mime::Type.register_alias "application/pdf", :pdf' + "\n", :before => "# Be sure to restart your server when you modify this file." )
|
52
52
|
else
|
53
53
|
puts "============> Engine : You must add `Mime::Type.register_alias \"application/pdf\", :pdf` to your config/initializers/mime_types.rb main app !"
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def generate_assets
|
59
59
|
stylesheetspath = "app/assets/stylesheets/"
|
60
60
|
stylesheetspath_dest = "#{stylesheetspath}#{engine_name}"
|
61
|
-
|
61
|
+
|
62
62
|
# Css
|
63
|
-
reset = "reset.css"
|
64
63
|
bc_css = [
|
65
|
-
"application-bs.css",
|
66
64
|
"beautiful-scaffold.css.scss",
|
67
65
|
"tagit-dark-grey.css",
|
68
|
-
"colorpicker.css",
|
69
66
|
"bootstrap-wysihtml5.css"
|
70
67
|
]
|
71
68
|
|
72
69
|
javascriptspath = "app/assets/javascripts/"
|
73
70
|
javascriptspath_dest = "#{javascriptspath}#{engine_name}"
|
74
71
|
|
75
|
-
|
72
|
+
bc_css.each do |path|
|
76
73
|
copy_file "#{stylesheetspath}#{path}", "#{stylesheetspath_dest}#{path}"
|
77
|
-
|
78
|
-
|
74
|
+
end
|
75
|
+
copy_file "#{stylesheetspath}application-bs.css", "#{stylesheetspath_dest}application-bs.scss"
|
76
|
+
|
77
|
+
# Jstree theme
|
78
|
+
directory "#{stylesheetspath}themes", "#{stylesheetspath}#{engine_name}themes"
|
79
|
+
|
80
|
+
if !engine_name.blank?
|
81
|
+
['beautiful-scaffold',
|
82
|
+
'tagit-dark-grey',
|
83
|
+
'bootstrap-wysihtml5'].each do |fileassets|
|
84
|
+
gsub_file File.join(stylesheetspath_dest, "application-bs.scss"), " *= require #{fileassets}", " *= require #{engine_name}#{fileassets}"
|
85
|
+
end
|
86
|
+
|
87
|
+
# Issue otherwise
|
88
|
+
gsub_file File.join(stylesheetspath_dest, "application-bs.scss"), '@import "tempusdominus-bootstrap-4.css";', '@import "../tempusdominus-bootstrap-4.css";'
|
89
|
+
gsub_file File.join(stylesheetspath_dest, "application-bs.scss"), 'require themes/default/style', "require #{engine_name}themes/default/style"
|
90
|
+
|
91
|
+
# treeview
|
92
|
+
gsub_file File.join(stylesheetspath_dest, 'themes', 'default', 'style.scss'), 'asset-url("themes', "asset-url(\"#{engine_name}themes"
|
93
|
+
gsub_file File.join(stylesheetspath_dest, 'themes', 'default-dark', 'style.scss'), 'asset-url("themes', "asset-url(\"#{engine_name}themes"
|
94
|
+
end
|
95
|
+
|
79
96
|
# Js
|
80
97
|
bc_js = [
|
81
98
|
"application-bs.js",
|
82
99
|
"beautiful_scaffold.js",
|
83
100
|
"bootstrap-datetimepicker-for-beautiful-scaffold.js",
|
84
|
-
"jquery.jstree.js",
|
85
101
|
"jquery-barcode.js",
|
102
|
+
"jstree.min.js",
|
86
103
|
"tagit.js",
|
87
|
-
"bootstrap-colorpicker.js",
|
88
104
|
"a-wysihtml5-0.3.0.min.js",
|
89
105
|
"bootstrap-wysihtml5.js",
|
90
106
|
"fixed_menu.js"
|
@@ -94,49 +110,78 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
|
|
94
110
|
copy_file "#{javascriptspath}#{path}", "#{javascriptspath_dest}#{path}"
|
95
111
|
}
|
96
112
|
|
97
|
-
|
98
|
-
|
113
|
+
if !engine_name.blank?
|
114
|
+
['a-wysihtml5-0.3.0.min',
|
115
|
+
'bootstrap-datetimepicker-for-beautiful-scaffold',
|
116
|
+
'bootstrap-wysihtml5',
|
117
|
+
'tagit.js',
|
118
|
+
'jstree.min.js',
|
119
|
+
'jquery-barcode',
|
120
|
+
'beautiful_scaffold',
|
121
|
+
'fixed_menu'].each do |fileassets|
|
122
|
+
gsub_file File.join(javascriptspath_dest, "application-bs.js"), "//= require #{fileassets}", "//= require #{engine_name}#{fileassets}"
|
123
|
+
end
|
124
|
+
end
|
99
125
|
|
100
126
|
# Images
|
101
127
|
dir_image = "app/assets/images"
|
102
128
|
dir_image_dest = "app/assets/images/#{engine_opt}"
|
103
129
|
directory dir_image, dir_image_dest
|
104
130
|
|
105
|
-
# Old method
|
106
|
-
#generate("bootstrap:install","static")
|
107
|
-
# New method
|
108
|
-
copy_file "#{stylesheetspath}bootstrap_and_overrides.css.less",
|
109
|
-
"#{stylesheetspath_dest}bootstrap_and_overrides.css.less"
|
110
|
-
|
111
131
|
# Precompile BS assets
|
112
|
-
|
113
|
-
|
132
|
+
path_to_assets_rb = "config/initializers/assets.rb"
|
133
|
+
if !File.exist?(path_to_assets_rb) && !engine_name.blank? # Engine
|
134
|
+
path_to_assets_rb = File.join("test", "dummy", "config/initializers/assets.rb")
|
135
|
+
end
|
136
|
+
|
137
|
+
append_to_file(path_to_assets_rb, "Rails.application.config.assets.precompile += ['#{engine_name}application-bs.css','#{engine_name}application-bs.js']")
|
138
|
+
if !engine_name.blank?
|
139
|
+
manifest_prefix = "#{engine_opt}_"
|
114
140
|
else
|
115
|
-
|
141
|
+
manifest_prefix = ""
|
116
142
|
end
|
143
|
+
#append_to_file("app/assets/config/#{manifest_prefix}manifest.js", '//= link_directory ../stylesheets/faq .css')
|
144
|
+
append_to_file("app/assets/config/#{manifest_prefix}manifest.js", '//= link_directory ../javascripts .js')
|
117
145
|
end
|
118
|
-
|
146
|
+
|
119
147
|
def generate_layout
|
120
|
-
template "app/views/layout.html.erb", "app/views/layouts
|
121
|
-
|
122
|
-
|
148
|
+
template "app/views/layout.html.erb", "app/views/layouts/#{engine_name}beautiful_layout.html.erb"
|
149
|
+
|
150
|
+
gsub_file "app/views/layouts/#{engine_name}beautiful_layout.html.erb", '"layouts/beautiful_menu"', "\"layouts/#{engine_name}beautiful_menu\""
|
151
|
+
|
152
|
+
if !File.exist?("app/views/layouts/#{engine_name}_beautiful_menu.html.erb")
|
153
|
+
template "app/views/_beautiful_menu.html.erb", "app/views/layouts/#{engine_name}_beautiful_menu.html.erb"
|
123
154
|
end
|
124
155
|
|
125
156
|
empty_directory "app/views/#{engine_name}beautiful"
|
126
157
|
template "app/views/dashboard.html.erb", "app/views/#{engine_name}beautiful/dashboard.html.erb"
|
127
|
-
copy_file "app/views/_modal_columns.html.erb", "app/views/layouts
|
128
|
-
copy_file "app/views/_mass_inserting.html.erb", "app/views/layouts
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
158
|
+
copy_file "app/views/_modal_columns.html.erb", "app/views/layouts/#{engine_name}_modal_columns.html.erb"
|
159
|
+
copy_file "app/views/_mass_inserting.html.erb", "app/views/layouts/#{engine_name}_mass_inserting.html.erb"
|
160
|
+
|
161
|
+
action_ctrl = "#{namespace_for_url}#{model.pluralize}"
|
162
|
+
|
163
|
+
inject_into_file("app/views/layouts/#{engine_name}_beautiful_menu.html.erb",
|
164
|
+
"\n" + '<%= link_to ' + i18n_t_m_p(model) + '.capitalize, ' + namespace_for_route + model.pluralize + '_path, class: "nav-link #{(params[:controller] == "' + action_ctrl + '" ? "active" : "")}" %>',
|
165
|
+
:after => "<!-- Beautiful Scaffold Menu Do Not Touch This -->")
|
134
166
|
end
|
135
167
|
|
136
168
|
def generate_model
|
137
169
|
generate("model", "#{model} #{beautiful_attr_to_rails_attr.join(' ')} #{@fulltext_field.join(' ')}")
|
170
|
+
directory "app/models/concerns", "app/models/concerns/#{engine_name}"
|
171
|
+
|
172
|
+
copy_file "app/models/pdf_report.rb", "app/models/#{engine_name}pdf_report.rb"
|
173
|
+
|
174
|
+
if !engine_name.blank?
|
175
|
+
['caption_concern', 'default_sorting_concern','fulltext_concern'].each do |f|
|
176
|
+
path_to_the_concern = "app/models/concerns/#{engine_name}#{f}.rb"
|
177
|
+
inject_into_file path_to_the_concern, "module #{engine_camel}\n", before: "module #{f.camelcase}"
|
178
|
+
append_to_file path_to_the_concern, "\nend #endofmodule \n"
|
179
|
+
end
|
138
180
|
|
139
|
-
|
181
|
+
path_to_the_pdf_report = "app/models/#{engine_name}pdf_report.rb"
|
182
|
+
inject_into_file path_to_the_pdf_report, "module #{engine_camel}\n", before: "class PdfReport"
|
183
|
+
append_to_file path_to_the_pdf_report, "\nend #endofmodule \n"
|
184
|
+
end
|
140
185
|
|
141
186
|
gsub_file "app/models/#{engine_name}#{model}.rb", 'ActiveRecord::Base', 'ApplicationRecord' # Rails 4 -> 5
|
142
187
|
inject_into_file("app/models/#{engine_name}#{model}.rb",'
|
@@ -153,31 +198,30 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
|
|
153
198
|
return ' + attributes_without_type.map{ |attr| ":#{attr}" }.join(",") + '
|
154
199
|
end', :after => "class #{model_camelize} < ApplicationRecord")
|
155
200
|
|
156
|
-
copy_file "app/models/pdf_report.rb", "app/models/pdf_report.rb"
|
157
201
|
end
|
158
202
|
|
159
203
|
def add_to_model
|
160
|
-
|
161
|
-
myattributes.each{ |attr|
|
162
|
-
a,t = attr.split(':')
|
163
|
-
if ['references', 'reference'].include?(t) then
|
164
|
-
begin
|
165
|
-
inject_into_file("app/models/#{engine_name}#{a}.rb", "\n has_many :#{model_pluralize}, :dependent => :nullify", :after => "ApplicationRecord")
|
166
|
-
rescue
|
167
|
-
end
|
168
|
-
end
|
169
|
-
}
|
204
|
+
add_relation
|
170
205
|
end
|
171
206
|
|
172
207
|
def generate_controller
|
173
|
-
|
208
|
+
beautiful_ctrl_path = "app/controllers/#{engine_name}beautiful_controller.rb"
|
209
|
+
copy_file "app/controllers/master_base.rb", beautiful_ctrl_path
|
210
|
+
# beautiful_controller in the context of engine
|
211
|
+
if !engine_name.empty?
|
212
|
+
inject_into_file beautiful_ctrl_path, "module #{engine_camel}\n", before: "class BeautifulController"
|
213
|
+
#gsub_file beautiful_ctrl_path, '< ApplicationController', "< ::#{engine_camel}::ApplicationController" # Rails 4 -> 5 'BeautifulController < ApplicationController'
|
214
|
+
append_to_file beautiful_ctrl_path, "end #endofmodule \n"
|
215
|
+
|
216
|
+
gsub_file beautiful_ctrl_path, 'layout "beautiful_layout"', "layout \"#{engine_name}beautiful_layout\""
|
217
|
+
end
|
174
218
|
dirs = ['app', 'controllers', engine_name, options[:namespace]].compact
|
175
219
|
# Avoid to remove app/controllers directory (https://github.com/rivsc/Beautiful-Scaffold/issues/6)
|
176
|
-
empty_directory File.join(dirs) if
|
220
|
+
empty_directory File.join(dirs) if !options[:namespace].blank?
|
177
221
|
dest_ctrl_file = File.join([dirs, "#{model_pluralize}_controller.rb"].flatten)
|
178
222
|
template "app/controllers/base.rb", dest_ctrl_file
|
179
223
|
end
|
180
|
-
|
224
|
+
|
181
225
|
def generate_helper
|
182
226
|
dest_bs_helper_file = "app/helpers/#{engine_name}beautiful_helper.rb"
|
183
227
|
template "app/helpers/beautiful_helper.rb", dest_bs_helper_file
|
@@ -191,19 +235,21 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
|
|
191
235
|
def generate_views
|
192
236
|
namespacedirs = ["app", "views", engine_name, options[:namespace]].compact
|
193
237
|
empty_directory File.join(namespacedirs)
|
194
|
-
|
238
|
+
|
195
239
|
dirs = [namespacedirs, model_pluralize]
|
196
240
|
empty_directory File.join(dirs)
|
197
|
-
|
241
|
+
|
198
242
|
[available_views, 'treeview'].flatten.each do |view|
|
199
243
|
filename = view + ".html.erb"
|
200
244
|
current_template_path = File.join([dirs, filename].flatten)
|
201
245
|
empty_template_path = File.join(["app", "views", filename].flatten)
|
202
|
-
|
203
246
|
template empty_template_path, current_template_path
|
247
|
+
|
248
|
+
gsub_file current_template_path, '"layouts/modal_columns"', "\"layouts/#{engine_name}modal_columns\""
|
249
|
+
gsub_file current_template_path, '"layouts/mass_inserting"', "\"layouts/#{engine_name}mass_inserting\""
|
204
250
|
end
|
205
251
|
|
206
|
-
copy_file "app/views/_form_habtm_tag.html.erb", "app/views/layouts
|
252
|
+
copy_file "app/views/_form_habtm_tag.html.erb", "app/views/layouts/#{engine_name}_form_habtm_tag.html.erb"
|
207
253
|
end
|
208
254
|
|
209
255
|
def install_ransack_intializer
|
@@ -215,19 +261,15 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
|
|
215
261
|
end
|
216
262
|
|
217
263
|
def routes
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
myroute = <<EOF
|
223
|
-
root :to => 'beautiful#dashboard'
|
224
|
-
match ':model_sym/select_fields' => 'beautiful#select_fields', :via => [:get, :post]
|
264
|
+
myroute = <<EOF
|
265
|
+
root :to => 'beautiful#dashboard'
|
266
|
+
match ':model_sym/select_fields' => 'beautiful#select_fields', as: :select_fields, via: [:get, :post]
|
225
267
|
|
226
268
|
concern :bs_routes do
|
227
269
|
collection do
|
228
270
|
post :batch
|
229
271
|
get :treeview
|
230
|
-
match :search_and_filter, :
|
272
|
+
match :search_and_filter, action: :index, as: :search, via: [:get, :post]
|
231
273
|
end
|
232
274
|
member do
|
233
275
|
post :treeview_update
|
@@ -237,16 +279,12 @@ root :to => 'beautiful#dashboard'
|
|
237
279
|
# Add route with concerns: :bs_routes here # Do not remove
|
238
280
|
EOF
|
239
281
|
|
240
|
-
|
241
|
-
end
|
242
|
-
|
243
|
-
search_namespace = namespace_alone + "/" if not namespace_alone.blank?
|
244
|
-
search_namespace ||= ""
|
282
|
+
inject_into_file("config/routes.rb", myroute, :after => "routes.draw do\n")
|
245
283
|
|
246
284
|
myroute = "\n "
|
247
|
-
myroute += "namespace :#{namespace_alone} do\n " if
|
285
|
+
myroute += "namespace :#{namespace_alone} do\n " if !namespace_alone.blank?
|
248
286
|
myroute += "resources :#{model_pluralize}, concerns: :bs_routes\n "
|
249
|
-
myroute += "end\n" if
|
287
|
+
myroute += "end\n" if !namespace_alone.blank?
|
250
288
|
|
251
289
|
inject_into_file("config/routes.rb", myroute, :after => ":bs_routes here # Do not remove")
|
252
290
|
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# encoding : utf-8
|
2
|
+
class BeautifulSorceryGenerator < Rails::Generators::Base
|
3
|
+
require_relative 'beautiful_scaffold_common_methods'
|
4
|
+
include BeautifulScaffoldCommonMethods
|
5
|
+
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
#argument :model, :type => :string, :desc => "Name of model (ex: User)"
|
9
|
+
|
10
|
+
def install_sorcery
|
11
|
+
model = "User"
|
12
|
+
view_path = "app/views/"
|
13
|
+
|
14
|
+
if !File.read('Gemfile').include?("sorcery")
|
15
|
+
gem("sorcery", "0.16.0")
|
16
|
+
end
|
17
|
+
|
18
|
+
Bundler.with_unbundled_env do
|
19
|
+
run "bundle install"
|
20
|
+
end
|
21
|
+
|
22
|
+
raise "Model must be specified" if model.blank?
|
23
|
+
|
24
|
+
# Install sorcery
|
25
|
+
generate("sorcery:install", "remember_me reset_password user_activation brute_force_protection external --model #{model}")
|
26
|
+
|
27
|
+
# If exist users migration just add columns
|
28
|
+
create_user_migration = Dir.glob("db/migrate/*create_users.rb").first
|
29
|
+
if create_user_migration
|
30
|
+
already_email = File.read(create_user_migration).include?(":email")
|
31
|
+
sorcery_core_file = Dir.glob("db/migrate/*sorcery_core.rb").first
|
32
|
+
File.open(sorcery_core_file, "w+") do |f|
|
33
|
+
f.write("class SorceryCore < ActiveRecord::Migration[6.1]
|
34
|
+
def change
|
35
|
+
#{(already_email ? '' : 'add_column :users, :email, :string')}
|
36
|
+
add_column :users, :crypted_password, :string
|
37
|
+
add_column :users, :salt, :string
|
38
|
+
|
39
|
+
#{(already_email ? '' : 'add_index :users, :email, unique: true')}
|
40
|
+
end
|
41
|
+
end")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Generate mailer
|
46
|
+
copy_file("app/mailers/user_mailer.rb")
|
47
|
+
|
48
|
+
# Install controllers
|
49
|
+
copy_file("app/controllers/user_sessions_controller.rb")
|
50
|
+
|
51
|
+
# ===== Controller
|
52
|
+
inject_into_file("app/controllers/users_controller.rb",
|
53
|
+
"\n
|
54
|
+
skip_before_action :require_login, only: [:new, :create, :activate]
|
55
|
+
\n", after: "< BeautifulController")
|
56
|
+
|
57
|
+
inject_into_file("app/controllers/users_controller.rb",
|
58
|
+
"def activate
|
59
|
+
if @user = User.load_from_activation_token(params[:id])
|
60
|
+
@user.activate!
|
61
|
+
redirect_to(login_path, :notice => 'User was successfully activated.')
|
62
|
+
else
|
63
|
+
not_authenticated
|
64
|
+
end
|
65
|
+
end\n\n ", before: "private")
|
66
|
+
|
67
|
+
# ====== Model
|
68
|
+
# Add password & password_confirmation in model
|
69
|
+
inject_into_file("app/models/user.rb",
|
70
|
+
"\n
|
71
|
+
validates :password, length: { minimum: 3 }, if: -> { new_record? || changes[:crypted_password] }
|
72
|
+
validates :password, confirmation: true, if: -> { new_record? || changes[:crypted_password] }
|
73
|
+
validates :password_confirmation, presence: true, if: -> { new_record? || changes[:crypted_password] }
|
74
|
+
|
75
|
+
before_update :setup_activation, if: -> { email_changed? }
|
76
|
+
after_update :send_activation_needed_email!, if: -> { previous_changes['email'].present? }\n",
|
77
|
+
after: "ApplicationRecord")
|
78
|
+
|
79
|
+
inject_into_file("app/models/user.rb", ":password,:password_confirmation,", :after => "def self.permitted_attributes\n return ")
|
80
|
+
|
81
|
+
# ====== Views
|
82
|
+
inject_into_file("app/views/users/_form.html.erb",
|
83
|
+
' <div class="form-group">
|
84
|
+
<%= f.label :password, t(\'app.models.user.bs_attributes.password\', :default => \'password\').capitalize, :class => "control-label" %><br />
|
85
|
+
<%= f.password_field :password, :class => "form-control" %>
|
86
|
+
</div>
|
87
|
+
<div class="form-group">
|
88
|
+
<%= f.label :password_confirmation, t(\'app.models.user.bs_attributes.password_confirmation\', :default => \'password_confirmation\').capitalize, :class => "control-label" %><br />
|
89
|
+
<%= f.password_field :password_confirmation, :class => "form-control" %>
|
90
|
+
</div>', before: '<!-- Beautiful_scaffold - AddField - Do not remove -->')
|
91
|
+
|
92
|
+
# Install all views for login/logout
|
93
|
+
directory "app/views/login_logout", "app/views"
|
94
|
+
|
95
|
+
# Domain in action_mailer
|
96
|
+
for current_env in ['production', 'development', 'test']
|
97
|
+
inject_into_file("config/environments/#{current_env}.rb", " config.action_mailer.default_url_options = { :host => 'localhost:3000' }", :after => "Rails.application.configure do\n" )
|
98
|
+
end
|
99
|
+
|
100
|
+
# In model
|
101
|
+
#remove_file("app/models/user.rb") # remove generated by sorcery
|
102
|
+
#copy_file("app/models/user.rb") # copy BS version ;)
|
103
|
+
|
104
|
+
# Limited access
|
105
|
+
inject_into_file("app/controllers/beautiful_controller.rb",
|
106
|
+
"\n before_action :require_login, except: [:dashboard]\n",
|
107
|
+
:after => 'layout "beautiful_layout"' + "\n")
|
108
|
+
|
109
|
+
inject_into_file("config/initializers/sorcery.rb",
|
110
|
+
"\nuser.user_activation_mailer = UserMailer\n",
|
111
|
+
:after => "# user.user_activation_mailer =\n")
|
112
|
+
|
113
|
+
# Routes (session)
|
114
|
+
inject_into_file("config/routes.rb",
|
115
|
+
'
|
116
|
+
resources :user_sessions, only: [:create]
|
117
|
+
get "login" => "user_sessions#new", :as => :login
|
118
|
+
post "logout" => "user_sessions#destroy", :as => :logout' + "\n\n\n",
|
119
|
+
:after => "Rails.application.routes.draw do\n")
|
120
|
+
|
121
|
+
# Activate
|
122
|
+
inject_into_file("config/routes.rb", " do
|
123
|
+
member do
|
124
|
+
get :activate
|
125
|
+
end
|
126
|
+
end", after: 'resources :users, concerns: :bs_routes')
|
127
|
+
|
128
|
+
copy_file("#{view_path}partials/_login_logout_register.html.erb", "#{view_path}layouts/_login_logout_register.html.erb")
|
129
|
+
|
130
|
+
# Sign in sign out
|
131
|
+
inject_into_file("#{view_path}layouts/beautiful_layout.html.erb",
|
132
|
+
"\n<%= render :partial => 'layouts/login_logout_register' %>\n",
|
133
|
+
:after => "<!-- Beautiful_scaffold - Signin - Do not remove -->")
|
134
|
+
|
135
|
+
say "Beautiful-Scaffold enable 'user_activation' sorcery module for you, so when you sign up, find in logs the activation link. You can't sign in yourself until you activate the account"
|
136
|
+
end
|
137
|
+
end
|