hot-glue 0.6.6.1 → 0.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/README.md +81 -2
- data/app/helpers/hot_glue/controller_helper.rb +9 -2
- data/lib/generators/hot_glue/field_factory.rb +2 -0
- data/lib/generators/hot_glue/fields/association_field.rb +42 -19
- data/lib/generators/hot_glue/fields/attachment_field.rb +19 -4
- data/lib/generators/hot_glue/fields/field.rb +26 -14
- data/lib/generators/hot_glue/markup_templates/erb.rb +1 -1
- data/lib/generators/hot_glue/scaffold_generator.rb +45 -3
- data/lib/generators/hot_glue/templates/controller.rb.erb +1 -1
- data/lib/hotglue/version.rb +1 -1
- metadata +3 -3
- /data/.circleci/{config.yml → DISABLED__config.yml} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86900d536cda31c5759bd3603aff4e32a7c141bd015f4c3910c1ac2fbd67c083
|
4
|
+
data.tar.gz: 4dfeabc8f4a4f65a626cf6510b11a546d6cf860735a6cb582b6811ac25bdb1a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40f77d7d6552441122511e1fbd144ff9090fac458840333d9d4062c443466e9fe12932fb2748e40a9799562b71fa028b53910f34da77eae281bb18b8055e0cd5
|
7
|
+
data.tar.gz: 281870175e5d080e79f0afc9d190e5f6047660cea7cc16470fe3feec2cdd18da67ef99e0d686fa2c9378d45a77cf4b0b9a041635df3aeee57c84796a972f69fe
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hot-glue (0.6.
|
4
|
+
hot-glue (0.6.8)
|
5
5
|
ffaker (~> 2.16)
|
6
6
|
kaminari (~> 1.2)
|
7
7
|
rails (> 5.1)
|
@@ -90,7 +90,7 @@ GEM
|
|
90
90
|
xpath (~> 3.2)
|
91
91
|
concurrent-ruby (1.1.10)
|
92
92
|
crass (1.0.6)
|
93
|
-
date (3.
|
93
|
+
date (3.4.1)
|
94
94
|
devise (4.8.1)
|
95
95
|
bcrypt (~> 3.0)
|
96
96
|
orm_adapter (~> 0.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.
|
142
|
+
net-imap (0.5.1)
|
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.4.
|
238
|
+
timeout (0.4.2)
|
239
239
|
turbo-rails (1.3.2)
|
240
240
|
actionpack (>= 6.0.0)
|
241
241
|
activejob (>= 6.0.0)
|
data/README.md
CHANGED
@@ -690,10 +690,60 @@ Notice that each modifiers can be used with specific field types.
|
|
690
690
|
| tinymce | applies to text fields only, be sure to setup TineMCE globally | text fields only | | |
|
691
691
|
| typeahead | turns a foreign key (only) into a searchable typeahead field | foreign keys only | | |
|
692
692
|
| timezone | turns a string (varchar) into a drop down of timezones | foreign keys only | | |
|
693
|
-
|
693
|
+
| none | special modifier for using badges |
|
694
694
|
|
695
695
|
Except for "(truthy label)" and "(falsy label)" which use the special syntax, use the modifier _exactly_ as it is named.
|
696
696
|
|
697
|
+
apply badge behavior using `[` and `]` markers after the modification marker.
|
698
|
+
|
699
|
+
`--modify=opened_at{opened|closed}[bg-primary|bg-secondary]`
|
700
|
+
Applies a badge `bg-primary` to rows with opened_at truthy and `bg-secondary` to rows with opened_at falsy.
|
701
|
+
|
702
|
+
to display a badge on everything, use the `none` modifier with the
|
703
|
+
`--modify=opened_at{none}[bg-dark]`
|
704
|
+
|
705
|
+
|
706
|
+
|
707
|
+
### `--alt-foreign-key-lookup=`
|
708
|
+
|
709
|
+
Use for a join table to specify that a field should be looked up by a different field
|
710
|
+
|
711
|
+
|
712
|
+
`./bin/rails generate hot_glue:scaffold AccountUser --alt-foreign-key-lookup=user_id{email}`
|
713
|
+
|
714
|
+
Here we are specifying that the `user_id` field should be looked up by the `email` field on the User table.
|
715
|
+
If no existing user exists, we create one because we are using the `find_or_create_by!` method.
|
716
|
+
|
717
|
+
Use with a factory pattern like this one:
|
718
|
+
```
|
719
|
+
class AccountUserFactory
|
720
|
+
attr_accessor :account_user
|
721
|
+
|
722
|
+
def initialize(params: {}, account: nil)
|
723
|
+
begin
|
724
|
+
user = User.find_or_create_by!( email: params[:__lookup_email])
|
725
|
+
rescue ActiveRecord::RecordInvalid => e
|
726
|
+
@account_user = AccountUser.new({account: account})
|
727
|
+
|
728
|
+
@account_user.errors.add(:user, e.message)
|
729
|
+
end
|
730
|
+
|
731
|
+
@account_user = AccountUser.new(params.tap{|x| x.delete(:__lookup_email)}
|
732
|
+
.merge({user: user,
|
733
|
+
account: account}))
|
734
|
+
end
|
735
|
+
end
|
736
|
+
```
|
737
|
+
|
738
|
+
this works with a factory creation syntax like so:
|
739
|
+
|
740
|
+
```
|
741
|
+
--factory-creation='factory = AccountUserFactory.new(params: account_user_params, account: account)
|
742
|
+
```
|
743
|
+
*See the `--factory-creation` section.
|
744
|
+
|
745
|
+
|
746
|
+
|
697
747
|
### `--pundit`
|
698
748
|
If you enable Pundit, your controllers will look for a Policy that matches the name of the thing being built.
|
699
749
|
|
@@ -1612,6 +1662,35 @@ These automatic pickups for partials are detected at buildtime. This means that
|
|
1612
1662
|
|
1613
1663
|
# VERSION HISTORY
|
1614
1664
|
|
1665
|
+
|
1666
|
+
#### 2024-12-05 - v0.6.8
|
1667
|
+
• fixes in modify_date_inputs_on_params for current_user_object
|
1668
|
+
|
1669
|
+
• adds back alt_lookup feature from version 0.5.7; use with --alt-foreign-key-lookup
|
1670
|
+
|
1671
|
+
• badges can be added to modified fields using `[` and `]` which come after the modification flag inside `{...}`.
|
1672
|
+
for booleans separate with pipes `|`
|
1673
|
+
|
1674
|
+
• you can add badges to fields that have no other modification using the `none` modifier
|
1675
|
+
|
1676
|
+
|
1677
|
+
#### 2024-11-26 - v0.6.7
|
1678
|
+
|
1679
|
+
Patch for my non-:00 seconds problem. I have discovered that the root of my issues was a quirk in how browsers display datetime-local fields.
|
1680
|
+
|
1681
|
+
This implementation favors a no-seconds approach, which is a good idea for most applications. If you need seconds, you should use a different approach.
|
1682
|
+
|
1683
|
+
here is a note about the problem:
|
1684
|
+
# note: as according to https://stackoverflow.com/questions/20111413/html5-datetime-local-control-how-to-hide-seconds
|
1685
|
+
# there is no way to set the seconds to 00 in the datetime-local input field
|
1686
|
+
# as I have implemented a "seconds don't matter" solution,
|
1687
|
+
# the only solution is to avoid setting any non-00 datetime values into the database
|
1688
|
+
# if they already exist in your database, you should zero them out
|
1689
|
+
# or apply .change(sec: 0) when displaying them as output in the form
|
1690
|
+
# this will prevent seconds from being added by the browser
|
1691
|
+
|
1692
|
+
|
1693
|
+
|
1615
1694
|
#### 2024-11-18 - v0.6.6.1
|
1616
1695
|
|
1617
1696
|
- Adds hg- classes to the form fields for easier styling
|
@@ -2137,7 +2216,7 @@ div[class$="--phone_number"] {
|
|
2137
2216
|
#### 2023-02-13 - v0.5.7 - factory-creation, alt lookups, update show only, fixes to Enums, support for Ruby 3.2
|
2138
2217
|
• See `--factory-creation` section.
|
2139
2218
|
|
2140
|
-
• `--alt-
|
2219
|
+
• `--alt-foreign-key-lookup`
|
2141
2220
|
Allows you to specify that a foreign key should act as a search field, allowing the user to input a unique value (like an email) to search for a related record.
|
2142
2221
|
|
2143
2222
|
• `--update-show-only`
|
@@ -69,7 +69,7 @@ module HotGlue
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def modify_date_inputs_on_params(modified_params, current_user_object = nil, field_list = nil)
|
72
|
-
use_timezone = (
|
72
|
+
use_timezone = (current_user_object.try(:timezone)) || Time.zone
|
73
73
|
modified_params = modified_params.tap do |params|
|
74
74
|
params.keys.each{|k|
|
75
75
|
|
@@ -81,7 +81,14 @@ module HotGlue
|
|
81
81
|
if include_me && params[k].present?
|
82
82
|
if use_timezone
|
83
83
|
parse_date = "#{params[k].gsub("T", " ")} #{use_timezone.formatted_offset}"
|
84
|
-
|
84
|
+
# note: as according to https://stackoverflow.com/questions/20111413/html5-datetime-local-control-how-to-hide-seconds
|
85
|
+
# there is no way to set the seconds to 00 in the datetime-local input field
|
86
|
+
# as I have implemented a "seconds don't matter" solution,
|
87
|
+
# the only solution is to avoid setting any non-00 datetime values into the database
|
88
|
+
# if they already exist in your database, you should zero them out
|
89
|
+
# or apply .change(sec: 0) when displaying them as output in the form
|
90
|
+
# this will prevent seconds from being added by the browser
|
91
|
+
params[k] = Time.strptime(parse_date, "%Y-%m-%d %H:%M %Z")
|
85
92
|
end
|
86
93
|
end
|
87
94
|
}
|
@@ -49,6 +49,7 @@ class FieldFactory
|
|
49
49
|
end
|
50
50
|
@class_name = class_name
|
51
51
|
|
52
|
+
|
52
53
|
@field = field_class.new(name: name,
|
53
54
|
layout_strategy: generator.layout_strategy,
|
54
55
|
form_placeholder_labels: generator.form_placeholder_labels,
|
@@ -57,6 +58,7 @@ class FieldFactory
|
|
57
58
|
hawk_keys: generator.hawk_keys,
|
58
59
|
auth: generator.auth,
|
59
60
|
class_name: generator.singular_class,
|
61
|
+
alt_lookup: generator.alt_lookups[name] || nil,
|
60
62
|
singular: generator.singular,
|
61
63
|
self_auth: generator.self_auth,
|
62
64
|
update_show_only: generator.update_show_only,
|
@@ -3,9 +3,9 @@ require_relative './field.rb'
|
|
3
3
|
|
4
4
|
class AssociationField < Field
|
5
5
|
|
6
|
-
attr_accessor :assoc_name, :assoc_class, :assoc
|
6
|
+
attr_accessor :assoc_name, :assoc_class, :assoc, :alt_lookup
|
7
7
|
|
8
|
-
def initialize( class_name: , default_boolean_display:, display_as: ,
|
8
|
+
def initialize( alt_lookup: , class_name: , default_boolean_display:, display_as: ,
|
9
9
|
name: , singular: ,
|
10
10
|
update_show_only: ,
|
11
11
|
hawk_keys: , auth: , sample_file_path:, ownership_field: ,
|
@@ -13,6 +13,7 @@ class AssociationField < Field
|
|
13
13
|
form_labels_position:, modify_as: , self_auth: , namespace:, pundit: )
|
14
14
|
super
|
15
15
|
|
16
|
+
|
16
17
|
@assoc_model = eval("#{class_name}.reflect_on_association(:#{assoc})")
|
17
18
|
|
18
19
|
if assoc_model.nil?
|
@@ -47,7 +48,7 @@ class AssociationField < Field
|
|
47
48
|
end
|
48
49
|
|
49
50
|
def spec_setup_and_change_act(which_partial)
|
50
|
-
if which_partial == :
|
51
|
+
if which_partial == :update_show_only && update_show_only.include?(name)
|
51
52
|
|
52
53
|
else
|
53
54
|
" #{name}_selector = find(\"[name='#{singular}[#{name}]']\").click \n" +
|
@@ -75,10 +76,38 @@ class AssociationField < Field
|
|
75
76
|
" let!(:#{assoc}1) {create(:#{the_foreign_class}" + hawk_keys_on_lets + ")}"
|
76
77
|
end
|
77
78
|
|
79
|
+
def raw_view_field
|
80
|
+
assoc_name = name.to_s.gsub("_id","")
|
81
|
+
assoc = eval("#{class_name}.reflect_on_association(:#{assoc_name})")
|
82
|
+
if assoc.nil?
|
83
|
+
exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
84
|
+
exit
|
85
|
+
end
|
86
|
+
is_owner = name == ownership_field
|
87
|
+
assoc_class_name = assoc.class_name.to_s
|
88
|
+
display_column = HotGlue.derrive_reference_name(assoc_class_name)
|
89
|
+
|
90
|
+
|
91
|
+
"<%= #{singular}.#{assoc_name}.#{display_column} %>"
|
92
|
+
end
|
93
|
+
|
78
94
|
def form_field_output
|
79
95
|
assoc_name = name.to_s.gsub("_id","")
|
80
96
|
assoc = eval("#{class_name}.reflect_on_association(:#{assoc_name})")
|
81
|
-
|
97
|
+
|
98
|
+
if alt_lookup
|
99
|
+
alt = alt_lookup[:lookup_as]
|
100
|
+
assoc_name = name.to_s.gsub("_id","")
|
101
|
+
assoc = eval("#{class_name}.reflect_on_association(:#{assoc_name})")
|
102
|
+
|
103
|
+
alt = alt_lookup[:lookup_as]
|
104
|
+
"<%= f.text_field :__lookup_#{alt}, value: @#{singular}.#{assoc_name}.try(:#{alt}), placeholder: \"search by #{alt}\" %>"
|
105
|
+
|
106
|
+
# if modify_as
|
107
|
+
# modified_display_output
|
108
|
+
# else
|
109
|
+
# end
|
110
|
+
elsif modify_as && modify_as[:typeahead]
|
82
111
|
search_url = "#{namespace ? namespace + "_" : ""}#{assoc.class_name.downcase.pluralize}_typeahead_index_url"
|
83
112
|
"<div class='typeahead typeahead--#{assoc.name}_id'
|
84
113
|
data-controller='typeahead'
|
@@ -122,25 +151,19 @@ class AssociationField < Field
|
|
122
151
|
end
|
123
152
|
|
124
153
|
def form_show_only_output
|
125
|
-
assoc_name = name.to_s.gsub("_id","")
|
126
|
-
assoc = eval("#{class_name}.reflect_on_association(:#{assoc_name})")
|
127
|
-
if assoc.nil?
|
128
|
-
exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
129
|
-
exit
|
130
|
-
end
|
131
154
|
|
132
|
-
is_owner = name == ownership_field
|
133
|
-
assoc_class_name = assoc.class_name.to_s
|
134
|
-
display_column = HotGlue.derrive_reference_name(assoc_class_name)
|
135
155
|
|
136
|
-
if hawk_keys[assoc.foreign_key.to_sym]
|
137
|
-
|
138
|
-
|
156
|
+
# if hawk_keys[assoc.foreign_key.to_sym]
|
157
|
+
# hawk_definition = hawk_keys[assoc.foreign_key.to_sym]
|
158
|
+
# hawked_association = hawk_definition.join(".")
|
159
|
+
# else
|
160
|
+
# hawked_association = "#{assoc.class_name}.all"
|
161
|
+
# end
|
162
|
+
if modify_as && modify_as[:none]
|
163
|
+
"<span class='badge #{modify_as[:badges]}'>" + raw_view_field + "</span>"
|
139
164
|
else
|
140
|
-
|
165
|
+
raw_view_field
|
141
166
|
end
|
142
|
-
"<%= #{singular}.#{assoc_name}.#{display_column} %>"
|
143
|
-
|
144
167
|
end
|
145
168
|
|
146
169
|
def line_field_output
|
@@ -1,9 +1,24 @@
|
|
1
1
|
class AttachmentField < Field
|
2
2
|
attr_accessor :attachment_data
|
3
|
-
def initialize(
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
def initialize(alt_lookup:,
|
4
|
+
attachment_data:,
|
5
|
+
auth:,
|
6
|
+
class_name:,
|
7
|
+
display_as:, singular:,
|
8
|
+
default_boolean_display: ,
|
9
|
+
form_placeholder_labels: ,
|
10
|
+
form_labels_position:,
|
11
|
+
hawk_keys:,
|
12
|
+
layout_strategy: ,
|
13
|
+
name:,
|
14
|
+
namespace:,
|
15
|
+
modify_as:,
|
16
|
+
ownership_field:,
|
17
|
+
pundit: ,
|
18
|
+
sample_file_path: nil,
|
19
|
+
self_auth:,
|
20
|
+
update_show_only:
|
21
|
+
)
|
7
22
|
super
|
8
23
|
|
9
24
|
@attachment_data = attachment_data
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class Field
|
2
|
-
attr_accessor :assoc_model, :assoc_name, :assoc_class, :associations, :
|
2
|
+
attr_accessor :assoc_model, :assoc_name, :assoc_class, :associations, :alt_lookup, :auth,
|
3
3
|
:assoc_label, :class_name, :default_boolean_display, :display_as, :form_placeholder_labels,
|
4
4
|
:form_labels_position,
|
5
5
|
:hawk_keys, :layout_strategy, :limit, :modify_as, :name, :object, :sample_file_path,
|
@@ -11,6 +11,7 @@ class Field
|
|
11
11
|
auth: ,
|
12
12
|
attachment_data: nil,
|
13
13
|
class_name: ,
|
14
|
+
alt_lookup: ,
|
14
15
|
default_boolean_display: ,
|
15
16
|
display_as: ,
|
16
17
|
form_labels_position:,
|
@@ -29,7 +30,7 @@ class Field
|
|
29
30
|
)
|
30
31
|
@name = name
|
31
32
|
@layout_strategy = layout_strategy
|
32
|
-
@
|
33
|
+
@alt_lookup = alt_lookup
|
33
34
|
@singular = singular
|
34
35
|
@class_name = class_name
|
35
36
|
@update_show_only = update_show_only
|
@@ -123,13 +124,22 @@ class Field
|
|
123
124
|
|
124
125
|
def viewable_output
|
125
126
|
if modify_as
|
126
|
-
modified_display_output
|
127
|
+
modified_display_output(show_only: true)
|
128
|
+
else
|
129
|
+
field_view_output
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def field_view_output
|
134
|
+
if modify_as && modify_as[:none]
|
135
|
+
"<span class='badge #{modify_as[:badges]}'>" + field_view_output + "</span>"
|
127
136
|
else
|
128
137
|
"<%= #{singular}.#{name} %>"
|
129
138
|
end
|
130
139
|
end
|
131
140
|
|
132
|
-
|
141
|
+
|
142
|
+
def modified_display_output(show_only: false)
|
133
143
|
res = +''
|
134
144
|
|
135
145
|
if modify_as[:cast] && modify_as[:cast] == "$"
|
@@ -141,19 +151,21 @@ class Field
|
|
141
151
|
elsif modify_as[:timezone]
|
142
152
|
res += "<%= #{singular}.#{name} %>"
|
143
153
|
elsif modify_as[:enum]
|
144
|
-
|
154
|
+
elsif modify_as[:none]
|
155
|
+
field_view_output
|
156
|
+
# res += "<%= render partial: #{singular}.#{name}, locals: {#{singular}: #{singular}} %>"
|
145
157
|
end
|
146
158
|
|
147
|
-
if modify_as[:badges]
|
148
|
-
badge_code = if modify_as[:binary]
|
149
|
-
"#{singular}.#{name} ? '#{modify_as[:badges].split("|")[0]}' : '#{modify_as[:badges].split("|")[1]}'"
|
150
|
-
else
|
151
|
-
modify_as[:badges].split("|").to_s + "[#{singular}.#{name}]"
|
152
|
-
end
|
153
|
-
res = "<span class='badge <%= #{badge_code} %>'>" + res + "</span>"
|
154
|
-
end
|
155
|
-
# byebug
|
156
159
|
|
160
|
+
# if modify_as[:badges]
|
161
|
+
# badge_code = if modify_as[:binary]
|
162
|
+
# "#{singular}.#{name} ? '#{modify_as[:badges].split("|")[0]}' : '#{modify_as[:badges].split("|")[1]}'"
|
163
|
+
# else
|
164
|
+
# modify_as[:badges].split("|").to_s + "[#{singular}.#{name}]"
|
165
|
+
# end
|
166
|
+
# res = "<span class='badge <%= #{badge_code} %>'>" + res + "</span>"
|
167
|
+
# end
|
168
|
+
# byebug
|
157
169
|
res
|
158
170
|
end
|
159
171
|
|
@@ -150,7 +150,7 @@ module HotGlue
|
|
150
150
|
elsif update_show_only.include?(col) && @pundit && eval("defined? #{singular_class}Policy") && eval("#{singular_class}Policy").instance_methods.include?("#{col}_able?".to_sym)
|
151
151
|
"<% if @action == 'new' && policy(@#{singular}).#{col}_able? %>" + columns_map[col].form_field_output + "<% else %>" + columns_map[col].form_show_only_output + "<% end %>"
|
152
152
|
|
153
|
-
|
153
|
+
# show only on the update action overrides any pundit policy
|
154
154
|
elsif @pundit && eval("defined? #{singular_class}Policy") && eval("#{singular_class}Policy").instance_methods.include?("#{col}_able?".to_sym)
|
155
155
|
"<% if policy(@#{singular}).#{col}_able? %>" + columns_map[col].form_field_output + "<% else %>" + columns_map[col].form_show_only_output + "<% end %>"
|
156
156
|
else
|
@@ -16,7 +16,9 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
16
16
|
hook_for :form_builder, :as => :scaffold
|
17
17
|
|
18
18
|
source_root File.expand_path('templates', __dir__)
|
19
|
-
attr_accessor :
|
19
|
+
attr_accessor :alt_lookups, :attachments, :auth,
|
20
|
+
:big_edit, :button_icons, :bootstrap_column_width,
|
21
|
+
:columns,
|
20
22
|
:default_boolean_display,
|
21
23
|
:display_as, :downnest_children, :downnest_object, :hawk_keys, :layout_object,
|
22
24
|
:modify_as,
|
@@ -260,6 +262,8 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
260
262
|
@modify_as[key.to_sym] = {typeahead: 1, badges: $3}
|
261
263
|
elsif $2 == "timezone"
|
262
264
|
@modify_as[key.to_sym] = {timezone: 1, badges: $3}
|
265
|
+
elsif $2 == "none"
|
266
|
+
@modify_as[key.to_sym] = {none: 1, badges: $3}
|
263
267
|
else
|
264
268
|
raise "unknown modification direction #{$2}"
|
265
269
|
end
|
@@ -466,6 +470,30 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
466
470
|
buttons_width = ((!@no_edit && 1) || 0) + ((!@no_delete && 1) || 0) + @magic_buttons.count
|
467
471
|
|
468
472
|
|
473
|
+
# alt_lookups_entry =
|
474
|
+
|
475
|
+
|
476
|
+
@alt_lookups = {}
|
477
|
+
|
478
|
+
options['alt_foreign_key_lookup'].split(",").each do |setting|
|
479
|
+
setting =~ /(.*){(.*)}/
|
480
|
+
key, lookup_as = $1, $2
|
481
|
+
|
482
|
+
assoc = eval("#{class_name}.reflect_on_association(:#{key.to_s.gsub("_id","")}).class_name")
|
483
|
+
|
484
|
+
data = {lookup_as: lookup_as.gsub("+",""),
|
485
|
+
assoc: assoc,
|
486
|
+
with_create: lookup_as.include?("+")}
|
487
|
+
@alt_lookups[key] = data
|
488
|
+
end
|
489
|
+
|
490
|
+
puts "------ ALT LOOKUPS for #{@alt_lookups}"
|
491
|
+
|
492
|
+
# @update_alt_lookups = @alt_lookups.collect{|key, value|
|
493
|
+
# @update_show_only.include?(key) ?
|
494
|
+
# { key: value }
|
495
|
+
# : nil}.compact
|
496
|
+
|
469
497
|
|
470
498
|
|
471
499
|
# build a new polymorphic object
|
@@ -554,6 +582,15 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
554
582
|
@layout_object = builder.construct
|
555
583
|
|
556
584
|
|
585
|
+
|
586
|
+
# syntax should be xyz_id{xyz_email},abc_id{abc_email}
|
587
|
+
# instead of a drop-down for the foreign entity, a text field will be presented
|
588
|
+
# You must ALSO use a factory that contains a parameter of the same name as the 'value' (for example, `xyz_email`)
|
589
|
+
|
590
|
+
|
591
|
+
|
592
|
+
|
593
|
+
|
557
594
|
# create the template object
|
558
595
|
|
559
596
|
|
@@ -612,6 +649,10 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
612
649
|
end
|
613
650
|
|
614
651
|
hawk_scope = key.gsub("_id", "").pluralize
|
652
|
+
if eval(singular_class + ".reflect_on_association(:#{key.gsub('_id', '')})").nil?
|
653
|
+
raise "Could not find `#{key.gsub('_id', '')}` association; add this to the #{singular_class} class: \nbelongs_to :#{key.gsub('_id', '')} "
|
654
|
+
end
|
655
|
+
|
615
656
|
optional = eval(singular_class + ".reflect_on_association(:#{key.gsub('_id', '')})").options[:optional]
|
616
657
|
|
617
658
|
@hawk_keys[key.to_sym] = { bind_to: [hawk_to], optional: optional }
|
@@ -1253,9 +1294,10 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
1253
1294
|
def insert_into_nav_template
|
1254
1295
|
# how does this get called(?)
|
1255
1296
|
nav_file = "#{Rails.root}/app/views/#{namespace_with_trailing_dash}_nav.html.#{@markup}"
|
1256
|
-
|
1297
|
+
|
1298
|
+
if include_nav_template
|
1257
1299
|
append_text = " <li class='nav-item'>
|
1258
|
-
<%= link_to '#{@list_label_heading}', #{path_helper_plural}, class: \"nav-link \#{'active' if nav == '#{plural_name}'}\" %>
|
1300
|
+
<%= link_to '#{@list_label_heading.humanize}', #{path_helper_plural(@nested_set.any? ? true: false)}, class: \"nav-link \#{'active' if nav == '#{plural_name}'}\" %>
|
1259
1301
|
</li>"
|
1260
1302
|
|
1261
1303
|
text = File.read(nav_file)
|
@@ -226,7 +226,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
226
226
|
end<% end %><% end %>
|
227
227
|
|
228
228
|
def <%=singular_name%>_params
|
229
|
-
params.require(:<%= testing_name %>).permit(<%= ((fields_filtered_for_strong_params - @show_only ) + @magic_buttons.collect{|x| "__#{x}"}).collect{|sym| ":#{sym}"}.join(", ") %><%= ", " + @related_sets.collect{|key, rs| "#{rs[:association_ids_method]}: []"}.join(", ") if @related_sets.any? %>)
|
229
|
+
params.require(:<%= testing_name %>).permit(<%= ((fields_filtered_for_strong_params - @show_only ) + @magic_buttons.collect{|x| "__#{x}"}).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[:lookup_as]}" }.join(", ") if @alt_lookups.any? %>)
|
230
230
|
end<% if @update_show_only %>
|
231
231
|
|
232
232
|
<% unless @no_edit %>
|
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.6.
|
4
|
+
version: 0.6.8
|
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: 2024-
|
11
|
+
date: 2024-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -59,7 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- ".circleci/
|
62
|
+
- ".circleci/DISABLED__config.yml"
|
63
63
|
- ".github/FUNDING.yml"
|
64
64
|
- ".github/workflows/test_suite.yml"
|
65
65
|
- ".gitignore"
|
File without changes
|