hot-glue 0.2.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -2
  3. data/Gemfile.lock +4 -24
  4. data/LICENCE +11 -4
  5. data/README.md +0 -524
  6. data/app/helpers/hot_glue/controller_helper.rb +8 -5
  7. data/app/views/layouts/_flash_notices.erb +12 -0
  8. data/lib/generators/hot_glue/install_generator.rb +110 -1
  9. data/lib/generators/hot_glue/markup_templates/erb.rb +68 -29
  10. data/lib/generators/hot_glue/markup_templates/haml.rb +5 -3
  11. data/lib/generators/hot_glue/scaffold_generator.rb +223 -58
  12. data/lib/generators/hot_glue/templates/capybara_login.rb +8 -0
  13. data/lib/generators/hot_glue/templates/controller.rb.erb +41 -32
  14. data/lib/generators/hot_glue/templates/erb/_form.erb +1 -1
  15. data/lib/generators/hot_glue/templates/erb/_line.erb +3 -2
  16. data/lib/generators/hot_glue/templates/erb/_list.erb +24 -8
  17. data/lib/generators/hot_glue/templates/erb/_show.erb +24 -4
  18. data/lib/generators/hot_glue/templates/erb/create.turbo_stream.erb +4 -4
  19. data/lib/generators/hot_glue/templates/erb/destroy.turbo_stream.erb +2 -2
  20. data/lib/generators/hot_glue/templates/erb/edit.erb +3 -13
  21. data/lib/generators/hot_glue/templates/erb/index.erb +11 -9
  22. data/lib/generators/hot_glue/templates/erb/update.turbo_stream.erb +5 -2
  23. data/lib/generators/hot_glue/templates/haml/_line.haml +1 -1
  24. data/lib/generators/hot_glue/templates/haml/_list.haml +6 -2
  25. data/lib/generators/hot_glue/templates/haml/create.turbo_stream.haml +3 -3
  26. data/lib/generators/hot_glue/templates/haml/destroy.turbo_stream.haml +1 -1
  27. data/lib/generators/hot_glue/templates/haml/edit.haml +0 -2
  28. data/lib/generators/hot_glue/templates/haml/index.haml +2 -3
  29. data/lib/generators/hot_glue/templates/system_spec.rb.erb +146 -47
  30. data/lib/generators/hot_glue/templates/themes/hotglue_scaffold_dark_knight.scss +158 -0
  31. data/lib/generators/hot_glue/templates/themes/hotglue_scaffold_like_bootstrap.scss +154 -0
  32. data/lib/generators/hot_glue/templates/themes/hotglue_scaffold_like_los_gatos.scss +182 -0
  33. data/lib/generators/hot_glue/templates/themes/hotglue_scaffold_like_mountain_view.scss +179 -0
  34. data/lib/hot-glue.rb +1 -2
  35. data/lib/hotglue/version.rb +1 -1
  36. metadata +15 -33
@@ -5,12 +5,41 @@ module HotGlue
5
5
  class InstallGenerator < Rails::Generators::Base
6
6
  hook_for :form_builder, :as => :scaffold
7
7
  class_option :markup, type: :string, default: "erb"
8
+ class_option :theme, type: :string, default: nil
9
+ class_option :layout, type: :string, default: "hotglue"
8
10
 
9
11
  source_root File.expand_path('templates', __dir__)
10
12
 
11
-
12
13
  def initialize(*args) #:nodoc:
13
14
  super
15
+ @layout = options['layout'] || "hotglue"
16
+ @theme = options['theme']
17
+
18
+ if @layout == "hotglue" && options['theme'].nil?
19
+ puts "You have selected to install Hot Glue without a theme. You can either use the --layout=bootstrap to install NO HOT GLUE THEME, or to use a Hot Glue theme please choose: like_boostrap, like_menlo_park, like_cupertino, like_mountain_view, dark_knight"
20
+ exit
21
+ end
22
+
23
+ if @layout == 'boostrap'
24
+ puts "IMPORTANT: You have selected to install Hot Glue with Bootstrap layout (legacy). Be sure to always use ``--layout=bootstrap` when building your scaffold. No Hot Glue theme will be installed at this time.` "
25
+ end
26
+
27
+ ### INTERACTIVE LICENSING
28
+ #
29
+
30
+
31
+ print "(To purchase a license, please see https://heliosdev.shop/hot-glue-license) \n Please enter your license key: "
32
+ license_activation_key = STDIN.gets
33
+
34
+ print "Please enter the EMAIL you used to purchase this license: "
35
+ license_email = STDIN.gets
36
+ app_name = Rails.application.class.module_parent_name
37
+ license_should_be = Digest::SHA1.hexdigest("HotGlueLicense--#{app_name}--#{license_email}")
38
+ if (license_should_be != license_activation_key)
39
+ puts "Ooops... it seems that Hot Glue license is not valid. Please check 1) the email address you used for this license, 2) The app name you used to purchase this license, and 3) the activation key itself."
40
+ exit
41
+ end
42
+
14
43
  @markup = options['markup']
15
44
  if @markup == "haml"
16
45
  copy_file "haml/_flash_notices.haml", "#{'spec/dummy/' if Rails.env.test?}app/views/layouts/_flash_notices.haml"
@@ -21,7 +50,87 @@ module HotGlue
21
50
 
22
51
  if Rails.version.split(".")[0].to_i >= 7
23
52
  copy_file "confirmable.js", "#{'spec/dummy/' if Rails.env.test?}app/javascript/controllers/confirmable.js"
53
+ end
54
+
55
+ if Rails.version.split(".")[0].to_i == 6
56
+ app_js_contents = File.read("app/javascript/packs/application.js")
57
+ if app_js_contents.include?("import Turbolinks from \"turbolinks\"")
58
+ app_js_contents.gsub!("import Turbolinks from \"turbolinks\"", "import { Turbo } from \"@hotwired/turbo-rails\"")
59
+ puts " HOTGLUE --> fixed packs/application.js: swapping old Turbolinks syntas for new Turbo-Rails syntax [ import { Turbo } from \"@hotwired/turbo-rails\" ] "
60
+ end
61
+
62
+ if app_js_contents.include?("Turbolinks.start()")
63
+ app_js_contents.gsub!("Turbolinks.start()", "Turbo.start()")
64
+ puts " HOTGLUE --> fixed packs/application.js: swapping old Turbolinks syntas for new Turbo-Rails syntax[ Turbolinks.start() ] "
65
+ end
66
+ File.write("app/javascript/packs/application.js", app_js_contents)
67
+
68
+ end
69
+
70
+
71
+ rails_helper_contents = File.read("spec/rails_helper.rb")
72
+ if !rails_helper_contents.include?("Capybara.default_driver =")
73
+ rails_helper_contents << "\nCapybara.default_driver = :selenium_chrome_headless "
74
+ puts " HOTGLUE --> added to spec/rails_helper.rb: `Capybara.default_driver = :selenium_chrome_headless` "
75
+ end
76
+
77
+ if !rails_helper_contents.include?("include FactoryBot::Syntax::Methods")
78
+ rails_helper_contents.gsub!("RSpec.configure do |config|", "RSpec.configure do |config| \n
79
+ config.include FactoryBot::Syntax::Methods
80
+ ")
81
+ puts " HOTGLUE --> added to spec/rails_helper.rb: `config.include FactoryBot::Syntax::Methods` "
82
+ end
83
+
84
+ if ! rails_helper_contents.include?("require 'support/capybara_login.rb'")
85
+ rails_helper_contents.gsub!("require 'rspec/rails'","require 'rspec/rails' \nrequire 'support/capybara_login.rb'")
86
+ puts " HOTGLUE --> added to spec/rails_helper.rb: `require 'support/capybara_login.rb'` "
87
+ end
88
+ File.write("spec/rails_helper.rb", rails_helper_contents)
89
+
90
+
91
+ application_layout_contents = File.read("app/views/layouts/application.html.erb")
92
+
93
+ if !application_layout_contents.include?("render partial: 'layouts/flash_notices'")
94
+ application_layout_contents.gsub!("<body>", "<body>\n
95
+ <%= render partial: 'layouts/flash_notices' %>
96
+ ")
97
+ File.write("app/views/layouts/application.html.erb", application_layout_contents)
98
+ puts " HOTGLUE --> added to app/views/layouts/application.html.erb: `<%= render partial: 'layouts/flash_notices' %>` "
99
+ end
100
+
101
+
102
+ if @layout == "hotglue"
103
+ theme_location = "themes/hotglue_scaffold_#{@theme}.scss"
104
+ theme_file = "hotglue_scaffold_#{@theme}.scss"
105
+
106
+ copy_file theme_location, "#{'spec/dummy/' if Rails.env.test?}app/assets/stylesheets/#{theme_file}"
107
+
108
+ application_scss = File.read("app/assets/stylesheets/application.scss")
109
+
110
+ if !application_scss.include?("@import '#{theme_file}';")
111
+ application_scss << ( "\n @import '#{theme_file}'; ")
112
+ File.write("app/assets/stylesheets/application.scss", application_scss)
113
+ puts " HOTGLUE --> added to app/assets/stylesheets/application.scss: @import '#{theme_file}' "
114
+ else
115
+ puts " HOTGLUE --> already found theme in app/assets/stylesheets/application.scss: @import '#{theme_file}' "
116
+ end
117
+ end
118
+
119
+
120
+
121
+ if !File.exists?("config/hot_glue.yml")
122
+
123
+ yaml = {layout: @layout,
124
+ markup: @markup,
125
+ license_activation_key: license_activation_key,
126
+ license_email: license_email}.to_yaml
127
+ File.write("#{'spec/dummy/' if Rails.env.test?}config/hot_glue.yml", yaml)
128
+
129
+ end
130
+
24
131
 
132
+ if !File.exists?("spec/support/capybara_login.rb")
133
+ copy_file "capybara_login.rb", "#{'spec/dummy/' if Rails.env.test?}spec/support/capybara_login.rb"
25
134
  end
26
135
  end
27
136
  end
@@ -5,16 +5,46 @@ module HotGlue
5
5
  attr_accessor :singular
6
6
 
7
7
  def field_output(col, type = nil, width, col_identifier )
8
- "<div class='col form-group <%='alert-danger' if @#{singular}.errors.details.keys.include?(:#{col.to_s})%>' > \n" +
9
- " <%= f.text_field :#{col.to_s}, value: @#{@singular}.#{col.to_s}, size: #{width}, class: 'form-control', type: '#{type}' %>\n "+
8
+ "<div class='#{col_identifier} form-group <%='alert-danger' if @#{singular}.errors.details.keys.include?(:#{col.to_s})%>' > \n" +
9
+ " <%= f.text_field :#{col.to_s}, value: @#{@singular}.#{col.to_s}, autocomplete: 'off', size: #{width}, class: 'form-control', type: '#{type}' %>\n "+
10
10
  " <label class='form-text' >#{col.to_s.humanize}</label>\n" +
11
11
  "</div>"
12
12
  end
13
13
 
14
+
15
+ def magic_button_output(*args)
16
+ path_helper_singular = args[0][:path_helper_singular]
17
+ path_helper_args = args[0][:path_helper_args]
18
+ singular = args[0][:singular]
19
+ magic_buttons = args[0][:magic_buttons]
20
+
21
+ magic_buttons.collect{ |button_name|
22
+ "<%= form_with model: #{singular}, url: #{path_helper_singular}(#{path_helper_args}) do |f| %>
23
+ <%= f.hidden_field :#{button_name}, value: \"#{button_name}\" %>
24
+ <%= f.submit '#{button_name.titleize}'.html_safe, data: {confirm: 'Are you sure you want to #{button_name} this #{singular}?'}, class: '#{singular}-button btn btn-primary ' %>
25
+ <% end %>"
26
+ }.join("\n")
27
+ end
28
+
29
+ def text_area_output(col, field_length, col_identifier )
30
+ lines = field_length % 40
31
+ if lines > 5
32
+ lines = 5
33
+ end
34
+
35
+ "<div class=\"#{col_identifier} form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\">" +
36
+ "<%= f.text_area :#{col.to_s}, class: 'form-control', autocomplete: 'off', cols: 40, rows: '#{lines}' %>" +
37
+ "<label class='form-text'>#{col.to_s.humanize}</label>"+
38
+ "</div>"
39
+
40
+ end
41
+
14
42
  def list_column_headings(*args)
15
43
  columns = args[0][:columns]
44
+ column_width = args[0][:column_width]
45
+ col_identifier = args[0][:col_identifier]
16
46
 
17
- columns.map(&:to_s).map{|col_name| "<div class='col'>#{col_name.humanize}</div>"}.join("\n")
47
+ columns.map(&:to_s).map{|col_name| "<div class='#{col_identifier}' style='flex-basis: #{column_width}%'>#{col_name.humanize}</div>"}.join("\n")
18
48
  end
19
49
 
20
50
 
@@ -22,13 +52,15 @@ module HotGlue
22
52
  columns = args[0][:columns]
23
53
  show_only = args[0][:show_only]
24
54
  singular_class = args[0][:singular_class]
55
+ col_identifier = args[0][:col_identifier]
56
+
25
57
 
26
58
  # TODO: CLEAN ME
27
59
  @singular = args[0][:singular]
28
60
  singular = @singular
29
61
 
30
62
 
31
- col_identifier = "col"
63
+
32
64
  col_spaces_prepend = " "
33
65
 
34
66
  res = columns.map { |col|
@@ -70,25 +102,20 @@ module HotGlue
70
102
 
71
103
  end
72
104
  when :string
73
- limit ||= 256
74
- if limit <= 256
75
- field_output(col, nil, limit, col_identifier)
105
+ if sql_type == "varchar" || sql_type == "character varying"
106
+ field_output(col, nil, limit || 40, col_identifier)
76
107
  else
77
- text_area_output(col, limit, col_identifier)
108
+ text_area_output(col, 65536, col_identifier)
78
109
  end
79
110
 
80
111
  when :text
81
- limit ||= 256
82
- if limit <= 256
112
+ if sql_type == "varchar"
83
113
  field_output(col, nil, limit, col_identifier)
84
114
  else
85
- text_area_output(col, limit, col_identifier)
115
+ text_area_output(col, 65536, col_identifier)
86
116
  end
87
117
  when :float
88
- limit ||= 256
89
- field_output(col, nil, limit, col_identifier)
90
-
91
-
118
+ field_output(col, nil, 5, col_identifier)
92
119
  when :datetime
93
120
 
94
121
 
@@ -113,9 +140,11 @@ module HotGlue
113
140
  " <%= f.label(:#{col.to_s}, value: 'Yes', for: '#{singular}_#{col.to_s}_1') %>\n" +
114
141
  "</div>"
115
142
  when :enum
116
- enum_name ="enum_name"
143
+ enum_name = "enum_name"
144
+ # byebug
145
+ enum_type = eval("#{singular_class}.columns.select{|x| x.name == '#{col.to_s}'}[0].sql_type")
117
146
  "<div class='#{col_identifier} form-group <%= 'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s}) %>' >
118
- <%= f.collection_select(:#{col.to_s}, enum_to_collection_select( #{singular_class}.defined_enums['#{col.to_s}']), :key, :value, {prompt: true, selected: @#{singular}.#{col.to_s} }, class: 'form-control') %>
147
+ <%= f.collection_select(:#{col.to_s}, enum_to_collection_select( #{singular_class}.defined_enums['#{enum_type}']), :key, :value, {prompt: true, selected: @#{singular}.#{col.to_s} }, class: 'form-control') %>
119
148
  <label class='small form-text text-muted'>#{col.to_s.humanize}</label></div>"
120
149
 
121
150
  end
@@ -138,11 +167,18 @@ module HotGlue
138
167
  show_only = args[0][:show_only]
139
168
  singular_class = args[0][:singular_class]
140
169
  singular = args[0][:singular]
170
+ perc_width = args[0][:perc_width]
141
171
 
142
172
  columns_count = columns.count + 1
143
- perc_width = (100/columns_count).floor
173
+ perc_width = (perc_width).floor
174
+
175
+ if @layout == "boostrap"
176
+ col_identifer = "col"
144
177
 
145
- col_identifer = "col"
178
+ else
179
+ col_identifer = "scaffold-cell"
180
+
181
+ end
146
182
  columns.map { |col|
147
183
  type = eval("#{singular_class}.columns_hash['#{col}']").type
148
184
  limit = eval("#{singular_class}.columns_hash['#{col}']").limit
@@ -160,35 +196,37 @@ module HotGlue
160
196
 
161
197
  if assoc.nil?
162
198
  exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
163
- raise(HotGlue::Error,exit_message)
199
+ puts exit_message
200
+ exit
201
+ # raise(HotGlue::Error,exit_message)
164
202
  end
165
203
 
166
204
  display_column = HotGlue.derrive_reference_name(assoc.class_name)
167
205
 
168
- "<div class='#{col_identifer}'>
206
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
169
207
  <%= #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe %>
170
208
  </div>"
171
209
 
172
210
  else
173
- "<div class='#{col_identifer}'>
211
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
174
212
  <%= #{singular}.#{col}%></div>"
175
213
  end
176
214
  when :float
177
215
  width = (limit && limit < 40) ? limit : (40)
178
- "<div class='#{col_identifer}'>
216
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
179
217
  <%= #{singular}.#{col}%></div>"
180
218
  when :string
181
219
  width = (limit && limit < 40) ? limit : (40)
182
- "<div class='#{col_identifer}'>
220
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
183
221
  <%= #{singular}.#{col} %>
184
222
  </div>"
185
223
  when :text
186
- "<div class='#{col_identifer}'>
224
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
187
225
  <%= #{singular}.#{col} %>
188
226
  </div>"
189
227
  when :datetime
190
228
 
191
- "<div class='#{col_identifer}'>
229
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
192
230
  <% unless #{singular}.#{col}.nil? %>
193
231
  <%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone) %>
194
232
  <% else %>
@@ -196,7 +234,7 @@ module HotGlue
196
234
  <% end %>
197
235
  </div>"
198
236
  when :date
199
- "<div class='#{col_identifer}'>
237
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
200
238
  <% unless #{singular}.#{col}.nil? %>
201
239
  <%= #{singular}.#{col} %>
202
240
  <% else %>
@@ -204,7 +242,7 @@ module HotGlue
204
242
  <% end %>
205
243
  </div>"
206
244
  when :time
207
- "<div class='#{col_identifer}'>
245
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
208
246
  <% unless #{singular}.#{col}.nil? %>
209
247
  <%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone) %>
210
248
  <% else %>
@@ -213,7 +251,7 @@ module HotGlue
213
251
  </div>
214
252
  "
215
253
  when :boolean
216
- "<div class='#{col_identifer}'>
254
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
217
255
  <% if #{singular}.#{col}.nil? %>
218
256
  <span class='alert-danger'>MISSING</span>
219
257
  <% elsif #{singular}.#{col} %>
@@ -238,4 +276,5 @@ module HotGlue
238
276
 
239
277
 
240
278
 
279
+
241
280
  end
@@ -64,7 +64,7 @@ module HotGlue
64
64
  exit_message= "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
65
65
  exit
66
66
  end
67
- display_column = derrive_reference_name(assoc.class_name)
67
+ display_column = HotGlue.derrive_reference_name(assoc.class_name)
68
68
 
69
69
 
70
70
  "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{assoc_name.to_s})}\"}
@@ -159,10 +159,12 @@ module HotGlue
159
159
 
160
160
  if assoc.nil?
161
161
  exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
162
- raise(HotGlue::Error,exit_message)
162
+ puts exit_message
163
+ exit
164
+ # raise(HotGlue::Error,exit_message)
163
165
  end
164
166
 
165
- display_column = derrive_reference_name(assoc.class_name)
167
+ display_column = HotGlue.derrive_reference_name(assoc.class_name)
166
168
 
167
169
 
168
170
  "#{col_identifer}