view_component 2.55.0 → 2.56.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of view_component might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/controllers/concerns/view_component/preview_actions.rb +2 -1
- data/docs/CHANGELOG.md +38 -0
- data/lib/view_component/preview.rb +4 -3
- data/lib/view_component/render_preview_helper.rb +40 -0
- data/lib/view_component/test_helpers.rb +18 -7
- data/lib/view_component/version.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afe785add49fc05a089c0d317b73ab372489e85473fced3b8b4ae13d11271e78
|
4
|
+
data.tar.gz: e52674e539ea4ee9bb147ac8394575d9b45f7096ed3f92503b47da7c63ba3b47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d6b9fc86ac35aa9cc1831d2b3eb4b1bf8f7197658342edfc6201ccf62e9f01abdca2a31226dd9a9b5d039a0af3d8b997ff38c7626e2da33841f0fc573254fc4
|
7
|
+
data.tar.gz: 1efe944077b322fe594d7ef3b6a21ee7fa887efd4c237546c877de54b85be5b7bc5ba01a4e75b1d5518f645302ae6360c4c8aa1e2d519fa04b27bd80f622921c
|
@@ -8,7 +8,6 @@ module ViewComponent
|
|
8
8
|
prepend_view_path File.expand_path("../../../views", __dir__)
|
9
9
|
|
10
10
|
around_action :set_locale, only: :previews
|
11
|
-
before_action :find_preview, only: :previews
|
12
11
|
before_action :require_local!, unless: :show_previews?
|
13
12
|
|
14
13
|
if respond_to?(:content_security_policy)
|
@@ -23,6 +22,8 @@ module ViewComponent
|
|
23
22
|
end
|
24
23
|
|
25
24
|
def previews
|
25
|
+
find_preview
|
26
|
+
|
26
27
|
if params[:path] == @preview.preview_name
|
27
28
|
@page_title = "Component Previews for #{@preview.preview_name}"
|
28
29
|
render "view_components/previews", **determine_layout
|
data/docs/CHANGELOG.md
CHANGED
@@ -9,6 +9,44 @@ title: Changelog
|
|
9
9
|
|
10
10
|
## main
|
11
11
|
|
12
|
+
## 2.56.2
|
13
|
+
|
14
|
+
* Restore removed `rendered_component`, marking it for deprecation in v3.0.0.
|
15
|
+
|
16
|
+
*Tyson Gach*, *Richard Macklin*, *Joel Hawksley*
|
17
|
+
|
18
|
+
## 2.56.1
|
19
|
+
|
20
|
+
* Rename private accessor `rendered_component` to `rendered_content`.
|
21
|
+
|
22
|
+
*Yoshiyuki Hirano*, *Simon Dawson*
|
23
|
+
|
24
|
+
## 2.56.0
|
25
|
+
|
26
|
+
* Introduce experimental `render_preview` test helper. Note: `@rendered_component` in `TestHelpers` has been renamed to `@rendered_content`.
|
27
|
+
|
28
|
+
*Joel Hawksley*
|
29
|
+
|
30
|
+
* Move framework tests into sandbox application.
|
31
|
+
|
32
|
+
*Joel Hawksley*
|
33
|
+
|
34
|
+
* Add G2 to list of companies that use ViewComponent.
|
35
|
+
|
36
|
+
*Jack Shuff*
|
37
|
+
|
38
|
+
* Add Within3 to list of companies that use ViewComponent.
|
39
|
+
|
40
|
+
*Drew Bragg*
|
41
|
+
|
42
|
+
* Add Mission Met to list of companies that use ViewComponent.
|
43
|
+
|
44
|
+
*Nick Smith*
|
45
|
+
|
46
|
+
* Fix `#with_request_url` test helper not parsing nested query parameters into nested hashes.
|
47
|
+
|
48
|
+
*Richard Marbach*
|
49
|
+
|
12
50
|
## 2.55.0
|
13
51
|
|
14
52
|
* Add `render_parent` convenience method to avoid confusion between `<%= super %>` and `<% super %>` in template code.
|
@@ -30,7 +30,8 @@ module ViewComponent # :nodoc:
|
|
30
30
|
class << self
|
31
31
|
# Returns all component preview classes.
|
32
32
|
def all
|
33
|
-
load_previews
|
33
|
+
load_previews
|
34
|
+
|
34
35
|
descendants
|
35
36
|
end
|
36
37
|
|
@@ -98,14 +99,14 @@ module ViewComponent # :nodoc:
|
|
98
99
|
source[1...(source.size - 1)].join("\n")
|
99
100
|
end
|
100
101
|
|
101
|
-
private
|
102
|
-
|
103
102
|
def load_previews
|
104
103
|
Array(preview_paths).each do |preview_path|
|
105
104
|
Dir["#{preview_path}/**/*_preview.rb"].sort.each { |file| require_dependency file }
|
106
105
|
end
|
107
106
|
end
|
108
107
|
|
108
|
+
private
|
109
|
+
|
109
110
|
def preview_paths
|
110
111
|
Base.preview_paths
|
111
112
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ViewComponent
|
4
|
+
module RenderPreviewHelper
|
5
|
+
# Render a preview inline. Internally sets `page` to be a `Capybara::Node::Simple`,
|
6
|
+
# allowing for Capybara assertions to be used:
|
7
|
+
#
|
8
|
+
# ```ruby
|
9
|
+
# render_preview(:default)
|
10
|
+
# assert_text("Hello, World!")
|
11
|
+
# ```
|
12
|
+
#
|
13
|
+
# Note: `#rendered_preview` expects a preview to be defined with the same class
|
14
|
+
# name as the calling test, but with `Test` replaced with `Preview`:
|
15
|
+
#
|
16
|
+
# MyComponentTest -> MyComponentPreview etc.
|
17
|
+
#
|
18
|
+
# @param preview [String] The name of the preview to be rendered.
|
19
|
+
# @return [Nokogiri::HTML]
|
20
|
+
def render_preview(name)
|
21
|
+
begin
|
22
|
+
preview_klass = self.class.name.gsub("Test", "Preview")
|
23
|
+
preview_klass = preview_klass.constantize
|
24
|
+
rescue NameError
|
25
|
+
raise NameError.new(
|
26
|
+
"`render_preview` expected to find #{preview_klass}, but it does not exist."
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
previews_controller = build_controller(ViewComponent::Base.preview_controller.constantize)
|
31
|
+
previews_controller.request.params[:path] = "#{preview_klass.preview_name}/#{name}"
|
32
|
+
previews_controller.response = ActionDispatch::Response.new
|
33
|
+
result = previews_controller.previews
|
34
|
+
|
35
|
+
@rendered_content = result
|
36
|
+
|
37
|
+
Nokogiri::HTML.fragment(@rendered_content)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "view_component/render_preview_helper"
|
4
|
+
|
3
5
|
module ViewComponent
|
4
6
|
module TestHelpers
|
5
7
|
begin
|
@@ -7,7 +9,7 @@ module ViewComponent
|
|
7
9
|
include Capybara::Minitest::Assertions
|
8
10
|
|
9
11
|
def page
|
10
|
-
Capybara::Node::Simple.new(@
|
12
|
+
Capybara::Node::Simple.new(@rendered_content)
|
11
13
|
end
|
12
14
|
|
13
15
|
def refute_component_rendered
|
@@ -28,7 +30,16 @@ module ViewComponent
|
|
28
30
|
end
|
29
31
|
|
30
32
|
# @private
|
31
|
-
attr_reader :
|
33
|
+
attr_reader :rendered_content
|
34
|
+
|
35
|
+
def rendered_component
|
36
|
+
ViewComponent::Deprecation.warn(
|
37
|
+
"`rendered_component` is deprecated and will be removed in v3.0.0. " \
|
38
|
+
"Use `page` instead."
|
39
|
+
)
|
40
|
+
|
41
|
+
rendered_content
|
42
|
+
end
|
32
43
|
|
33
44
|
# Render a component inline. Internally sets `page` to be a `Capybara::Node::Simple`,
|
34
45
|
# allowing for Capybara assertions to be used:
|
@@ -41,14 +52,14 @@ module ViewComponent
|
|
41
52
|
# @param component [ViewComponent::Base, ViewComponent::Collection] The instance of the component to be rendered.
|
42
53
|
# @return [Nokogiri::HTML]
|
43
54
|
def render_inline(component, **args, &block)
|
44
|
-
@
|
55
|
+
@rendered_content =
|
45
56
|
if Rails.version.to_f >= 6.1
|
46
57
|
controller.view_context.render(component, args, &block)
|
47
58
|
else
|
48
59
|
controller.view_context.render_component(component, &block)
|
49
60
|
end
|
50
61
|
|
51
|
-
Nokogiri::HTML.fragment(@
|
62
|
+
Nokogiri::HTML.fragment(@rendered_content)
|
52
63
|
end
|
53
64
|
|
54
65
|
# Execute the given block in the view context. Internally sets `page` to be a
|
@@ -62,8 +73,8 @@ module ViewComponent
|
|
62
73
|
# assert_text("Hello, World!")
|
63
74
|
# ```
|
64
75
|
def render_in_view_context(&block)
|
65
|
-
@
|
66
|
-
Nokogiri::HTML.fragment(@
|
76
|
+
@rendered_content = controller.view_context.instance_exec(&block)
|
77
|
+
Nokogiri::HTML.fragment(@rendered_content)
|
67
78
|
end
|
68
79
|
|
69
80
|
# @private
|
@@ -136,7 +147,7 @@ module ViewComponent
|
|
136
147
|
|
137
148
|
request.path_info = path
|
138
149
|
request.path_parameters = Rails.application.routes.recognize_path(path)
|
139
|
-
request.set_header("action_dispatch.request.query_parameters", Rack::Utils.
|
150
|
+
request.set_header("action_dispatch.request.query_parameters", Rack::Utils.parse_nested_query(path.split("?")[1]))
|
140
151
|
request.set_header(Rack::QUERY_STRING, path.split("?")[1])
|
141
152
|
yield
|
142
153
|
ensure
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: view_component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.56.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub Open Source
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -345,6 +345,7 @@ files:
|
|
345
345
|
- lib/view_component/render_component_helper.rb
|
346
346
|
- lib/view_component/render_component_to_string_helper.rb
|
347
347
|
- lib/view_component/render_monkey_patch.rb
|
348
|
+
- lib/view_component/render_preview_helper.rb
|
348
349
|
- lib/view_component/render_to_string_monkey_patch.rb
|
349
350
|
- lib/view_component/rendering_component_helper.rb
|
350
351
|
- lib/view_component/rendering_monkey_patch.rb
|