render_turbo_stream 0.1.42 → 0.1.44

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: 262075083599385cfe9bf300a909ae3dd0feee5f7ba32691a3024260307301c5
4
- data.tar.gz: 71629066a9d7dfd6a2fab896e63011d23a8b735539cda0afb21eec2a4807d571
3
+ metadata.gz: ea0b39e1e5da88d8de2c8d84f287f6ce8ca6012b6ca203266fdf0f647f05a50f
4
+ data.tar.gz: a488032ebb3f9975e8ca9ec90b5e86238780f85a385efca0e4a01ece52f3440c
5
5
  SHA512:
6
- metadata.gz: ae1caa61d33da5504bc562eabd139d1c0566b4ac7a23989603e4225464b7e41a6e423e67e2141255f0488698ca08ac65533cf1e87013a734362b0404f48e0705
7
- data.tar.gz: e95004ea0010b2c4ee433208b36250ad47fd4dd48646f962bfa4a0cd966deb5421fc95dbb82d6ff8759ed09b5da14dab3808976895bf64270203f6902755a29e
6
+ metadata.gz: f137735dcfc2b7d77147e6cee12e432377f165b57fc7d42fd33274cd7865f99a8c8d58b66340ee3de695ceb3393c6a88584a70347143de211fab80200962a14d
7
+ data.tar.gz: 44813c9288b2c1d4d206e848969ddcc3a486ef1e3034a13bb66b581a582044dc42dfff8e2c12df573efbf45b9a55ab52d2b5a6e5651837a1b73957b22e89e94f
data/README.md CHANGED
@@ -32,11 +32,11 @@ spec/rails_helper.rb
32
32
 
33
33
  ```ruby
34
34
  RSpec.configure do |config|
35
- config.include RenderTurboStream::RequestTestHelpers, type: :request
35
+ config.include RenderTurboStream::Test::RequestHelpers, type: :request
36
36
  end
37
37
  ```
38
38
 
39
- Redirection
39
+ **Redirection**
40
40
 
41
41
  For redirection to work, you must follow the installation steps
42
42
  from [turbo_power](https://github.com/marcoroth/turbo_power).
@@ -132,8 +132,8 @@ RSpec.describe "Articles", type: :request do
132
132
 
133
133
  expect(partial_response('flash'){|r|r.inner_html.include?('Article could not be created')}).to eq(true)
134
134
  expect(partial_response('flash'){|r|r.css('div').inner_html.include?('Article could not be created')}).to eq(true)
135
- #=> you can use the validators of nokogiri, check: https://nokogiri.org/tutorials/parsing_an_html_xml_document.html
136
135
  #=> if a partial was rendered more than once: at least one response must match
136
+ #=> you can use the validators of nokogiri, check: https://nokogiri.org/tutorials/parsing_an_html_xml_document.html
137
137
  end
138
138
 
139
139
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  <% streams.each do |s| %>
4
4
 
5
- <% html = (render s[:partial], locals: s[:locals], formats: [:html]) %>
5
+ <% html = (render s[:partial], locals: s[:locals].symbolize_keys, formats: [:html]) %>
6
6
 
7
7
  <% rendered_partials.push({ html_response: html }.merge(s)) %>
8
8
 
@@ -17,21 +17,21 @@
17
17
  <% ctl[:action] = :replace %>
18
18
  <% Rails.logger.debug(" • render-turbo-stream REPLACE => #{info}") %>
19
19
  <%= turbo_stream.replace s[:id] do %>
20
- <%= render s[:partial], locals: s[:locals] %>
20
+ <%= render s[:partial], locals: s[:locals].symbolize_keys %>
21
21
  <% end %>
22
22
 
23
23
  <% elsif s[:action].to_sym == :prepend %>
24
24
  <% ctl[:action] = :prepend %>
25
25
  <% Rails.logger.debug(" • render-turbo-stream PREPEND => #{info}") %>
26
26
  <%= turbo_stream.prepend s[:id] do %>
27
- <%= render s[:partial], locals: s[:locals] %>
27
+ <%= render s[:partial], locals: s[:locals].symbolize_keys %>
28
28
  <% end %>
29
29
 
30
30
  <% elsif s[:action].to_sym == :append %>
31
31
  <% ctl[:action] = :append %>
32
32
  <% Rails.logger.debug(" • render-turbo-stream APPEND => #{info}") %>
33
33
  <%= turbo_stream.prepend s[:id] do %>
34
- <%= render s[:partial], locals: s[:locals] %>
34
+ <%= render s[:partial], locals: s[:locals].symbolize_keys %>
35
35
  <% end %>
36
36
 
37
37
  <% else %>
@@ -43,8 +43,8 @@ module RenderTurboStream
43
43
  end
44
44
 
45
45
 
46
- def partial_response(partial, id: nil, count: 1, &block)
47
- RenderTurboStream::Libs.partial_response(response, partial, id, count, &block )
46
+ def partial_response_count(partial, id: nil, total: 1, &block)
47
+ RenderTurboStream::Libs.partial_response_count(response, partial, id, total, &block )
48
48
  end
49
49
 
50
50
  end
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "0.1.42"
2
+ VERSION = "0.1.44"
3
3
  end
@@ -216,7 +216,7 @@ module RenderTurboStream
216
216
  else
217
217
  a['id'] == id
218
218
  end
219
- partial_matched || id_matched
219
+ partial_matched && (id.present? ? id_matched : true)
220
220
  end
221
221
 
222
222
  end
@@ -233,26 +233,22 @@ module RenderTurboStream
233
233
  part.length
234
234
  end
235
235
 
236
- def self.partial_response(response, partial, id, count, &block)
236
+ def self.partial_response_count(response, partial, id, total, &block)
237
237
  responses = select_responses(response, partial, id)
238
- if block_given?
239
238
 
240
- success = false
241
-
242
- responses.each do |r|
239
+ if total && responses.count != total
240
+ false
241
+ elsif block_given?
242
+ res = responses.select do |r|
243
243
  parsed = Nokogiri::HTML(r['html_response'])
244
244
  r = yield parsed
245
- success = true if r.present?
246
- end
247
- success
248
-
245
+ r.present?
246
+ end.length
247
+ (res == 0 ? nil : res)
249
248
  else
250
- if count
251
- responses.length == count
252
- else
253
- nil
254
- end
249
+ responses.length
255
250
  end
251
+
256
252
  end
257
253
 
258
254
  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: 0.1.42
4
+ version: 0.1.44
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian
@@ -26,8 +26,8 @@ dependencies:
26
26
  version: 7.0.4.3
27
27
  description: 'Writing views like (create|update).turbo_stream.haml annoyed me. This
28
28
  gem handles translated flash messages, sets status, and renders partials through
29
- turbo-stream. You can control it directly from the controller. It also handles redirection:
30
- turbo_power is included. Comes with predefined test helpers.'
29
+ turbo-stream. You can control them directly from the controller. It also handles
30
+ redirection: turbo_power is included. Includes helpers for enabling request testing.'
31
31
  email:
32
32
  - christian@sedlmair.ch
33
33
  executables: []
@@ -71,5 +71,6 @@ requirements: []
71
71
  rubygems_version: 3.4.12
72
72
  signing_key:
73
73
  specification_version: 4
74
- summary: Render turbo-stream partials directly from the controller
74
+ summary: Render turbo-stream partials directly from the controller, including test
75
+ helpers
75
76
  test_files: []