render_turbo_stream 0.1.17 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/render_turbo_stream/test_helpers.rb +16 -1
- data/lib/render_turbo_stream/version.rb +1 -1
- data/lib/render_turbo_stream.rb +11 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f816fb8eab0243274dc8b448982358b90e12fe3d7d431f104dd12d3e56d2aacb
|
4
|
+
data.tar.gz: 1b515e61a40ac0126aba2cc43940b181f3fca19e3305320d13eb0e5848f4fc7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a98cc8fff61ac5044c0af6051a59262383b1f41d5b1559bcfc2ccd3b87e46df14a576fd7615286c51617e76b2570046f84c10dade94c71c9757103fe29116a3b
|
7
|
+
data.tar.gz: c09722e38db120023eb577187ef4f7c1b1e3562a6ab6af6cf9ed3f86f2b8acf36df96d1aa621cbc796ad73cf272d9adbb67d9ebd2f3872cbfcc73447b9041438
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Defining templates like `(create|update).turbo_stream.haml` annoyed me.
|
|
4
4
|
|
5
5
|
Working consistently with turbo_stream means shooting lots of partials from the backend to the frontend, which always needs the same attributes: ID, partial, and maybe some locals. This gem serializes that: Partials can be controlled directly from the controller.
|
6
6
|
|
7
|
-
It sets the status, generates a flash message, handles redirection, pushes it all to the front and
|
7
|
+
It sets the status, generates a flash message, handles redirection, pushes it all to the front and comes with predefined helpers for enabling request-specs.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module RenderTurboStream
|
2
2
|
module TestHelpers
|
3
|
-
def
|
3
|
+
def rendered_ids
|
4
4
|
e = Nokogiri::HTML(response.body).search('#check-json').first
|
5
5
|
JSON.parse(e.inner_html).keys
|
6
6
|
end
|
@@ -9,6 +9,21 @@ module RenderTurboStream
|
|
9
9
|
JSON.parse(e.inner_html)
|
10
10
|
end
|
11
11
|
|
12
|
+
# returns all partials that would be streamed to a given ID
|
13
|
+
# note: if more than one partial by turbo_stream.replace are streamed to same ID, render_turbo_stream, in test mode already throws a error
|
14
|
+
def rendered_partials_where_id(id)
|
15
|
+
partials = Nokogiri::HTML(response.body).search('#rendered-partials').first
|
16
|
+
JSON.parse(e.inner_html)
|
17
|
+
partials.select{|p| p[id] == id }
|
18
|
+
end
|
19
|
+
|
20
|
+
# returns the first partial that would be streamed to a given ID
|
21
|
+
def rendered_partials_find_id(id)
|
22
|
+
partials = Nokogiri::HTML(response.body).search('#rendered-partials').first
|
23
|
+
JSON.parse(e.inner_html)
|
24
|
+
partials.select{|p| p[id] == id }.first
|
25
|
+
end
|
26
|
+
|
12
27
|
def rendered_partials_count
|
13
28
|
rendered_partials.length
|
14
29
|
end
|
data/lib/render_turbo_stream.rb
CHANGED
@@ -150,13 +150,23 @@ module RenderTurboStream
|
|
150
150
|
if request.format.to_sym == :turbo_stream
|
151
151
|
render template: 'render_turbo_stream_partials', locals: { streams: ary }, layout: false
|
152
152
|
else
|
153
|
+
if Rails.env.test?
|
154
|
+
check_ids = {}
|
155
|
+
ary.each do |a|
|
156
|
+
if a[:action] == 'replace'
|
157
|
+
check_ids[a[:id]] ||= 0
|
158
|
+
check_ids[a[:id]] += 1
|
159
|
+
throw "More than one partial rendered to ID «#{a[:id]}» by replace" if check_ids[a[:id]] >= 2
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
153
163
|
check = {}
|
154
164
|
ary.each do |a|
|
155
165
|
b = a.dup
|
156
166
|
b.delete(:id)
|
157
167
|
check[a[:id]] = b
|
158
168
|
end
|
159
|
-
#render json: check
|
169
|
+
# render json: check
|
160
170
|
render template: 'render_turbo_stream_partials', locals: { check: check, streams: ary }, layout: false, formats: :html
|
161
171
|
end
|
162
172
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: render_turbo_stream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- christian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -25,9 +25,9 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 7.0.4.3
|
27
27
|
description: 'Writing views like (create|update).turbo_stream.haml annoyed me. This
|
28
|
-
gem handles translated flash messages, sets status, and renders partials
|
29
|
-
You can control
|
30
|
-
turbo_power is included.'
|
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.'
|
31
31
|
email:
|
32
32
|
- christian@sedlmair.ch
|
33
33
|
executables: []
|