beautiful_scaffold 0.3.5 → 2.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +2 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG +66 -1
  5. data/Gemfile +24 -17
  6. data/Gemfile.lock +209 -0
  7. data/README.rdoc +56 -44
  8. data/Rakefile +32 -0
  9. data/beautiful_scaffold.gemspec +8 -5
  10. data/lib/beautiful_scaffold/version.rb +3 -0
  11. data/lib/generators/beautiful_devisecancan_generator.rb +1 -1
  12. data/lib/generators/beautiful_jointable_generator.rb +40 -7
  13. data/lib/generators/beautiful_locale_generator.rb +102 -80
  14. data/lib/generators/beautiful_migration_generator.rb +12 -20
  15. data/lib/generators/beautiful_scaffold_common_methods.rb +88 -29
  16. data/lib/generators/beautiful_scaffold_generator.rb +166 -111
  17. data/lib/generators/templates/app/assets/javascripts/application-bs.js +11 -19
  18. data/lib/generators/templates/app/assets/javascripts/beautiful_scaffold.js +68 -78
  19. data/lib/generators/templates/app/assets/javascripts/bootstrap-datetimepicker-for-beautiful-scaffold.js +23 -42
  20. data/lib/generators/templates/app/assets/javascripts/fixed_menu.js +3 -1
  21. data/lib/generators/templates/app/assets/javascripts/jstree.min.js +6 -0
  22. data/lib/generators/templates/app/assets/stylesheets/application-bs.css +14 -12
  23. data/lib/generators/templates/app/assets/stylesheets/beautiful-scaffold.css.scss +36 -3
  24. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/32px.png +0 -0
  25. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/40px.png +0 -0
  26. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/style.scss +1146 -0
  27. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/throbber.gif +0 -0
  28. data/lib/generators/templates/app/assets/stylesheets/themes/default/32px.png +0 -0
  29. data/lib/generators/templates/app/assets/stylesheets/themes/default/40px.png +0 -0
  30. data/lib/generators/templates/app/assets/stylesheets/themes/default/style.scss +1102 -0
  31. data/lib/generators/templates/app/assets/stylesheets/themes/default/throbber.gif +0 -0
  32. data/lib/generators/templates/app/controllers/base.rb +32 -15
  33. data/lib/generators/templates/app/controllers/master_base.rb +55 -47
  34. data/lib/generators/templates/app/helpers/beautiful_helper.rb +104 -67
  35. data/lib/generators/templates/app/helpers/model_helper.rb +14 -3
  36. data/lib/generators/templates/app/initializers/link_renderer.rb +24 -17
  37. data/lib/generators/templates/app/initializers/ransack.rb +16 -0
  38. data/lib/generators/templates/app/locales/beautiful_scaffold.ja.yml +50 -0
  39. data/lib/generators/templates/app/models/concerns/fulltext_concern.rb +10 -10
  40. data/lib/generators/templates/app/views/_form.html.erb +5 -2
  41. data/lib/generators/templates/app/views/_form_habtm_tag.html.erb +6 -2
  42. data/lib/generators/templates/app/views/_mass_inserting.html.erb +40 -31
  43. data/lib/generators/templates/app/views/_modal_columns.html.erb +4 -4
  44. data/lib/generators/templates/app/views/edit.html.erb +1 -3
  45. data/lib/generators/templates/app/views/index.html.erb +84 -58
  46. data/lib/generators/templates/app/views/layout.html.erb +29 -47
  47. data/lib/generators/templates/app/views/new.html.erb +0 -2
  48. data/lib/generators/templates/app/views/partials/_forget_password.html.erb +2 -2
  49. data/lib/generators/templates/app/views/partials/_form_field.html.erb +7 -33
  50. data/lib/generators/templates/app/views/partials/_index_batch.html.erb +1 -1
  51. data/lib/generators/templates/app/views/partials/_index_column.html.erb +4 -6
  52. data/lib/generators/templates/app/views/partials/_index_header.html.erb +1 -1
  53. data/lib/generators/templates/app/views/partials/_index_search.html.erb +2 -4
  54. data/lib/generators/templates/app/views/partials/_index_search_default_fields.html.erb +1 -1
  55. data/lib/generators/templates/app/views/partials/_register_form.html.erb +2 -2
  56. data/lib/generators/templates/app/views/partials/_show_field.html.erb +3 -3
  57. data/lib/generators/templates/app/views/partials/_sign_in_form.html.erb +1 -1
  58. data/lib/generators/templates/app/views/partials/_sign_in_sign_out.html.erb +2 -2
  59. data/lib/generators/templates/app/views/show.html.erb +2 -2
  60. data/lib/generators/templates/app/views/treeview.html.erb +8 -5
  61. metadata +43 -188
  62. data/lib/generators/templates/app/assets/javascripts/bootstrap-datepicker.js +0 -834
  63. data/lib/generators/templates/app/assets/javascripts/bootstrap-timepicker.js +0 -797
  64. data/lib/generators/templates/app/assets/javascripts/jquery.jstree.js +0 -4551
  65. data/lib/generators/templates/app/assets/javascripts/jquery.livequery.js +0 -226
  66. data/lib/generators/templates/app/assets/stylesheets/bootstrap_and_overrides.css.less +0 -40
  67. data/lib/generators/templates/app/assets/stylesheets/datepicker.css +0 -224
  68. data/lib/generators/templates/app/assets/stylesheets/reset.css +0 -48
  69. data/lib/generators/templates/app/assets/stylesheets/themes/default/d.gif +0 -0
  70. data/lib/generators/templates/app/assets/stylesheets/themes/default/d.png +0 -0
  71. data/lib/generators/templates/app/assets/stylesheets/themes/default/style.css +0 -74
  72. data/lib/generators/templates/app/assets/stylesheets/timepicker.css +0 -89
  73. data/lib/generators/templates/markitup/jquery.markitup.js +0 -593
  74. data/lib/generators/templates/markitup/sets/bbcode/images/bold.png +0 -0
  75. data/lib/generators/templates/markitup/sets/bbcode/images/clean.png +0 -0
  76. data/lib/generators/templates/markitup/sets/bbcode/images/code.png +0 -0
  77. data/lib/generators/templates/markitup/sets/bbcode/images/fonts.png +0 -0
  78. data/lib/generators/templates/markitup/sets/bbcode/images/italic.png +0 -0
  79. data/lib/generators/templates/markitup/sets/bbcode/images/link.png +0 -0
  80. data/lib/generators/templates/markitup/sets/bbcode/images/list-bullet.png +0 -0
  81. data/lib/generators/templates/markitup/sets/bbcode/images/list-item.png +0 -0
  82. data/lib/generators/templates/markitup/sets/bbcode/images/list-numeric.png +0 -0
  83. data/lib/generators/templates/markitup/sets/bbcode/images/picture.png +0 -0
  84. data/lib/generators/templates/markitup/sets/bbcode/images/preview.png +0 -0
  85. data/lib/generators/templates/markitup/sets/bbcode/images/quotes.png +0 -0
  86. data/lib/generators/templates/markitup/sets/bbcode/images/stroke.png +0 -0
  87. data/lib/generators/templates/markitup/sets/bbcode/images/underline.png +0 -0
  88. data/lib/generators/templates/markitup/sets/bbcode/readme.txt +0 -11
  89. data/lib/generators/templates/markitup/sets/bbcode/set.js +0 -39
  90. data/lib/generators/templates/markitup/sets/bbcode/style.css +0 -47
  91. data/lib/generators/templates/markitup/sets/default/images/bold.png +0 -0
  92. data/lib/generators/templates/markitup/sets/default/images/clean.png +0 -0
  93. data/lib/generators/templates/markitup/sets/default/images/image.png +0 -0
  94. data/lib/generators/templates/markitup/sets/default/images/italic.png +0 -0
  95. data/lib/generators/templates/markitup/sets/default/images/link.png +0 -0
  96. data/lib/generators/templates/markitup/sets/default/images/list-bullet.png +0 -0
  97. data/lib/generators/templates/markitup/sets/default/images/list-numeric.png +0 -0
  98. data/lib/generators/templates/markitup/sets/default/images/picture.png +0 -0
  99. data/lib/generators/templates/markitup/sets/default/images/preview.png +0 -0
  100. data/lib/generators/templates/markitup/sets/default/images/stroke.png +0 -0
  101. data/lib/generators/templates/markitup/sets/default/set.js +0 -30
  102. data/lib/generators/templates/markitup/sets/default/style.css +0 -34
  103. data/lib/generators/templates/markitup/sets/html/images/bold.png +0 -0
  104. data/lib/generators/templates/markitup/sets/html/images/clean.png +0 -0
  105. data/lib/generators/templates/markitup/sets/html/images/h1.png +0 -0
  106. data/lib/generators/templates/markitup/sets/html/images/h2.png +0 -0
  107. data/lib/generators/templates/markitup/sets/html/images/h3.png +0 -0
  108. data/lib/generators/templates/markitup/sets/html/images/h4.png +0 -0
  109. data/lib/generators/templates/markitup/sets/html/images/h5.png +0 -0
  110. data/lib/generators/templates/markitup/sets/html/images/h6.png +0 -0
  111. data/lib/generators/templates/markitup/sets/html/images/image.png +0 -0
  112. data/lib/generators/templates/markitup/sets/html/images/italic.png +0 -0
  113. data/lib/generators/templates/markitup/sets/html/images/link.png +0 -0
  114. data/lib/generators/templates/markitup/sets/html/images/list-bullet.png +0 -0
  115. data/lib/generators/templates/markitup/sets/html/images/list-item.png +0 -0
  116. data/lib/generators/templates/markitup/sets/html/images/list-numeric.png +0 -0
  117. data/lib/generators/templates/markitup/sets/html/images/paragraph.png +0 -0
  118. data/lib/generators/templates/markitup/sets/html/images/picture.png +0 -0
  119. data/lib/generators/templates/markitup/sets/html/images/preview.png +0 -0
  120. data/lib/generators/templates/markitup/sets/html/images/stroke.png +0 -0
  121. data/lib/generators/templates/markitup/sets/html/readme.txt +0 -11
  122. data/lib/generators/templates/markitup/sets/html/set.js +0 -39
  123. data/lib/generators/templates/markitup/sets/html/style.css +0 -59
  124. data/lib/generators/templates/markitup/sets/markdown/images/bold.png +0 -0
  125. data/lib/generators/templates/markitup/sets/markdown/images/code.png +0 -0
  126. data/lib/generators/templates/markitup/sets/markdown/images/h1.png +0 -0
  127. data/lib/generators/templates/markitup/sets/markdown/images/h2.png +0 -0
  128. data/lib/generators/templates/markitup/sets/markdown/images/h3.png +0 -0
  129. data/lib/generators/templates/markitup/sets/markdown/images/h4.png +0 -0
  130. data/lib/generators/templates/markitup/sets/markdown/images/h5.png +0 -0
  131. data/lib/generators/templates/markitup/sets/markdown/images/h6.png +0 -0
  132. data/lib/generators/templates/markitup/sets/markdown/images/italic.png +0 -0
  133. data/lib/generators/templates/markitup/sets/markdown/images/link.png +0 -0
  134. data/lib/generators/templates/markitup/sets/markdown/images/list-bullet.png +0 -0
  135. data/lib/generators/templates/markitup/sets/markdown/images/list-numeric.png +0 -0
  136. data/lib/generators/templates/markitup/sets/markdown/images/picture.png +0 -0
  137. data/lib/generators/templates/markitup/sets/markdown/images/preview.png +0 -0
  138. data/lib/generators/templates/markitup/sets/markdown/images/quotes.png +0 -0
  139. data/lib/generators/templates/markitup/sets/markdown/readme.txt +0 -11
  140. data/lib/generators/templates/markitup/sets/markdown/set.js +0 -52
  141. data/lib/generators/templates/markitup/sets/markdown/style.css +0 -54
  142. data/lib/generators/templates/markitup/sets/textile/images/bold.png +0 -0
  143. data/lib/generators/templates/markitup/sets/textile/images/code.png +0 -0
  144. data/lib/generators/templates/markitup/sets/textile/images/h1.png +0 -0
  145. data/lib/generators/templates/markitup/sets/textile/images/h2.png +0 -0
  146. data/lib/generators/templates/markitup/sets/textile/images/h3.png +0 -0
  147. data/lib/generators/templates/markitup/sets/textile/images/h4.png +0 -0
  148. data/lib/generators/templates/markitup/sets/textile/images/h5.png +0 -0
  149. data/lib/generators/templates/markitup/sets/textile/images/h6.png +0 -0
  150. data/lib/generators/templates/markitup/sets/textile/images/italic.png +0 -0
  151. data/lib/generators/templates/markitup/sets/textile/images/link.png +0 -0
  152. data/lib/generators/templates/markitup/sets/textile/images/list-bullet.png +0 -0
  153. data/lib/generators/templates/markitup/sets/textile/images/list-numeric.png +0 -0
  154. data/lib/generators/templates/markitup/sets/textile/images/paragraph.png +0 -0
  155. data/lib/generators/templates/markitup/sets/textile/images/picture.png +0 -0
  156. data/lib/generators/templates/markitup/sets/textile/images/preview.png +0 -0
  157. data/lib/generators/templates/markitup/sets/textile/images/quotes.png +0 -0
  158. data/lib/generators/templates/markitup/sets/textile/images/stroke.png +0 -0
  159. data/lib/generators/templates/markitup/sets/textile/readme.txt +0 -11
  160. data/lib/generators/templates/markitup/sets/textile/set.js +0 -40
  161. data/lib/generators/templates/markitup/sets/textile/style.css +0 -60
  162. data/lib/generators/templates/markitup/sets/wiki/images/bold.png +0 -0
  163. data/lib/generators/templates/markitup/sets/wiki/images/code.png +0 -0
  164. data/lib/generators/templates/markitup/sets/wiki/images/h1.png +0 -0
  165. data/lib/generators/templates/markitup/sets/wiki/images/h2.png +0 -0
  166. data/lib/generators/templates/markitup/sets/wiki/images/h3.png +0 -0
  167. data/lib/generators/templates/markitup/sets/wiki/images/h4.png +0 -0
  168. data/lib/generators/templates/markitup/sets/wiki/images/h5.png +0 -0
  169. data/lib/generators/templates/markitup/sets/wiki/images/h6.png +0 -0
  170. data/lib/generators/templates/markitup/sets/wiki/images/italic.png +0 -0
  171. data/lib/generators/templates/markitup/sets/wiki/images/link.png +0 -0
  172. data/lib/generators/templates/markitup/sets/wiki/images/list-bullet.png +0 -0
  173. data/lib/generators/templates/markitup/sets/wiki/images/list-numeric.png +0 -0
  174. data/lib/generators/templates/markitup/sets/wiki/images/picture.png +0 -0
  175. data/lib/generators/templates/markitup/sets/wiki/images/preview.png +0 -0
  176. data/lib/generators/templates/markitup/sets/wiki/images/quotes.png +0 -0
  177. data/lib/generators/templates/markitup/sets/wiki/images/stroke.png +0 -0
  178. data/lib/generators/templates/markitup/sets/wiki/images/url.png +0 -0
  179. data/lib/generators/templates/markitup/sets/wiki/readme.txt +0 -11
  180. data/lib/generators/templates/markitup/sets/wiki/set.js +0 -37
  181. data/lib/generators/templates/markitup/sets/wiki/style.css +0 -57
  182. data/lib/generators/templates/markitup/skins/markitup/images/bg-container.png +0 -0
  183. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-bbcode.png +0 -0
  184. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-dotclear.png +0 -0
  185. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-html.png +0 -0
  186. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-json.png +0 -0
  187. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-markdown.png +0 -0
  188. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-textile.png +0 -0
  189. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-wiki.png +0 -0
  190. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-xml.png +0 -0
  191. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor.png +0 -0
  192. data/lib/generators/templates/markitup/skins/markitup/images/handle.png +0 -0
  193. data/lib/generators/templates/markitup/skins/markitup/images/menu.png +0 -0
  194. data/lib/generators/templates/markitup/skins/markitup/images/submenu.png +0 -0
  195. data/lib/generators/templates/markitup/skins/markitup/style.css +0 -147
  196. data/lib/generators/templates/markitup/skins/simple/images/handle.png +0 -0
  197. data/lib/generators/templates/markitup/skins/simple/images/menu.png +0 -0
  198. data/lib/generators/templates/markitup/skins/simple/images/submenu.png +0 -0
  199. data/lib/generators/templates/markitup/skins/simple/style.css +0 -118
  200. data/lib/generators/templates/markitup/templates/preview.css +0 -5
  201. data/lib/generators/templates/markitup/templates/preview.html +0 -11
@@ -3,35 +3,51 @@ module BeautifulScaffoldCommonMethods
3
3
 
4
4
  private
5
5
 
6
+ #############
7
+ # Engine
8
+ #############
9
+
10
+ def engine_opt
11
+ options[:mountable_engine].to_s.downcase
12
+ end
13
+
14
+ def engine_name
15
+ engine_opt.blank? ? '' : "#{engine_opt}/"
16
+ end
17
+
18
+ def engine_camel
19
+ options[:mountable_engine].to_s.camelize
20
+ end
21
+
6
22
  #############
7
23
  # Namespace
8
24
  #############
9
-
25
+
10
26
  def namespace_for_class
11
27
  str = namespace_alone
12
28
  str = str.camelcase + '::' if not str.blank?
13
29
  return str
14
30
  end
15
-
31
+
16
32
  def namespace_for_route
17
33
  str = namespace_alone
18
34
  str = str.downcase + '_' if not str.blank?
19
35
  return str
20
36
  end
21
-
37
+
22
38
  def namespace_for_url
23
39
  str = namespace_alone
24
40
  str = str.downcase + '/' if not str.blank?
25
41
  return str
26
42
  end
27
-
43
+
28
44
  def namespace_alone
29
45
  return options[:namespace].to_s.downcase
30
46
  end
31
47
 
32
48
  def render_partial(path)
33
49
  source = File.expand_path(find_in_source_paths(path.to_s))
34
- result = ERB.new(::File.binread(source), nil, '-').result(binding)
50
+ result = ERB.new(::File.binread(source), trim_mode: '-').result(binding)
35
51
  return result
36
52
  end
37
53
 
@@ -39,10 +55,18 @@ module BeautifulScaffoldCommonMethods
39
55
  # Models
40
56
  ############
41
57
 
58
+ def model
59
+ model_opt.underscore
60
+ end
61
+
42
62
  def model_camelize
43
63
  model.camelize
44
64
  end
45
65
 
66
+ def model_with_engine_camelize
67
+ (engine_name.blank? ? model.camelize : "#{engine_camel}::#{model_camelize}")
68
+ end
69
+
46
70
  def model_pluralize
47
71
  model.pluralize
48
72
  end
@@ -50,7 +74,7 @@ module BeautifulScaffoldCommonMethods
50
74
  def model_class
51
75
  model.camelize
52
76
  end
53
-
77
+
54
78
  ############
55
79
  # Table
56
80
  ############
@@ -93,7 +117,7 @@ module BeautifulScaffoldCommonMethods
93
117
  def available_views
94
118
  %w(index edit show new _form)
95
119
  end
96
-
120
+
97
121
  def attributes
98
122
  # https://raw.github.com/rails/rails/master/railties/lib/rails/generators/generated_attribute.rb
99
123
  require 'rails/generators/generated_attribute'
@@ -103,19 +127,21 @@ module BeautifulScaffoldCommonMethods
103
127
  }
104
128
  end
105
129
 
106
- def beautiful_attr_to_rails_attr(for_migration = false)
130
+ def beautiful_attr_to_rails_attr #(for_migration = false)
107
131
  newmyattributes = []
108
132
  myattributes.each{ |attr|
109
133
  a,t = attr.split(':')
110
134
  newt = t
111
- if ['richtext', 'wysiwyg'].include?(t) then
135
+
136
+ # Special columns
137
+ if ['wysiwyg'].include?(t)
112
138
  newt = 'text'
113
- elsif t == 'price' then
139
+ elsif t == 'price'
114
140
  newt = 'float'
115
- elsif ['references', 'reference'].include?(t) and for_migration then
116
- a = a + '_id'
141
+ elsif ['references', 'reference'].include?(t) # Because Rails generate corrupted files (migrations)
142
+ a = "#{a}_id"
117
143
  newt = 'integer:index'
118
- elsif t == 'color' then
144
+ elsif t == 'color'
119
145
  newt = 'string'
120
146
  end
121
147
 
@@ -130,10 +156,15 @@ module BeautifulScaffoldCommonMethods
130
156
  myattributes.each{ |attr|
131
157
  a,t = attr.split(':')
132
158
 
133
- if ['references', 'reference'].include?(t) then
159
+ if ['references', 'reference'].include?(t)
134
160
  a = a + '_id'
135
161
  end
136
162
 
163
+ # Add the typetext to permitted_attr
164
+ if t == 'wysiwyg'
165
+ newmyattributes << "#{a}_typetext"
166
+ end
167
+
137
168
  newmyattributes << a
138
169
  }
139
170
 
@@ -144,7 +175,7 @@ module BeautifulScaffoldCommonMethods
144
175
  fulltext_field = []
145
176
  myattributes.each{ |attr|
146
177
  a,t = attr.split(':')
147
- if ['richtext', 'wysiwyg'].include?(t) then
178
+ if ['wysiwyg'].include?(t)
148
179
  fulltext_field << a
149
180
  end
150
181
  }
@@ -152,24 +183,52 @@ module BeautifulScaffoldCommonMethods
152
183
  end
153
184
 
154
185
  def richtext_type
155
- return ["bbcode","html","text","wiki","textile","markdown"]
186
+ return ["html","text"]
156
187
  end
157
188
 
158
189
  def require_gems
190
+ gems = {
191
+ 'will_paginate' => nil, # v 3.1.5
192
+ 'ransack' => nil, #'2.3.2',
193
+ 'jquery-ui-rails' => nil,
194
+ 'prawn' => nil, #'2.1.0',
195
+ 'prawn-table' => nil, #'0.2.2',
196
+ 'sanitize' => 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',
200
+ 'momentjs-rails' => '>= 2.9.0',
201
+ 'bootstrap4-datetime-picker-rails' => nil,
202
+ 'jquery-rails' => '4.3.1',
203
+ 'jstree-rails-4' => '3.3.8'
204
+ }
205
+
206
+ # Si engine il faut mettre les gems dans le gemspec et faire le require
207
+ if !Dir.glob('./*.gemspec').empty?
208
+ puts "============> Engine : You must add gems to your main app \n #{gems.to_a.map{ |a| "gem '#{a[0]}'#{(a[1].nil? ? '' : ", '#{a[1]}'")} " }.join("\n")}"
209
+ end
210
+
211
+ gems.each{ |gem_to_add, version|
212
+ gem(gem_to_add, version)
213
+ }
214
+ end
215
+
216
+ def add_relation
217
+ myattributes.each{ |attr|
218
+ a,t = attr.split(':')
219
+
220
+ foreign_key = a
159
221
 
160
- gem('less-rails', :github => "CQQL/less-rails", :branch => 'less-2.5')
161
- gem('will_paginate')
162
- gem('ransack', :github => 'activerecord-hackery/ransack', :branch => 'rails-4.2')
163
- gem('polyamorous', :github => 'activerecord-hackery/polyamorous')
164
- gem('jquery-ui-rails')
165
- gem('prawn', '1.0.0')
166
- gem('RedCloth')
167
- gem('bb-ruby')
168
- gem('bluecloth')
169
- gem('rdiscount')
170
- gem('sanitize')
171
- gem('twitter-bootstrap-rails', :github => 'seyhunak/twitter-bootstrap-rails', :branch => 'bootstrap3')
172
- gem('chardinjs-rails')
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
+ }
173
232
  end
174
233
 
175
234
  end
@@ -1,6 +1,6 @@
1
1
  # encoding : utf-8
2
2
  class BeautifulScaffoldGenerator < Rails::Generators::Base
3
- require 'beautiful_scaffold_common_methods'
3
+ require_relative 'beautiful_scaffold_common_methods'
4
4
  include BeautifulScaffoldCommonMethods
5
5
 
6
6
  # Resources
@@ -13,19 +13,20 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
13
13
 
14
14
  source_root File.expand_path('../templates', __FILE__)
15
15
 
16
- argument :model, :type => :string, :desc => "Name of model (downcase singular)"
17
- argument :myattributes, :type => :array, :default => [], :banner => "field:type field:type"
18
-
19
- class_option :namespace, :default => nil
20
- class_option :donttouchgem, :default => nil
16
+ argument :model_opt, type: :string, desc: "Name of model (singular)"
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
21
22
 
22
23
  def install_gems
23
- if options[:donttouchgem].blank? then
24
+ if options[:donttouchgem].blank?
24
25
  require_gems
25
26
  end
26
27
 
27
28
  #inside Rails.root do # Bug ?!
28
- Bundler.with_clean_env do
29
+ Bundler.with_unbundled_env do
29
30
  run "bundle install"
30
31
  end
31
32
  end
@@ -35,8 +36,8 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
35
36
  @fulltext_field = []
36
37
  myattributes.each{ |attr|
37
38
  a,t = attr.split(':')
38
- if ['richtext', 'wysiwyg'].include?(t) then
39
- # _typetext = {bbcode|html|text|wiki|textile|markdown}
39
+ if ['wysiwyg'].include?(t)
40
+ # _typetext = {html|text}
40
41
  # _fulltext = text without any code
41
42
  @fulltext_field << [a + '_typetext', 'string'].join(':')
42
43
  @fulltext_field << [a + '_fulltext', 'text'].join(':')
@@ -45,96 +46,149 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
45
46
  end
46
47
 
47
48
  def mimetype
48
- if not File.exist?("app/controllers/beautiful_controller.rb") then
49
- 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." )
49
+ if !File.exist?("app/controllers/beautiful_controller.rb")
50
+ if File.exist?("config/initializers/mime_types.rb") # For mountable engine
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
+ else
53
+ puts "============> Engine : You must add `Mime::Type.register_alias \"application/pdf\", :pdf` to your config/initializers/mime_types.rb main app !"
54
+ end
50
55
  end
51
56
  end
52
-
57
+
53
58
  def generate_assets
54
59
  stylesheetspath = "app/assets/stylesheets/"
55
-
60
+ stylesheetspath_dest = "#{stylesheetspath}#{engine_name}"
61
+
56
62
  # Css
57
- reset = "#{stylesheetspath}reset.css"
58
63
  bc_css = [
59
- "#{stylesheetspath}application-bs.css",
60
- "#{stylesheetspath}datepicker.css",
61
- "#{stylesheetspath}timepicker.css",
62
- "#{stylesheetspath}beautiful-scaffold.css.scss",
63
- "#{stylesheetspath}tagit-dark-grey.css",
64
- "#{stylesheetspath}colorpicker.css",
65
- "#{stylesheetspath}bootstrap-wysihtml5.css"
64
+ "beautiful-scaffold.css.scss",
65
+ "tagit-dark-grey.css",
66
+ "colorpicker.css",
67
+ "bootstrap-wysihtml5.css"
66
68
  ]
67
-
69
+
68
70
  javascriptspath = "app/assets/javascripts/"
69
-
71
+ javascriptspath_dest = "#{javascriptspath}#{engine_name}"
72
+
73
+ bc_css.each do |path|
74
+ copy_file "#{stylesheetspath}#{path}", "#{stylesheetspath_dest}#{path}"
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
97
+
70
98
  # Js
71
99
  bc_js = [
72
- "#{javascriptspath}application-bs.js",
73
- "#{javascriptspath}beautiful_scaffold.js",
74
- "#{javascriptspath}bootstrap-datepicker.js",
75
- "#{javascriptspath}bootstrap-datetimepicker-for-beautiful-scaffold.js",
76
- "#{javascriptspath}bootstrap-timepicker.js",
77
- "#{javascriptspath}jquery.livequery.js",
78
- "#{javascriptspath}jquery.jstree.js",
79
- "#{javascriptspath}jquery-barcode.js",
80
- "#{javascriptspath}tagit.js",
81
- "#{javascriptspath}bootstrap-colorpicker.js",
82
- "#{javascriptspath}a-wysihtml5-0.3.0.min.js",
83
- "#{javascriptspath}bootstrap-wysihtml5.js",
84
- "#{javascriptspath}fixed_menu.js"
100
+ "application-bs.js",
101
+ "beautiful_scaffold.js",
102
+ "bootstrap-datetimepicker-for-beautiful-scaffold.js",
103
+ "jquery-barcode.js",
104
+ "jstree.min.js",
105
+ "tagit.js",
106
+ "bootstrap-colorpicker.js",
107
+ "a-wysihtml5-0.3.0.min.js",
108
+ "bootstrap-wysihtml5.js",
109
+ "fixed_menu.js"
85
110
  ]
86
111
 
87
- [reset, bc_css, bc_js].flatten.each{ |path|
88
- copy_file path, path
112
+ [bc_js].flatten.each{ |path|
113
+ copy_file "#{javascriptspath}#{path}", "#{javascriptspath_dest}#{path}"
89
114
  }
90
115
 
91
- # Jstree theme
92
- directory "app/assets/stylesheets/themes", "app/assets/stylesheets/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
93
129
 
94
130
  # Images
95
131
  dir_image = "app/assets/images"
96
- directory dir_image, dir_image
132
+ dir_image_dest = "app/assets/images/#{engine_opt}"
133
+ directory dir_image, dir_image_dest
97
134
 
98
- # Old method
99
- #generate("bootstrap:install","static")
100
- # New method
101
- copy_file "#{stylesheetspath}bootstrap_and_overrides.css.less",
102
- "#{stylesheetspath}bootstrap_and_overrides.css.less"
135
+ # Precompile BS assets
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}_"
144
+ else
145
+ manifest_prefix = ""
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')
103
149
  end
104
-
150
+
105
151
  def generate_layout
106
- template "app/views/layout.html.erb", "app/views/layouts/beautiful_layout.html.erb"
107
- if not File.exist?("app/views/layouts/_beautiful_menu.html.erb") then
108
- 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"
109
158
  end
110
159
 
111
- empty_directory "app/views/beautiful"
112
- template "app/views/dashboard.html.erb", "app/views/beautiful/dashboard.html.erb"
113
- copy_file "app/views/_modal_columns.html.erb", "app/views/layouts/_modal_columns.html.erb"
114
- copy_file "app/views/_mass_inserting.html.erb", "app/views/layouts/_mass_inserting.html.erb"
115
-
116
- inject_into_file("app/views/layouts/_beautiful_menu.html.erb",'
117
- <li class="<%= "active" if params[:controller] == "' + namespace_for_url + model.pluralize + '" %>">
118
- <%= link_to ' + i18n_t_m_p(model) + '.capitalize, ' + namespace_for_route + model.pluralize + '_path %>
119
- </li>', :after => "<!-- Beautiful Scaffold Menu Do Not Touch This -->")
120
- end
160
+ empty_directory "app/views/#{engine_name}beautiful"
161
+ template "app/views/dashboard.html.erb", "app/views/#{engine_name}beautiful/dashboard.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"
164
+
165
+ action_ctrl = "#{namespace_for_url}#{model.pluralize}"
121
166
 
122
- def install_markitup
123
- # CSS
124
- directory "markitup/skins", "app/assets/stylesheets/markitup/skins"
125
- # JS
126
- copy_file "markitup/jquery.markitup.js", "app/assets/javascripts/jquery.markitup.js"
127
- # JS and CSS
128
- directory "markitup/sets", "app/assets/stylesheets/markitup/sets"
129
- directory "markitup/sets", "app/assets/javascripts/markitup/sets"
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 -->")
130
170
  end
131
171
 
132
172
  def generate_model
133
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"
134
177
 
135
- 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
136
189
 
137
- inject_into_file("app/models/#{model}.rb",'
190
+ gsub_file "app/models/#{engine_name}#{model}.rb", 'ActiveRecord::Base', 'ApplicationRecord' # Rails 4 -> 5
191
+ inject_into_file("app/models/#{engine_name}#{model}.rb",'
138
192
 
139
193
  include DefaultSortingConcern
140
194
  include FulltextConcern
@@ -146,55 +200,64 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
146
200
 
147
201
  def self.permitted_attributes
148
202
  return ' + attributes_without_type.map{ |attr| ":#{attr}" }.join(",") + '
149
- end', :after => "class #{model_camelize} < ActiveRecord::Base")
203
+ end', :after => "class #{model_camelize} < ApplicationRecord")
150
204
 
151
- copy_file "app/models/pdf_report.rb", "app/models/pdf_report.rb"
152
205
  end
153
206
 
154
207
  def add_to_model
155
- # Add relation
156
- myattributes.each{ |attr|
157
- a,t = attr.split(':')
158
- if ['references', 'reference'].include?(t) then
159
- begin
160
- inject_into_file("app/models/#{a}.rb", "\n has_many :#{model_pluralize}, :dependent => :nullify", :after => "ActiveRecord::Base")
161
- rescue
162
- end
163
- end
164
- }
208
+ add_relation
165
209
  end
166
210
 
167
211
  def generate_controller
168
- copy_file "app/controllers/master_base.rb", "app/controllers/beautiful_controller.rb"
169
- dirs = ['app', 'controllers', options[:namespace]].compact
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
222
+ dirs = ['app', 'controllers', engine_name, options[:namespace]].compact
170
223
  # Avoid to remove app/controllers directory (https://github.com/rivsc/Beautiful-Scaffold/issues/6)
171
- empty_directory File.join(dirs) if not options[:namespace].blank?
172
- template "app/controllers/base.rb", File.join([dirs, "#{model_pluralize}_controller.rb"].flatten)
224
+ empty_directory File.join(dirs) if !options[:namespace].blank?
225
+ dest_ctrl_file = File.join([dirs, "#{model_pluralize}_controller.rb"].flatten)
226
+ template "app/controllers/base.rb", dest_ctrl_file
173
227
  end
174
-
228
+
175
229
  def generate_helper
176
- copy_file "app/helpers/beautiful_helper.rb", "app/helpers/beautiful_helper.rb"
177
- dirs = ['app', 'helpers', options[:namespace]].compact
230
+ dest_bs_helper_file = "app/helpers/#{engine_name}beautiful_helper.rb"
231
+ template "app/helpers/beautiful_helper.rb", dest_bs_helper_file
232
+
233
+ dirs = ['app', 'helpers', engine_name, options[:namespace]].compact
178
234
  empty_directory File.join(dirs)
179
- template "app/helpers/model_helper.rb", File.join([dirs, "#{model_pluralize}_helper.rb"].flatten)
235
+ dest_helper_file = File.join([dirs, "#{model_pluralize}_helper.rb"].flatten)
236
+ template "app/helpers/model_helper.rb", dest_helper_file
180
237
  end
181
238
 
182
239
  def generate_views
183
- namespacedirs = ["app", "views", options[:namespace]].compact
240
+ namespacedirs = ["app", "views", engine_name, options[:namespace]].compact
184
241
  empty_directory File.join(namespacedirs)
185
-
242
+
186
243
  dirs = [namespacedirs, model_pluralize]
187
244
  empty_directory File.join(dirs)
188
-
245
+
189
246
  [available_views, 'treeview'].flatten.each do |view|
190
247
  filename = view + ".html.erb"
191
248
  current_template_path = File.join([dirs, filename].flatten)
192
249
  empty_template_path = File.join(["app", "views", filename].flatten)
193
-
194
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\""
195
254
  end
196
255
 
197
- 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"
257
+ end
258
+
259
+ def install_ransack_intializer
260
+ copy_file "app/initializers/ransack.rb", "config/initializers/ransack.rb"
198
261
  end
199
262
 
200
263
  def install_willpaginate_renderer_for_bootstrap
@@ -202,19 +265,15 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
202
265
  end
203
266
 
204
267
  def routes
205
- routes_in_text = File.read("config/routes.rb")
206
-
207
- if not routes_in_text[/beautiful#dashboard/] and not routes_in_text[/beautiful#select_fields/] then
208
-
209
- myroute = <<EOF
210
- root :to => 'beautiful#dashboard'
211
- match ':model_sym/select_fields' => 'beautiful#select_fields', :via => [:get, :post]
268
+ myroute = <<EOF
269
+ root :to => 'beautiful#dashboard'
270
+ match ':model_sym/select_fields' => 'beautiful#select_fields', as: :select_fields, via: [:get, :post]
212
271
 
213
272
  concern :bs_routes do
214
273
  collection do
215
274
  post :batch
216
275
  get :treeview
217
- match :search_and_filter, :action => :index, :as => :search, :via => [:get, :post]
276
+ match :search_and_filter, action: :index, as: :search, via: [:get, :post]
218
277
  end
219
278
  member do
220
279
  post :treeview_update
@@ -224,16 +283,12 @@ root :to => 'beautiful#dashboard'
224
283
  # Add route with concerns: :bs_routes here # Do not remove
225
284
  EOF
226
285
 
227
- route(myroute)
228
- end
229
-
230
- search_namespace = namespace_alone + "/" if not namespace_alone.blank?
231
- search_namespace ||= ""
286
+ inject_into_file("config/routes.rb", myroute, :after => "routes.draw do\n")
232
287
 
233
288
  myroute = "\n "
234
- myroute += "namespace :#{namespace_alone} do\n " if not namespace_alone.blank?
289
+ myroute += "namespace :#{namespace_alone} do\n " if !namespace_alone.blank?
235
290
  myroute += "resources :#{model_pluralize}, concerns: :bs_routes\n "
236
- myroute += "end\n" if not namespace_alone.blank?
291
+ myroute += "end\n" if !namespace_alone.blank?
237
292
 
238
293
  inject_into_file("config/routes.rb", myroute, :after => ":bs_routes here # Do not remove")
239
294
  end