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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d66f0d9cb7dc4822dbcaf38e286b855386e8637b07a922db1714b14ab63d0c6d
4
- data.tar.gz: 017a6047f0c07a1f2847f7be92d810483c00690e1c31f0cb31581004d48f8f18
3
+ metadata.gz: de051d73d56102cedd1c2a29e0794041dbe3cd18577300002005ac050eb085e4
4
+ data.tar.gz: 0224b8f893ecb5408f917b4fe201650b54a815bab020fc3a549cc869da9615a6
5
5
  SHA512:
6
- metadata.gz: a3853c69389798f965cb41e629fb208e6926b3a4ce2d5f0f925554cec41d470fa5963ad6d88dd1712e787be3db683f1e61cce7411c78f8dda574069f7d5a9b55
7
- data.tar.gz: 78719ff0ab9c7299639161ba2a966786d18dc79b9f401e8112b58656f2270436c51119c3eb6297f73c4df4e40dc7843bebe4496a9a5cbcc6d187b6898fa00245
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.new)
206
- #=> 'new-customer-my-form'
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 !id
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
- id.id ?
69
- [id.class.to_s.downcase, id.id] :
70
- ['new', id.class.to_s.downcase]
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
 
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "4.3.3"
2
+ VERSION = "4.3.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: render_turbo_stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.3
4
+ version: 4.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian