hot-glue 0.2.5 → 0.3.7

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 +3 -23
  4. data/LICENCE +11 -4
  5. data/README.md +0 -556
  6. data/app/helpers/hot_glue/controller_helper.rb +2 -1
  7. data/app/views/layouts/_flash_notices.erb +12 -0
  8. data/lib/generators/hot_glue/install_generator.rb +129 -20
  9. data/lib/generators/hot_glue/markup_templates/erb.rb +51 -24
  10. data/lib/generators/hot_glue/markup_templates/haml.rb +5 -3
  11. data/lib/generators/hot_glue/scaffold_generator.rb +222 -57
  12. data/lib/generators/hot_glue/templates/capybara_login.rb +8 -0
  13. data/lib/generators/hot_glue/templates/controller.rb.erb +40 -31
  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 +25 -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 +2 -5
  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 +19 -8
  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
@@ -0,0 +1,12 @@
1
+ <%= turbo_frame_tag "flash_notices" do %>
2
+ <% unless notice.nil? %>
3
+ <div class="alert alert-notice alert-dismissible">
4
+ <%= notice %>
5
+ </div>
6
+ <% end %>
7
+ <% unless alert.nil? %>
8
+ <div class="alert alert-danger alert-dismissible">
9
+ <%= alert %>
10
+ </div>
11
+ <% end %>
12
+ <% end %>
@@ -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"
@@ -23,33 +52,113 @@ module HotGlue
23
52
  copy_file "confirmable.js", "#{'spec/dummy/' if Rails.env.test?}app/javascript/controllers/confirmable.js"
24
53
  end
25
54
 
26
- rails_helper_contents = File.read("spec/rails_helper.rb")
27
- if !rails_helper_contents.include?("include FactoryBot::Syntax::Methods")
28
- rails_helper_contents.gsub!("RSpec.configure do |config|", "RSpec.configure do |config| \n
29
- config.include FactoryBot::Syntax::Methods
30
- ")
55
+
56
+ begin
57
+ if Rails.version.split(".")[0].to_i == 6
58
+ app_js_contents = File.read("app/javascript/packs/application.js")
59
+ if app_js_contents.include?("import Turbolinks from \"turbolinks\"")
60
+ app_js_contents.gsub!("import Turbolinks from \"turbolinks\"", "import { Turbo } from \"@hotwired/turbo-rails\"")
61
+ puts " HOTGLUE --> fixed packs/application.js: swapping old Turbolinks syntas for new Turbo-Rails syntax [ import { Turbo } from \"@hotwired/turbo-rails\" ] "
62
+ end
63
+
64
+ if app_js_contents.include?("Turbolinks.start()")
65
+ app_js_contents.gsub!("Turbolinks.start()", "Turbo.start()")
66
+ puts " HOTGLUE --> fixed packs/application.js: swapping old Turbolinks syntas for new Turbo-Rails syntax[ Turbolinks.start() ] "
67
+ end
68
+ File.write("app/javascript/packs/application.js", app_js_contents)
69
+ end
70
+ rescue StandardError => e
71
+ puts "WARNING: error writing to app/javascript/packs/application.js --- #{e.message}"
72
+ end
73
+
74
+
75
+
76
+ begin
77
+ rails_helper_contents = File.read("spec/rails_helper.rb")
78
+ if !rails_helper_contents.include?("Capybara.default_driver =")
79
+ rails_helper_contents << "\nCapybara.default_driver = :selenium_chrome_headless "
80
+ puts " HOTGLUE --> added to spec/rails_helper.rb: `Capybara.default_driver = :selenium_chrome_headless` "
81
+ end
82
+
83
+ if !rails_helper_contents.include?("include FactoryBot::Syntax::Methods")
84
+ rails_helper_contents.gsub!("RSpec.configure do |config|", "RSpec.configure do |config| \n
85
+ config.include FactoryBot::Syntax::Methods
86
+ ")
87
+ puts " HOTGLUE --> added to spec/rails_helper.rb: `config.include FactoryBot::Syntax::Methods` "
88
+ end
89
+
90
+ if ! rails_helper_contents.include?("require 'support/capybara_login.rb'")
91
+ rails_helper_contents.gsub!("require 'rspec/rails'","require 'rspec/rails' \nrequire 'support/capybara_login.rb'")
92
+ puts " HOTGLUE --> added to spec/rails_helper.rb: `require 'support/capybara_login.rb'` "
93
+ end
31
94
  File.write("spec/rails_helper.rb", rails_helper_contents)
32
- puts " HOTGLUE --> add to spec/rails_helper.rb: `config.include FactoryBot::Syntax::Methods` "
95
+
96
+ rescue StandardError => e
97
+ puts "WARNING: error writing to spec/rails_helper --- #{e.message}"
33
98
  end
34
99
 
35
- application_layout_contents = File.read("app/views/layouts/application.html.erb")
36
100
 
37
- if !application_layout_contents.include?("render partial: 'layouts/flash_notices'")
38
- application_layout_contents.gsub!("<body>", "<body>\n
39
- <%= render partial: 'flash_notices' %>
40
- ")
41
- File.write("app/views/layouts/application.html.erb", application_layout_contents)
42
- puts " HOTGLUE --> add to app/views/layouts/application.html.erb: `<%= render partial: 'layouts/flash_notices' %>` "
101
+ begin
102
+ application_layout_contents = File.read("app/views/layouts/application.html.erb")
103
+
104
+ if !application_layout_contents.include?("render partial: 'layouts/flash_notices'")
105
+ application_layout_contents.gsub!("<body>", "<body>\n
106
+ <%= render partial: 'layouts/flash_notices' %>
107
+ ")
108
+ File.write("app/views/layouts/application.html.erb", application_layout_contents)
109
+ puts " HOTGLUE --> added to app/views/layouts/application.html.erb: `<%= render partial: 'layouts/flash_notices' %>` "
110
+ end
111
+ rescue StandardError => e
112
+ puts "WARNING: error writing to app/views/layouts/application.html.erb --- #{e.message}"
43
113
  end
44
114
 
45
- #
46
115
 
47
- # TODO>: look for config.include FactoryBot::Syntax::Methods
48
- # inside of spec/rails_Helper.rb and inject it if it is not there
49
- # rspec_file = File.read("spec/rails_helper.rb")
50
- #
51
- # "RSpec.configure do |config|"
116
+ begin
117
+ if @layout == "hotglue"
118
+ theme_location = "themes/hotglue_scaffold_#{@theme}.scss"
119
+ theme_file = "hotglue_scaffold_#{@theme}.scss"
120
+
121
+ copy_file theme_location, "#{'spec/dummy/' if Rails.env.test?}app/assets/stylesheets/#{theme_file}"
122
+
123
+ application_scss = File.read("app/assets/stylesheets/application.scss")
124
+
125
+ if !application_scss.include?("@import '#{theme_file}';")
126
+ application_scss << ( "\n @import '#{theme_file}'; ")
127
+ File.write("app/assets/stylesheets/application.scss", application_scss)
128
+ puts " HOTGLUE --> added to app/assets/stylesheets/application.scss: @import '#{theme_file}' "
129
+ else
130
+ puts " HOTGLUE --> already found theme in app/assets/stylesheets/application.scss: @import '#{theme_file}' "
131
+ end
132
+ end
133
+ rescue StandardError => e
134
+ puts "WARNING: error writing to app/assets/stylesheets/application.scss --- #{e.message}"
135
+ end
52
136
 
137
+
138
+
139
+ begin
140
+
141
+ if !File.exists?("config/hot_glue.yml")
142
+
143
+ yaml = {layout: @layout,
144
+ markup: @markup,
145
+ license_activation_key: license_activation_key,
146
+ license_email: license_email}.to_yaml
147
+ File.write("#{'spec/dummy/' if Rails.env.test?}config/hot_glue.yml", yaml)
148
+
149
+ end
150
+ rescue StandardError => e
151
+ puts "WARNING: error writing to config/hot_glue.yml --- #{e.message}"
152
+ end
153
+
154
+
155
+ begin
156
+ if !File.exists?("spec/support/capybara_login.rb")
157
+ copy_file "capybara_login.rb", "#{'spec/dummy/' if Rails.env.test?}spec/support/capybara_login.rb"
158
+ end
159
+ rescue StandardError => e
160
+ puts "WARNING: error writing to spec/support/capybara_login.rb --- #{e.message}"
161
+ end
53
162
  end
54
163
  end
55
164
  end
@@ -5,13 +5,27 @@ 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
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
+
15
29
  def text_area_output(col, field_length, col_identifier )
16
30
  lines = field_length % 40
17
31
  if lines > 5
@@ -19,7 +33,7 @@ module HotGlue
19
33
  end
20
34
 
21
35
  "<div class=\"#{col_identifier} form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\">" +
22
- "<%= f.text_area :#{col.to_s}, class: 'form-control', cols: 40, rows: '#{lines}' %>" +
36
+ "<%= f.text_area :#{col.to_s}, class: 'form-control', autocomplete: 'off', cols: 40, rows: '#{lines}' %>" +
23
37
  "<label class='form-text'>#{col.to_s.humanize}</label>"+
24
38
  "</div>"
25
39
 
@@ -27,8 +41,10 @@ module HotGlue
27
41
 
28
42
  def list_column_headings(*args)
29
43
  columns = args[0][:columns]
44
+ column_width = args[0][:column_width]
45
+ col_identifier = args[0][:col_identifier]
30
46
 
31
- 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")
32
48
  end
33
49
 
34
50
 
@@ -36,13 +52,15 @@ module HotGlue
36
52
  columns = args[0][:columns]
37
53
  show_only = args[0][:show_only]
38
54
  singular_class = args[0][:singular_class]
55
+ col_identifier = args[0][:col_identifier]
56
+
39
57
 
40
58
  # TODO: CLEAN ME
41
59
  @singular = args[0][:singular]
42
60
  singular = @singular
43
61
 
44
62
 
45
- col_identifier = "col"
63
+
46
64
  col_spaces_prepend = " "
47
65
 
48
66
  res = columns.map { |col|
@@ -97,10 +115,7 @@ module HotGlue
97
115
  text_area_output(col, 65536, col_identifier)
98
116
  end
99
117
  when :float
100
- limit ||= 256
101
- field_output(col, nil, limit, col_identifier)
102
-
103
-
118
+ field_output(col, nil, 5, col_identifier)
104
119
  when :datetime
105
120
 
106
121
 
@@ -125,9 +140,11 @@ module HotGlue
125
140
  " <%= f.label(:#{col.to_s}, value: 'Yes', for: '#{singular}_#{col.to_s}_1') %>\n" +
126
141
  "</div>"
127
142
  when :enum
128
- 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")
129
146
  "<div class='#{col_identifier} form-group <%= 'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s}) %>' >
130
- <%= 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') %>
131
148
  <label class='small form-text text-muted'>#{col.to_s.humanize}</label></div>"
132
149
 
133
150
  end
@@ -150,11 +167,18 @@ module HotGlue
150
167
  show_only = args[0][:show_only]
151
168
  singular_class = args[0][:singular_class]
152
169
  singular = args[0][:singular]
170
+ perc_width = args[0][:perc_width]
153
171
 
154
172
  columns_count = columns.count + 1
155
- perc_width = (100/columns_count).floor
173
+ perc_width = (perc_width).floor
174
+
175
+ if @layout == "boostrap"
176
+ col_identifer = "col"
156
177
 
157
- col_identifer = "col"
178
+ else
179
+ col_identifer = "scaffold-cell"
180
+
181
+ end
158
182
  columns.map { |col|
159
183
  type = eval("#{singular_class}.columns_hash['#{col}']").type
160
184
  limit = eval("#{singular_class}.columns_hash['#{col}']").limit
@@ -172,35 +196,37 @@ module HotGlue
172
196
 
173
197
  if assoc.nil?
174
198
  exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
175
- raise(HotGlue::Error,exit_message)
199
+ puts exit_message
200
+ exit
201
+ # raise(HotGlue::Error,exit_message)
176
202
  end
177
203
 
178
204
  display_column = HotGlue.derrive_reference_name(assoc.class_name)
179
205
 
180
- "<div class='#{col_identifer}'>
206
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
181
207
  <%= #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe %>
182
208
  </div>"
183
209
 
184
210
  else
185
- "<div class='#{col_identifer}'>
211
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
186
212
  <%= #{singular}.#{col}%></div>"
187
213
  end
188
214
  when :float
189
215
  width = (limit && limit < 40) ? limit : (40)
190
- "<div class='#{col_identifer}'>
216
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
191
217
  <%= #{singular}.#{col}%></div>"
192
218
  when :string
193
219
  width = (limit && limit < 40) ? limit : (40)
194
- "<div class='#{col_identifer}'>
220
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
195
221
  <%= #{singular}.#{col} %>
196
222
  </div>"
197
223
  when :text
198
- "<div class='#{col_identifer}'>
224
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
199
225
  <%= #{singular}.#{col} %>
200
226
  </div>"
201
227
  when :datetime
202
228
 
203
- "<div class='#{col_identifer}'>
229
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
204
230
  <% unless #{singular}.#{col}.nil? %>
205
231
  <%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone) %>
206
232
  <% else %>
@@ -208,7 +234,7 @@ module HotGlue
208
234
  <% end %>
209
235
  </div>"
210
236
  when :date
211
- "<div class='#{col_identifer}'>
237
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
212
238
  <% unless #{singular}.#{col}.nil? %>
213
239
  <%= #{singular}.#{col} %>
214
240
  <% else %>
@@ -216,7 +242,7 @@ module HotGlue
216
242
  <% end %>
217
243
  </div>"
218
244
  when :time
219
- "<div class='#{col_identifer}'>
245
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
220
246
  <% unless #{singular}.#{col}.nil? %>
221
247
  <%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone) %>
222
248
  <% else %>
@@ -225,7 +251,7 @@ module HotGlue
225
251
  </div>
226
252
  "
227
253
  when :boolean
228
- "<div class='#{col_identifer}'>
254
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
229
255
  <% if #{singular}.#{col}.nil? %>
230
256
  <span class='alert-danger'>MISSING</span>
231
257
  <% elsif #{singular}.#{col} %>
@@ -235,7 +261,7 @@ module HotGlue
235
261
  <% end %>
236
262
  </div>
237
263
  " when :enum
238
- "<div class='#{col_identifer}'>
264
+ "<div class='#{col_identifer}' style='flex-basis: #{perc_width}%'>
239
265
  <% if #{singular}.#{col}.nil? %>
240
266
  <span class='alert-danger'>MISSING</span>
241
267
  <% else %>
@@ -250,4 +276,5 @@ module HotGlue
250
276
 
251
277
 
252
278
 
279
+
253
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}