view_component 2.54.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 +61 -2
- data/lib/view_component/base.rb +15 -1
- data/lib/view_component/preview.rb +4 -3
- data/lib/view_component/render_preview_helper.rb +40 -0
- data/lib/view_component/slotable_v2.rb +0 -1
- data/lib/view_component/test_helpers.rb +23 -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,13 +9,68 @@ 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
|
+
|
38
|
+
## 2.55.0
|
39
|
+
|
40
|
+
* Add `render_parent` convenience method to avoid confusion between `<%= super %>` and `<% super %>` in template code.
|
41
|
+
|
42
|
+
*Cameron Dutro*
|
43
|
+
|
44
|
+
* Add note about discouraging inheritance.
|
45
|
+
|
46
|
+
*Joel Hawksley*
|
47
|
+
|
48
|
+
* Clean up grammar in documentation.
|
49
|
+
|
50
|
+
*Joel Hawksley*
|
51
|
+
|
52
|
+
* The ViewComponent team at GitHub is hiring! We're looking for a Rails engineer with accessibility experience: [https://boards.greenhouse.io/github/jobs/4020166](https://boards.greenhouse.io/github/jobs/4020166). Reach out to joelhawksley@github.com with any questions!
|
53
|
+
|
54
|
+
* The ViewComponent team is hosting a happy hour at RailsConf. Join us for snacks, drinks, and stickers: [https://www.eventbrite.com/e/viewcomponent-happy-hour-tickets-304168585427](https://www.eventbrite.com/e/viewcomponent-happy-hour-tickets-304168585427)
|
55
|
+
|
56
|
+
## 2.54.1
|
57
|
+
|
58
|
+
* Update docs dependencies.
|
59
|
+
|
60
|
+
*Joel Hawksley*
|
61
|
+
|
62
|
+
* Resolve warning in slots API.
|
63
|
+
* Raise in the test environment when ViewComponent code emits a warning.
|
64
|
+
|
65
|
+
*Blake Williams*
|
66
|
+
|
12
67
|
## 2.54.0
|
13
68
|
|
14
69
|
* Add `with_*` slot API for defining slots. Note: we plan to deprecate the non `with_*` API for slots in an upcoming release.
|
15
70
|
|
16
71
|
*Blake Williams*
|
17
72
|
|
18
|
-
* Add QuickNode to list of companies that
|
73
|
+
* Add QuickNode to list of companies that use ViewComponent.
|
19
74
|
|
20
75
|
*Luc Castera*
|
21
76
|
|
@@ -49,7 +104,7 @@ title: Changelog
|
|
49
104
|
|
50
105
|
*Jason Swett*
|
51
106
|
|
52
|
-
* Add Bearer to list of companies that
|
107
|
+
* Add Bearer to list of companies that use ViewComponent.
|
53
108
|
|
54
109
|
*Yaroslav Shmarov*
|
55
110
|
|
@@ -57,6 +112,10 @@ title: Changelog
|
|
57
112
|
|
58
113
|
*Joel Hawksley*
|
59
114
|
|
115
|
+
* Enable rendering arbitrary block contents in the view context in tests.
|
116
|
+
|
117
|
+
*Cameron Dutro*
|
118
|
+
|
60
119
|
## 2.52.0
|
61
120
|
|
62
121
|
* Add ADR for separate slot getter/setter API.
|
data/lib/view_component/base.rb
CHANGED
@@ -70,7 +70,7 @@ module ViewComponent
|
|
70
70
|
@view_context = view_context
|
71
71
|
self.__vc_original_view_context ||= view_context
|
72
72
|
|
73
|
-
@output_buffer = ActionView::OutputBuffer.new unless @global_buffer_in_use
|
73
|
+
@output_buffer = ActionView::OutputBuffer.new unless defined?(@global_buffer_in_use) && @global_buffer_in_use
|
74
74
|
|
75
75
|
@lookup_context ||= view_context.lookup_context
|
76
76
|
|
@@ -117,6 +117,20 @@ module ViewComponent
|
|
117
117
|
render_template_for(@__vc_variant).to_s + _output_postamble
|
118
118
|
end
|
119
119
|
|
120
|
+
# Subclass components that call `super` inside their template code will cause a
|
121
|
+
# double render if they accidentally emit the result:
|
122
|
+
#
|
123
|
+
# <%= super %> # double-renders
|
124
|
+
#
|
125
|
+
# <% super %> # does not double-render
|
126
|
+
#
|
127
|
+
# Calls `super`, returning nil to avoid rendering the result twice.
|
128
|
+
def render_parent
|
129
|
+
mtd = @__vc_variant ? "call_#{@__vc_variant}" : "call"
|
130
|
+
method(mtd).super_method.call
|
131
|
+
nil
|
132
|
+
end
|
133
|
+
|
120
134
|
# :nocov:
|
121
135
|
def render_template_for(variant = nil)
|
122
136
|
# Force compilation here so the compiler always redefines render_template_for.
|
@@ -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
|
@@ -155,7 +155,6 @@ module ViewComponent
|
|
155
155
|
set_slot(slot_name, nil, **args, &block)
|
156
156
|
end
|
157
157
|
end
|
158
|
-
ruby2_keywords(:"with_#{slot_name}") if respond_to?(:ruby2_keywords, true)
|
159
158
|
|
160
159
|
# Instantiates and and adds multiple slots forwarding the first
|
161
160
|
# argument to each slot constructor
|
@@ -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
|
@@ -19,8 +21,8 @@ module ViewComponent
|
|
19
21
|
# :nocov:
|
20
22
|
if ENV["DEBUG"]
|
21
23
|
warn(
|
22
|
-
"WARNING in `ViewComponent::TestHelpers`:
|
23
|
-
"to
|
24
|
+
"WARNING in `ViewComponent::TestHelpers`: Add `capybara` " \
|
25
|
+
"to Gemfile to use Capybara assertions."
|
24
26
|
)
|
25
27
|
end
|
26
28
|
|
@@ -41,14 +43,29 @@ 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)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Execute the given block in the view context. Internally sets `page` to be a
|
57
|
+
# `Capybara::Node::Simple`, allowing for Capybara assertions to be used:
|
58
|
+
#
|
59
|
+
# ```ruby
|
60
|
+
# render_in_view_context do
|
61
|
+
# render(MyComponent.new)
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# assert_text("Hello, World!")
|
65
|
+
# ```
|
66
|
+
def render_in_view_context(&block)
|
67
|
+
@rendered_content = controller.view_context.instance_exec(&block)
|
68
|
+
Nokogiri::HTML.fragment(@rendered_content)
|
52
69
|
end
|
53
70
|
|
54
71
|
# @private
|
@@ -121,7 +138,7 @@ module ViewComponent
|
|
121
138
|
|
122
139
|
request.path_info = path
|
123
140
|
request.path_parameters = Rails.application.routes.recognize_path(path)
|
124
|
-
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]))
|
125
142
|
request.set_header(Rack::QUERY_STRING, path.split("?")[1])
|
126
143
|
yield
|
127
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
|