render_turbo_stream 4.3.3 → 4.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -6
- data/lib/render_turbo_stream/libs.rb +21 -13
- data/lib/render_turbo_stream/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de051d73d56102cedd1c2a29e0794041dbe3cd18577300002005ac050eb085e4
|
4
|
+
data.tar.gz: 0224b8f893ecb5408f917b4fe201650b54a815bab020fc3a549cc869da9615a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f756884588c93fcf1052cfcb358fb69e7d996b746aa79d8cf3b134a91037e6acc3ea34253184491b3383a79bf87c2e8b046a4b67b70db950bb1182e41f8c49ca
|
7
|
+
data.tar.gz: 23bcf3db97515ace21d9f84fde860941326db0001c9388e44cb152a08f6288c64e72e949d884fd9be9f06ba3fc8cfe4a2ce9231f877ecc0c8536642e228c65b5
|
data/README.md
CHANGED
@@ -190,9 +190,6 @@ The target ID for turbo has to be unique for sure, and it has to be nice, becaus
|
|
190
190
|
```ruby
|
191
191
|
# target_id(virtual_view_path, object)
|
192
192
|
target_id('customers/_form', Customer.new) #=> 'new-customer-form'
|
193
|
-
target_id('customers/_form', Customer.first) #=> 'customer-1-form'
|
194
|
-
target_id('customers/_form', nil) #=> 'customers-form'
|
195
|
-
target_id('customers/_form', 'hi-joe') #=> 'hi-joe'
|
196
193
|
```
|
197
194
|
|
198
195
|
View-helper: Assuming we are inside `customers/_my_form`:
|
@@ -202,10 +199,13 @@ View-helper: Assuming we are inside `customers/_my_form`:
|
|
202
199
|
target_id
|
203
200
|
#=> 'customer-1-my-form'
|
204
201
|
|
205
|
-
target_id(Customer.
|
206
|
-
#=> '
|
202
|
+
target_id(Customer.first) #=> 'customer-1-my-form'
|
203
|
+
target_id( [Customer.first, Article.last, 'hello'] ) #=> 'customer-1-article-7-hello-my-form'
|
204
|
+
target_id('hi-joe') #=> 'hi-joe'
|
207
205
|
```
|
208
206
|
|
207
|
+
Why include the filename in a html-id? Because for turbo its likely to have multiple cases for the same object on the same page, for example: _form, _show, _password. These can all be the same customer.
|
208
|
+
|
209
209
|
**Target-ID: Avoid the same definition in multiple places**
|
210
210
|
|
211
211
|
Without this gem a turbo action would be wrapped within two frames, for example:
|
@@ -213,7 +213,6 @@ Without this gem a turbo action would be wrapped within two frames, for example:
|
|
213
213
|
```haml
|
214
214
|
= turbo_stream.replace 'target-id' do
|
215
215
|
= render 'a partial'
|
216
|
-
|
217
216
|
```
|
218
217
|
|
219
218
|
and within a partial:
|
@@ -53,26 +53,34 @@ module RenderTurboStream
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def self.target_id(virt_view_path, id)
|
56
|
+
|
56
57
|
if id.is_a?(String)
|
57
58
|
id
|
58
|
-
elsif
|
59
|
-
[
|
60
|
-
virt_view_path.gsub('/', '-').gsub('-_', '-')
|
61
|
-
].join('-')
|
62
|
-
else
|
63
|
-
unless id.methods.include?(:id)
|
64
|
-
raise("target_id / argument ID: Only String or object with method :id accepted")
|
65
|
-
end
|
59
|
+
elsif id
|
66
60
|
(
|
67
|
-
(
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
61
|
+
(id.is_a?(Array) ? id : [id]).map do |_id|
|
62
|
+
|
63
|
+
if _id.is_a?(String)
|
64
|
+
_id
|
65
|
+
elsif _id.methods.include?(:id)
|
66
|
+
(
|
67
|
+
_id.id ?
|
68
|
+
[_id.class.to_s.downcase, _id.id] :
|
69
|
+
['new', _id.class.to_s.downcase]
|
70
|
+
).join('-')
|
71
|
+
else
|
72
|
+
raise("target_id / argument ID: Only String or object with method :id accepted")
|
73
|
+
end
|
74
|
+
end +
|
72
75
|
[
|
73
76
|
virt_view_path.split('/').last.sub(/^_/, '')
|
74
77
|
]
|
75
78
|
).join('-')
|
79
|
+
|
80
|
+
else
|
81
|
+
[
|
82
|
+
virt_view_path.gsub('/', '-').gsub('-_', '-')
|
83
|
+
].join('-')
|
76
84
|
end
|
77
85
|
end
|
78
86
|
|