view_component 2.55.0 → 2.57.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6460c94f3bb4f2b19cd5311d957d2187e437276c0c19b657834cccba39fb36f
4
- data.tar.gz: c0dfc55481d2bcfcdc2f54ea4f4bacc94780e2dce39b77eaf5828490c1d0fc52
3
+ metadata.gz: a22d7248560f80072ed000776afa4f92b164cd80931570feb4a3416bb6ba3627
4
+ data.tar.gz: 9bc617ae2ff51bad6f61b41412b4b3827c4bbe3f2366e0a3829ee00216d9518d
5
5
  SHA512:
6
- metadata.gz: 6ffed42bf70668cf3dbf811f5f24e4a9e2e6cca7fdaea3674f8323c08a60b0f7c49f94c9a1d0bb1c962fb04c0c6dbdb219891116b70385bb8d3fe5f650d86f91
7
- data.tar.gz: 416501060d316e680dbf7f65543aa9a57b693e13bf8a9ebd8c244794155b33702863b22723d140bb85df560e4b18d746f3d534a9a98f4698ced8435cecce3375
6
+ metadata.gz: 648585993d06389775c8d14edee060fc551394edadaa7337a4b10709183941f9143cad71dc045ec4dca50db5bd568b8b57066518c0222e32e569f89e787043af
7
+ data.tar.gz: 4c8fbee2640a2fba303ce93010bdf789cbe094f233e7253dc4491207cadd3101914d86ae22c4b85e7c3db78b18e048b14955b41ce86ceb510fd4495e6ef216dc
@@ -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,58 @@ title: Changelog
9
9
 
10
10
  ## main
11
11
 
12
+ ## 2.57.0
13
+
14
+ * Add missing `require` for `Translatable` module in `Base`.
15
+
16
+ *Hans Lemuet*
17
+
18
+ * Allow anything that responds to `#render_in` to be rendered in the parent component's view context.
19
+
20
+ *Cameron Dutro*
21
+
22
+ * Fix script/release so it honors semver.
23
+
24
+ *Cameron Dutro*
25
+
26
+ ## 2.56.2
27
+
28
+ * Restore removed `rendered_component`, marking it for deprecation in v3.0.0.
29
+
30
+ *Tyson Gach*, *Richard Macklin*, *Joel Hawksley*
31
+
32
+ ## 2.56.1
33
+
34
+ * Rename private accessor `rendered_component` to `rendered_content`.
35
+
36
+ *Yoshiyuki Hirano*, *Simon Dawson*
37
+
38
+ ## 2.56.0
39
+
40
+ * Introduce experimental `render_preview` test helper. Note: `@rendered_component` in `TestHelpers` has been renamed to `@rendered_content`.
41
+
42
+ *Joel Hawksley*
43
+
44
+ * Move framework tests into sandbox application.
45
+
46
+ *Joel Hawksley*
47
+
48
+ * Add G2 to list of companies that use ViewComponent.
49
+
50
+ *Jack Shuff*
51
+
52
+ * Add Within3 to list of companies that use ViewComponent.
53
+
54
+ *Drew Bragg*
55
+
56
+ * Add Mission Met to list of companies that use ViewComponent.
57
+
58
+ *Nick Smith*
59
+
60
+ * Fix `#with_request_url` test helper not parsing nested query parameters into nested hashes.
61
+
62
+ *Richard Marbach*
63
+
12
64
  ## 2.55.0
13
65
 
14
66
  * Add `render_parent` convenience method to avoid confusion between `<%= super %>` and `<% super %>` in template code.
@@ -9,6 +9,7 @@ require "view_component/polymorphic_slots"
9
9
  require "view_component/previewable"
10
10
  require "view_component/slotable"
11
11
  require "view_component/slotable_v2"
12
+ require "view_component/translatable"
12
13
  require "view_component/with_content_helper"
13
14
 
14
15
  module ViewComponent
@@ -182,8 +183,11 @@ module ViewComponent
182
183
  #
183
184
  # @private
184
185
  def render(options = {}, args = {}, &block)
185
- if options.is_a? ViewComponent::Base
186
- options.__vc_original_view_context = __vc_original_view_context
186
+ if options.respond_to?(:render_in)
187
+ if options.is_a?(ViewComponent::Base)
188
+ options.__vc_original_view_context = __vc_original_view_context
189
+ end
190
+
187
191
  super
188
192
  else
189
193
  __vc_original_view_context.render(options, args, &block)
@@ -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 if descendants.empty?
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(@rendered_component)
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 :rendered_component
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
- @rendered_component =
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(@rendered_component)
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
- @rendered_component = controller.view_context.instance_exec(&block)
66
- Nokogiri::HTML.fragment(@rendered_component)
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.parse_query(path.split("?")[1]))
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
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 55
6
+ MINOR = 57
7
7
  PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
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.55.0
4
+ version: 2.57.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-13 00:00:00.000000000 Z
11
+ date: 2022-06-10 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