hot-glue 0.1.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +8 -7
  3. data/README.md +95 -17
  4. data/app/helpers/hot_glue/controller_helper.rb +1 -1
  5. data/lib/generators/hot_glue/install_generator.rb +8 -3
  6. data/lib/generators/hot_glue/markup_templates/base.rb +7 -0
  7. data/lib/generators/hot_glue/markup_templates/erb.rb +227 -0
  8. data/lib/generators/hot_glue/markup_templates/haml.rb +236 -0
  9. data/lib/generators/hot_glue/markup_templates/slim.rb +9 -0
  10. data/lib/generators/hot_glue/scaffold_generator.rb +143 -258
  11. data/lib/generators/hot_glue/templates/controller.rb.erb +16 -4
  12. data/lib/generators/hot_glue/templates/erb/_errors.erb +11 -0
  13. data/lib/generators/hot_glue/templates/erb/_flash_notices.erb +12 -0
  14. data/lib/generators/hot_glue/templates/erb/_form.erb +8 -0
  15. data/lib/generators/hot_glue/templates/erb/_line.erb +10 -0
  16. data/lib/generators/hot_glue/templates/erb/_list.erb +19 -0
  17. data/lib/generators/hot_glue/templates/erb/_new_button.erb +3 -0
  18. data/lib/generators/hot_glue/templates/erb/_new_form.erb +8 -0
  19. data/lib/generators/hot_glue/templates/erb/_show.erb +8 -0
  20. data/lib/generators/hot_glue/templates/erb/create.turbo_stream.erb +18 -0
  21. data/lib/generators/hot_glue/templates/erb/destroy.turbo_stream.erb +3 -0
  22. data/lib/generators/hot_glue/templates/erb/edit.erb +30 -0
  23. data/lib/generators/hot_glue/templates/erb/edit.turbo_stream.erb +3 -0
  24. data/lib/generators/hot_glue/templates/erb/index.erb +10 -0
  25. data/lib/generators/hot_glue/templates/erb/new.erb +1 -0
  26. data/lib/generators/hot_glue/templates/erb/update.turbo_stream.erb +10 -0
  27. data/lib/generators/hot_glue/templates/{_errors.haml → haml/_errors.haml} +0 -0
  28. data/lib/generators/hot_glue/templates/{_flash_notices.haml → haml/_flash_notices.haml} +0 -0
  29. data/lib/generators/hot_glue/templates/{_form.haml → haml/_form.haml} +0 -0
  30. data/lib/generators/hot_glue/templates/{_line.haml → haml/_line.haml} +0 -0
  31. data/lib/generators/hot_glue/templates/{_list.haml → haml/_list.haml} +0 -0
  32. data/lib/generators/hot_glue/templates/{_new_button.haml → haml/_new_button.haml} +0 -0
  33. data/lib/generators/hot_glue/templates/{_new_form.haml → haml/_new_form.haml} +0 -0
  34. data/lib/generators/hot_glue/templates/{_show.haml → haml/_show.haml} +0 -0
  35. data/lib/generators/hot_glue/templates/{create.turbo_stream.haml → haml/create.turbo_stream.haml} +0 -0
  36. data/lib/generators/hot_glue/templates/{destroy.turbo_stream.haml → haml/destroy.turbo_stream.haml} +0 -0
  37. data/lib/generators/hot_glue/templates/{edit.haml → haml/edit.haml} +0 -0
  38. data/lib/generators/hot_glue/templates/{edit.turbo_stream.haml → haml/edit.turbo_stream.haml} +0 -0
  39. data/lib/generators/hot_glue/templates/{index.haml → haml/index.haml} +0 -0
  40. data/lib/generators/hot_glue/templates/{new.haml → haml/new.haml} +0 -0
  41. data/lib/generators/hot_glue/templates/{update.turbo_stream.haml → haml/update.turbo_stream.haml} +0 -0
  42. data/lib/generators/hot_glue/templates/system_spec.rb.erb +1 -1
  43. data/lib/hot-glue.rb +6 -20
  44. data/lib/hotglue/version.rb +1 -1
  45. metadata +49 -24
@@ -1,67 +1,41 @@
1
1
  require 'rails/generators/erb/scaffold/scaffold_generator'
2
2
  require 'ffaker'
3
3
 
4
+ require_relative './markup_templates/base'
5
+ require_relative './markup_templates/erb'
6
+ require_relative './markup_templates/haml'
7
+ require_relative './markup_templates/slim'
4
8
 
5
9
  module HotGlue
6
10
  class Error < StandardError
7
11
  end
8
12
 
9
- module GeneratorHelper
10
- def derrive_reference_name thing_as_string
11
- assoc_class = eval(thing_as_string)
12
-
13
- if assoc_class.respond_to?("name")
14
- display_column = "name"
15
- elsif assoc_class.respond_to?("to_label")
16
- display_column = "to_label"
17
- elsif assoc_class.respond_to?("full_name")
18
- display_column = "full_name"
19
- elsif assoc_class.respond_to?("display_name")
20
- display_column = "display_name"
21
- elsif assoc_class.respond_to?("email")
22
- display_column = "email"
23
- else
24
- raise("this should have been caught by the checker in the initializer")
25
- # puts "*** Oops: Can't find any column to use as the display label for the #{assoc.name.to_s} association on the #{singular_class} model . TODO: Please implement just one of: 1) name, 2) to_label, 3) full_name, 4) display_name, or 5) email directly on your #{assoc.class_name} model (either as database field or model methods), then RERUN THIS GENERATOR. (If more than one is implemented, the field to use will be chosen based on the rank here, e.g., if name is present it will be used; if not, I will look for a to_label, etc)"
26
- end
27
- display_column
28
- end
29
-
30
-
31
- def text_area_output(col, field_length, col_identifier )
32
- lines = field_length % 40
33
- if lines > 5
34
- lines = 5
35
- end
36
-
37
- "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
38
- = f.text_area :#{col.to_s}, class: 'form-control', cols: 40, rows: '#{lines}'
39
- %label.form-text
40
- #{col.to_s.humanize}\n"
41
- end
42
-
43
-
44
-
45
- def field_output(col, type = nil, width, col_identifier )
46
-
47
- "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
48
- = f.text_field :#{col.to_s}, value: @#{singular}.#{col.to_s}, size: #{width}, class: 'form-control', type: '#{type}'
49
- %label.form-text
50
- #{col.to_s.humanize}\n"
51
- end
13
+ def self.derrive_reference_name(thing_as_string)
14
+ assoc_class = eval(thing_as_string)
15
+
16
+ if assoc_class.respond_to?("name")
17
+ display_column = "name"
18
+ elsif assoc_class.respond_to?("to_label")
19
+ display_column = "to_label"
20
+ elsif assoc_class.respond_to?("full_name")
21
+ display_column = "full_name"
22
+ elsif assoc_class.respond_to?("display_name")
23
+ display_column = "display_name"
24
+ elsif assoc_class.respond_to?("email")
25
+ display_column = "email"
26
+ else
27
+ raise("this should have been caught by the checker in the initializer")
28
+ # puts "*** Oops: Can't find any column to use as the display label for the #{assoc.name.to_s} association on the #{singular_class} model . TODO: Please implement just one of: 1) name, 2) to_label, 3) full_name, 4) display_name, or 5) email directly on your #{assoc.class_name} model (either as database field or model methods), then RERUN THIS GENERATOR. (If more than one is implemented, the field to use will be chosen based on the rank here, e.g., if name is present it will be used; if not, I will look for a to_label, etc)"
29
+ end
30
+ display_column
52
31
  end
53
32
 
54
-
55
33
  class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
56
- hook_for :form_builder, :as => :scaffold
34
+ hook_for :form_builder, :as => :scaffold
57
35
 
58
36
  source_root File.expand_path('templates', __dir__)
59
37
  attr_accessor :path, :singular, :plural, :singular_class, :nest_with
60
38
 
61
-
62
- include GeneratorHelper
63
-
64
-
65
39
  class_option :singular, type: :string, default: nil
66
40
  class_option :plural, type: :string, default: nil
67
41
  class_option :singular_class, type: :string, default: nil
@@ -80,12 +54,24 @@ module HotGlue
80
54
  class_option :no_paginate, type: :boolean, default: false
81
55
  class_option :big_edit, type: :boolean, default: false
82
56
  class_option :show_only, type: :string, default: ""
57
+ class_option :markup, type: :string, default: "erb"
58
+ class_option :stimulus_syntax, type: :boolean, default: nil
59
+
60
+
61
+
62
+ # def erb_replace_ampersands
63
+ # if @template_builder.is_a?(HotGlue::ErbTemplate)
64
+ # @output_buffer.gsub!('\%', '%')
65
+ # end
66
+ # end
83
67
 
84
- def initialize(*meta_args) #:nodoc:
68
+
69
+
70
+ def initialize(*meta_args)
85
71
  super
86
72
 
87
73
  begin
88
- object = eval(class_name)
74
+ @the_object = eval(class_name)
89
75
  rescue StandardError => e
90
76
  message = "*** Oops: It looks like there is no object for #{class_name}. Please define the object + database table first."
91
77
  raise(HotGlue::Error, message)
@@ -95,6 +81,26 @@ module HotGlue
95
81
  raise(HotGlue::Error, "*** Oops: You seem to have specified both the --specs-only flag and --no-specs flags. this doesn't make any sense, so I am aborting. sorry.")
96
82
  end
97
83
 
84
+ if @stimulus_syntax.nil?
85
+ if Rails.version.split(".")[0].to_i >= 7
86
+ @stimulus_syntax = true
87
+ else
88
+ @stimulus_syntax = false
89
+ end
90
+ end
91
+
92
+ if options['markup'] == "erb"
93
+ @template_builder = HotGlue::ErbTemplate.new
94
+ elsif options['markup'] == "slim"
95
+ puts "SLIM IS NOT IMPLEMENTED; please see https://github.com/jasonfb/hot-glue/issues/3"
96
+ abort
97
+ @template_builder = HotGlue::SlimTemplate.new
98
+
99
+ elsif options['markup'] == "haml"
100
+ @template_builder = HotGlue::HamlTemplate.new
101
+ end
102
+ @markup = options['markup']
103
+
98
104
 
99
105
  args = meta_args[0]
100
106
  @singular = args.first.tableize.singularize # should be in form hello_world
@@ -121,7 +127,6 @@ module HotGlue
121
127
  @show_only += options['show_only'].split(",").collect(&:to_sym)
122
128
  end
123
129
 
124
- auth_assoc = @auth.gsub("current_","")
125
130
 
126
131
  @god = options['god'] || options['gd'] || false
127
132
  @specs_only = options['specs_only'] || false
@@ -168,15 +173,23 @@ module HotGlue
168
173
  end
169
174
  end
170
175
 
176
+ @reference_name = HotGlue.derrive_reference_name(singular_class)
177
+
178
+ identify_object_owner
179
+ setup_fields
180
+ end
181
+
182
+ def identify_object_owner
183
+ auth_assoc = @auth && @auth.gsub("current_","")
171
184
 
172
185
  if !@object_owner_sym.empty?
173
- auth_assoc_field = auth_assoc + "_id"
186
+ auth_assoc_field = auth_assoc + "_id" unless @god
174
187
  assoc = eval("#{singular_class}.reflect_on_association(:#{@object_owner_sym})")
175
188
 
176
189
  if assoc
177
- ownership_field = assoc.name.to_s + "_id"
190
+ @ownership_field = assoc.name.to_s + "_id"
178
191
  elsif !@nest
179
- exit_message = "*** Oops: It looks like is no association from current_#{@object_owner_sym} to a class called #{@singular_class}. If your user is called something else, pass with flag auth=current_X where X is the model for your users as lowercase. Also, be sure to implement current_X as a method on your controller. (If you really don't want to implement a current_X on your controller and want me to check some other method for your current user, see the section in the docs for auth_identifier.) To make a controller that can read all records, specify with --god."
192
+ exit_message = "*** Oops: It looks like is no association from current_#{@object_owner_sym} to a class called #{@singular_class}. If your user is called something else, pass with flag auth=current_X where X is the model for your users as lowercase. Also, be sure to implement current_X as a method on your controller. (If you really don't want to implement a current_X on your controller and want me to check some other method for your current user, see the section in the docs for auth_identifier.) To make a controller that can read all records, specify with --god."
180
193
 
181
194
  else
182
195
  if @god
@@ -197,6 +210,11 @@ module HotGlue
197
210
  raise(HotGlue::Error, exit_message)
198
211
  end
199
212
  end
213
+ end
214
+
215
+
216
+ def setup_fields
217
+ auth_assoc = @auth && @auth.gsub("current_","")
200
218
 
201
219
  if !@include_fields
202
220
  @exclude_fields.push :id, :created_at, :updated_at, :encrypted_password,
@@ -205,15 +223,14 @@ module HotGlue
205
223
  :confirmation_token, :confirmed_at,
206
224
  :confirmation_sent_at, :unconfirmed_email
207
225
 
208
- @exclude_fields.push(auth_assoc_field.to_sym) if !auth_assoc_field.nil?
209
- @exclude_fields.push(ownership_field.to_sym) if !ownership_field.nil?
226
+ @exclude_fields.push( (auth_assoc + "_id").to_sym) if ! auth_assoc.nil?
227
+ @exclude_fields.push( @ownership_field.to_sym ) if ! @ownership_field.nil?
210
228
 
211
229
 
212
- @columns = object.columns.map(&:name).map(&:to_sym).reject{|field| @exclude_fields.include?(field) }
230
+ @columns = @the_object.columns.map(&:name).map(&:to_sym).reject{|field| @exclude_fields.include?(field) }
213
231
 
214
232
  else
215
- @columns = object.columns.map(&:name).map(&:to_sym).reject{|field| !@include_fields.include?(field) }
216
-
233
+ @columns = @the_object.columns.map(&:name).map(&:to_sym).reject{|field| !@include_fields.include?(field) }
217
234
  end
218
235
 
219
236
  @columns.each do |col|
@@ -221,7 +238,7 @@ module HotGlue
221
238
  @show_only << col
222
239
  end
223
240
 
224
- if object.columns_hash[col.to_s].type == :integer
241
+ if @the_object.columns_hash[col.to_s].type == :integer
225
242
  if col.to_s.ends_with?("_id")
226
243
  # guess the association name label
227
244
  assoc_name = col.to_s.gsub("_id","")
@@ -260,8 +277,6 @@ module HotGlue
260
277
  end
261
278
  end
262
279
 
263
-
264
-
265
280
  #
266
281
  def formats
267
282
  [format]
@@ -273,7 +288,6 @@ module HotGlue
273
288
 
274
289
  def copy_controller_and_spec_files
275
290
  @default_colspan = @columns.size
276
-
277
291
  unless @specs_only
278
292
  template "controller.rb.erb", File.join("#{'spec/dummy/' if Rails.env.test?}app/controllers#{namespace_with_dash}", "#{plural}_controller.rb")
279
293
  if @namespace
@@ -290,11 +304,12 @@ module HotGlue
290
304
  template "system_spec.rb.erb", File.join("#{'spec/dummy/' if Rails.env.test?}spec/system#{namespace_with_dash}", "#{plural}_behavior_spec.rb")
291
305
  end
292
306
 
293
- template "_errors.haml", File.join("#{'spec/dummy/' if Rails.env.test?}app/views#{namespace_with_dash}", "_errors.haml")
307
+ template "#{@markup}/_errors.#{@markup}", File.join("#{'spec/dummy/' if Rails.env.test?}app/views#{namespace_with_dash}", "_errors.#{@markup}")
294
308
  end
295
309
 
296
310
  def list_column_headings
297
- @columns.map(&:to_s).map{|col_name| ' .col ' + col_name.humanize}.join("\n")
311
+ @template_builder.list_column_headings(columns: @columns)
312
+
298
313
  end
299
314
 
300
315
  def columns_spec_with_sample_data
@@ -365,11 +380,6 @@ module HotGlue
365
380
  @auth_identifier
366
381
  end
367
382
 
368
-
369
- # def path_helper_full
370
- # "#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_" if @nested_args.any?)}#{singular}_path"
371
- # end
372
-
373
383
  def path_helper_args
374
384
  if @nested_args.any?
375
385
  [(@nested_args).collect{|a| "@#{a}"} , singular].join(",")
@@ -407,7 +417,14 @@ module HotGlue
407
417
  end
408
418
 
409
419
  def new_path_name
410
- "new_#{@namespace+"_" if @namespace}#{singular}_path"
420
+
421
+ base = "new_#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_") if @nested_args.any?}#{singular}_path"
422
+ if @nested_args.any?
423
+ base += "(" + @nested_args.collect { |arg|
424
+ "@#{arg}.id"
425
+ }.join(", ") + ")"
426
+ end
427
+ base
411
428
  end
412
429
 
413
430
  def nested_assignments
@@ -462,40 +479,60 @@ module HotGlue
462
479
  end
463
480
 
464
481
  def all_objects_variable
465
-
466
- # needs the authenticated root user
467
- # "#{@auth}.#{ @nested_args.map{|a| "#{@nested_args_plural[a]}.find(@#{a})"}.join('.') + "." if @nested_args.any?}#{plural}"
468
-
469
482
  all_objects_root + ".page(params[:page])"
470
-
471
483
  end
472
484
 
473
485
  def auth_object
474
486
  @auth
475
487
  end
476
488
 
477
-
478
489
  def no_devise_installed
479
490
  !Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }['devise']
480
491
  end
481
492
 
493
+ # def erb_replace_ampersands!(filename = nil)
494
+ #
495
+ # return if filename.nil?
496
+ # file = File.open(filename, "r")
497
+ # contents = file.read
498
+ # file.close
499
+ #
500
+ # file = File.open(filename, "w")
501
+ # file.write( contents.gsub('\%', '%'))
502
+ # file.close
503
+ # end
504
+
482
505
 
483
506
 
484
507
 
485
508
 
486
509
  def copy_view_files
487
510
  return if @specs_only
488
- haml_views.each do |view|
511
+ all_views.each do |view|
489
512
  formats.each do |format|
490
- filename = cc_filename_with_extensions(view, "haml")
491
- template filename, File.join("#{'spec/dummy/' if Rails.env.test?}app/views#{namespace_with_dash}", controller_file_path, filename)
513
+ source_filename = cc_filename_with_extensions("#{@markup}/#{view}", "#{@markup}")
514
+ dest_filename = cc_filename_with_extensions("#{view}", "#{@markup}")
515
+ dest_filepath = File.join("#{'spec/dummy/' if Rails.env.test?}app/views#{namespace_with_dash}",
516
+ controller_file_path, dest_filename)
517
+
518
+
519
+ template source_filename, dest_filepath
520
+ gsub_file dest_filepath, '\%', '%'
521
+
492
522
  end
493
523
  end
494
524
 
495
525
  turbo_stream_views.each do |view|
496
526
  formats.each do |format|
497
- filename = cc_filename_with_extensions(view, 'turbo_stream.haml')
498
- template filename, File.join("#{'spec/dummy/' if Rails.env.test?}app/views#{namespace_with_dash}", controller_file_path, filename)
527
+ source_filename = cc_filename_with_extensions( "#{@markup}/#{view}.turbo_stream.#{@markup}")
528
+ dest_filename = cc_filename_with_extensions("#{view}", "turbo_stream.#{@markup}")
529
+ dest_filepath = File.join("#{'spec/dummy/' if Rails.env.test?}app/views#{namespace_with_dash}",
530
+ controller_file_path, dest_filename)
531
+
532
+
533
+ template source_filename, dest_filepath
534
+ gsub_file dest_filepath, '\%', '%'
535
+
499
536
  end
500
537
  end
501
538
  end
@@ -516,7 +553,7 @@ module HotGlue
516
553
  end
517
554
  end
518
555
 
519
- def haml_views
556
+ def all_views
520
557
  res = %w(index edit _form _line _list _show _errors)
521
558
 
522
559
  unless @no_create
@@ -548,180 +585,23 @@ module HotGlue
548
585
  end
549
586
 
550
587
  def all_form_fields
551
- col_identifier = " .col"
552
- col_spaces_prepend = " "
553
-
554
- res = @columns.map { |col|
555
-
556
- if @show_only.include?(col)
557
-
558
- "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
559
- = @#{singular}.#{col.to_s}
560
- %label.form-text
561
- #{col.to_s.humanize}\n"
562
- else
563
-
564
-
565
- type = eval("#{singular_class}.columns_hash['#{col}']").type
566
- limit = eval("#{singular_class}.columns_hash['#{col}']").limit
567
- sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
568
-
569
- case type
570
- when :integer
571
- # look for a belongs_to on this object
572
- if col.to_s.ends_with?("_id")
573
- assoc_name = col.to_s.gsub("_id","")
574
- assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
575
- if assoc.nil?
576
- exit_message= "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
577
- exit
578
- end
579
- display_column = derrive_reference_name(assoc.class_name)
580
-
581
-
582
- "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{assoc_name.to_s})}\"}
583
- #{col_spaces_prepend}= f.collection_select(:#{col.to_s}, #{assoc.class_name}.all, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col.to_s} }, class: 'form-control')
584
- #{col_spaces_prepend}%label.small.form-text.text-muted
585
- #{col_spaces_prepend} #{col.to_s.humanize}"
586
-
587
- else
588
- "#{col_identifier}{class: \"form-group \#{'alert-danger' if @#{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
589
- #{col_spaces_prepend}= f.text_field :#{col.to_s}, value: #{singular}.#{col.to_s}, class: 'form-control', size: 4, type: 'number'
590
- #{col_spaces_prepend}%label.form-text
591
- #{col_spaces_prepend} #{col.to_s.humanize}\n"
592
- end
593
- when :string
594
- limit ||= 256
595
- if limit <= 256
596
- field_output(col, nil, limit, col_identifier)
597
- else
598
- text_area_output(col, limit, col_identifier)
599
- end
600
-
601
- when :text
602
- limit ||= 256
603
- if limit <= 256
604
- field_output(col, nil, limit, col_identifier)
605
- else
606
- text_area_output(col, limit, col_identifier)
607
- end
608
- when :float
609
- limit ||= 256
610
- field_output(col, nil, limit, col_identifier)
611
-
612
-
613
- when :datetime
614
- "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
615
- #{col_spaces_prepend}= datetime_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
616
- when :date
617
- "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
618
- #{col_spaces_prepend}= date_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
619
- when :time
620
- "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
621
- #{col_spaces_prepend}= time_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
622
- when :boolean
623
- "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
624
- #{col_spaces_prepend}%span
625
- #{col_spaces_prepend} #{col.to_s.humanize}
626
- #{col_spaces_prepend}= f.radio_button(:#{col.to_s}, '0', checked: #{singular}.#{col.to_s} ? '' : 'checked')
627
- #{col_spaces_prepend}= f.label(:#{col.to_s}, value: 'No', for: '#{singular}_#{col.to_s}_0')
628
-
629
- #{col_spaces_prepend}= f.radio_button(:#{col.to_s}, '1', checked: #{singular}.#{col.to_s} ? 'checked' : '')
630
- #{col_spaces_prepend}= f.label(:#{col.to_s}, value: 'Yes', for: '#{singular}_#{col.to_s}_1')
631
- "
632
- end
633
- end
634
- }.join("\n")
635
- return res
588
+ @template_builder.all_form_fields(
589
+ columns: @columns,
590
+ show_only: @show_only,
591
+ singular_class: singular_class,
592
+ singular: singular
593
+ )
636
594
  end
637
595
 
638
-
639
596
  def all_line_fields
640
- columns = @columns.count + 1
641
- perc_width = (100/columns).floor
642
-
643
- col_identifer = ".col"
644
- @columns.map { |col|
645
- type = eval("#{singular_class}.columns_hash['#{col}']").type
646
- limit = eval("#{singular_class}.columns_hash['#{col}']").limit
647
- sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
648
-
649
- case type
650
- when :integer
651
- # look for a belongs_to on this object
652
- if col.to_s.ends_with?("_id")
653
-
654
- assoc_name = col.to_s.gsub("_id","")
655
-
656
-
657
- assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
658
-
659
- if assoc.nil?
660
- exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
661
- raise(HotGlue::Error,exit_message)
662
- end
663
-
664
- display_column = derrive_reference_name(assoc.class_name)
665
-
666
-
667
- "#{col_identifer}
668
- = #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe"
669
-
670
- else
671
- "#{col_identifer}
672
- = #{singular}.#{col}"
673
- end
674
- when :float
675
- width = (limit && limit < 40) ? limit : (40)
676
- "#{col_identifer}
677
- = #{singular}.#{col}"
678
-
679
- when :string
680
- width = (limit && limit < 40) ? limit : (40)
681
- "#{col_identifer}
682
- = #{singular}.#{col}"
683
- when :text
684
- "#{col_identifer}
685
- = #{singular}.#{col}"
686
- when :datetime
687
- "#{col_identifer}
688
- - unless #{singular}.#{col}.nil?
689
- = #{singular}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone)
690
- - else
691
- %span.alert-danger
692
- MISSING
693
- "
694
- when :date
695
- ".cell
696
- - unless #{singular}.#{col}.nil?
697
- = #{singular}.#{col}
698
- - else
699
- %span.alert-danger
700
- MISSING
701
- "
702
- when :time
703
- "#{col_identifer}
704
- - unless #{singular}.#{col}.nil?
705
- = #{singular}.#{col}.in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone)
706
- - else
707
- %span.alert-danger
708
- MISSING
709
- "
710
- when :boolean
711
- "#{col_identifer}
712
- - if #{singular}.#{col}.nil?
713
- %span.alert-danger
714
- MISSING
715
- - elsif #{singular}.#{col}
716
- YES
717
- - else
718
- NO
719
- "
720
- end
721
- }.join("\n")
597
+ @template_builder.all_line_fields(
598
+ columns: @columns,
599
+ show_only: @show_only,
600
+ singular_class: singular_class,
601
+ singular: singular
602
+ )
722
603
  end
723
604
 
724
-
725
605
  def controller_descends_from
726
606
  if defined?(@namespace.titlecase + "::BaseController")
727
607
  @namespace.titlecase + "::BaseController"
@@ -774,13 +654,19 @@ module HotGlue
774
654
  end
775
655
  end
776
656
 
657
+ def paginate
658
+ @template_builder.paginate(plural: plural)
659
+ end
777
660
 
778
-
779
- def paginate
780
- "- if #{plural}.respond_to?(:total_pages)
781
- = paginate #{plural}"
661
+ def delete_confirmation_syntax
662
+ if !@stimulus_syntax
663
+ "{confirm: 'Are you sure?'}"
664
+ else
665
+ "{controller: 'confirmable', 'confirm-message': \"Are you sure you want to delete \#{ @#{@singular}.#{ display_class } } \", 'action': 'confirmation#confirm'}"
666
+ end
782
667
  end
783
668
 
669
+
784
670
  private # thor does something fancy like sending the class all of its own methods during some strange run sequence
785
671
  # does not like public methods
786
672
 
@@ -788,7 +674,6 @@ module HotGlue
788
674
  [name, file_format].compact.join(".")
789
675
  end
790
676
  end
791
-
792
677
  end
793
678
 
794
679
 
@@ -1,6 +1,11 @@
1
1
  class <%= controller_class_name %> < <%= controller_descends_from %>
2
2
  <% unless @auth_identifier == '' || @auth.nil? %>before_action :authenticate_<%= @auth_identifier %>!<% end %>
3
3
 
4
+ <% if any_nested? %><% nest_chain = [] %> <% @nested_args.each { |arg|
5
+ this_scope = nest_chain.empty? ? "#{@auth ? auth_object : class_name}.#{arg}s" : "#{nest_chain.last}.#{arg}s"
6
+ nest_chain << arg %>
7
+ before_action :<%= arg %>
8
+ <% } %><% end %>
4
9
  before_action :load_<%= singular_name %>, only: [:show, :edit, :update, :destroy]
5
10
  helper :hot_glue
6
11
  include HotGlue::ControllerHelper
@@ -9,9 +14,16 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
9
14
  # TODO: implement current_user or use Devise
10
15
  <% end %>
11
16
 
17
+
18
+
12
19
  <% if any_nested? %><% nest_chain = [] %> <% @nested_args.each { |arg|
13
- this_scope = nest_chain.empty? ? "#{@auth ? auth_object : class_name}.#{arg}s" : "#{nest_chain.last}.#{arg}s"
14
- nest_chain << arg %>
20
+ if !@god
21
+ this_scope = nest_chain.empty? ? "#{@auth ? auth_object : class_name}.#{arg}s" : "#{nest_chain.last}.#{arg}s"
22
+ else
23
+ this_scope = eval(class_name + ".reflect_on_association(:#{arg})").class_name
24
+ end
25
+ nest_chain << arg
26
+ %>
15
27
  def <%= arg %>
16
28
  @<%= arg %> ||= <%= this_scope %>.find(params[:<%= arg %>_id])
17
29
  end<% } %><% end %>
@@ -56,7 +68,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
56
68
  load_all_<%= plural %>
57
69
  respond_to do |format|
58
70
  format.turbo_stream
59
- format.html { redirect_to <%= plural %>_path }
71
+ format.html { redirect_to <%= path_helper_plural %> }
60
72
  end
61
73
  else
62
74
  flash[:alert] = "Oops, your <%= singular_name %> could not be created."
@@ -101,7 +113,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
101
113
  load_all_<%= plural %>
102
114
  respond_to do |format|
103
115
  format.turbo_stream
104
- format.html { redirect_to <%= plural %>_path }
116
+ format.html { redirect_to <%= path_helper_plural %> }
105
117
  end
106
118
  end<% end %>
107
119
 
@@ -0,0 +1,11 @@
1
+ <\%= turbo_frame_tag "errors" do %>
2
+ <\% if resource.errors.any? %>
3
+ <div id="error_explanation">
4
+ <\% resource.errors.full_messages.each do |message| %>
5
+ <div class="alert alert-danger">
6
+ <\%= message %>
7
+ </div>
8
+ <\% end %>
9
+ </div>
10
+ <\% end %>
11
+ <\% end %>
@@ -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 %>
@@ -0,0 +1,8 @@
1
+ <div class="row">
2
+ <%= all_form_fields %>
3
+
4
+ <div class="col">
5
+ <\%= link_to "Cancel", <%= path_helper_plural %>, {class: "btn btn-secondary"} %>
6
+ <\%= f.submit "Save", class: "btn btn-primary pull-right" %>
7
+ </div>
8
+ </div>
@@ -0,0 +1,10 @@
1
+
2
+ <\%= turbo_frame_tag "<%= singular %>__#{ <%= singular %>.id }" do %>
3
+ <div class='row' data-id='<\%= <%= singular %>.id %>' data-edit='false'>
4
+ <\%= render partial: '<%= show_path_partial %>', locals: { <%= singular %>: <%= singular %>} %>
5
+ </div>
6
+ <\% end %>
7
+
8
+
9
+
10
+