beautiful_scaffold 1.0.2 → 2.0.0.pre

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 (59) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/CHANGELOG +24 -1
  4. data/Gemfile +24 -9
  5. data/Gemfile.lock +209 -0
  6. data/README.rdoc +25 -26
  7. data/Rakefile +27 -4
  8. data/beautiful_scaffold.gemspec +6 -4
  9. data/lib/beautiful_scaffold/version.rb +3 -0
  10. data/lib/generators/beautiful_jointable_generator.rb +39 -6
  11. data/lib/generators/beautiful_migration_generator.rb +11 -19
  12. data/lib/generators/beautiful_scaffold_common_methods.rb +51 -26
  13. data/lib/generators/beautiful_scaffold_generator.rb +100 -43
  14. data/lib/generators/templates/app/assets/javascripts/application-bs.js +5 -6
  15. data/lib/generators/templates/app/assets/javascripts/beautiful_scaffold.js +64 -77
  16. data/lib/generators/templates/app/assets/javascripts/bootstrap-datetimepicker-for-beautiful-scaffold.js +25 -41
  17. data/lib/generators/templates/app/assets/javascripts/fixed_menu.js +3 -1
  18. data/lib/generators/templates/app/assets/javascripts/jstree.min.js +6 -0
  19. data/lib/generators/templates/app/assets/stylesheets/application-bs.css +14 -6
  20. data/lib/generators/templates/app/assets/stylesheets/beautiful-scaffold.css.scss +10 -1
  21. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/32px.png +0 -0
  22. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/40px.png +0 -0
  23. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/style.scss +1146 -0
  24. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/throbber.gif +0 -0
  25. data/lib/generators/templates/app/assets/stylesheets/themes/default/32px.png +0 -0
  26. data/lib/generators/templates/app/assets/stylesheets/themes/default/40px.png +0 -0
  27. data/lib/generators/templates/app/assets/stylesheets/themes/default/style.scss +1102 -0
  28. data/lib/generators/templates/app/assets/stylesheets/themes/default/throbber.gif +0 -0
  29. data/lib/generators/templates/app/controllers/base.rb +7 -5
  30. data/lib/generators/templates/app/controllers/master_base.rb +18 -24
  31. data/lib/generators/templates/app/helpers/beautiful_helper.rb +83 -61
  32. data/lib/generators/templates/app/initializers/link_renderer.rb +23 -18
  33. data/lib/generators/templates/app/views/_form.html.erb +2 -2
  34. data/lib/generators/templates/app/views/_form_habtm_tag.html.erb +6 -2
  35. data/lib/generators/templates/app/views/_mass_inserting.html.erb +38 -30
  36. data/lib/generators/templates/app/views/_modal_columns.html.erb +3 -3
  37. data/lib/generators/templates/app/views/index.html.erb +83 -79
  38. data/lib/generators/templates/app/views/layout.html.erb +29 -36
  39. data/lib/generators/templates/app/views/partials/_forget_password.html.erb +2 -2
  40. data/lib/generators/templates/app/views/partials/_form_field.html.erb +7 -7
  41. data/lib/generators/templates/app/views/partials/_index_batch.html.erb +1 -1
  42. data/lib/generators/templates/app/views/partials/_index_column.html.erb +4 -4
  43. data/lib/generators/templates/app/views/partials/_index_header.html.erb +1 -1
  44. data/lib/generators/templates/app/views/partials/_index_search.html.erb +1 -1
  45. data/lib/generators/templates/app/views/partials/_register_form.html.erb +2 -2
  46. data/lib/generators/templates/app/views/partials/_show_field.html.erb +3 -3
  47. data/lib/generators/templates/app/views/partials/_sign_in_form.html.erb +1 -1
  48. data/lib/generators/templates/app/views/partials/_sign_in_sign_out.html.erb +2 -2
  49. data/lib/generators/templates/app/views/show.html.erb +2 -2
  50. data/lib/generators/templates/app/views/treeview.html.erb +8 -5
  51. metadata +21 -19
  52. data/lib/generators/templates/app/assets/javascripts/jquery.jstree.js +0 -4551
  53. data/lib/generators/templates/app/assets/stylesheets/datepicker.css +0 -224
  54. data/lib/generators/templates/app/assets/stylesheets/reset.css +0 -48
  55. data/lib/generators/templates/app/assets/stylesheets/themes/default/d.gif +0 -0
  56. data/lib/generators/templates/app/assets/stylesheets/themes/default/d.png +0 -0
  57. data/lib/generators/templates/app/assets/stylesheets/themes/default/style.css +0 -74
  58. data/lib/generators/templates/app/assets/stylesheets/timepicker.css +0 -89
  59. data/test/scaffold_test.rb +0 -68
@@ -0,0 +1,3 @@
1
+ module BeautifulScaffold
2
+ VERSION = '2.0.0.pre'
3
+ end
@@ -6,6 +6,8 @@ class BeautifulJointableGenerator < Rails::Generators::Base
6
6
  source_root File.expand_path('../templates', __FILE__)
7
7
 
8
8
  argument :join_models, :type => :array, :default => [], :banner => "model model"
9
+
10
+ class_option :mountable_engine, default: nil
9
11
 
10
12
  def create_join_table
11
13
  if join_models.length != 2 then
@@ -13,14 +15,21 @@ class BeautifulJointableGenerator < Rails::Generators::Base
13
15
  else
14
16
  sorted_model = join_models.sort
15
17
 
18
+ prefix_str = ''
19
+ if engine_name.present?
20
+ prefix_str = "#{engine_opt}_"
21
+ end
22
+
23
+ join_table_name = "#{prefix_str}#{sorted_model[0].pluralize}_#{sorted_model[1].pluralize}"
24
+
16
25
  # Generate migration
17
26
  migration_content = "
18
- create_table :#{sorted_model[0].pluralize}_#{sorted_model[1].pluralize}, :id => false do |t|
27
+ create_table :#{join_table_name}, :id => false do |t|
19
28
  t.integer :#{sorted_model[0]}_id
20
29
  t.integer :#{sorted_model[1]}_id
21
30
  end
22
31
 
23
- add_index :#{sorted_model[0].pluralize}_#{sorted_model[1].pluralize}, [:#{sorted_model[0]}_id, :#{sorted_model[1]}_id]
32
+ add_index :#{join_table_name}, [:#{sorted_model[0]}_id, :#{sorted_model[1]}_id]
24
33
  "
25
34
 
26
35
  migration_name = "create_join_table_for_#{sorted_model[0]}_and_#{sorted_model[1]}"
@@ -31,11 +40,35 @@ class BeautifulJointableGenerator < Rails::Generators::Base
31
40
  inject_into_file(filename, migration_content, :after => "def change")
32
41
 
33
42
  # Add habtm relation
34
- inject_into_file("app/models/#{sorted_model[0]}.rb", "\n has_and_belongs_to_many :#{sorted_model[1].pluralize}", :after => "ActiveRecord::Base")
35
- inject_into_file("app/models/#{sorted_model[1]}.rb", "\n has_and_belongs_to_many :#{sorted_model[0].pluralize}", :after => "ActiveRecord::Base")
36
- inject_into_file("app/models/#{sorted_model[0]}.rb", ":#{sorted_model[1]}_ids, ", :after => "attr_accessible ")
37
- inject_into_file("app/models/#{sorted_model[1]}.rb", ":#{sorted_model[0]}_ids, ", :after => "attr_accessible ")
43
+ inject_into_file("app/models/#{engine_name}#{sorted_model[0]}.rb", "\n #{engine_name.present? ? ' ' : ''}has_and_belongs_to_many :#{sorted_model[1].pluralize}", :after => "ApplicationRecord")
44
+ inject_into_file("app/models/#{engine_name}#{sorted_model[1]}.rb", "\n #{engine_name.present? ? ' ' : ''}has_and_belongs_to_many :#{sorted_model[0].pluralize}", :after => "ApplicationRecord")
45
+ inject_into_file("app/models/#{engine_name}#{sorted_model[0]}.rb", "{ :#{sorted_model[1]}_ids => [] }, ", :after => "permitted_attributes
46
+ return ")
47
+ inject_into_file("app/models/#{engine_name}#{sorted_model[1]}.rb", "{ :#{sorted_model[0]}_ids => [] }, ", :after => "permitted_attributes
48
+ return ")
38
49
  end
39
50
  end
40
51
 
52
+ def add_habtm_field_in_forms
53
+ models = join_models.sort
54
+
55
+ 2.times do
56
+ html = "<%=
57
+ render :partial => 'layouts/#{engine_name}form_habtm_tag', :locals => {
58
+ :model_class => @#{models[0]},
59
+ :model_name => '#{models[0]}',
60
+ :plural_model_name => '#{models[0].pluralize}',
61
+ :linked_model_name => '#{models[1]}',
62
+ :plural_linked_model_name => '#{models[1].pluralize}',
63
+ :namespace_bs => '',
64
+ :engine_bs => '#{engine_opt}',
65
+ :field_to_search_for_linked_model => 'name',
66
+ :attr_to_show => 'caption',
67
+ :f => f
68
+ } %>"
69
+
70
+ inject_into_file("app/views/#{engine_name}#{models[0].pluralize}/_form.html.erb", html, :before => "<!-- Beautiful_scaffold - AddField - Do not remove -->")
71
+ models = models.reverse
72
+ end
73
+ end
41
74
  end
@@ -7,14 +7,15 @@ class BeautifulMigrationGenerator < Rails::Generators::Base
7
7
 
8
8
  source_root File.expand_path('../templates', __FILE__)
9
9
 
10
- argument :name, :type => :string, :desc => "Name of the migration CamelCase AddXxxToYyy (Yyy must be plural)"
11
- argument :myattributes, :type => :array, :default => [], :banner => "field:type field:type (for bt relation model:references)"
10
+ argument :name, type: :string, desc: "Name of the migration (in CamelCase) AddXxxTo[Engine]Yyy (Yyy must be plural)"
11
+ argument :myattributes, type: :array, default: [], banner: "field:type field:type (for bt relation model:references)"
12
12
 
13
- class_option :namespace, :default => nil
14
- class_option :donttouchgem, :default => nil
13
+ class_option :namespace, default: nil
14
+ class_option :donttouchgem, default: nil
15
+ class_option :mountable_engine, default: nil
15
16
 
16
17
  def install_gems
17
- if options[:donttouchgem].blank? then
18
+ if options[:donttouchgem].blank?
18
19
  require_gems
19
20
  end
20
21
  end
@@ -24,7 +25,7 @@ class BeautifulMigrationGenerator < Rails::Generators::Base
24
25
  @fulltext_field = []
25
26
  myattributes.each{ |attr|
26
27
  a,t = attr.split(':')
27
- if ['richtext', 'wysiwyg'].include?(t) then
28
+ if ['richtext', 'wysiwyg'].include?(t)
28
29
  # _typetext = {bbcode|html|text|wiki|textile|markdown}
29
30
  # _fulltext = text without any code
30
31
  @fulltext_field << [a + '_typetext', 'string'].join(':')
@@ -34,24 +35,15 @@ class BeautifulMigrationGenerator < Rails::Generators::Base
34
35
  end
35
36
 
36
37
  def generate_model
37
- generate("migration", "#{name} #{beautiful_attr_to_rails_attr(true).join(' ')} #{@fulltext_field.join(' ')}")
38
+ generate("migration", "#{name} #{beautiful_attr_to_rails_attr.join(' ')} #{@fulltext_field.join(' ')}")
38
39
  end
39
40
 
40
41
  def add_to_model
41
- myattributes.each{ |attr|
42
- a,t = attr.split(':')
43
- if ['references', 'reference'].include?(t) then
44
- inject_into_file("app/models/#{model}.rb", "\n belongs_to :#{a}", :after => "ApplicationRecord")
45
- inject_into_file("app/models/#{a}.rb", "\n has_many :#{model_pluralize}, :dependent => :nullify", :after => "ApplicationRecord")
46
- a += "_id"
47
- end
48
-
49
- inject_into_file("app/models/#{model}.rb", ":#{a},", :after => "def self.permitted_attributes\n return ")
50
- }
42
+ add_relation
51
43
  end
52
44
 
53
45
  def generate_views
54
- commonpath = "app/views/#{namespace_for_url}#{model_pluralize}/"
46
+ commonpath = "app/views/#{engine_name}#{namespace_for_url}#{model_pluralize}/"
55
47
 
56
48
  # Form
57
49
  inject_into_file("#{commonpath}_form.html.erb", render_partial("app/views/partials/_form_field.html.erb"), :before => "<!-- Beautiful_scaffold - AddField - Do not remove -->\n" )
@@ -68,7 +60,7 @@ class BeautifulMigrationGenerator < Rails::Generators::Base
68
60
  private
69
61
 
70
62
  def model
71
- return name.scan(/^Add(.*)To(.*)$/).flatten[1].underscore.singularize
63
+ return name.scan(/^Add(.*)To(.*)$/).flatten[1].underscore.singularize.gsub("#{options[:mountable_engine].underscore}_",'')
72
64
  end
73
65
 
74
66
  end
@@ -8,7 +8,7 @@ module BeautifulScaffoldCommonMethods
8
8
  #############
9
9
 
10
10
  def engine_opt
11
- options[:mountable_engine].to_s
11
+ options[:mountable_engine].to_s.downcase
12
12
  end
13
13
 
14
14
  def engine_name
@@ -16,38 +16,38 @@ module BeautifulScaffoldCommonMethods
16
16
  end
17
17
 
18
18
  def engine_camel
19
- options[:mountable_engine].camelize
19
+ options[:mountable_engine].to_s.camelize
20
20
  end
21
21
 
22
22
  #############
23
23
  # Namespace
24
24
  #############
25
-
25
+
26
26
  def namespace_for_class
27
27
  str = namespace_alone
28
28
  str = str.camelcase + '::' if not str.blank?
29
29
  return str
30
30
  end
31
-
31
+
32
32
  def namespace_for_route
33
33
  str = namespace_alone
34
34
  str = str.downcase + '_' if not str.blank?
35
35
  return str
36
36
  end
37
-
37
+
38
38
  def namespace_for_url
39
39
  str = namespace_alone
40
40
  str = str.downcase + '/' if not str.blank?
41
41
  return str
42
42
  end
43
-
43
+
44
44
  def namespace_alone
45
45
  return options[:namespace].to_s.downcase
46
46
  end
47
47
 
48
48
  def render_partial(path)
49
49
  source = File.expand_path(find_in_source_paths(path.to_s))
50
- result = ERB.new(::File.binread(source), nil, '-').result(binding)
50
+ result = ERB.new(::File.binread(source), trim_mode: '-').result(binding)
51
51
  return result
52
52
  end
53
53
 
@@ -74,7 +74,7 @@ module BeautifulScaffoldCommonMethods
74
74
  def model_class
75
75
  model.camelize
76
76
  end
77
-
77
+
78
78
  ############
79
79
  # Table
80
80
  ############
@@ -117,7 +117,7 @@ module BeautifulScaffoldCommonMethods
117
117
  def available_views
118
118
  %w(index edit show new _form)
119
119
  end
120
-
120
+
121
121
  def attributes
122
122
  # https://raw.github.com/rails/rails/master/railties/lib/rails/generators/generated_attribute.rb
123
123
  require 'rails/generators/generated_attribute'
@@ -127,19 +127,21 @@ module BeautifulScaffoldCommonMethods
127
127
  }
128
128
  end
129
129
 
130
- def beautiful_attr_to_rails_attr(for_migration = false)
130
+ def beautiful_attr_to_rails_attr #(for_migration = false)
131
131
  newmyattributes = []
132
132
  myattributes.each{ |attr|
133
133
  a,t = attr.split(':')
134
134
  newt = t
135
- if ['wysiwyg'].include?(t) then
135
+
136
+ # Special columns
137
+ if ['wysiwyg'].include?(t)
136
138
  newt = 'text'
137
- elsif t == 'price' then
139
+ elsif t == 'price'
138
140
  newt = 'float'
139
- elsif ['references', 'reference'].include?(t) and for_migration then
140
- a = a + '_id'
141
+ elsif ['references', 'reference'].include?(t) # Because Rails generate corrupted files (migrations)
142
+ a = "#{a}_id"
141
143
  newt = 'integer:index'
142
- elsif t == 'color' then
144
+ elsif t == 'color'
143
145
  newt = 'string'
144
146
  end
145
147
 
@@ -154,10 +156,15 @@ module BeautifulScaffoldCommonMethods
154
156
  myattributes.each{ |attr|
155
157
  a,t = attr.split(':')
156
158
 
157
- if ['references', 'reference'].include?(t) then
159
+ if ['references', 'reference'].include?(t)
158
160
  a = a + '_id'
159
161
  end
160
162
 
163
+ # Add the typetext to permitted_attr
164
+ if t == 'wysiwyg'
165
+ newmyattributes << "#{a}_typetext"
166
+ end
167
+
161
168
  newmyattributes << a
162
169
  }
163
170
 
@@ -168,7 +175,7 @@ module BeautifulScaffoldCommonMethods
168
175
  fulltext_field = []
169
176
  myattributes.each{ |attr|
170
177
  a,t = attr.split(':')
171
- if ['wysiwyg'].include?(t) then
178
+ if ['wysiwyg'].include?(t)
172
179
  fulltext_field << a
173
180
  end
174
181
  }
@@ -182,18 +189,18 @@ module BeautifulScaffoldCommonMethods
182
189
  def require_gems
183
190
  gems = {
184
191
  'will_paginate' => nil, # v 3.1.5
185
- 'ransack' => '1.8.4',
186
- 'polyamorous' => '1.3.1',
192
+ 'ransack' => nil, #'2.3.2',
187
193
  'jquery-ui-rails' => nil,
188
- 'prawn' => '2.1.0',
189
- 'prawn-table' => '0.2.2',
194
+ 'prawn' => nil, #'2.1.0',
195
+ 'prawn-table' => nil, #'0.2.2',
190
196
  'sanitize' => nil,
191
- 'twitter-bootstrap-rails' => '3.2.2',
192
- 'font-awesome-rails' => '4.7.0.2',
193
- 'chardinjs-rails' => nil,
197
+ #'twitter-bootstrap-rails' => '3.2.2', # Bootstrap 3 for Rails 6+
198
+ 'bootstrap' => '~> 4.3.1', # Bootstrap 4 for Rails 6+
199
+ 'font-awesome-sass' => '~> 5.13.0',
194
200
  'momentjs-rails' => '>= 2.9.0',
195
- 'bootstrap3-datetimepicker-rails' => '~> 4.17.47',
196
- 'jquery-rails' => '4.3.1'
201
+ 'bootstrap4-datetime-picker-rails' => nil,
202
+ 'jquery-rails' => '4.3.1',
203
+ 'jstree-rails-4' => '3.3.8'
197
204
  }
198
205
 
199
206
  # Si engine il faut mettre les gems dans le gemspec et faire le require
@@ -206,4 +213,22 @@ module BeautifulScaffoldCommonMethods
206
213
  }
207
214
  end
208
215
 
216
+ def add_relation
217
+ myattributes.each{ |attr|
218
+ a,t = attr.split(':')
219
+
220
+ foreign_key = a
221
+
222
+ if ['references', 'reference'].include?(t)
223
+ foreign_key = "#{a}_id"
224
+
225
+ # question (model) belongs_to user (a)
226
+ inject_into_file("app/models/#{engine_name}#{model}.rb", "\n belongs_to :#{a}, optional: true", :after => "ApplicationRecord")
227
+ inject_into_file("app/models/#{engine_name}#{a}.rb", "\n has_many :#{model_pluralize}, :dependent => :nullify", :after => "ApplicationRecord")
228
+ end
229
+
230
+ inject_into_file("app/models/#{engine_name}#{model}.rb", ":#{foreign_key},", :after => "def self.permitted_attributes\n return ")
231
+ }
232
+ end
233
+
209
234
  end
@@ -21,12 +21,12 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
21
21
  class_option :mountable_engine, default: nil
22
22
 
23
23
  def install_gems
24
- if options[:donttouchgem].blank? then
24
+ if options[:donttouchgem].blank?
25
25
  require_gems
26
26
  end
27
27
 
28
28
  #inside Rails.root do # Bug ?!
29
- Bundler.with_clean_env do
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) then
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,8 +46,8 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
46
46
  end
47
47
 
48
48
  def mimetype
49
- if not File.exist?("app/controllers/beautiful_controller.rb") then
50
- if File.exist?("config/initializers/mime_types.rb") then # For mountable engine
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 !"
@@ -60,9 +60,7 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
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
66
  "colorpicker.css",
@@ -72,17 +70,38 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
72
70
  javascriptspath = "app/assets/javascripts/"
73
71
  javascriptspath_dest = "#{javascriptspath}#{engine_name}"
74
72
 
75
- [reset, bc_css].flatten.each{ |path|
73
+ bc_css.each do |path|
76
74
  copy_file "#{stylesheetspath}#{path}", "#{stylesheetspath_dest}#{path}"
77
- }
75
+ end
76
+ copy_file "#{stylesheetspath}application-bs.css", "#{stylesheetspath_dest}application-bs.scss"
77
+
78
+ # Jstree theme
79
+ directory "#{stylesheetspath}themes", "#{stylesheetspath}#{engine_name}themes"
80
+
81
+ if !engine_name.blank?
82
+ ['beautiful-scaffold',
83
+ 'tagit-dark-grey',
84
+ 'colorpicker',
85
+ 'bootstrap-wysihtml5'].each do |fileassets|
86
+ gsub_file File.join(stylesheetspath_dest, "application-bs.scss"), " *= require #{fileassets}", " *= require #{engine_name}#{fileassets}"
87
+ end
88
+
89
+ # Issue otherwise
90
+ gsub_file File.join(stylesheetspath_dest, "application-bs.scss"), '@import "tempusdominus-bootstrap-4.css";', '@import "../tempusdominus-bootstrap-4.css";'
91
+ gsub_file File.join(stylesheetspath_dest, "application-bs.scss"), 'require themes/default/style', "require #{engine_name}themes/default/style"
92
+
93
+ # treeview
94
+ gsub_file File.join(stylesheetspath_dest, 'themes', 'default', 'style.scss'), 'asset-url("themes', "asset-url(\"#{engine_name}themes"
95
+ gsub_file File.join(stylesheetspath_dest, 'themes', 'default-dark', 'style.scss'), 'asset-url("themes', "asset-url(\"#{engine_name}themes"
96
+ end
78
97
 
79
98
  # Js
80
99
  bc_js = [
81
100
  "application-bs.js",
82
101
  "beautiful_scaffold.js",
83
102
  "bootstrap-datetimepicker-for-beautiful-scaffold.js",
84
- "jquery.jstree.js",
85
103
  "jquery-barcode.js",
104
+ "jstree.min.js",
86
105
  "tagit.js",
87
106
  "bootstrap-colorpicker.js",
88
107
  "a-wysihtml5-0.3.0.min.js",
@@ -94,8 +113,19 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
94
113
  copy_file "#{javascriptspath}#{path}", "#{javascriptspath_dest}#{path}"
95
114
  }
96
115
 
97
- # Jstree theme
98
- directory "#{stylesheetspath}themes", "#{stylesheetspath}themes"
116
+ if !engine_name.blank?
117
+ ['a-wysihtml5-0.3.0.min',
118
+ 'bootstrap-colorpicker',
119
+ 'bootstrap-datetimepicker-for-beautiful-scaffold',
120
+ 'bootstrap-wysihtml5',
121
+ 'tagit.js',
122
+ 'jstree.min.js',
123
+ 'jquery-barcode',
124
+ 'beautiful_scaffold',
125
+ 'fixed_menu'].each do |fileassets|
126
+ gsub_file File.join(javascriptspath_dest, "application-bs.js"), "//= require #{fileassets}", "//= require #{engine_name}#{fileassets}"
127
+ end
128
+ end
99
129
 
100
130
  # Images
101
131
  dir_image = "app/assets/images"
@@ -103,34 +133,59 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
103
133
  directory dir_image, dir_image_dest
104
134
 
105
135
  # Precompile BS assets
106
- if File.exist?("config/initializers/assets.rb") then # For mountable engine
107
- inject_into_file("config/initializers/assets.rb", "Rails.application.config.assets.precompile += ['#{engine_name}application-bs.css','#{engine_name}application-bs.js']", after: /\z/m)
136
+ path_to_assets_rb = "config/initializers/assets.rb"
137
+ if !File.exist?(path_to_assets_rb) && !engine_name.blank? # Engine
138
+ path_to_assets_rb = File.join("test", "dummy", "config/initializers/assets.rb")
139
+ end
140
+
141
+ append_to_file(path_to_assets_rb, "Rails.application.config.assets.precompile += ['#{engine_name}application-bs.css','#{engine_name}application-bs.js']")
142
+ if !engine_name.blank?
143
+ manifest_prefix = "#{engine_opt}_"
108
144
  else
109
- puts "============> Engine : You must add `Rails.application.config.assets.precompile += ['#{engine_name}application-bs.css','#{engine_name}application-bs.js']` to your config/initializers/assets.rb main app !"
145
+ manifest_prefix = ""
110
146
  end
147
+ #append_to_file("app/assets/config/#{manifest_prefix}manifest.js", '//= link_directory ../stylesheets/faq .css')
148
+ append_to_file("app/assets/config/#{manifest_prefix}manifest.js", '//= link_directory ../javascripts/faq .js')
111
149
  end
112
150
 
113
151
  def generate_layout
114
- template "app/views/layout.html.erb", "app/views/layouts/beautiful_layout.html.erb"
115
- if not File.exist?("app/views/layouts/_beautiful_menu.html.erb") then
116
- template "app/views/_beautiful_menu.html.erb", "app/views/layouts/_beautiful_menu.html.erb"
152
+ template "app/views/layout.html.erb", "app/views/layouts/#{engine_name}beautiful_layout.html.erb"
153
+
154
+ gsub_file "app/views/layouts/#{engine_name}beautiful_layout.html.erb", '"layouts/beautiful_menu"', "\"layouts/#{engine_name}beautiful_menu\""
155
+
156
+ if !File.exist?("app/views/layouts/#{engine_name}_beautiful_menu.html.erb")
157
+ template "app/views/_beautiful_menu.html.erb", "app/views/layouts/#{engine_name}_beautiful_menu.html.erb"
117
158
  end
118
159
 
119
160
  empty_directory "app/views/#{engine_name}beautiful"
120
161
  template "app/views/dashboard.html.erb", "app/views/#{engine_name}beautiful/dashboard.html.erb"
121
- copy_file "app/views/_modal_columns.html.erb", "app/views/layouts/_modal_columns.html.erb"
122
- copy_file "app/views/_mass_inserting.html.erb", "app/views/layouts/_mass_inserting.html.erb"
162
+ copy_file "app/views/_modal_columns.html.erb", "app/views/layouts/#{engine_name}_modal_columns.html.erb"
163
+ copy_file "app/views/_mass_inserting.html.erb", "app/views/layouts/#{engine_name}_mass_inserting.html.erb"
123
164
 
124
- inject_into_file("app/views/layouts/_beautiful_menu.html.erb",'
125
- <li class="<%= "active" if params[:controller] == "' + namespace_for_url + model.pluralize + '" %>">
126
- <%= link_to ' + i18n_t_m_p(model) + '.capitalize, ' + namespace_for_route + model.pluralize + '_path %>
127
- </li>', :after => "<!-- Beautiful Scaffold Menu Do Not Touch This -->")
165
+ action_ctrl = "#{namespace_for_url}#{model.pluralize}"
166
+
167
+ inject_into_file("app/views/layouts/#{engine_name}_beautiful_menu.html.erb",
168
+ "\n" + '<%= link_to ' + i18n_t_m_p(model) + '.capitalize, ' + namespace_for_route + model.pluralize + '_path, class: "nav-link #{(params[:controller] == "' + action_ctrl + '" ? "active" : "")}" %>',
169
+ :after => "<!-- Beautiful Scaffold Menu Do Not Touch This -->")
128
170
  end
129
171
 
130
172
  def generate_model
131
173
  generate("model", "#{model} #{beautiful_attr_to_rails_attr.join(' ')} #{@fulltext_field.join(' ')}")
174
+ directory "app/models/concerns", "app/models/concerns/#{engine_name}"
175
+
176
+ copy_file "app/models/pdf_report.rb", "app/models/#{engine_name}pdf_report.rb"
132
177
 
133
- directory "app/models/concerns", "app/models/concerns"
178
+ if !engine_name.blank?
179
+ ['caption_concern', 'default_sorting_concern','fulltext_concern'].each do |f|
180
+ path_to_the_concern = "app/models/concerns/#{engine_name}#{f}.rb"
181
+ inject_into_file path_to_the_concern, "module #{engine_camel}\n", before: "module #{f.camelcase}"
182
+ append_to_file path_to_the_concern, "\nend #endofmodule \n"
183
+ end
184
+
185
+ path_to_the_pdf_report = "app/models/#{engine_name}pdf_report.rb"
186
+ inject_into_file path_to_the_pdf_report, "module #{engine_camel}\n", before: "class PdfReport"
187
+ append_to_file path_to_the_pdf_report, "\nend #endofmodule \n"
188
+ end
134
189
 
135
190
  gsub_file "app/models/#{engine_name}#{model}.rb", 'ActiveRecord::Base', 'ApplicationRecord' # Rails 4 -> 5
136
191
  inject_into_file("app/models/#{engine_name}#{model}.rb",'
@@ -147,27 +202,26 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
147
202
  return ' + attributes_without_type.map{ |attr| ":#{attr}" }.join(",") + '
148
203
  end', :after => "class #{model_camelize} < ApplicationRecord")
149
204
 
150
- copy_file "app/models/pdf_report.rb", "app/models/pdf_report.rb"
151
205
  end
152
206
 
153
207
  def add_to_model
154
- # Add relation
155
- myattributes.each{ |attr|
156
- a,t = attr.split(':')
157
- if ['references', 'reference'].include?(t) then
158
- begin
159
- inject_into_file("app/models/#{engine_name}#{a}.rb", "\n has_many :#{model_pluralize}, :dependent => :nullify", :after => "ApplicationRecord")
160
- rescue
161
- end
162
- end
163
- }
208
+ add_relation
164
209
  end
165
210
 
166
211
  def generate_controller
167
- copy_file "app/controllers/master_base.rb", "app/controllers/#{engine_name}beautiful_controller.rb"
212
+ beautiful_ctrl_path = "app/controllers/#{engine_name}beautiful_controller.rb"
213
+ copy_file "app/controllers/master_base.rb", beautiful_ctrl_path
214
+ # beautiful_controller in the context of engine
215
+ if !engine_name.empty?
216
+ inject_into_file beautiful_ctrl_path, "module #{engine_camel}\n", before: "class BeautifulController"
217
+ #gsub_file beautiful_ctrl_path, '< ApplicationController', "< ::#{engine_camel}::ApplicationController" # Rails 4 -> 5 'BeautifulController < ApplicationController'
218
+ append_to_file beautiful_ctrl_path, "end #endofmodule \n"
219
+
220
+ gsub_file beautiful_ctrl_path, 'layout "beautiful_layout"', "layout \"#{engine_name}beautiful_layout\""
221
+ end
168
222
  dirs = ['app', 'controllers', engine_name, options[:namespace]].compact
169
223
  # Avoid to remove app/controllers directory (https://github.com/rivsc/Beautiful-Scaffold/issues/6)
170
- empty_directory File.join(dirs) if not options[:namespace].blank?
224
+ empty_directory File.join(dirs) if !options[:namespace].blank?
171
225
  dest_ctrl_file = File.join([dirs, "#{model_pluralize}_controller.rb"].flatten)
172
226
  template "app/controllers/base.rb", dest_ctrl_file
173
227
  end
@@ -194,9 +248,12 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
194
248
  current_template_path = File.join([dirs, filename].flatten)
195
249
  empty_template_path = File.join(["app", "views", filename].flatten)
196
250
  template empty_template_path, current_template_path
251
+
252
+ gsub_file current_template_path, '"layouts/modal_columns"', "\"layouts/#{engine_name}modal_columns\""
253
+ gsub_file current_template_path, '"layouts/mass_inserting"', "\"layouts/#{engine_name}mass_inserting\""
197
254
  end
198
255
 
199
- copy_file "app/views/_form_habtm_tag.html.erb", "app/views/layouts/_form_habtm_tag.html.erb"
256
+ copy_file "app/views/_form_habtm_tag.html.erb", "app/views/layouts/#{engine_name}_form_habtm_tag.html.erb"
200
257
  end
201
258
 
202
259
  def install_ransack_intializer
@@ -210,13 +267,13 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
210
267
  def routes
211
268
  myroute = <<EOF
212
269
  root :to => 'beautiful#dashboard'
213
- match ':model_sym/select_fields' => 'beautiful#select_fields', :via => [:get, :post]
270
+ match ':model_sym/select_fields' => 'beautiful#select_fields', as: :select_fields, via: [:get, :post]
214
271
 
215
272
  concern :bs_routes do
216
273
  collection do
217
274
  post :batch
218
275
  get :treeview
219
- match :search_and_filter, :action => :index, :as => :search, :via => [:get, :post]
276
+ match :search_and_filter, action: :index, as: :search, via: [:get, :post]
220
277
  end
221
278
  member do
222
279
  post :treeview_update
@@ -229,9 +286,9 @@ EOF
229
286
  inject_into_file("config/routes.rb", myroute, :after => "routes.draw do\n")
230
287
 
231
288
  myroute = "\n "
232
- myroute += "namespace :#{namespace_alone} do\n " if not namespace_alone.blank?
289
+ myroute += "namespace :#{namespace_alone} do\n " if !namespace_alone.blank?
233
290
  myroute += "resources :#{model_pluralize}, concerns: :bs_routes\n "
234
- myroute += "end\n" if not namespace_alone.blank?
291
+ myroute += "end\n" if !namespace_alone.blank?
235
292
 
236
293
  inject_into_file("config/routes.rb", myroute, :after => ":bs_routes here # Do not remove")
237
294
  end