view_component 2.55.0 → 2.56.0
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 +26 -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 +8 -6
- data/lib/view_component/version.rb +1 -1
- 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: eb12aeca73f2c8cbd2e34b616060492b7a511a3578df16ec57736e4e0c99c25a
|
4
|
+
data.tar.gz: 13de0099bbf28122b3a722cd105ad77f15f025a420434a156ffa1dc9899bc216
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3845987cc4992cca1e52eefe1f28df12d38edf53a8c7e82fd8bad8af2d47c9630522485d9a51a2111b2ec4dc5b74109f76ab2fb5509b34318e3d4f5b5f5c894e
|
7
|
+
data.tar.gz: 9942a4e3ca9a1d84ad25cb10b50cc416acf823611dc1a77811a529974ae78c0fb25882694e6d216624eac466993df1c8a0888cdcaecc59b89020e1011bf42557
|
@@ -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,32 @@ title: Changelog
|
|
9
9
|
|
10
10
|
## main
|
11
11
|
|
12
|
+
## 2.56.0
|
13
|
+
|
14
|
+
* Introduce experimental `render_preview` test helper. Note: `@rendered_component` in `TestHelpers` has been renamed to `@rendered_content`.
|
15
|
+
|
16
|
+
*Joel Hawksley*
|
17
|
+
|
18
|
+
* Move framework tests into sandbox application.
|
19
|
+
|
20
|
+
*Joel Hawksley*
|
21
|
+
|
22
|
+
* Add G2 to list of companies that use ViewComponent.
|
23
|
+
|
24
|
+
*Jack Shuff*
|
25
|
+
|
26
|
+
* Add Within3 to list of companies that use ViewComponent.
|
27
|
+
|
28
|
+
*Drew Bragg*
|
29
|
+
|
30
|
+
* Add Mission Met to list of companies that use ViewComponent.
|
31
|
+
|
32
|
+
*Nick Smith*
|
33
|
+
|
34
|
+
* Fix `#with_request_url` test helper not parsing nested query parameters into nested hashes.
|
35
|
+
|
36
|
+
*Richard Marbach*
|
37
|
+
|
12
38
|
## 2.55.0
|
13
39
|
|
14
40
|
* 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
|
@@ -41,14 +43,14 @@ module ViewComponent
|
|
41
43
|
# @param component [ViewComponent::Base, ViewComponent::Collection] The instance of the component to be rendered.
|
42
44
|
# @return [Nokogiri::HTML]
|
43
45
|
def render_inline(component, **args, &block)
|
44
|
-
@
|
46
|
+
@rendered_content =
|
45
47
|
if Rails.version.to_f >= 6.1
|
46
48
|
controller.view_context.render(component, args, &block)
|
47
49
|
else
|
48
50
|
controller.view_context.render_component(component, &block)
|
49
51
|
end
|
50
52
|
|
51
|
-
Nokogiri::HTML.fragment(@
|
53
|
+
Nokogiri::HTML.fragment(@rendered_content)
|
52
54
|
end
|
53
55
|
|
54
56
|
# Execute the given block in the view context. Internally sets `page` to be a
|
@@ -62,8 +64,8 @@ module ViewComponent
|
|
62
64
|
# assert_text("Hello, World!")
|
63
65
|
# ```
|
64
66
|
def render_in_view_context(&block)
|
65
|
-
@
|
66
|
-
Nokogiri::HTML.fragment(@
|
67
|
+
@rendered_content = controller.view_context.instance_exec(&block)
|
68
|
+
Nokogiri::HTML.fragment(@rendered_content)
|
67
69
|
end
|
68
70
|
|
69
71
|
# @private
|
@@ -136,7 +138,7 @@ module ViewComponent
|
|
136
138
|
|
137
139
|
request.path_info = path
|
138
140
|
request.path_parameters = Rails.application.routes.recognize_path(path)
|
139
|
-
request.set_header("action_dispatch.request.query_parameters", Rack::Utils.
|
141
|
+
request.set_header("action_dispatch.request.query_parameters", Rack::Utils.parse_nested_query(path.split("?")[1]))
|
140
142
|
request.set_header(Rack::QUERY_STRING, path.split("?")[1])
|
141
143
|
yield
|
142
144
|
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.0
|
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-05-
|
11
|
+
date: 2022-05-31 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
|