hot-glue 0.6.31 → 0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd6bfe4a874a5e894d6b315e72c145f1a563ac3a851e2d4849e41eb127b4402f
4
- data.tar.gz: d88aeb4540484a0335150c0d637a8781b1781ff33b227cd65b60d96fa13703ac
3
+ metadata.gz: c823d274b52531414bbf843d1f44ccd364400ab9c736405a74b1cc5793774b48
4
+ data.tar.gz: 52d175d729d5b57c063da43bb7b7cb2940ea334be16e99637ade700ddaa2593a
5
5
  SHA512:
6
- metadata.gz: 16e4242488830bb7b4da394a9e6e919b32ef885ddf5ce506e05954ca5830b918a47b2662661289d0bf4adbb6b3e4bf5d89fdb2ddbb59f9333126622461fabb81
7
- data.tar.gz: 9ac25352156d69caf694303602f968990441cded93504d6fc340df1b92091bb450f6372d409c10ba2be8a0599e1217e5d037e053b908c2b5136bad148f7719cb
6
+ metadata.gz: a1c8b8309b61f0ddbb1f27ca3a73bde4e8349f13fb114c6f3f5dcc15343dcc597fa4fbdd11476c1456d38c772cfe29b61d7ca4bee7d79ad421592227cf305d49
7
+ data.tar.gz: 9b915be8972458f2fee1163e00c9f6c58a6ddf74ec829da2449989f3a5640597d16efb93c5ede4ea449bc786714997f511d3830a584029ff33222c6cef4d626e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hot-glue (0.6.30)
4
+ hot-glue (0.7)
5
5
  ffaker (~> 2.16)
6
6
  rails (> 5.1)
7
7
 
data/README.md CHANGED
@@ -655,7 +655,16 @@ If you specify an include list, it will be treated as a whitelist: no fields wil
655
655
 
656
656
  You may not specify both include and exclude.
657
657
 
658
- Include setting is affected by both specified grouping mode and smart layouts, explained below.
658
+ Many options allow you to specify fields in multiple modes:
659
+ • Standard
660
+ • Smart layout
661
+ • Specified grouping
662
+
663
+ see "Layout & Manipulation features" for details on how to build your `--include` statement, including how to use `:` and `,`
664
+
665
+ Also review Omitted Fields (`-` and `=`), Dynamic Blocks (`**`), Omitted Dynamic Blocks (`**-` and `**=`)
666
+
667
+ Also see Set Column Widths ( `(` ... `)` ) to set the column widths explicitly in your `--include`
659
668
 
660
669
 
661
670
  ### `--exclude=`
@@ -665,7 +674,6 @@ By default, all fields are included unless they are on the default exclude list.
665
674
 
666
675
  If you specify any exclude list, those excluded **and** the default exclude list will be excluded. (If you need any of the fields on the default exclude list, you must use `--include` instead.)
667
676
 
668
-
669
677
  `./bin/rails generate hot_glue:scaffold Account --exclude=password`
670
678
 
671
679
 
@@ -1059,10 +1067,72 @@ This is what would happen if 9 fields, specified in the order A,B,C,D,E,F,G,H,I,
1059
1067
  (If you had a number of fields that wasn't easily divisible by the number of columns, it would leave the final column one or a few fields short of the others.)
1060
1068
 
1061
1069
 
1062
- ### `--new-button-position` (above, below; default: above)
1063
- Show the new button above or below the list.
1064
1070
 
1071
+ ### Omitted fields
1072
+
1073
+ Note that these additions all affect how you write your `--include` setting, but they operate in addition to all of the field visibility rules above. Notice that omitting a form means we by design omit it on both the new and edit actions. If you want to determine if it shows up on new vs. edit granularly, use a different approach.
1074
+
1075
+ Generally, you will only omit a field in special cases. To omit a field, prefix either `-` (omit on list) or `=` to omit on form (new & edit), like so :
1076
+
1077
+ `--include=-abd,=dfg`
1078
+
1079
+ Here, the abc field will be omitted on the list and the dfg will be omitted on the form (new & edit)
1080
+
1081
+
1082
+ This works for any include setting type, whether the grouping mode is specified or not.
1083
+
1084
+ `--include=-abd,=dfg`
1085
+ `--include=-abd:=dfg` # same as above but builder will use specified grouping mode
1086
+
1087
+ ### Dynamic Blocks
1088
+
1089
+ Next, you can now dynamically pull any partials from the view folder (of the name of your choosing) into your object's field display- before, between, or after any part of the column groupings using the `:` and `,` characters. (Review specified grouping mode in "Layout & Manipulation Features.")
1090
+
1091
+ You simply make up any partial name, treat it as if it is one of the fields in the field list, and prefix it with `**`. (When specified, don't use `_` but remember to use the `_` in the file name.)
1092
+
1093
+ It looks like this (let's assume I've made an arbitrary partial called `_jello.erb` in my build folder, which expects to be passed a `thing` local variable)
1094
+
1095
+ `rails generate hot_glue:scaffold Thing --include='**jello:name:birthday:gender'`
1096
+
1097
+ Here, you'll get four columns:
1098
+
1099
+ The first column will pull a partial from the same folder being built. You build this partial, not Hot Glue.
1100
+
1101
+ ```
1102
+ <%= render partial: 'jello', locals: {thing: thing } %>
1103
+ ```
1104
+
1105
+ (Remember, the partial file name begins with `_` but is referenced without the underscore)
1106
+
1107
+ Because you separated that first column using `:` from the other three, the partial will take up the whole column.
1108
+ The next 3 columns will contain name, birthday & gender, respectively.
1109
+
1110
+ If you specify it this way:
1111
+ rails generate hot_glue:scaffold Thing --include='**jello,name:birthday:gender'
1112
+
1113
+ Notice that between **jello and name is now a comma, putting the jello partial and name into the same column. Now the partial will be displayed before the name in that column.
1114
+
1115
+ You can mix & match any number of partials inserted anywhere into the field layout.
1116
+
1117
+
1118
+ ### Omitted Dynamic Blocks
1119
+
1120
+ Dynamic blocks respond to the new `-` and `=` settings for omitting fields the same way fields do. Prefixing a dynamic partial with `**-` will mean it will be omitted from the list, and `**=` will omit it from the form (new & edit)
1121
+
1122
+ This way, the omitted syntax is parallel to the dynamic block structure. No other tye-in is made with the other field visibility settings.
1123
+
1124
+
1125
+ ### Set Column Widths
1126
+
1127
+ In other modes, Hot Glue decides how many bootstrap columns each column should span, defaulting to 2 unless using `--smart-layout`, in which case it ranges from 2 to 5 depending on how many fields you have. Generally, I start my scaffolds using either standard or smart, but soon, I'm often upgrading to specified grouping mode for fine-grained control.
1065
1128
 
1129
+ When using specified group mode (activated when a `:` character appears in the `--include` list), you can append to the end of EACH COLUMN (not each field) a parenthetical setting for the number of bootstrap columns.
1130
+
1131
+ (When the setting includes this special character, you'll need `'` to wrap the entire setting for `--include` on the command line.)
1132
+
1133
+
1134
+ ### `--new-button-position` (above, below; default: above)
1135
+ Show the new button above or below the list.
1066
1136
 
1067
1137
  ### `--button-icons` (default is no icons)
1068
1138
  You can specify this either as builder flag or as a config setting (in `config/hot_glue.yml`)
@@ -1075,8 +1145,6 @@ Can also be specified globally in `config/hot_glue.yml`
1075
1145
 
1076
1146
 
1077
1147
  ### `--modify=field1{...},field2{...}`
1078
-
1079
-
1080
1148
  You can apply modification to the viewable (non-edit) display of field using the `--modify` switch.
1081
1149
 
1082
1150
  The syntax is `--modify=cost{$},price{$}`
@@ -1179,7 +1247,7 @@ In these contexts, the lookup must be exact match to the text entered (no partia
1179
1247
 
1180
1248
  Use `+` to map to the `find_or_create_by` method. (Without `+` it will use `find_by`.)
1181
1249
 
1182
- This is accomlished using a little magic of a lookup field called `__lookup_X_Y` passed in the form parameters.
1250
+ This is accomplished using a little magic of a lookup field called `__lookup_X_Y` passed in the form parameters.
1183
1251
 
1184
1252
  The lookup field is used to look up the associated record, then deleted from the params.
1185
1253
 
@@ -1443,10 +1511,15 @@ As shown in the method `name_able?` of the example ThingPolicy above, if this fi
1443
1511
  ### `--hidden=` (affects both create + update actions)
1444
1512
  ### `--create-hidden=`
1445
1513
  ### `--update-hidden=`
1446
- TODO: RENAME ME TO INVISIBLE
1447
1514
  Separate list of fields.
1448
1515
 
1449
- These fields will exist on the create or update form exist as hidden_field, and so the update will still work._
1516
+ These fields will exist on the create or update form exist as `<input type='hidden'>` (html) field and so the *actual update or create action will continue to expect data from the front end.**
1517
+
1518
+ (The data, being in a hidden field, is not visible to the user but it is in the browser's form, available to a hacker, and passed to the back-end for updating.)
1519
+
1520
+ You do your own javascript here to insert/set the value programmatically. The example below uses a library called EditorView to create a HTML editor.
1521
+
1522
+ The dynamic interface's value from the edited html gets stuffed back into the form by Javascript before the form is updated
1450
1523
 
1451
1524
 
1452
1525
  EXAMPLE:
@@ -1539,10 +1612,9 @@ Like show only, these will check for `*_able?` methods on the object or Policy a
1539
1612
 
1540
1613
  It will also block the field from being updated on the backend, so don't use this if you want to create a hidden_field tag but still allow the controller to update it. (For that, see `--hidden=`.)
1541
1614
 
1542
-
1543
1615
  Like show-only, note special behavior with pundit.
1544
1616
 
1545
- A field can be marked invisible and show-only, in which case the invisible rule take prescedence when the access control is denied (field removed from form) but th show-only rule takes prescedance when the access control is granted,
1617
+ A field can be marked invisible and show-only, in which case the invisible rule take precedence when the access control is denied (field removed from form) but the show-only rule takes precedence when the access control is granted.
1546
1618
 
1547
1619
  Hidden can be used with invisible. In this case, the access control will be applied to the field. When editable, the hidden field output will be used.
1548
1620
 
@@ -1598,6 +1670,12 @@ If thing is not a Thing, then it is active relation (so this applies to the colu
1598
1670
  Remember, since the `_able?` methods are not otherwise called during Pundit's index cycle, this applies only to the list column headings and has no bearing on create, update, read, delete for which the access control can be anything you want that is available to the Poilcy.
1599
1671
 
1600
1672
 
1673
+ ###
1674
+
1675
+
1676
+
1677
+
1678
+
1601
1679
 
1602
1680
  ## Code Insertion Features
1603
1681
  '
@@ -2331,6 +2409,48 @@ These automatic pickups for partials are detected at build time. This means that
2331
2409
 
2332
2410
  # VERSION HISTORY
2333
2411
 
2412
+ #### 2025-11-05 - v0.7
2413
+
2414
+ Hot Glue already has a robust set of tools to provide field-by-field access control, hiding or turning visible-only fields by multiple methods, described under Access Control & Field Visibility Features.
2415
+
2416
+ Remember that Hot Glue's opinionated design has two ways a field is displayed: show (which appears on the list view and is always just viewable), and form (which is usees by both the new and edit actions to display a form). Within the `form` output, the form might be used for either new or edit, and further refinements can be applied to new or edit.
2417
+
2418
+ Here's a quick review those methods now:
2419
+
2420
+ --pundit
2421
+ • No distinction is made between the new and edit contexts
2422
+ • If policy says not able (_able? method returns false), the field is shown as viewable-only. That is, a user with access to the controller but not the field-level access granted by Pundit will see the field's value but cannot edit it. If you want instead the Policy to determine if the field is editable or completely invisible (not shown to the user), use invible below
2423
+
2424
+ --show-only=
2425
+ • Turns fields on this list viewable only for both create & edit actions
2426
+ • overrides what's on the policy, but asks the policy if not on this list
2427
+
2428
+ --update-show-only=
2429
+ • Turns fields on this list viewable only for the edit action
2430
+ • overrides what's on the policy, but asks the policy if not on this list
2431
+
2432
+
2433
+ --hidden=, --create-hidden=, --update-hidden=
2434
+ • Creates <input type='hidden'> fields on the form, not seen by the user but available to a hacker in the browser, and submitted to the back end.
2435
+
2436
+ --invisible=, --create-invisible=, --update-invisible=
2437
+ • Must be used with Pundit.
2438
+ • If policy returns true, the field is viewable on list & editable as normal.
2439
+ • If the policy return false, the field is taken away (invisible) for that user
2440
+
2441
+
2442
+
2443
+ Today, with v0.7 of this gem, I'm introducing three more features that are all available from within the `--include` setting.
2444
+
2445
+ • Omitted fields: using `-` is omit on list & show; use `=` to omit the field on the form (new & edit)
2446
+ • Dynamic blocks (which can also be omitted using
2447
+ • Set column widths when using specified grouping made (--include contains `:`)
2448
+
2449
+ For details, see "Layout & Manipulation Features"
2450
+
2451
+
2452
+
2453
+
2334
2454
  #### 2025-10-28 - v0.6.31
2335
2455
 
2336
2456
  - new modification directive: `urlwrap`: use to wrap the field contents in a clickable link.
@@ -219,7 +219,7 @@ class AssociationField < Field
219
219
  autofocus: true,
220
220
  autocomplete: 'off',
221
221
  value: @q['0']['#{name}'].present? ? #{assoc.class_name}.find(@q['0']['#{name}']).try(:name) : \"\" %>
222
- <%= f.hidden_field \'q[0][#{name}]\', value: @q['0']['#{name}_search'].try(:id), 'data-typeahead-target': 'hiddenFormValue' %>
222
+ <%= f.hidden_field \'q[0][#{name}]\', value: @q['0']['#{name}'], 'data-typeahead-target': 'hiddenFormValue' %>
223
223
  <div data-typeahead-target='results'></div>
224
224
  <div data-typeahead-target='classIdentifier' data-id=\"typeahead--q_0_#{name}_search\"></div>
225
225
  </div>"
@@ -11,8 +11,8 @@ module HotGlue
11
11
  :stacked_downnesting, :bootstrap_column_width
12
12
 
13
13
  def initialize(generator: ,
14
- include_setting: ,
15
- buttons_width: )
14
+ include_setting:,
15
+ buttons_width: )
16
16
 
17
17
 
18
18
  @generator = generator
@@ -41,7 +41,11 @@ module HotGlue
41
41
  columns: {
42
42
  size_each: smart_layout ? bootstrap_column_width : (specified_grouping_mode ? nil : 1),
43
43
  container: [] , # array of arrays,
44
- bootstrap_column_width: []
44
+ bootstrap_column_width: [],
45
+ column_custom_widths: [],
46
+ fields: {
47
+
48
+ }, # hash of fields
45
49
  },
46
50
  portals: {
47
51
 
@@ -103,15 +107,21 @@ module HotGlue
103
107
  }
104
108
  layout_object[:columns][:container] = (0..available_columns-1).collect { |x| [columns[x]] }
105
109
  layout_object[:columns][:container].reject!{|x| x == [nil]}
106
- # layout_object[:columns][:size_each] = bootstrap_column_width
110
+
107
111
  end
112
+
108
113
  elsif ! specified_grouping_mode
109
114
  # not smart and no specified grouping
110
115
  layout_object[:columns][:button_columns] = bootstrap_column_width
111
116
 
112
117
  layout_object[:columns][:container] = columns.collect{|col| [col]}
113
118
 
114
- else # specified grouping mode -- the builder is given control
119
+ if include_setting.split(",").any?{|col| col.include?("(")}
120
+ raise "Your include list has a ( character; to specify a column width, use specified grouping mode only"
121
+ end
122
+
123
+
124
+ else # specified grouping mode -- the builder is given control unless a column width is explicitly set using (..)
115
125
  layout_object[:columns][:button_columns] = bootstrap_column_width
116
126
 
117
127
  (0..available_columns-1).each do |int|
@@ -121,16 +131,22 @@ module HotGlue
121
131
  # input control
122
132
 
123
133
  user_layout_columns = @include_setting.split(":")
134
+ fixed_widths = {}
135
+
136
+ user_layout_columns.each_with_index do |column_data,i |
137
+ if column_data.include?("(")
138
+ column_data =~ /(.*)\((.*)\)/
139
+ column_fields = $1
140
+ fixed_col_width = $2
141
+ fixed_widths[i] = fixed_col_width
142
+ else
143
+ column_fields = column_data
144
+ end
145
+ user_layout_columns[i] = column_fields
146
+ end
124
147
 
125
- extra_columns = available_columns - user_layout_columns.size
126
- # size_each = (bootstrap_columns / user_layout_columns.count).floor # this is the bootstrap size
127
- #
128
- # layout_object[:columns][:size_each] = size_each
129
-
130
- # if user_layout_columns.size > available_columns
131
- # raise "Your include statement #{@include_setting } has #{user_layout_columns.size} columns, but I can only construct up to #{available_columns}"
132
- # end
133
148
 
149
+ extra_columns = available_columns - user_layout_columns.size
134
150
 
135
151
  columns_to_work_with = (12 - @buttons_width)
136
152
 
@@ -142,10 +158,17 @@ module HotGlue
142
158
  extra_columns = columns_to_work_with % user_layout_columns.size
143
159
 
144
160
 
145
- user_layout_columns.each_with_index do |column,i|
146
- layout_object[:columns][:container][i] = column.split(",").collect(&:to_sym)
147
- layout_object[:columns][:bootstrap_column_width][i] = target_col_size
148
- if i < extra_columns
161
+ user_layout_columns.each_with_index do |column, i|
162
+
163
+ layout_object[:columns][:container][i] = column.split(",").collect{|x|
164
+ x.gsub("-","").gsub("=","")
165
+ }.collect(&:to_sym)
166
+
167
+
168
+
169
+ layout_object[:columns][:bootstrap_column_width][i] = fixed_widths[i] || target_col_size
170
+
171
+ if i < extra_columns && ! fixed_widths[i]
149
172
  layout_object[:columns][:bootstrap_column_width][i] += 1
150
173
  end
151
174
  end
@@ -153,14 +176,46 @@ module HotGlue
153
176
  if user_layout_columns.size < layout_object[:columns][:container].size
154
177
  layout_object[:columns][:container].reject!{|x| x == []}
155
178
  end
179
+ end
156
180
 
181
+ # go through the columns and build the split visibility (show / form)
182
+
183
+ columns.each do |col|
184
+ layout_object[:columns][:fields][col] = {show: true, form: true}
157
185
  end
158
186
 
187
+ @include_setting.split(":").collect { |column_list|
188
+ column_list.split(",").collect do |field|
189
+ if field.include?("(")
190
+ field =~ /(.*)\((.*)\)/
191
+ field_short = $1
192
+ else
193
+ field_short = field
194
+ end
195
+
196
+ field_short = field_short.gsub("-", "").gsub("=", "")
197
+
198
+ layout_object[:columns][:fields][field_short.to_sym] = {
199
+ show: true,
200
+ form: true
201
+ }
159
202
 
160
- puts "*** constructed smart layout columns #{layout_object.inspect}"
203
+ if field.starts_with?("**")
204
+ nil
205
+ end
206
+
207
+ if field.include?("-")
208
+ layout_object[:columns][:fields][field_short.to_sym][:show] = false;
209
+ end
210
+ if field.include?("=")
211
+ layout_object[:columns][:fields][field_short.to_sym][:form] = false;
212
+ end
213
+
214
+ end
215
+ }
216
+ puts "*** SPECIFIED GROUPING SETTINGS: #{layout_object.inspect}"
161
217
  layout_object
162
218
  end
163
-
164
219
  end
165
220
  end
166
221
  end
@@ -98,11 +98,15 @@ module HotGlue
98
98
  size = layout_object[:columns][:bootstrap_column_width][i]
99
99
  "<div class='#{layout_strategy.column_classes_for_column_headings(size)} hg-heading-row heading--#{singular}--#{column.join("-")}' " + col_style + ">" +
100
100
  column.map(&:to_s).map{|col_name|
101
- the_output = "#{col_name.humanize}"
101
+ unless col_name.starts_with?("**")
102
+ the_output = "#{col_name.humanize}"
103
+ else
104
+ the_output = ""
105
+ end
102
106
  if invisible_update.include?(col_name.to_sym)
103
107
  if_statements = []
104
108
  if_statements << "false" if invisible_update.include?(col_name.to_sym)
105
- # if_statements << "@action == 'new'" if invisible_create.include?(col_name.to_sym)
109
+
106
110
  the_output = "<% if ( " + if_statements.join(" || ") + " || policy(#{@plural}).#{col_name}_able? ) %>" +
107
111
  + the_output + "<% end %>"
108
112
 
@@ -158,7 +162,7 @@ module HotGlue
158
162
  dom_label = choice[:label].downcase.gsub(" ","_")
159
163
  if data[:type] == "radio"
160
164
  res << "\n<input type='radio'
161
- id='#{search_field}_search__#{dom_label}}'
165
+ id='#{search_field}_search__#{dom_label}'
162
166
  name='q[0][#{search_field}_search]' value='#{dom_label}'
163
167
  <%= 'checked' if @q['0'][:#{search_field}_search] == \"#{dom_label}\" %> />"
164
168
  elsif data[:type] == "checkboxes"
@@ -196,65 +200,71 @@ module HotGlue
196
200
 
197
201
  " <div class='#{layout_strategy.column_classes_for_form_fields(size)} cell--#{singular}--#{column.join("-")}' >" +
198
202
  column.map { |col|
203
+ if col.to_s.starts_with?("**") && layout_object[:columns][:fields][col][:form]
204
+ the_output = "<%= render partial: '#{col.to_s.gsub!("**","")}', locals: {#{singular}: #{singular} } %>"
205
+ elsif ! layout_object[:columns][:fields][col][:form]
206
+ # omit from show action
207
+ else
199
208
 
200
- field_error_name = columns_map[col].field_error_name
209
+ field_error_name = columns_map[col].field_error_name
201
210
 
202
- label_class = columns_map[col].label_class
203
- label_for = columns_map[col].label_for
211
+ label_class = columns_map[col].label_class
212
+ label_for = columns_map[col].label_for
204
213
 
205
- the_label = "\n<label class='#{label_class}' for='#{label_for}'>#{col.to_s.humanize}</label>"
206
-
207
-
208
- field_result =
209
- if show_only.include?(col)
210
- columns_map[col].form_show_only_output
211
- elsif update_show_only.include?(col) && !@pundit
212
- "<% if @action == 'edit' %>" + columns_map[col].form_show_only_output + "<% else %>" + columns_map[col].form_field_output + "<% end %>"
213
- elsif update_show_only.include?(col) && @pundit && eval("defined? #{singular_class}Policy") && eval("#{singular_class}Policy").instance_methods.include?("#{col}_able?".to_sym)
214
- "<% if @action == 'new' && policy(@#{singular}).#{col}_able? %>" + columns_map[col].form_field_output + "<% else %>" + columns_map[col].form_show_only_output + "<% end %>"
215
- # show only on the update action overrides any pundit policy
216
- elsif @pundit && eval("defined? #{singular_class}Policy") && eval("#{singular_class}Policy").instance_methods.include?("#{col}_able?".to_sym)
217
- "<% if policy(@#{singular}).#{col}_able? %>" + columns_map[col].form_field_output + "<% else %>" + columns_map[col].form_show_only_output + "<% end %>"
218
- elsif update_show_only.include?(col)
219
- "<% if @action == 'edit' %>" + columns_map[col].form_show_only_output + "<% else %>" + columns_map[col].form_field_output + "<% end %>"
220
- else
221
- columns_map[col].form_field_output
222
- end
214
+ the_label = "\n<label class='#{label_class}' for='#{label_for}'>#{col.to_s.humanize}</label>"
223
215
 
224
216
 
225
- @tinymce_stimulus_controller = (columns_map[col].modify_as == {tinymce: 1} ? "data-controller='tiny-mce' " : "")
217
+ field_result =
218
+ if show_only.include?(col)
219
+ columns_map[col].form_show_only_output
220
+ elsif update_show_only.include?(col) && !@pundit
221
+ "<% if @action == 'edit' %>" + columns_map[col].form_show_only_output + "<% else %>" + columns_map[col].form_field_output + "<% end %>"
222
+ elsif update_show_only.include?(col) && @pundit && eval("defined? #{singular_class}Policy") && eval("#{singular_class}Policy").instance_methods.include?("#{col}_able?".to_sym)
223
+ "<% if @action == 'new' && policy(@#{singular}).#{col}_able? %>" + columns_map[col].form_field_output + "<% else %>" + columns_map[col].form_show_only_output + "<% end %>"
224
+ # show only on the update action overrides any pundit policy
225
+ elsif @pundit && eval("defined? #{singular_class}Policy") && eval("#{singular_class}Policy").instance_methods.include?("#{col}_able?".to_sym)
226
+ "<% if policy(@#{singular}).#{col}_able? %>" + columns_map[col].form_field_output + "<% else %>" + columns_map[col].form_show_only_output + "<% end %>"
227
+ elsif update_show_only.include?(col)
228
+ "<% if @action == 'edit' %>" + columns_map[col].form_show_only_output + "<% else %>" + columns_map[col].form_field_output + "<% end %>"
229
+ else
230
+ columns_map[col].form_field_output
231
+ end
226
232
 
227
- if @stimmify
228
- col_target = HotGlue.to_camel_case(col.to_s.gsub("_", " "))
229
- data_attr = " data-#{@stimmify}-target='#{col_target}Wrapper'"
230
- end
231
233
 
234
+ @tinymce_stimulus_controller = (columns_map[col].modify_as == {tinymce: 1} ? "data-controller='tiny-mce' " : "")
232
235
 
233
- the_output = add_spaces_each_line( "\n <div #{@tinymce_stimulus_controller}class='<%= \"alert alert-danger\" if #{singular}.errors.details.keys.include?(:#{field_error_name}) %>' #{data_attr} >\n" +
234
- add_spaces_each_line( (form_labels_position == 'before' ? (the_label || "") + "<br />\n" : "") +
235
- + field_result +
236
- (form_labels_position == 'after' ? ( columns_map[col].newline_after_field? ? "<br />\n" : "") + (the_label || "") : "") , 4) +
237
- "\n </div>\n ", 2)
236
+ if @stimmify
237
+ col_target = HotGlue.to_camel_case(col.to_s.gsub("_", " "))
238
+ data_attr = " data-#{@stimmify}-target='#{col_target}Wrapper'"
239
+ end
238
240
 
239
241
 
240
- if hidden_create.include?(col.to_sym) || hidden_update.include?(col.to_sym)
241
- if_statements = []
242
- if_statements << "@action == 'edit'" if hidden_update.include?(col.to_sym)
243
- if_statements << "@action == 'new'" if hidden_create.include?(col.to_sym)
242
+ the_output = add_spaces_each_line( "\n <div #{@tinymce_stimulus_controller}class='<%= \"alert alert-danger\" if #{singular}.errors.details.keys.include?(:#{field_error_name}) %>' #{data_attr} >\n" +
243
+ add_spaces_each_line( (form_labels_position == 'before' ? (the_label || "") + "<br />\n" : "") +
244
+ + field_result +
245
+ (form_labels_position == 'after' ? ( columns_map[col].newline_after_field? ? "<br />\n" : "") + (the_label || "") : "") , 4) +
246
+ "\n </div>\n ", 2)
244
247
 
245
- the_output = "<% if " + if_statements.join(" || ") + " %>" +
246
- columns_map[col].hidden_output + "<% else %>" + the_output + "<% end %>"
247
- end
248
248
 
249
- if invisible_create.include?(col) || invisible_update.include?(col)
250
- if_statements = []
251
- if_statements << "@action == 'edit'" if invisible_update.include?(col.to_sym)
252
- if_statements << "@action == 'new'" if invisible_create.include?(col.to_sym)
249
+ if hidden_create.include?(col.to_sym) || hidden_update.include?(col.to_sym)
250
+ if_statements = []
251
+ if_statements << "@action == 'edit'" if hidden_update.include?(col.to_sym)
252
+ if_statements << "@action == 'new'" if hidden_create.include?(col.to_sym)
253
253
 
254
- the_output = "<% if !(" + if_statements.join(" || ") + ") || policy(@#{singular}).#{col}_able? %>" +
255
- + the_output + "<% end %>"
256
- end
254
+ the_output = "<% if " + if_statements.join(" || ") + " %>" +
255
+ columns_map[col].hidden_output + "<% else %>" + the_output + "<% end %>"
256
+ end
257
+
258
+ if invisible_create.include?(col) || invisible_update.include?(col)
259
+ if_statements = []
260
+ if_statements << "@action == 'edit'" if invisible_update.include?(col.to_sym)
261
+ if_statements << "@action == 'new'" if invisible_create.include?(col.to_sym)
257
262
 
263
+ the_output = "<% if !(" + if_statements.join(" || ") + ") || policy(@#{singular}).#{col}_able? %>" +
264
+ + the_output + "<% end %>"
265
+ end
266
+
267
+ end # end of if col.to_s.starts_with?("**")
258
268
 
259
269
 
260
270
  the_output
@@ -298,35 +308,39 @@ module HotGlue
298
308
  style_with_flex_basis = layout_strategy.style_with_flex_basis(perc_width)
299
309
 
300
310
  result = columns.map.with_index{ |column,i|
301
-
302
311
  size = layout_object[:columns][:bootstrap_column_width][i]
303
-
304
312
  "<div class='hg-col #{layout_strategy.column_classes_for_line_fields(size)} #{singular}--#{column.join("-")}'#{style_with_flex_basis}> " +
305
313
  column.map { |col|
306
- if eval("#{singular_class}.columns_hash['#{col}']").nil? && !attachments.keys.include?(col) && !related_sets.include?(col)
314
+ if col.starts_with?("**") && layout_object[:columns][:fields][col][:show]
315
+ the_output = "<%= render partial: '#{col.to_s.gsub!("**","")}', locals: {#{singular}: #{singular} } %>"
316
+ elsif ! layout_object[:columns][:fields][col][:show]
317
+ the_output = ""
318
+ elsif eval("#{singular_class}.columns_hash['#{col}']").nil? && !attachments.keys.include?(col) && !related_sets.include?(col)
307
319
  raise "Can't find column '#{col}' on #{singular_class}, are you sure that is the column name?"
308
- end
320
+ # omit from show action
321
+ else
309
322
 
310
- field_output = columns_map[col].line_field_output
311
-
312
- label = "<label class='small form-text text-muted'>#{col.to_s.humanize}</label>"
323
+ field_output = columns_map[col].line_field_output
313
324
 
314
- the_output = "#{inline_list_labels == 'before' ? label + "<br/>" : ''}#{field_output}#{inline_list_labels == 'after' ? "<br/>" + label : ''}"
315
- if invisible_create.include?(col) || invisible_update.include?(col)
316
- if_statements = []
317
- if invisible_update.include?(col.to_sym) && invisible_create.include?(col.to_sym)
318
- # elsif invisible_create.include?(col.to_sym)
319
- # if_statements << "!(@action == 'new')"
320
- else
321
- if_statements << "@action == 'edit'"
322
- end
325
+ label = "<label class='small form-text text-muted'>#{col.to_s.humanize}</label>"
323
326
 
324
- if_statements << " policy(#{singular}).#{col}_able?"
325
- the_output = "<% if " + if_statements.join(" || ") + " %>" +
326
- + the_output + "<% end %>"
327
+ the_output = "#{inline_list_labels == 'before' ? label + "<br/>" : ''}#{field_output}#{inline_list_labels == 'after' ? "<br/>" + label : ''}"
328
+ the_output += "\n"
329
+ if invisible_create.include?(col) || invisible_update.include?(col)
330
+ if_statements = []
331
+ if invisible_update.include?(col.to_sym) && invisible_create.include?(col.to_sym)
332
+ else
333
+ if_statements << "@action == 'edit'"
334
+ end
335
+
336
+ if_statements << " policy(#{singular}).#{col}_able?"
337
+ the_output = "<% if " + if_statements.join(" || ") + " %>" +
338
+ + the_output + "<% end %>"
339
+ end
327
340
  end
341
+
328
342
  the_output
329
- }.join( "<br />") + "</div>"
343
+ }.join( "<br />\n") + "</div>"
330
344
  }.join("\n")
331
345
  return result
332
346
 
@@ -256,11 +256,26 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
256
256
  @include_fields = []
257
257
 
258
258
  # semicolon to denote layout columns; commas separate fields
259
- @include_fields += options['include'].split(":").collect { |x| x.split(",") }.flatten.collect(&:to_sym)
259
+ #
260
+ @include_fields += options['include'].split(":").collect { |column_list|
261
+ column_list.split(",").collect do |field|
262
+ if field.include?("(")
263
+ field =~ /(.*)\((.*)\)/
264
+ field_short = $1
265
+ else
266
+ field_short = field
267
+ end
268
+ if field_short.starts_with?("**")
269
+ nil
270
+ else
271
+ field_short.gsub("-", "").gsub("=", "")
272
+ end
273
+ end
274
+ }.flatten.compact.collect(&:to_sym)
275
+ puts "INCLUDED FIELDS: #{@include_fields}"
260
276
  end
261
277
 
262
278
 
263
-
264
279
  @show_only = options['show_only'].split(",").collect(&:to_sym)
265
280
  if @show_only.any?
266
281
  puts "show only field #{@show_only}}"
@@ -1084,6 +1099,19 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1084
1099
  end
1085
1100
  end
1086
1101
 
1102
+ # def omit_fields_show
1103
+ #
1104
+ # layout_object[:columns][:fields].each { |key, value|
1105
+ # value[:show] == false
1106
+ # }.reduce(:&)
1107
+ # end
1108
+
1109
+ def omit_fields_form
1110
+ layout_object[:columns][:fields].collect { |key, value| value[:form] == false ? key : nil }.compact.reject!{|x| x.starts_with?("**")} || []
1111
+ end
1112
+
1113
+
1114
+
1087
1115
  def check_if_sample_file_is_present
1088
1116
  if sample_file_path.nil?
1089
1117
  puts "you have no sample file path set in config/hot_glue.yml"
@@ -1892,7 +1920,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1892
1920
  if phantom_data[:type] == "radio"
1893
1921
  phantom_data[:choices].each do |choice|
1894
1922
  unless choice[:scope] == ".all"
1895
- res << "\n @#{plural} = @#{plural}#{choice[:scope]} if @q['0'][:#{phantom_key}_search] == \"#{choice[:label]}\""
1923
+ res << "\n @#{plural} = @#{plural}#{choice[:scope]} if @q['0'][:#{phantom_key}_search] == \"#{choice[:label].downcase.gsub(" ","_")}\""
1896
1924
  end
1897
1925
  end
1898
1926
  elsif phantom_data[:type] == "checkboxes"
@@ -1903,7 +1931,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1903
1931
  res << "\n @#{plural} = @#{plural}#{choice[:scope]} if @q['0'][:#{phantom_key}_search__#{choice[:label].gsub(" ", "_").downcase}] == \"1\""
1904
1932
  end
1905
1933
  unless choice[:scope_negative] == ".all"
1906
- res << "\n @#{plural} = @#{plural}#{choice[:scope_negative]} if @q['0'][:#{phantom_key}_search___#{choice[:label].gsub(" ", "_").downcase}] != \"1\""
1934
+ res << "\n @#{plural} = @#{plural}#{choice[:scope_negative]} if @q['0'][:#{phantom_key}_search__#{choice[:label].gsub(" ", "_").downcase}] != \"1\""
1907
1935
  end
1908
1936
  end
1909
1937
  end
@@ -288,13 +288,13 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
288
288
  end<% end %><% end %>
289
289
 
290
290
  def <%=singular_name%>_params
291
- fields = <%= ((fields_filtered_for_strong_params - @show_only) + @magic_buttons.collect{|x| "__#{x}"} + @phantom_create_params.split(",")).collect{|sym| ":#{sym}"}.join(", ") %><%= ", " + @related_sets.collect{|key, rs| "{#{rs[:association_ids_method]}: []}"}.join(", ") if @related_sets.any? %><%= ", " + @alt_lookups.collect{|k,v| ":__lookup_#{v[:assoc].downcase}_#{v[:lookup_as]}" }.join(", ") if @alt_lookups.any? %>
291
+ fields = <%= ((fields_filtered_for_strong_params - @show_only - omit_fields_form) + @magic_buttons.collect{|x| "__#{x}"} + @phantom_create_params.split(",")).collect{|sym| ":#{sym}"}.join(", ") %><%= ", " + @related_sets.collect{|key, rs| "{#{rs[:association_ids_method]}: []}"}.join(", ") if @related_sets.any? %><%= ", " + @alt_lookups.collect{|k,v| ":__lookup_#{v[:assoc].downcase}_#{v[:lookup_as]}" }.join(", ") if @alt_lookups.any? %>
292
292
  params.require(:<%= testing_name %>).permit(fields)
293
293
  end<% if @update_show_only %>
294
294
 
295
295
  <% unless @no_edit %>
296
296
  def update_<%=singular_name%>_params
297
- fields = <%= ((fields_filtered_for_strong_params - @update_show_only) + @magic_buttons.collect{|x| "__#{x}"} + @phantom_update_params.split(",")).collect{|sym| ":#{sym}"}.join(", ") %><%= ", " + @related_sets.collect{|key, rs| "{#{rs[:association_ids_method]}: []}"}.join(", ") if @related_sets.any? %><%= ", " + @alt_lookups.collect{|k,v| ":__lookup_#{v[:assoc].downcase}_#{v[:lookup_as]}" }.join(", ") if @alt_lookups.any? %>
297
+ fields = <%= ((fields_filtered_for_strong_params - @update_show_only - omit_fields_form) + @magic_buttons.collect{|x| "__#{x}"} + @phantom_update_params.split(",")).collect{|sym| ":#{sym}"}.join(", ") %><%= ", " + @related_sets.collect{|key, rs| "{#{rs[:association_ids_method]}: []}"}.join(", ") if @related_sets.any? %><%= ", " + @alt_lookups.collect{|k,v| ":__lookup_#{v[:assoc].downcase}_#{v[:lookup_as]}" }.join(", ") if @alt_lookups.any? %>
298
298
  <%= (fields_filtered_for_strong_params - @update_show_only).collect{|col|
299
299
  # TODO : fields not on show only also not invisible should be checked here
300
300
  # for _able? methods and added only when able
@@ -1,5 +1,5 @@
1
1
  module HotGlue
2
2
  class Version
3
- CURRENT = '0.6.31'
3
+ CURRENT = '0.7'
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.6.31
4
+ version: '0.7'
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: 2025-10-28 00:00:00.000000000 Z
11
+ date: 2025-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails