hot-glue 0.5.15 → 0.5.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a4b8f9da30750e8df7e69820c0bd934c0f8b16080bb21f5e5412d49c773dd28
4
- data.tar.gz: 66b8fa328ca3f96f12e13c7df2f6006a730ff635078dd7e109d0d42467985502
3
+ metadata.gz: 61d066f183e4a0563768d26589b1fcf140c4867ea540458fea8e084ef3903b03
4
+ data.tar.gz: 32361a4068d3b9808f2d9caa2a9e1c22d484e1c23d3196fdde6e0939d6b6ce60
5
5
  SHA512:
6
- metadata.gz: 45e3e6d56cf8125b67383f68985888a8d131cf2a68643d41e1015f3298b7a0175ff6752a790daed42db151f59b36f567e53b1f293240f393a64498730ee123bd
7
- data.tar.gz: 82c3d1439c5333da6f0427994de3d962a0767453432cc1edd25b7df27532c4e264b033421eb2ff8a3bb2885a1882d6495f58141eceafc3ac04848dda4f240f63
6
+ metadata.gz: 3ca1797468a13ade3f508d5fb8fc8799532bc9ec010ff0adffad7702bc569c42d6eb5926ee6682474d8b9ea3f4aeadaabe7e721a5ce3dc03996573767d04ff1c
7
+ data.tar.gz: 7ec34f2f77fa45740e521ec867bec02c712cbd80f4f91a59a8011a76f10e5595ea91bdf3cb3c48770d8959606b7d9a6424ad13d0f0aa2e80fa7821000e66d272
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hot-glue (0.5.14)
4
+ hot-glue (0.5.15)
5
5
  ffaker (~> 2.16)
6
6
  kaminari (~> 1.2)
7
7
  rails (> 5.1)
@@ -139,7 +139,7 @@ GEM
139
139
  mini_mime (1.1.2)
140
140
  mini_portile2 (2.8.4)
141
141
  minitest (5.16.3)
142
- net-imap (0.3.4)
142
+ net-imap (0.3.7)
143
143
  date
144
144
  net-protocol
145
145
  net-pop (0.1.2)
@@ -235,7 +235,7 @@ GEM
235
235
  stimulus-rails (1.1.1)
236
236
  railties (>= 6.0.0)
237
237
  thor (1.2.1)
238
- timeout (0.3.2)
238
+ timeout (0.4.0)
239
239
  turbo-rails (1.3.2)
240
240
  actionpack (>= 6.0.0)
241
241
  activejob (>= 6.0.0)
@@ -245,7 +245,7 @@ GEM
245
245
  warden (1.2.9)
246
246
  rack (>= 2.0.9)
247
247
  websocket (1.2.9)
248
- websocket-driver (0.7.5)
248
+ websocket-driver (0.7.6)
249
249
  websocket-extensions (>= 0.1.0)
250
250
  websocket-extensions (0.1.5)
251
251
  xpath (3.2.0)
data/README.md CHANGED
@@ -605,9 +605,7 @@ With Hot Glue in specified grouping or smart layout mode, it automatically attem
605
605
 
606
606
  Using Bootstrap with neither specified grouping nor smart layouts may make more than 12 columns, which will produce strange results. (Bootstrap is not designed to work with, for example, a 13-column layout.)
607
607
 
608
- You should typically either specify your grouping or use smart layouts when building with Bootstrap, but if your use case does not fit the stacking feature you can specify neither flag and then you may then have to deal with the over-stuffed layouts as explained.
609
-
610
-
608
+ You should typically either specify your grouping or use smart layouts when building with Bootstrap, but if your use case does not fit the stacking feature you can specify neither flag and then you may then have to deal with the over-stuffed layouts as explained.
611
609
 
612
610
  ### `--smart-layout` (also known as automatic grouping)
613
611
 
@@ -656,6 +654,26 @@ IMPORTANT: By default, all fields that begin with an underscore (`_`) are automa
656
654
 
657
655
  This is for fields you want globally non-editable by users in your app. For example, a counter cache or other field set only by a backend mechanism.
658
656
 
657
+ ### `--modify=field1{...},field2{...}`
658
+
659
+
660
+ You can apply modification to the viewable (non-edit) display of field using the `--modify` switch.
661
+
662
+ The syntax is `--modify=cost{$},price{$}`
663
+
664
+ Here, the `cost` and `price` fields will be displayed as wrapped in `number_to_currency()` when displayed on the list view and when displayed as show-only.
665
+
666
+ (You will need to separately specify them as show-only if you want them to be non-editable.)
667
+
668
+ The availabel modifiers are:
669
+
670
+ | modifier | what it does | can be used on | | |
671
+ |---------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------|---|---|
672
+ | $ | wraps output in `number_to_currency()` | float, integer | | |
673
+ | truthy label\|falsy label | specify a binary switch with a pipe (\|) character if the value is truthy, it will display as "truthy label" if the value is falsy, it will display as "falsy label" | boolean, datetime, date, time | | |
674
+ | | | | | |
675
+
676
+
659
677
 
660
678
  ### `--update-show-only`
661
679
  (separate field names by COMMA)
@@ -1253,6 +1271,10 @@ end
1253
1271
 
1254
1272
  # VERSION HISTORY
1255
1273
 
1274
+ #### 2023-08-17 - v0.5.16
1275
+
1276
+ - Adds `--modidy` flag to turn numbers into currency and apply binary labels (see docs for `--modify` flag)
1277
+
1256
1278
  #### 2023-08-11 - v0.5.15
1257
1279
 
1258
1280
  - When using big edit, updating a child will now re-render the parent EDIT record automatically.
@@ -1263,7 +1285,6 @@ For example
1263
1285
 
1264
1286
  Whenever the line item is created, updated, or destroyed, the parent invoice record gets (edit action) re-rendered automatically. This happens for the big edit screen of the invoice.
1265
1287
 
1266
-
1267
1288
  - Refactors fields into polymoric objects
1268
1289
 
1269
1290
  - Adds test coverage for Postgres Enums
@@ -57,6 +57,7 @@ class FieldFactory
57
57
  singular: generator.singular,
58
58
  update_show_only: generator.update_show_only,
59
59
  attachment_data: generator.attachments[name.to_sym],
60
- sample_file_path: generator.sample_file_path)
60
+ sample_file_path: generator.sample_file_path,
61
+ modify: generator.modify[name.to_sym] || nil )
61
62
  end
62
63
  end
@@ -8,7 +8,7 @@ class AssociationField < Field
8
8
  def initialize(name: , class_name: , alt_lookups: , singular: , update_show_only: ,
9
9
  hawk_keys: , auth: , sample_file_path:, ownership_field: ,
10
10
  attachment_data: nil , layout_strategy: , form_placeholder_labels: nil,
11
- form_labels_position: )
11
+ form_labels_position:, modify: )
12
12
  super
13
13
 
14
14
  @assoc_model = eval("#{class_name}.reflect_on_association(:#{assoc})")
@@ -2,7 +2,7 @@ class AttachmentField < Field
2
2
  attr_accessor :attachment_data
3
3
  def initialize(name:, class_name:, alt_lookups:, singular:, update_show_only:, hawk_keys:, auth:,
4
4
  sample_file_path: nil, attachment_data:, ownership_field:, layout_strategy: ,
5
- form_placeholder_labels: , form_labels_position:)
5
+ form_placeholder_labels: , form_labels_position:, modify: )
6
6
  super
7
7
 
8
8
  @attachment_data = attachment_data
@@ -13,27 +13,36 @@ class BooleanField < Field
13
13
  end
14
14
 
15
15
  def spec_list_view_assertion
16
- " " + ["expect(page).to have_content(#{singular}#{1}.#{name} ? 'YES' : 'NO')"].join("\n ")
16
+ ["expect(page).to have_content(#{singular}#{1}.#{name} ? 'YES' : 'NO')"].join("\n ")
17
17
  end
18
18
 
19
19
 
20
20
  def form_field_output
21
21
  (form_labels_position == 'before' ? " <br />" : "") +
22
22
  " <%= f.radio_button(:#{name}, '0', checked: #{singular}.#{name} ? '' : 'checked') %>\n" +
23
- " <%= f.label(:#{name}, value: 'No', for: '#{singular}_#{name}_0') %>\n" +
24
- " <%= f.radio_button(:#{name}, '1', checked: #{singular}.#{name} ? 'checked' : '') %>\n" +
25
- " <%= f.label(:#{name}, value: 'Yes', for: '#{singular}_#{name}_1') %>\n" +
23
+ " <%= f.label(:#{name}, value: '#{modify_binary? && modify[:binary][:falsy] || 'No'}', for: '#{singular}_#{name}_0') %>\n" +
24
+ " <br /> <%= f.radio_button(:#{name}, '1', checked: #{singular}.#{name} ? 'checked' : '') %>\n" +
25
+ " <%= f.label(:#{name}, value: '#{modify_binary? && modify[:binary][:truthy] || 'Yes'}', for: '#{singular}_#{name}_1') %>\n" +
26
26
  (form_labels_position == 'after' ? " <br />" : "")
27
27
  end
28
28
 
29
29
  def line_field_output
30
- "
31
- <% if #{singular}.#{name}.nil? %>
30
+ if modify_binary?
31
+ "<% if #{singular}.#{name}.nil? %>
32
+ <span class='alert-danger'>MISSING</span>
33
+ <% elsif #{singular}.#{name} %>
34
+ #{modify[:binary][:truthy]}
35
+ <% else %>
36
+ #{modify[:binary][:falsy]}
37
+ <% end %>"
38
+ else
39
+ "<% if #{singular}.#{name}.nil? %>
32
40
  <span class='alert-danger'>MISSING</span>
33
41
  <% elsif #{singular}.#{name} %>
34
42
  YES
35
43
  <% else %>
36
44
  NO
37
45
  <% end %>"
46
+ end
38
47
  end
39
48
  end
@@ -10,7 +10,11 @@ class DateTimeField < Field
10
10
  end
11
11
 
12
12
  def spec_make_assertion
13
- "expect(page).to have_content(new_#{name}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone))"
13
+ if !modify_binary?
14
+ "expect(page).to have_content(new_#{name}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone))"
15
+ else
16
+ "expect(page).to have_content('#{modify[:binary][:truthy]}'"
17
+ end
14
18
  end
15
19
 
16
20
  def spec_setup_let_arg
@@ -18,6 +22,14 @@ class DateTimeField < Field
18
22
  end
19
23
 
20
24
  def spec_list_view_assertion
25
+ if modify_binary?
26
+ "expect(page).to have_content('#{modify[:binary][:truthy]}')"
27
+ else
28
+ spec_list_view_natural_assertion
29
+ end
30
+ end
31
+
32
+ def spec_list_view_natural_assertion
21
33
  "expect(page).to have_content(#{singular}#{1}.#{name}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ').gsub(' ', ' ') + timezonize(current_timezone) )"
22
34
  end
23
35
 
@@ -26,10 +38,14 @@ class DateTimeField < Field
26
38
  end
27
39
 
28
40
  def line_field_output
29
- "<% unless #{singular}.#{name}.nil? %>
41
+ if modify_binary?
42
+ modified_display_output
43
+ else
44
+ "<% unless #{singular}.#{name}.nil? %>
30
45
  <%= #{singular}.#{name}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone) %>
31
46
  <% else %>
32
47
  <span class='alert-danger'>MISSING</span>
33
48
  <% end %>"
49
+ end
34
50
  end
35
51
  end
@@ -1,16 +1,26 @@
1
1
  class Field
2
- attr_accessor :name, :object, :singular_class, :class_name, :singular,
2
+ attr_accessor :assoc_model, :assoc_name, :assoc_class, :associations, :alt_lookups, :auth,
3
+ :assoc_label, :class_name, :form_placeholder_labels, :form_labels_position,
4
+ :hawk_keys, :layout_strategy, :limit, :modify, :name, :object, :sample_file_path,
5
+ :singular_class, :singular, :sql_type, :ownership_field,
3
6
  :update_show_only
4
- attr_accessor :assoc_model, :assoc_name, :assoc_class, :associations, :alt_lookups, :assoc_label
5
-
6
- attr_accessor :hawk_keys, :auth, :sample_file_path, :form_placeholder_labels, :ownership_field,
7
- :sql_type, :limit, :layout_strategy, :form_labels_position
8
-
9
- def initialize(name: , class_name: , alt_lookups: , singular: , update_show_only: , form_labels_position:,
10
- form_placeholder_labels: ,
11
- auth: , ownership_field: , hawk_keys: nil, layout_strategy: ,
12
- sample_file_path: nil, attachment_data: nil )
13
7
 
8
+ def initialize(
9
+ auth: ,
10
+ alt_lookups: ,
11
+ attachment_data: nil,
12
+ class_name: ,
13
+ form_labels_position:,
14
+ form_placeholder_labels: ,
15
+ hawk_keys: nil,
16
+ layout_strategy: ,
17
+ modify: ,
18
+ name: ,
19
+ ownership_field: ,
20
+ sample_file_path: nil,
21
+ singular: ,
22
+ update_show_only:
23
+ )
14
24
  @name = name
15
25
  @layout_strategy = layout_strategy
16
26
  @alt_lookups = alt_lookups
@@ -23,7 +33,7 @@ class Field
23
33
  @form_placeholder_labels = form_placeholder_labels
24
34
  @ownership_field = ownership_field
25
35
  @form_labels_position = form_labels_position
26
-
36
+ @modify = modify
27
37
 
28
38
  # TODO: remove knowledge of subclasses from Field
29
39
  unless self.class == AttachmentField
@@ -52,28 +62,59 @@ class Field
52
62
  ""
53
63
  end
54
64
 
65
+
55
66
  def spec_make_assertion
56
- "expect(page).to have_content(new_#{name})"
67
+ if !modify_binary?
68
+ "expect(page).to have_content(new_#{name})"
69
+ else
70
+ "expect(page).to have_content('#{modify[:binary][:truthy]}'"
71
+ end
57
72
  end
58
73
 
74
+
59
75
  def spec_setup_let_arg
60
76
 
61
77
  end
62
78
 
63
- def spec_list_view_assertion
79
+ def spec_list_view_natural_assertion
64
80
  "expect(page).to have_content(#{singular}#{1}.#{name})"
65
81
  end
66
82
 
83
+ def spec_list_view_assertion
84
+ if modify_binary?
85
+ "expect(page).to have_content('#{modify[:binary][:truthy]}'"
86
+ else
87
+ spec_list_view_natural_assertion
88
+ end
89
+ end
90
+
91
+
67
92
  def spec_related_column_lets
68
93
  ""
69
94
  end
70
95
 
96
+ def line_field_output
97
+ viewable_output
98
+ end
99
+
71
100
  def form_show_only_output
72
- "<%= #{singular}.#{name} %>"
101
+ viewable_output
73
102
  end
74
103
 
75
- def line_field_output
76
- "<%= #{singular}.#{name} %>"
104
+ def viewable_output
105
+ if modify
106
+ modified_display_output
107
+ else
108
+ "<%= #{singular}.#{name} %>"
109
+ end
110
+ end
111
+
112
+ def modified_display_output
113
+ if modify[:cast] && modify[:cast] == "$"
114
+ "<%= number_to_currency(#{singular}.#{name}) %>"
115
+ elsif modify[:binary]
116
+ "<%= #{singular}.#{name} ? '#{modify[:binary][:truthy]}' : '#{modify[:binary][:falsy]}' %>"
117
+ end
77
118
  end
78
119
 
79
120
  def field_output(type = nil, width )
@@ -85,7 +126,10 @@ class Field
85
126
  if lines > 5
86
127
  lines = 5
87
128
  end
88
-
89
129
  "<%= f.text_area :#{name}, class: 'form-control', autocomplete: 'off', cols: 40, rows: '#{lines}'" + ( form_placeholder_labels ? ", placeholder: '#{name.to_s.humanize}'" : "") + " %>"
90
130
  end
131
+
132
+ def modify_binary? # safe
133
+ !!(modify && modify[:binary])
134
+ end
91
135
  end
@@ -5,6 +5,7 @@ class FloatField < Field
5
5
 
6
6
  end
7
7
 
8
+
8
9
  def spec_setup_let_arg
9
10
  "#{name}: rand(1)*10000"
10
11
  end
@@ -13,8 +14,9 @@ class FloatField < Field
13
14
  field_output(nil, 5)
14
15
  end
15
16
 
16
- def line_field_output
17
- width = (limit && limit < 40) ? limit : (40)
18
- "<%= #{singular}.#{name}%>"
19
- end
17
+ # def line_field_output
18
+ # width = (limit && limit < 40) ? limit : (40)
19
+ #
20
+ # "<%= #{singular}.#{name} %>"
21
+ # end
20
22
  end
@@ -16,6 +16,7 @@ module HotGlue
16
16
 
17
17
  @generator = generator
18
18
 
19
+ @modify = generator.modify
19
20
  @columns = generator.columns
20
21
  @smart_layout = generator.smart_layout
21
22
  @stacked_downnesting = generator.stacked_downnesting || false
@@ -39,7 +40,8 @@ module HotGlue
39
40
  portals: {
40
41
 
41
42
  },
42
- buttons: { size: @buttons_width}
43
+ buttons: { size: @buttons_width},
44
+ modify: @modify
43
45
  }
44
46
 
45
47
  # downnest_object.each do |child, size|
@@ -68,7 +70,7 @@ module HotGlue
68
70
  raise "Cannot build layout -- too few columns"
69
71
  end
70
72
 
71
- # smart layout: bootstrap_column_width columns per field; 4 column for EACH downnested portals, 2 column for buttons
73
+ # smart layout: bootstrap_column_width columns per field; 4 column for EACH downnested portal, 2 column for buttons
72
74
  if smart_layout
73
75
  # automatic control
74
76
  #
@@ -1,4 +1,3 @@
1
-
2
1
  require 'rails/generators/erb/scaffold/scaffold_generator'
3
2
  require_relative './default_config_loader'
4
3
  require 'ffaker'
@@ -12,23 +11,15 @@ require_relative './layout_strategy/bootstrap'
12
11
  require_relative './layout_strategy/hot_glue'
13
12
  require_relative './layout_strategy/tailwind'
14
13
 
15
-
16
-
17
14
  class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
18
15
  include DefaultConfigLoader
19
16
  hook_for :form_builder, :as => :scaffold
20
17
 
21
18
  source_root File.expand_path('templates', __dir__)
22
- attr_accessor :alt_lookups, :attachments, :auth,
23
- :big_edit, :bootstrap_column_width,
24
- :columns,
25
- :downnest_children, :downnest_object,
26
- :button_icons,
27
- :hawk_keys, :layout_object,
28
- :nest_with,
29
- :path, :plural,
30
- :sample_file_path, :singular, :singular_class, :smart_layout,
31
- :stacked_downnesting, :update_show_only, :ownership_field,
19
+ attr_accessor :alt_lookups, :attachments, :auth, :big_edit, :button_icons, :bootstrap_column_width, :columns,
20
+ :downnest_children, :downnest_object, :hawk_keys, :layout_object, :modify,
21
+ :nest_with, :path, :plural, :sample_file_path, :show_only_data, :singular,
22
+ :singular_class, :smart_layout, :stacked_downnesting, :update_show_only, :ownership_field,
32
23
  :layout_strategy, :form_placeholder_labels, :form_labels_position
33
24
 
34
25
  class_option :singular, type: :string, default: nil
@@ -77,7 +68,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
77
68
 
78
69
  # determines if the labels show up BEFORE or AFTER on the NEW/EDIT (form)
79
70
  class_option :form_labels_position, type: :string, default: 'after' # choices are before, after, omit
80
- class_option :form_placeholder_labels, type: :boolean, default: false # puts the field names into the placeholder labels
71
+ class_option :form_placeholder_labels, type: :boolean, default: false # puts the field names into the placeholder labels
81
72
 
82
73
  # determines if labels appear within the rows of the VIEWABLE list (does NOT affect the list heading)
83
74
  class_option :inline_list_labels, default: 'omit' # choices are before, after, omit
@@ -85,8 +76,9 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
85
76
  class_option :alt_foreign_key_lookup, default: '' #
86
77
  class_option :attachments, default: ''
87
78
  class_option :stacked_downnesting, default: false
88
- class_option :bootstrap_column_width, default: nil #must be nil to detect if user has not passed
79
+ class_option :bootstrap_column_width, default: nil # must be nil to detect if user has not passed
89
80
  class_option :button_icons, default: nil
81
+ class_option :modify, default: {}
90
82
 
91
83
  def initialize(*meta_args)
92
84
  super
@@ -102,17 +94,16 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
102
94
  @meta_args = meta_args
103
95
 
104
96
  if options['specs_only'] && options['no_specs']
105
- 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. Aborting.")
97
+ 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. Aborting.")
106
98
  end
107
99
 
108
100
  if !options['exclude'].empty? && !options['include'].empty?
109
- exit_message = "*** Oops: You seem to have specified both --include and --exclude. Please use one or the other. Aborting."
101
+ exit_message = "*** Oops: You seem to have specified both --include and --exclude. Please use one or the other. Aborting."
110
102
  puts exit_message
111
103
 
112
104
  raise(HotGlue::Error, exit_message)
113
105
  end
114
106
 
115
-
116
107
  if @stimulus_syntax.nil?
117
108
  @stimulus_syntax = true
118
109
  end
@@ -122,7 +113,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
122
113
  raise(HotGlue::Error, message)
123
114
  end
124
115
 
125
- @markup = get_default_from_config(key: :markup)
116
+ @markup = get_default_from_config(key: :markup)
126
117
  @sample_file_path = get_default_from_config(key: :sample_file_path)
127
118
  @bootstrap_column_width ||= get_default_from_config(key: :bootstrap_column_width) || 2
128
119
 
@@ -157,13 +148,13 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
157
148
 
158
149
  @plural = options['plural'] || @singular.pluralize # respects what you set in inflections.rb, to override, use plural option
159
150
  @namespace = options['namespace'] || nil
160
- use_controller_name = plural.titleize.gsub(" ", "")
161
- @controller_build_name = (( @namespace.titleize.gsub(" ","") + "::" if @namespace) || "") + use_controller_name + "Controller"
151
+ use_controller_name = plural.titleize.gsub(" ", "")
152
+ @controller_build_name = ((@namespace.titleize.gsub(" ", "") + "::" if @namespace) || "") + use_controller_name + "Controller"
162
153
  @controller_build_folder = use_controller_name.underscore
163
154
  @controller_build_folder_singular = singular
164
155
 
165
156
  @auth = options['auth'] || "current_user"
166
- @auth_identifier = options['auth_identifier'] || (! @god && @auth.gsub("current_", "")) || nil
157
+ @auth_identifier = options['auth_identifier'] || (!@god && @auth.gsub("current_", "")) || nil
167
158
 
168
159
  if options['nest']
169
160
  raise HotGlue::Error, "STOP: the flag --nest has been replaced with --nested; please re-run using the --nested flag"
@@ -180,20 +171,48 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
180
171
  @include_fields = []
181
172
 
182
173
  # semicolon to denote layout columns; commas separate fields
183
- @include_fields += options['include'].split(":").collect{|x|x.split(",")}.flatten.collect(&:to_sym)
174
+ @include_fields += options['include'].split(":").collect { |x| x.split(",") }.flatten.collect(&:to_sym)
184
175
  end
185
176
 
186
- @show_only = []
187
- if !options['show_only'].empty?
188
- @show_only += options['show_only'].split(",").collect(&:to_sym)
177
+ # @show_only_data = {}
178
+ # if !options['show_only'].empty?
179
+ # show_only_input = options['show_only'].split(",")
180
+ # show_only_input.each do |setting|
181
+ # if setting.include?("[")
182
+ # setting =~ /(.*)\[(.*)\]/
183
+ # key, lookup_as = $1, $2
184
+ # @show_only_data[key.to_sym] = {cast: $2 }
185
+ # else
186
+ # @show_only_data[setting.to_sym] = {cast: nil}
187
+ # end
188
+ # end
189
+ # end
190
+
191
+ @show_only = options['show_only'].split(",").collect(&:to_sym)
192
+ if @show_only.any?
193
+ puts "show only field #{@show_only}}"
189
194
  end
190
195
 
196
+ @modify = {}
197
+ if !options['modify'].empty?
198
+ modify_input = options['modify'].split(",")
199
+ modify_input.each do |setting|
200
+ setting =~ /(.*){(.*)}/
201
+ key, lookup_as = $1, $2
202
+
203
+ if ["$"].include?($2)
204
+ @modify[key.to_sym] = {cast: $2}
205
+ elsif $2.include?("|")
206
+ binary = $2.split("|")
207
+ @modify[key.to_sym] = {binary: {truthy: binary[0], falsy: binary[1]}}
208
+ end
209
+ end
210
+ end
191
211
  @update_show_only = []
192
212
  if !options['update_show_only'].empty?
193
213
  @update_show_only += options['update_show_only'].split(",").collect(&:to_sym)
194
214
  end
195
215
 
196
-
197
216
  # syntax should be xyz_id{xyz_email},abc_id{abc_email}
198
217
  # instead of a drop-down for the foreign entity, a text field will be presented
199
218
  # You must ALSO use a factory that contains a parameter of the same name as the 'value' (for example, `xyz_email`)
@@ -203,48 +222,40 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
203
222
  @alt_foreign_key_lookup = alt_lookups_entry.each do |setting|
204
223
  setting =~ /(.*){(.*)}/
205
224
  key, lookup_as = $1, $2
206
- assoc = eval("#{class_name}.reflect_on_association(:#{key.to_s.gsub("_id","")}).class_name")
225
+ assoc = eval("#{class_name}.reflect_on_association(:#{key.to_s.gsub("_id", "")}).class_name")
207
226
 
208
- data = {lookup_as: lookup_as.gsub("+",""),
209
- assoc: assoc,
210
- with_create: lookup_as.include?("+")}
227
+ data = { lookup_as: lookup_as.gsub("+", ""),
228
+ assoc: assoc,
229
+ with_create: lookup_as.include?("+") }
211
230
  @alt_lookups[key] = data
212
231
  end
213
232
 
214
233
  puts "------ ALT LOOKUPS for #{@alt_lookups}"
215
234
 
216
- @update_alt_lookups = @alt_lookups.collect{|key, value|
235
+ @update_alt_lookups = @alt_lookups.collect { |key, value|
217
236
  @update_show_only.include?(key) ?
218
- { key: value }
219
- : nil}.compact
237
+ { key: value }
238
+ : nil }.compact
220
239
 
221
- @label = options['label'] || ( eval("#{class_name}.class_variable_defined?(:@@table_label_singular)") ? eval("#{class_name}.class_variable_get(:@@table_label_singular)") : singular.gsub("_", " ").titleize )
222
- @list_label_heading = options['list_label_heading'] || ( eval("#{class_name}.class_variable_defined?(:@@table_label_plural)") ? eval("#{class_name}.class_variable_get(:@@table_label_plural)") : plural.gsub("_", " ").upcase )
240
+ @label = options['label'] || (eval("#{class_name}.class_variable_defined?(:@@table_label_singular)") ? eval("#{class_name}.class_variable_get(:@@table_label_singular)") : singular.gsub("_", " ").titleize)
241
+ @list_label_heading = options['list_label_heading'] || (eval("#{class_name}.class_variable_defined?(:@@table_label_plural)") ? eval("#{class_name}.class_variable_get(:@@table_label_plural)") : plural.gsub("_", " ").upcase)
223
242
 
224
- @new_button_label = options['new_button_label'] || ( eval("#{class_name}.class_variable_defined?(:@@table_label_singular)") ? "New " + eval("#{class_name}.class_variable_get(:@@table_label_singular)") : "New " + singular.gsub("_", " ").titleize )
243
+ @new_button_label = options['new_button_label'] || (eval("#{class_name}.class_variable_defined?(:@@table_label_singular)") ? "New " + eval("#{class_name}.class_variable_get(:@@table_label_singular)") : "New " + singular.gsub("_", " ").titleize)
225
244
  @new_form_heading = options['new_form_heading'] || "New #{@label}"
226
245
 
227
-
228
-
229
246
  setup_hawk_keys
230
247
  @form_placeholder_labels = options['form_placeholder_labels'] # true or false
231
- @inline_list_labels = options['inline_list_labels'] || 'omit' # 'before','after','omit'
232
-
248
+ @inline_list_labels = options['inline_list_labels'] || 'omit' # 'before','after','omit'
233
249
 
234
250
  @form_labels_position = options['form_labels_position']
235
- if !['before','after','omit'].include?(@form_labels_position)
251
+ if !['before', 'after', 'omit'].include?(@form_labels_position)
236
252
  raise HotGlue::Error, "You passed '#{@form_labels_position}' as the setting for --form-labels-position but the only allowed options are before, after (default), and omit"
237
253
  end
238
254
 
239
- if !['before','after','omit'].include?(@inline_list_labels)
255
+ if !['before', 'after', 'omit'].include?(@inline_list_labels)
240
256
  raise HotGlue::Error, "You passed '#{@inline_list_labels}' as the setting for --inline-list-labels but the only allowed options are before, after, and omit (default)"
241
257
  end
242
258
 
243
-
244
-
245
-
246
-
247
-
248
259
  @god = options['god'] || options['gd'] || false
249
260
  @specs_only = options['specs_only'] || false
250
261
 
@@ -261,9 +272,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
261
272
  @no_list_heading = options['no_list_heading'] || false
262
273
  @stacked_downnesting = options['stacked_downnesting']
263
274
 
264
-
265
-
266
-
267
275
  @display_list_after_update = options['display_list_after_update'] || false
268
276
  @smart_layout = options['smart_layout']
269
277
 
@@ -277,7 +285,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
277
285
  @downnest_children = [] # TODO: defactor @downnest_children in favor of downnest_object
278
286
  @downnest_object = {}
279
287
  if @downnest
280
- @downnest_children = @downnest.split(",").map{|child| child.gsub("+","")}
288
+ @downnest_children = @downnest.split(",").map { |child| child.gsub("+", "") }
281
289
  @downnest_object = HotGlue.construct_downnest_object(@downnest)
282
290
  end
283
291
 
@@ -300,7 +308,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
300
308
  @magic_buttons = options['magic_buttons'].split(',')
301
309
  end
302
310
 
303
-
304
311
  @small_buttons = options['small_buttons'] || false
305
312
 
306
313
  @build_update_action = !@no_edit || !@magic_buttons.empty?
@@ -311,7 +318,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
311
318
  @ujs_syntax = !defined?(Turbo::Engine)
312
319
  end
313
320
 
314
-
315
321
  # NEST CHAIN
316
322
  # new syntax
317
323
  # @nested_set = [
@@ -322,10 +328,10 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
322
328
  # }]
323
329
  @nested_set = []
324
330
 
325
- if ! @nested.nil?
331
+ if !@nested.nil?
326
332
  @nested_set = @nested.split("/").collect { |arg|
327
333
  is_optional = arg.start_with?("~")
328
- arg.gsub!("~","")
334
+ arg.gsub!("~", "")
329
335
  {
330
336
  singular: arg,
331
337
  plural: arg.pluralize,
@@ -343,8 +349,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
343
349
  @object_owner_optional = false
344
350
  @object_owner_name = @auth.gsub("current_", "").to_s
345
351
 
346
-
347
- elsif @auth && ! @self_auth && @nested_set.none? && !@auth.include?(".")
352
+ elsif @auth && !@self_auth && @nested_set.none? && !@auth.include?(".")
348
353
  @object_owner_sym = @auth.gsub("current_", "").to_sym
349
354
  @object_owner_eval = @auth
350
355
  @object_owner_optional = false
@@ -365,12 +370,11 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
365
370
  end
366
371
  end
367
372
 
368
-
369
373
  @factory_creation = options['factory_creation'].gsub(";", "\n")
370
374
  identify_object_owner
371
375
  setup_fields
372
376
 
373
- if (@columns - @show_only - (@ownership_field ? [@ownership_field.to_sym] : [])).empty?
377
+ if (@columns - @show_only - (@ownership_field ? [@ownership_field.to_sym] : [])).empty?
374
378
  @no_field_form = true
375
379
  end
376
380
 
@@ -380,7 +384,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
380
384
  @associations = []
381
385
  @columns_map = {}
382
386
  @columns.each do |col|
383
- if !(@the_object.columns_hash.keys.include?(col.to_s) || @attachments.keys.include?(col))
387
+ if !(@the_object.columns_hash.keys.include?(col.to_s) || @attachments.keys.include?(col))
384
388
  raise "couldn't find #{col} in either field list or attachments list"
385
389
  end
386
390
 
@@ -389,7 +393,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
389
393
  end
390
394
 
391
395
  if @the_object.columns_hash.keys.include?(col.to_s)
392
- type = @the_object.columns_hash[col.to_s].type
396
+ type = @the_object.columns_hash[col.to_s].type
393
397
  elsif @attachments.keys.include?(col)
394
398
  type = :attachment
395
399
  end
@@ -404,7 +408,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
404
408
  end
405
409
 
406
410
  # create the template object
407
- if @markup == "erb"
411
+ if @markup == "erb"
408
412
  @template_builder = HotGlue::ErbTemplate.new(
409
413
  layout_strategy: @layout_strategy,
410
414
  magic_buttons: @magic_buttons,
@@ -422,26 +426,22 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
422
426
  attachments: @attachments,
423
427
  columns_map: @columns_map
424
428
  )
425
- elsif @markup == "slim"
426
- raise(HotGlue::Error, "SLIM IS NOT IMPLEMENTED")
427
- elsif @markup == "haml"
428
- raise(HotGlue::Error, "HAML IS NOT IMPLEMENTED")
429
+ elsif @markup == "slim"
430
+ raise(HotGlue::Error, "SLIM IS NOT IMPLEMENTED")
431
+ elsif @markup == "haml"
432
+ raise(HotGlue::Error, "HAML IS NOT IMPLEMENTED")
429
433
  end
430
434
 
431
435
  builder = HotGlue::Layout::Builder.new(generator: self,
432
- include_setting: options['include'],
433
- buttons_width: buttons_width )
436
+ include_setting: options['include'],
437
+ buttons_width: buttons_width)
434
438
  @layout_object = builder.construct
435
439
 
436
-
437
-
438
440
  @menu_file_exists = true if @nested_set.none? && File.exist?("#{Rails.root}/app/views/#{namespace_with_trailing_dash}_menu.#{@markup}")
439
441
 
440
442
  @turbo_streams = !!options['with_turbo_streams']
441
443
  end
442
444
 
443
-
444
-
445
445
  def setup_hawk_keys
446
446
  @hawk_keys = {}
447
447
 
@@ -458,9 +458,9 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
458
458
  end
459
459
 
460
460
  hawk_scope = key.gsub("_id", "").pluralize
461
- optional = eval(singular_class + ".reflect_on_association(:#{key.gsub('_id','')})").options[:optional]
461
+ optional = eval(singular_class + ".reflect_on_association(:#{key.gsub('_id', '')})").options[:optional]
462
462
 
463
- @hawk_keys[key.to_sym] = {bind_to: [hawk_to], optional: optional}
463
+ @hawk_keys[key.to_sym] = { bind_to: [hawk_to], optional: optional }
464
464
  use_shorthand = !options["hawk"].include?("{")
465
465
 
466
466
  if use_shorthand # only include the hawk scope if using the shorthand
@@ -473,7 +473,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
473
473
  end
474
474
  end
475
475
 
476
-
477
476
  def setup_attachments
478
477
  @attachments = {}
479
478
 
@@ -538,7 +537,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
538
537
 
539
538
  direct_upload = nil
540
539
  field_for_original_filename = nil
541
- dropzone = nil
540
+ dropzone = nil
542
541
  end
543
542
 
544
543
  if thumbnail && !eval("#{singular_class}.reflect_on_attachment(:#{key}).variants.include?(:#{thumbnail})")
@@ -549,11 +548,10 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
549
548
  "
550
549
  end
551
550
 
552
-
553
- @attachments[key.to_sym] = {thumbnail: thumbnail,
554
- field_for_original_filename: field_for_original_filename,
555
- direct_upload: direct_upload,
556
- dropzone: dropzone}
551
+ @attachments[key.to_sym] = { thumbnail: thumbnail,
552
+ field_for_original_filename: field_for_original_filename,
553
+ direct_upload: direct_upload,
554
+ dropzone: dropzone }
557
555
  end
558
556
 
559
557
  puts "ATTACHMENTS: #{@attachments}"
@@ -561,15 +559,15 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
561
559
  end
562
560
 
563
561
  def identify_object_owner
564
- auth_assoc = @auth && @auth.gsub("current_","")
562
+ auth_assoc = @auth && @auth.gsub("current_", "")
565
563
 
566
- if @object_owner_sym && ! @self_auth
564
+ if @object_owner_sym && !@self_auth
567
565
  auth_assoc_field = auth_assoc + "_id" unless @god
568
566
  assoc = eval("#{singular_class}.reflect_on_association(:#{@object_owner_sym})")
569
567
 
570
568
  if assoc
571
569
  @ownership_field = assoc.name.to_s + "_id"
572
- elsif ! @nested_set.any?
570
+ elsif !@nested_set.any?
573
571
  exit_message = "*** Oops: It looks like is no association `#{@object_owner_sym}` from the object #{@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."
574
572
  raise(HotGlue::Error, exit_message)
575
573
 
@@ -582,7 +580,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
582
580
 
583
581
  raise(HotGlue::Error, exit_message)
584
582
  end
585
- elsif @object_owner_sym && ! @object_owner_eval.include?(".")
583
+ elsif @object_owner_sym && !@object_owner_eval.include?(".")
586
584
  @ownership_field = @object_owner_name + "_id"
587
585
  end
588
586
  end
@@ -595,18 +593,16 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
595
593
  :confirmation_token, :confirmed_at,
596
594
  :confirmation_sent_at, :unconfirmed_email
597
595
 
598
- @exclude_fields.push( @ownership_field.to_sym ) if ! @ownership_field.nil?
599
-
600
-
601
- @columns = @the_object.columns.map(&:name).map(&:to_sym).reject{|field| @exclude_fields.include?(field) }
596
+ @exclude_fields.push(@ownership_field.to_sym) if !@ownership_field.nil?
602
597
 
598
+ @columns = @the_object.columns.map(&:name).map(&:to_sym).reject { |field| @exclude_fields.include?(field) }
603
599
 
604
600
  else
605
- @columns = @the_object.columns.map(&:name).map(&:to_sym).reject{|field| !@include_fields.include?(field) }
601
+ @columns = @the_object.columns.map(&:name).map(&:to_sym).reject { |field| !@include_fields.include?(field) }
606
602
  end
607
603
 
608
604
  if @attachments.any?
609
- puts "adding attachments-as-columns: #{@attachments}"
605
+ puts "Adding attachments-as-columns: #{@attachments}"
610
606
  @attachments.keys.each do |attachment|
611
607
  @columns << attachment if !@columns.include?(attachment)
612
608
  end
@@ -615,21 +611,16 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
615
611
  end
616
612
  end
617
613
 
618
-
619
-
620
-
621
-
622
-
623
614
  def check_if_sample_file_is_present
624
615
  if sample_file_path.nil?
625
616
  puts "you have no sample file path set in config/hot_glue.yml"
626
617
  settings = File.read("config/hot_glue.yml")
627
618
  @sample_file_path = "spec/files/computer_code.jpg"
628
619
  added_setting = ":sample_file_path: #{sample_file_path}"
629
- File.open("config/hot_glue.yml", "w") { |f| f.write settings + "\n" + added_setting }
620
+ File.open("config/hot_glue.yml", "w") { |f| f.write settings + "\n" + added_setting }
630
621
 
631
622
  puts "adding `#{added_setting}` to config/hot_glue.yml"
632
- elsif ! File.exist?(sample_file_path)
623
+ elsif !File.exist?(sample_file_path)
633
624
  puts "NO SAMPLE FILE FOUND: adding sample file at #{sample_file_path}"
634
625
  template "computer_code.jpg", File.join("#{filepath_prefix}spec/files/", "computer_code.jpg")
635
626
  end
@@ -638,11 +629,11 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
638
629
  end
639
630
 
640
631
  def fields_filtered_for_email_lookups
641
- @columns.reject{|c| @alt_lookups.keys.include?(c) } + @alt_lookups.values.map{|v| ("__lookup_#{v[:lookup_as]}").to_sym}
632
+ @columns.reject { |c| @alt_lookups.keys.include?(c) } + @alt_lookups.values.map { |v| ("__lookup_#{v[:lookup_as]}").to_sym }
642
633
  end
643
634
 
644
635
  def creation_syntax
645
- merge_with = @alt_lookups.collect{ |key, data|
636
+ merge_with = @alt_lookups.collect { |key, data|
646
637
  "#{data[:assoc].downcase}: #{data[:assoc].downcase}_factory.#{data[:assoc].downcase}"
647
638
  }.join(", ")
648
639
 
@@ -686,14 +677,14 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
686
677
  unless @no_specs
687
678
  dest_file = File.join("#{filepath_prefix}spec/features#{namespace_with_dash}", "#{plural}_behavior_spec.rb")
688
679
 
689
- if File.exist?(dest_file)
680
+ if File.exist?(dest_file)
690
681
  existing_file = File.open(dest_file)
691
682
  existing_content = existing_file.read
692
683
  if existing_content =~ /\#HOTGLUE-SAVESTART/
693
- if existing_content !~ /\#HOTGLUE-END/
684
+ if existing_content !~ /\#HOTGLUE-END/
694
685
  raise "Your file at #{dest_file} contains a #HOTGLUE-SAVESTART marker without #HOTGLUE-END"
695
686
  end
696
- @existing_content = existing_content[(existing_content =~ /\#HOTGLUE-SAVESTART/) .. (existing_content =~ /\#HOTGLUE-END/)-1]
687
+ @existing_content = existing_content[(existing_content =~ /\#HOTGLUE-SAVESTART/)..(existing_content =~ /\#HOTGLUE-END/) - 1]
697
688
  @existing_content << "#HOTGLUE-END"
698
689
 
699
690
  end
@@ -702,7 +693,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
702
693
  @existing_content = " #HOTGLUE-SAVESTART\n #HOTGLUE-END"
703
694
  end
704
695
 
705
-
706
696
  template "system_spec.rb.erb", dest_file
707
697
  end
708
698
 
@@ -716,7 +706,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
716
706
  end
717
707
 
718
708
  def testing_name
719
- singular_class.gsub("::","_").underscore
709
+ singular_class.gsub("::", "_").underscore
720
710
  end
721
711
 
722
712
  def spec_related_column_lets
@@ -735,7 +725,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
735
725
  end
736
726
 
737
727
  def columns_spec_with_sample_data
738
- @columns_map.map { |col, col_object|
728
+ @columns_map.map { |col, col_object|
739
729
  unless col_object.is_a?(AssociationField)
740
730
  random_data = col_object.spec_random_data
741
731
  col.to_s + ": '" + random_data.to_s + "'"
@@ -744,14 +734,14 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
744
734
  end
745
735
 
746
736
  def regenerate_me_code
747
- "rails generate hot_glue:scaffold #{ @meta_args[0][0] } #{@meta_args[1].collect{|x| x.gsub(/\s*=\s*([\S\s]+)/, '=\'\1\'')}.join(" ")}"
737
+ "rails generate hot_glue:scaffold #{ @meta_args[0][0] } #{@meta_args[1].collect { |x| x.gsub(/\s*=\s*([\S\s]+)/, '=\'\1\'') }.join(" ")}"
748
738
  end
749
739
 
750
740
  def object_parent_mapping_as_argument_for_specs
751
741
 
752
742
  if @self_auth
753
743
  ""
754
- elsif @nested_set.any? && ! @nested_set.last[:optional]
744
+ elsif @nested_set.any? && !@nested_set.last[:optional]
755
745
  ", " + @nested_set.last[:singular] + ": " + @nested_set.last[:singular]
756
746
  elsif @auth && !@god
757
747
  ", #{@auth_identifier}: #{@auth}"
@@ -772,7 +762,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
772
762
  end
773
763
 
774
764
  def objest_nest_params_by_id_for_specs
775
- @nested_set.map{|arg|
765
+ @nested_set.map { |arg|
776
766
  "#{arg[:singular]}_id: #{arg[:singular]}.id"
777
767
  }.join(",\n ")
778
768
  end
@@ -790,8 +780,8 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
790
780
  end
791
781
 
792
782
  def capybara_make_updates(which_partial = :create)
793
- @columns_map.map { | col, col_obj|
794
- show_only_list = which_partial == :create ? @show_only : (@update_show_only+@show_only)
783
+ @columns_map.map { |col, col_obj|
784
+ show_only_list = which_partial == :create ? @show_only : (@update_show_only + @show_only)
795
785
 
796
786
  if show_only_list.include?(col)
797
787
  " page.should have_no_selector(:css, \"[name='#{testing_name}[#{ col.to_s }]'\")"
@@ -803,7 +793,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
803
793
 
804
794
  def path_helper_args
805
795
  if @nested_set.any? && @nested
806
- [(@nested_set).collect{|a| "#{a[:singular]}"} , singular].join(",")
796
+ [(@nested_set).collect { |a| "#{a[:singular]}" }, singular].join(",")
807
797
  else
808
798
  singular
809
799
  end
@@ -811,9 +801,9 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
811
801
 
812
802
  def path_helper_singular
813
803
  if @nested
814
- "#{@namespace+"_" if @namespace}#{(@nested_set.collect{|x| x[:singular]}.join("_") + "_" if @nested_set.any?)}#{@controller_build_folder_singular}_path"
804
+ "#{@namespace + "_" if @namespace}#{(@nested_set.collect { |x| x[:singular] }.join("_") + "_" if @nested_set.any?)}#{@controller_build_folder_singular}_path"
815
805
  else
816
- "#{@namespace+"_" if @namespace}#{@controller_build_folder_singular}_path"
806
+ "#{@namespace + "_" if @namespace}#{@controller_build_folder_singular}_path"
817
807
  end
818
808
  end
819
809
 
@@ -840,7 +830,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
840
830
  top_level: true)
841
831
  end
842
832
 
843
-
844
833
  def delete_path_helper
845
834
  HotGlue.optionalized_ternary(namespace: @namespace,
846
835
  target: @singular,
@@ -867,15 +856,15 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
867
856
  end
868
857
 
869
858
  def line_path_partial
870
- "#{@namespace+"/" if @namespace}#{@controller_build_folder}/line"
859
+ "#{@namespace + "/" if @namespace}#{@controller_build_folder}/line"
871
860
  end
872
861
 
873
862
  def show_path_partial
874
- "#{@namespace+"/" if @namespace}#{@controller_build_folder}/show"
863
+ "#{@namespace + "/" if @namespace}#{@controller_build_folder}/show"
875
864
  end
876
865
 
877
866
  def list_path_partial
878
- "#{@namespace+"/" if @namespace}#{@controller_build_folder}/list"
867
+ "#{@namespace + "/" if @namespace}#{@controller_build_folder}/list"
879
868
  end
880
869
 
881
870
  def new_path_name
@@ -888,11 +877,11 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
888
877
 
889
878
  def nested_assignments
890
879
  return "" if @nested_set.none?
891
- @nested_set.map{|a| "#{a}: #{a}"}.join(", ") #metaprgramming into Ruby hash
880
+ @nested_set.map { |a| "#{a}: #{a}" }.join(", ") # metaprgramming into Ruby hash
892
881
  end
893
882
 
894
883
  def nested_assignments_top_level # this is by accessing the instance variable-- only use at top level
895
- @nested_set.map{|a| "#{a[:singular]}"}.join(", ") #metaprgramming into Ruby hash
884
+ @nested_set.map { |a| "#{a[:singular]}" }.join(", ") # metaprgramming into Ruby hash
896
885
  end
897
886
 
898
887
  def nest_assignments_operator(top_level = false, leading_comma = false)
@@ -908,11 +897,11 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
908
897
  end
909
898
 
910
899
  def nested_objects_arity
911
- @nested_set.map{|a| "@#{a[:singular]}"}.join(", ")
900
+ @nested_set.map { |a| "@#{a[:singular]}" }.join(", ")
912
901
  end
913
902
 
914
903
  def nested_arity_for_path
915
- [@nested_set[0..-1].collect{|a| "@#{a[:singular]}"}].join(", ") #metaprgramming into arity for the Rails path helper
904
+ [@nested_set[0..-1].collect { |a| "@#{a[:singular]}" }].join(", ") # metaprgramming into arity for the Rails path helper
916
905
  end
917
906
 
918
907
  def object_scope
@@ -958,7 +947,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
958
947
  end
959
948
 
960
949
  def no_devise_installed
961
- !Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }['devise']
950
+ !Gem::Specification.sort_by { |g| [g.name.downcase, g.version] }.group_by { |g| g.name }['devise']
962
951
  end
963
952
 
964
953
  def magic_button_output
@@ -989,27 +978,24 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
989
978
  source_filename = cc_filename_with_extensions("#{@markup}/#{view}", "#{@markup}")
990
979
  dest_filename = cc_filename_with_extensions("#{view}", "#{@markup}")
991
980
 
992
-
993
981
  dest_filepath = File.join("#{filepath_prefix}app/views#{namespace_with_dash}",
994
982
  @controller_build_folder, dest_filename)
995
983
 
996
-
997
984
  template source_filename, dest_filepath
998
- gsub_file dest_filepath, '\%', '%'
985
+ gsub_file dest_filepath, '\%', '%'
999
986
 
1000
987
  end
1001
988
  end
1002
989
 
1003
990
  turbo_stream_views.each do |view|
1004
991
  formats.each do |format|
1005
- source_filename = cc_filename_with_extensions( "#{@markup}/#{view}.turbo_stream.#{@markup}")
992
+ source_filename = cc_filename_with_extensions("#{@markup}/#{view}.turbo_stream.#{@markup}")
1006
993
  dest_filename = cc_filename_with_extensions("#{view}", "turbo_stream.#{@markup}")
1007
994
  dest_filepath = File.join("#{filepath_prefix}app/views#{namespace_with_dash}",
1008
995
  @controller_build_folder, dest_filename)
1009
996
 
1010
-
1011
997
  template source_filename, dest_filepath
1012
- gsub_file dest_filepath, '\%', '%'
998
+ gsub_file dest_filepath, '\%', '%'
1013
999
 
1014
1000
  end
1015
1001
  end
@@ -1022,7 +1008,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1022
1008
  dest_filename = cc_filename_with_extensions("#{singular_class.underscore}", "rb")
1023
1009
  dest_filepath = File.join("#{filepath_prefix}app/models", dest_filename)
1024
1010
 
1025
-
1026
1011
  puts "appending turbo callbacks to #{dest_filepath}"
1027
1012
 
1028
1013
  text = File.read(dest_filepath)
@@ -1034,7 +1019,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1034
1019
  append_text << " after_update_commit lambda { broadcast_replace_to self, target: \"#{@namespace}__\#{dom_id(self)}\", partial: \"#{@namespace}/#{@plural}/line\" }\n after_destroy_commit lambda { broadcast_remove_to self, target: \"#{@namespace}__\#{dom_id(self)}\"}\n"
1035
1020
 
1036
1021
  replace = text.gsub(/class #{singular_class} < ApplicationRecord/, append_text)
1037
- File.open(dest_filepath, "w") {|file| file.puts replace}
1022
+ File.open(dest_filepath, "w") { |file| file.puts replace }
1038
1023
  end
1039
1024
  end
1040
1025
 
@@ -1051,7 +1036,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1051
1036
  end
1052
1037
 
1053
1038
  def all_views
1054
- res = %w(index _line _list _show)
1039
+ res = %w(index _line _list _show)
1055
1040
 
1056
1041
  unless @no_create
1057
1042
  res += %w(new _new_form _new_button)
@@ -1061,7 +1046,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1061
1046
  res += %w{edit _edit}
1062
1047
  end
1063
1048
 
1064
- if !( @no_edit && @no_create)
1049
+ if !(@no_edit && @no_create)
1065
1050
  res << '_form'
1066
1051
  end
1067
1052
  res
@@ -1113,7 +1098,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1113
1098
  def all_line_fields
1114
1099
  @template_builder.all_line_fields(
1115
1100
  col_identifier: @layout_strategy.column_classes_for_line_fields,
1116
- perc_width: @layout_strategy.each_col, #undefined method `each_col'
1101
+ perc_width: @layout_strategy.each_col, # undefined method `each_col'
1117
1102
  layout_strategy: @layout_strategy,
1118
1103
  layout_object: @layout_object
1119
1104
  )
@@ -1172,7 +1157,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1172
1157
  end
1173
1158
 
1174
1159
  def controller_magic_button_update_actions
1175
- @magic_buttons.collect{ |magic_button|
1160
+ @magic_buttons.collect { |magic_button|
1176
1161
  " if #{singular}_params[:#{magic_button}]
1177
1162
  begin
1178
1163
  res = @#{singular}.#{magic_button}!
@@ -1187,15 +1172,14 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1187
1172
  }.join("\n") + "\n"
1188
1173
  end
1189
1174
 
1190
-
1191
1175
  def controller_update_params_tap_away_magic_buttons
1192
- @magic_buttons.collect{ |magic_button|
1176
+ @magic_buttons.collect { |magic_button|
1193
1177
  ".tap{ |ary| ary.delete('__#{magic_button}') }"
1194
1178
  }.join("")
1195
1179
  end
1196
1180
 
1197
1181
  def controller_update_params_tap_away_alt_lookups
1198
- @alt_lookups.collect{ |key, data|
1182
+ @alt_lookups.collect { |key, data|
1199
1183
  ".tap{ |ary| ary.delete('__lookup_#{data[:lookup_as]}') }"
1200
1184
  }.join("")
1201
1185
  end
@@ -1210,7 +1194,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1210
1194
 
1211
1195
  def n_plus_one_includes
1212
1196
  if @associations.any? || @attachments.any?
1213
- ".includes(" + (@associations.map{|x| x} + @attachments.collect{|k,v| "#{k}_attachment"}).map{|x| ":#{x.to_s}"}.join(", ") + ")"
1197
+ ".includes(" + (@associations.map { |x| x } + @attachments.collect { |k, v| "#{k}_attachment" }).map { |x| ":#{x.to_s}" }.join(", ") + ")"
1214
1198
  else
1215
1199
  ""
1216
1200
  end
@@ -1222,7 +1206,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1222
1206
  if @nested_set.none?
1223
1207
  "\"\""
1224
1208
  else
1225
- @nested_set.collect{|arg|
1209
+ @nested_set.collect { |arg|
1226
1210
  "(((\"__#{arg[:singular]}-\#{" + "@" + arg[:singular] + ".id}\") if @" + arg[:singular] + ") || \"\")"
1227
1211
  }.join(" + ")
1228
1212
  end
@@ -1234,7 +1218,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1234
1218
  if @nested_set.none?
1235
1219
  ""
1236
1220
  else
1237
- ", \n nested_for: \"" + @nested_set.collect{|a| "#{a[:singular]}-" + '#{' + instance_symbol + a[:singular] + ".id}"}.join("__") + "\""
1221
+ ", \n nested_for: \"" + @nested_set.collect { |a| "#{a[:singular]}-" + '#{' + instance_symbol + a[:singular] + ".id}" }.join("__") + "\""
1238
1222
  end
1239
1223
  end
1240
1224
 
@@ -1245,23 +1229,23 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1245
1229
  end
1246
1230
 
1247
1231
  def hawk_to_ruby
1248
- res = @hawk_keys.collect{ |k,v|
1232
+ res = @hawk_keys.collect { |k, v|
1249
1233
  "#{k.to_s}: [#{v[:bind_to].join(".")}]"
1250
1234
  }.join(", ")
1251
1235
  res
1252
1236
  end
1253
1237
 
1254
1238
  def controller_attachment_orig_filename_pickup_syntax
1255
- @attachments.collect{ |key, attachment| "\n" + " modified_params[:#{ attachment[:field_for_original_filename] }] = #{singular}_params['#{ key }'].original_filename" if attachment[:field_for_original_filename] }.compact.join("\n")
1239
+ @attachments.collect { |key, attachment| "\n" + " modified_params[:#{ attachment[:field_for_original_filename] }] = #{singular}_params['#{ key }'].original_filename" if attachment[:field_for_original_filename] }.compact.join("\n")
1256
1240
  end
1257
1241
 
1258
1242
  def any_datetime_fields?
1259
- (@columns - @attachments.keys.collect(&:to_sym)).collect{|col| eval("#{singular_class}.columns_hash['#{col}']").type}.include?(:datetime)
1243
+ (@columns - @attachments.keys.collect(&:to_sym)).collect { |col| eval("#{singular_class}.columns_hash['#{col}']").type }.include?(:datetime)
1260
1244
  end
1261
1245
 
1262
1246
  def post_action_parental_updates
1263
1247
  if @nested_set.any?
1264
- "\n" + @nested_set.collect{ |data|
1248
+ "\n" + @nested_set.collect { |data|
1265
1249
  parent = data[:singular]
1266
1250
  "@#{singular}.#{parent}.reload"
1267
1251
  }.join("\n")
@@ -1269,7 +1253,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1269
1253
  end
1270
1254
 
1271
1255
  def turbo_parental_updates
1272
- @nested_set.collect{| data|
1256
+ @nested_set.collect { |data|
1273
1257
  "<%= turbo_stream.replace \"#{@namespace + '__' if @namespace}\#{dom_id(@#{data[:singular]})}\" do %>
1274
1258
  <%= render partial: \"#{@namespace}/#{data[:plural]}/edit\", locals: {#{data[:singular]}: @#{singular}.#{data[:singular]}.reload} %>
1275
1259
  <% end %>"
@@ -6,7 +6,7 @@
6
6
 
7
7
  <h2>Editing <\%= @<%= @singular %>.<%= display_class %> %></h2>
8
8
  <\%= form_with model: <%= "@" + singular %>, url: <%= form_path_edit_helper %> do |f| %>
9
- <\%= render partial: "form", locals: {:<%= singular %> => <%= "@" + singular%>, f: f}<%= @nested_set.collect{|arg| ".merge(@#{arg[:singular]} ? {#{arg[:singular]}: @#{arg[:singular]}} : {})" }.join %> \%>
9
+ <\%= render partial: "<%= namespace_with_trailing_dash + @controller_build_folder + "/" %>form", locals: {:<%= singular %> => <%= "@" + singular%>, f: f}<%= @nested_set.collect{|arg| ".merge(@#{arg[:singular]} ? {#{arg[:singular]}: @#{arg[:singular]}} : {})" }.join %> \%>
10
10
  <\% end %>
11
11
  </div>
12
12
  <\% end %>
@@ -1,5 +1,5 @@
1
1
  module HotGlue
2
2
  class Version
3
- CURRENT = '0.5.15'
3
+ CURRENT = '0.5.16'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hot-glue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.15
4
+ version: 0.5.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Fleetwood-Boldt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-11 00:00:00.000000000 Z
11
+ date: 2023-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails