hot-glue 0.6.30 → 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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +198 -22
- data/lib/generators/hot_glue/fields/association_field.rb +6 -4
- data/lib/generators/hot_glue/fields/field.rb +6 -0
- data/lib/generators/hot_glue/layout/builder.rb +74 -19
- data/lib/generators/hot_glue/markup_templates/erb.rb +82 -68
- data/lib/generators/hot_glue/scaffold_generator.rb +41 -8
- data/lib/generators/hot_glue/templates/controller.rb.erb +2 -2
- data/lib/hotglue/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c823d274b52531414bbf843d1f44ccd364400ab9c736405a74b1cc5793774b48
|
|
4
|
+
data.tar.gz: 52d175d729d5b57c063da43bb7b7cb2940ea334be16e99637ade700ddaa2593a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a1c8b8309b61f0ddbb1f27ca3a73bde4e8349f13fb114c6f3f5dcc15343dcc597fa4fbdd11476c1456d38c772cfe29b61d7ca4bee7d79ad421592227cf305d49
|
|
7
|
+
data.tar.gz: 9b915be8972458f2fee1163e00c9f6c58a6ddf74ec829da2449989f3a5640597d16efb93c5ede4ea449bc786714997f511d3830a584029ff33222c6cef4d626e
|
data/Gemfile.lock
CHANGED
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
|
-
|
|
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)
|
|
1065
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.
|
|
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{$}`
|
|
@@ -1086,9 +1154,11 @@ Here, the `cost` and `price` fields will be displayed as wrapped in `number_to_c
|
|
|
1086
1154
|
You can also use a binary modifier, which can apply to booleans, datetimes, times, dates or anything else. When using the binary modify, a specific value is displayed if the field is truthy and another one is display if the field is falsy.
|
|
1087
1155
|
You specify it using a pipe | character like so:
|
|
1088
1156
|
|
|
1157
|
+
Example binary modification:
|
|
1158
|
+
|
|
1089
1159
|
`--modify=paid_at{paid|unpaid}`
|
|
1090
1160
|
|
|
1091
|
-
|
|
1161
|
+
Here, even though `paid_at` is a datetime field, it will display as-if it is a binary -- showing either the truthy
|
|
1092
1162
|
label or the falsy label depending on if `paid_at` is or is not null in the database.
|
|
1093
1163
|
For all fields except booleans, this affects only the viewable output —
|
|
1094
1164
|
what you see on the list page and on the edit page for show-only fields.
|
|
@@ -1099,20 +1169,25 @@ You will need to separately specify them as show-only if you want them to be non
|
|
|
1099
1169
|
|
|
1100
1170
|
Notice that each modifiers can be used with specific field types.
|
|
1101
1171
|
|
|
1102
|
-
| user modifier | what it does | Field types | |
|
|
1103
|
-
|
|
1104
|
-
| $ | wraps output in `number_to_currency()` | floats and integers | |
|
|
1172
|
+
| user modifier | what it does | Field types | | |
|
|
1173
|
+
|-------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------|---|----|
|
|
1174
|
+
| $ | wraps output in `number_to_currency()` | floats and integers | | |
|
|
1105
1175
|
| (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" | booleans, datetimes, dates, times | | |
|
|
1106
|
-
| partials | applies to enums only, you must have a partial whose name matches each enum type | enums only | |
|
|
1107
|
-
| tinymce | applies to text fields only, be sure to setup TineMCE globally | text fields only | |
|
|
1108
|
-
| typeahead | turns a foreign key (only) into a searchable typeahead field | foreign keys only | |
|
|
1109
|
-
| timezone | turns a string (varchar) into a drop down of timezones | foreign keys only | |
|
|
1110
|
-
| include_blank | special modifier for association fields, adds include_blank to the created dropdown
|
|
1176
|
+
| partials | applies to enums only, you must have a partial whose name matches each enum type | enums only | | |
|
|
1177
|
+
| tinymce | applies to text fields only, be sure to setup TineMCE globally | text fields only | | |
|
|
1178
|
+
| typeahead | turns a foreign key (only) into a searchable typeahead field | foreign keys only | | |
|
|
1179
|
+
| timezone | turns a string (varchar) into a drop down of timezones | foreign keys only | | |
|
|
1180
|
+
| include_blank | special modifier for association fields, adds include_blank to the created dropdown | |
|
|
1181
|
+
| urlwrap | wrap this field in a URL | any printable field | | |
|
|
1111
1182
|
| none | special modifier for using badges |
|
|
1112
1183
|
|
|
1113
1184
|
Except for "(truthy label)" and "(falsy label)" which use the special syntax, use the modifier _exactly_ as it is named.
|
|
1114
1185
|
|
|
1115
|
-
|
|
1186
|
+
Some modifiers take a 3rd parameter in `[` and `]` markers after the modification marker. The 3rd parameters function depends on which modifier you are using.
|
|
1187
|
+
|
|
1188
|
+
|
|
1189
|
+
#### Binary (use | to separate "true value" from "false value")
|
|
1190
|
+
Can take a bootstrap badge name as 3rd parameter
|
|
1116
1191
|
|
|
1117
1192
|
`--modify=opened_at{opened|closed}[bg-primary|bg-secondary]`
|
|
1118
1193
|
Applies a badge `bg-primary` to rows with opened_at truthy and `bg-secondary` to rows with opened_at falsy.
|
|
@@ -1120,10 +1195,50 @@ Applies a badge `bg-primary` to rows with opened_at truthy and `bg-secondary` to
|
|
|
1120
1195
|
to display a badge on everything, use the `none` modifier with the
|
|
1121
1196
|
`--modify=opened_at{none}[bg-dark]`
|
|
1122
1197
|
|
|
1198
|
+
#### $
|
|
1123
1199
|
For the `$` modifier only, if the field name ends with `_cents`, the modifier will automatically divide the field by 100 before displaying it.
|
|
1124
|
-
|
|
1125
1200
|
(This is consistent with Stripe'e paradigm to always store money in cents, and this way I force myself to put `_cents` on the end of my field names to remind myself that they are in cents.)
|
|
1126
1201
|
|
|
1202
|
+
|
|
1203
|
+
#### Typeahead
|
|
1204
|
+
3rd parameter (in `[...]`) used to specify the nested set IF the typeahead itself is nested (optional)
|
|
1205
|
+
- see the typeahead section for details
|
|
1206
|
+
|
|
1207
|
+
#### urlwrap
|
|
1208
|
+
|
|
1209
|
+
Use to wrap the field contents in a clickable link.
|
|
1210
|
+
|
|
1211
|
+
`rails generate hot_glue:scaffold BskyUser --gd --modify='handle{urlwrap}[bsky_url]'`
|
|
1212
|
+
|
|
1213
|
+
Here, we are telling Hot Glue that we want to modify the field called `handle` to be wrapped in a URL.
|
|
1214
|
+
We form that URL but calling the helper method `bsky_url` (must be defined in your helpers)
|
|
1215
|
+
|
|
1216
|
+
When we do make that call, notice that we pass two arguments to bsky_url (not seen):
|
|
1217
|
+
1) the field we are modifying
|
|
1218
|
+
2) the object
|
|
1219
|
+
|
|
1220
|
+
|
|
1221
|
+
`bsky_url(bsky_user.handle, bsky_user)`
|
|
1222
|
+
|
|
1223
|
+
(`bsky_user.handle` is the field to be modified, what will become the link text. `bsky_user` is the instance of the model
|
|
1224
|
+
object as it is displayed to the screen)
|
|
1225
|
+
|
|
1226
|
+
its implementation might look like this:
|
|
1227
|
+
|
|
1228
|
+
```
|
|
1229
|
+
module BskyUserHelper
|
|
1230
|
+
|
|
1231
|
+
def bsky_url(link_text, bsky_user)
|
|
1232
|
+
link_to link_text, "https://#{bsky_user.handle}", target: "_blank"
|
|
1233
|
+
end
|
|
1234
|
+
end
|
|
1235
|
+
```
|
|
1236
|
+
In this case I happen to be turning piece of text _that is the link itself_ into a link,
|
|
1237
|
+
which is why you see `"https://#{bsky_user.handle}"` in the URL being generated, but this is arbitrary.
|
|
1238
|
+
You can make any piece of text into a link, the helper method is only used to construct the link.
|
|
1239
|
+
|
|
1240
|
+
|
|
1241
|
+
|
|
1127
1242
|
### `--alt-foreign-key-lookup=`
|
|
1128
1243
|
|
|
1129
1244
|
Use for a join table to specify that a field should be looked up by a different field. For example, when you want to lookup a user by a (complete) email address.
|
|
@@ -1132,7 +1247,7 @@ In these contexts, the lookup must be exact match to the text entered (no partia
|
|
|
1132
1247
|
|
|
1133
1248
|
Use `+` to map to the `find_or_create_by` method. (Without `+` it will use `find_by`.)
|
|
1134
1249
|
|
|
1135
|
-
This is
|
|
1250
|
+
This is accomplished using a little magic of a lookup field called `__lookup_X_Y` passed in the form parameters.
|
|
1136
1251
|
|
|
1137
1252
|
The lookup field is used to look up the associated record, then deleted from the params.
|
|
1138
1253
|
|
|
@@ -1396,10 +1511,15 @@ As shown in the method `name_able?` of the example ThingPolicy above, if this fi
|
|
|
1396
1511
|
### `--hidden=` (affects both create + update actions)
|
|
1397
1512
|
### `--create-hidden=`
|
|
1398
1513
|
### `--update-hidden=`
|
|
1399
|
-
TODO: RENAME ME TO INVISIBLE
|
|
1400
1514
|
Separate list of fields.
|
|
1401
1515
|
|
|
1402
|
-
These fields will exist on the create or update form exist as
|
|
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
|
|
1403
1523
|
|
|
1404
1524
|
|
|
1405
1525
|
EXAMPLE:
|
|
@@ -1492,10 +1612,9 @@ Like show only, these will check for `*_able?` methods on the object or Policy a
|
|
|
1492
1612
|
|
|
1493
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=`.)
|
|
1494
1614
|
|
|
1495
|
-
|
|
1496
1615
|
Like show-only, note special behavior with pundit.
|
|
1497
1616
|
|
|
1498
|
-
A field can be marked invisible and show-only, in which case the invisible rule take
|
|
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.
|
|
1499
1618
|
|
|
1500
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.
|
|
1501
1620
|
|
|
@@ -1551,6 +1670,12 @@ If thing is not a Thing, then it is active relation (so this applies to the colu
|
|
|
1551
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.
|
|
1552
1671
|
|
|
1553
1672
|
|
|
1673
|
+
###
|
|
1674
|
+
|
|
1675
|
+
|
|
1676
|
+
|
|
1677
|
+
|
|
1678
|
+
|
|
1554
1679
|
|
|
1555
1680
|
## Code Insertion Features
|
|
1556
1681
|
'
|
|
@@ -2284,6 +2409,57 @@ These automatic pickups for partials are detected at build time. This means that
|
|
|
2284
2409
|
|
|
2285
2410
|
# VERSION HISTORY
|
|
2286
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
|
+
|
|
2454
|
+
#### 2025-10-28 - v0.6.31
|
|
2455
|
+
|
|
2456
|
+
- new modification directive: `urlwrap`: use to wrap the field contents in a clickable link.
|
|
2457
|
+
See docs for "urlwrap" in the `--modify=` section above
|
|
2458
|
+
|
|
2459
|
+
- Fixes for typeaheads: corrects search url when the typeahead is built against a two-word model name
|
|
2460
|
+
|
|
2461
|
+
- Fixes for source reflection on has_many associations
|
|
2462
|
+
|
|
2287
2463
|
#### 2025-10-19 - v0.6.30
|
|
2288
2464
|
- fixes references from search typeaheads to a typeahead controller which is nested
|
|
2289
2465
|
- `--nested` can now take square braces if the relationship from child to parent (belongs_to) uses a non-standard association name; @downnest_object fix for data array; changes to object_scope to accomodate new paradigm
|
|
@@ -103,8 +103,7 @@ class AssociationField < Field
|
|
|
103
103
|
|
|
104
104
|
search_url = "#{namespace ? namespace + "_" : ""}" +
|
|
105
105
|
modify_as[:nested].join("_") + ( modify_as[:nested].any? ? "_" : "") +
|
|
106
|
-
+ "#{assoc.
|
|
107
|
-
|
|
106
|
+
+ "#{assoc.name.to_s.pluralize}_typeahead_index_url"
|
|
108
107
|
|
|
109
108
|
if @modify_as[:nested].any?
|
|
110
109
|
search_url << "(" + modify_as[:nested].collect{|x| "#{x}"}.join(",") + ")"
|
|
@@ -204,7 +203,10 @@ class AssociationField < Field
|
|
|
204
203
|
assoc_name = name.to_s.gsub("_id","")
|
|
205
204
|
assoc = eval("#{class_name}.reflect_on_association(:#{assoc_name})")
|
|
206
205
|
if modify_as && modify_as[:typeahead]
|
|
207
|
-
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
search_url = "#{namespace ? namespace + "_" : ""}#{ modify_as[:nested][0] ? modify_as[:nested][0] + "_" : ""}#{assoc.name.to_s.pluralize}_typeahead_index_url"
|
|
209
|
+
|
|
208
210
|
|
|
209
211
|
# \"q[0][#{name}_search]\"
|
|
210
212
|
# @q['0']['#{name}_search']
|
|
@@ -217,7 +219,7 @@ class AssociationField < Field
|
|
|
217
219
|
autofocus: true,
|
|
218
220
|
autocomplete: 'off',
|
|
219
221
|
value: @q['0']['#{name}'].present? ? #{assoc.class_name}.find(@q['0']['#{name}']).try(:name) : \"\" %>
|
|
220
|
-
<%= f.hidden_field \'q[0][#{name}]\', value: @q['0']['#{name}
|
|
222
|
+
<%= f.hidden_field \'q[0][#{name}]\', value: @q['0']['#{name}'], 'data-typeahead-target': 'hiddenFormValue' %>
|
|
221
223
|
<div data-typeahead-target='results'></div>
|
|
222
224
|
<div data-typeahead-target='classIdentifier' data-id=\"typeahead--q_0_#{name}_search\"></div>
|
|
223
225
|
</div>"
|
|
@@ -146,7 +146,13 @@ class Field
|
|
|
146
146
|
|
|
147
147
|
elsif modify_as[:timezone]
|
|
148
148
|
res += "<%= #{singular}.#{name} %>"
|
|
149
|
+
elsif modify_as[:urlwrap]
|
|
150
|
+
# helper_method = modify_as[:helper_method].split(" ")[0]
|
|
151
|
+
# param = modify_as[:helper_method].split(" ")[1]
|
|
152
|
+
|
|
153
|
+
res += "<%= #{modify_as[:helper_method]}(#{singular}.#{name}, #{singular}) %>"
|
|
149
154
|
elsif modify_as[:enum]
|
|
155
|
+
|
|
150
156
|
elsif modify_as[:none]
|
|
151
157
|
field_view_output
|
|
152
158
|
# res += "<%= render partial: #{singular}.#{name}, locals: {#{singular}: #{singular}} %>"
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
147
|
-
layout_object[:columns][:
|
|
148
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
209
|
+
field_error_name = columns_map[col].field_error_name
|
|
201
210
|
|
|
202
|
-
|
|
203
|
-
|
|
211
|
+
label_class = columns_map[col].label_class
|
|
212
|
+
label_for = columns_map[col].label_for
|
|
204
213
|
|
|
205
|
-
|
|
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
|
-
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
|
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
|
-
|
|
320
|
+
# omit from show action
|
|
321
|
+
else
|
|
309
322
|
|
|
310
|
-
|
|
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
|
-
|
|
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
|
-
|
|
325
|
-
the_output
|
|
326
|
-
|
|
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
|
|
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
|
-
|
|
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}}"
|
|
@@ -300,6 +315,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
|
300
315
|
setting =~ /(.*){(.*)}/
|
|
301
316
|
key, lookup_as = $1, $2
|
|
302
317
|
end
|
|
318
|
+
|
|
303
319
|
if ["$"].include?($2)
|
|
304
320
|
@modify_as[key.to_sym] = {cast: $2, badges: $3}
|
|
305
321
|
elsif $2.include?("|")
|
|
@@ -322,6 +338,10 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
|
322
338
|
@modify_as[key.to_sym] = {timezone: 1, badges: $3}
|
|
323
339
|
elsif $2 == "include_blank"
|
|
324
340
|
@modify_as[key.to_sym] = {include_blank: true}
|
|
341
|
+
elsif $2 == "urlwrap"
|
|
342
|
+
helper_method = $3
|
|
343
|
+
@modify_as[key.to_sym] = { urlwrap: true,
|
|
344
|
+
helper_method: helper_method }
|
|
325
345
|
elsif $2 == "none"
|
|
326
346
|
@modify_as[key.to_sym] = {none: 1, badges: $3}
|
|
327
347
|
else
|
|
@@ -1079,6 +1099,19 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
|
1079
1099
|
end
|
|
1080
1100
|
end
|
|
1081
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
|
+
|
|
1082
1115
|
def check_if_sample_file_is_present
|
|
1083
1116
|
if sample_file_path.nil?
|
|
1084
1117
|
puts "you have no sample file path set in config/hot_glue.yml"
|
|
@@ -1443,15 +1476,15 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
|
1443
1476
|
.to_a.find{|x|
|
|
1444
1477
|
|
|
1445
1478
|
if x.source_reflection
|
|
1446
|
-
x.
|
|
1447
|
-
|
|
1448
|
-
# raise "#{singular_class} class declaration is missing source reflection for the `has_many :#{x.name}` association"
|
|
1479
|
+
x.table_name == plural
|
|
1449
1480
|
end
|
|
1450
1481
|
}.plural_name
|
|
1482
|
+
|
|
1451
1483
|
else
|
|
1452
1484
|
association = plural
|
|
1453
1485
|
end
|
|
1454
1486
|
|
|
1487
|
+
|
|
1455
1488
|
if @auth && !@god
|
|
1456
1489
|
if @nested_set.none?
|
|
1457
1490
|
@auth + ".#{association}"
|
|
@@ -1851,7 +1884,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
|
1851
1884
|
else
|
|
1852
1885
|
if !@self_auth
|
|
1853
1886
|
|
|
1854
|
-
res << spaces(4) + "@#{ plural_name } = #{ object_scope.gsub("@",'') }#{ n_plus_one_includes }#{
|
|
1887
|
+
res << spaces(4) + "@#{ plural_name } = #{ object_scope.gsub("@",'') }#{record_scope}#{ n_plus_one_includes }#{".all" if n_plus_one_includes.blank? && record_scope.blank? }"
|
|
1855
1888
|
|
|
1856
1889
|
if @search_fields
|
|
1857
1890
|
res << @search_fields.collect{ |field|
|
|
@@ -1887,7 +1920,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
|
1887
1920
|
if phantom_data[:type] == "radio"
|
|
1888
1921
|
phantom_data[:choices].each do |choice|
|
|
1889
1922
|
unless choice[:scope] == ".all"
|
|
1890
|
-
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(" ","_")}\""
|
|
1891
1924
|
end
|
|
1892
1925
|
end
|
|
1893
1926
|
elsif phantom_data[:type] == "checkboxes"
|
|
@@ -1898,7 +1931,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
|
1898
1931
|
res << "\n @#{plural} = @#{plural}#{choice[:scope]} if @q['0'][:#{phantom_key}_search__#{choice[:label].gsub(" ", "_").downcase}] == \"1\""
|
|
1899
1932
|
end
|
|
1900
1933
|
unless choice[:scope_negative] == ".all"
|
|
1901
|
-
res << "\n @#{plural} = @#{plural}#{choice[:scope_negative]} if @q['0'][:#{phantom_key}
|
|
1934
|
+
res << "\n @#{plural} = @#{plural}#{choice[:scope_negative]} if @q['0'][:#{phantom_key}_search__#{choice[:label].gsub(" ", "_").downcase}] != \"1\""
|
|
1902
1935
|
end
|
|
1903
1936
|
end
|
|
1904
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
|
data/lib/hotglue/version.rb
CHANGED
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.
|
|
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-
|
|
11
|
+
date: 2025-11-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|