view_component 2.40.0 → 2.41.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: a6b59c1dbd53f3cb893d36ca15cb6838e6b127a36c895d2e062f961929f03bb9
4
- data.tar.gz: b32e3ecaa9f9734eded75141a75baeaa4396652e475827ff9db29dcf647e36c7
3
+ metadata.gz: ec24d635f8ce5341c3735ab855b9099fe2ea9179bb21a8fe79ba0f14f374ec44
4
+ data.tar.gz: fbc578b4554de38f01a4e92bbcf6ddfaf146ac04fb75e871f8d2378f8a19c053
5
5
  SHA512:
6
- metadata.gz: e1e2312bb9dda96f1f52d6fa513514e461b2c3f9880ffa8321fcba69aabeaf1d87fc5199a7cf190c2596184051c0db30539b4600dbe2a15b5a560f76dc04240f
7
- data.tar.gz: fc65722d4b20457c22de5d0603b80b171777c18bbae19c579f841b4aa092e6feb8e821da8832b6c2fb283d6a2fbca8929967f379b96d68d8ad94c8b171fa2293
6
+ metadata.gz: 9ed08e30f614fc25aeb1c1826d159b312fba175a95a71966112069a27bc1da3255948b1c9504b06f55b6c476fda4418f13b3e42050664dc3146def0ff1ba0636
7
+ data.tar.gz: b02c7784cc31a3e5cfe5d6ec55879bbe832446557810a3884034e871effece891164424f4d4bf34664c3d8a239683405ea31d92b7351321ce0fc8c33c802f3a5
data/docs/CHANGELOG.md CHANGED
@@ -7,6 +7,45 @@ title: Changelog
7
7
 
8
8
  ## main
9
9
 
10
+ ## 2.41.0
11
+
12
+ * Add `sprockets-rails` development dependency to fix test suite failures when using rails@main.
13
+
14
+ *Blake Williams*
15
+
16
+ * Fix Ruby indentation warning.
17
+
18
+ *Blake Williams*
19
+
20
+ * Add `--parent` generator option to specify the parent class.
21
+ * Add config option `config.view_component.component_parent_class` to change it project-wide.
22
+
23
+ *Hans Lemuet*
24
+
25
+ * Update docs to add example for using Devise helpers in tests.
26
+
27
+ *Matthew Rider*
28
+
29
+ * Fix bug where `with_collection_parameter` did not inherit from parent component.
30
+
31
+ *Will Drexler*, *Christian Campoli*
32
+
33
+ * Allow query parameters in `with_request_url` test helper.
34
+
35
+ *Javi Martín*
36
+
37
+ * Add "how to render a component to a string" to FAQ.
38
+
39
+ *Hans Lemuet*
40
+
41
+ * Add `#render_in` to API docs.
42
+
43
+ *Hans Lemuet*
44
+
45
+ * Forward keyword arguments from slot wrapper to component instance.
46
+
47
+ *Cameron Dutro*
48
+
10
49
  ## 2.40.0
11
50
 
12
51
  * Replace antipatterns section in the documentation with best practices.
@@ -62,7 +101,7 @@ title: Changelog
62
101
 
63
102
  * Add test case for conflict with internal `@variant` variable.
64
103
 
65
- *David Backeus*
104
+ *David Backeus*
66
105
 
67
106
  * Document decision to not change naming convention recommendation to remove `-Component` suffix.
68
107
 
@@ -126,7 +165,7 @@ title: Changelog
126
165
 
127
166
  * Ensure consistent indentation with Rubocop.
128
167
 
129
- *Joel Hawksley
168
+ *Joel Hawksley*
130
169
 
131
170
  * Bump `activesupport` upper bound from `< 7.0` to `< 8.0`.
132
171
 
@@ -12,6 +12,7 @@ module Rails
12
12
  argument :attributes, type: :array, default: [], banner: "attribute"
13
13
  check_class_collision suffix: "Component"
14
14
  class_option :inline, type: :boolean, default: false
15
+ class_option :parent, type: :string, desc: "The parent class for the generated component"
15
16
  class_option :stimulus, type: :boolean, default: ViewComponent::Base.generate_stimulus_controller
16
17
  class_option :sidecar, type: :boolean, default: false
17
18
 
@@ -32,7 +33,9 @@ module Rails
32
33
  private
33
34
 
34
35
  def parent_class
35
- defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base"
36
+ return options[:parent] if options[:parent]
37
+
38
+ ViewComponent::Base.component_parent_class || default_parent_class
36
39
  end
37
40
 
38
41
  def initialize_signature
@@ -48,6 +51,10 @@ module Rails
48
51
  def initialize_call_method_for_inline?
49
52
  options["inline"]
50
53
  end
54
+
55
+ def default_parent_class
56
+ defined?(ApplicationComponent) ? ApplicationComponent : ViewComponent::Base
57
+ end
51
58
  end
52
59
  end
53
60
  end
@@ -39,29 +39,12 @@ module ViewComponent
39
39
 
40
40
  # Entrypoint for rendering components.
41
41
  #
42
- # view_context: ActionView context from calling view
43
- # block: optional block to be captured within the view context
42
+ # - `view_context`: ActionView context from calling view
43
+ # - `block`: optional block to be captured within the view context
44
44
  #
45
- # returns HTML that has been escaped by the respective template handler
45
+ # Returns HTML that has been escaped by the respective template handler.
46
46
  #
47
- # Example subclass:
48
- #
49
- # app/components/my_component.rb:
50
- # class MyComponent < ViewComponent::Base
51
- # def initialize(title:)
52
- # @title = title
53
- # end
54
- # end
55
- #
56
- # app/components/my_component.html.erb
57
- # <span title="<%= @title %>">Hello, <%= content %>!</span>
58
- #
59
- # In use:
60
- # <%= render MyComponent.new(title: "greeting") do %>world<% end %>
61
- # returns:
62
- # <span title="greeting">Hello, world!</span>
63
- #
64
- # @private
47
+ # @return [String]
65
48
  def render_in(view_context, &block)
66
49
  self.class.compile(raise_errors: true)
67
50
 
@@ -298,6 +281,14 @@ module ViewComponent
298
281
  # Defaults to "app/components".
299
282
  mattr_accessor :view_component_path, instance_writer: false, default: "app/components"
300
283
 
284
+ # Parent class for generated components
285
+ #
286
+ # config.view_component.component_parent_class = "MyBaseComponent"
287
+ #
288
+ # Defaults to "ApplicationComponent" if defined, "ViewComponent::Base" otherwise.
289
+ mattr_accessor :component_parent_class,
290
+ instance_writer: false
291
+
301
292
  class << self
302
293
  # @private
303
294
  attr_accessor :source_location, :virtual_path
@@ -384,6 +375,9 @@ module ViewComponent
384
375
  %r{(.*#{Regexp.quote(ViewComponent::Base.view_component_path)})|(\.rb)}, ""
385
376
  )
386
377
 
378
+ # Set collection parameter to the extended component
379
+ child.with_collection_parameter provided_collection_parameter
380
+
387
381
  super
388
382
  end
389
383
 
@@ -62,7 +62,7 @@ module ViewComponent
62
62
  view_context.capture(&@__vc_content_block)
63
63
  elsif defined?(@__vc_content_set_by_with_content)
64
64
  @__vc_content_set_by_with_content
65
- end
65
+ end
66
66
 
67
67
  @content = @content.to_s
68
68
  end
@@ -86,8 +86,14 @@ module ViewComponent
86
86
  # end
87
87
  # end
88
88
  #
89
- def method_missing(symbol, *args, &block)
90
- @__vc_component_instance.public_send(symbol, *args, &block)
89
+ if RUBY_VERSION >= "2.7.0"
90
+ def method_missing(symbol, *args, **kwargs, &block)
91
+ @__vc_component_instance.public_send(symbol, *args, **kwargs, &block)
92
+ end
93
+ else
94
+ def method_missing(symbol, *args, &block)
95
+ @__vc_component_instance.public_send(symbol, *args, &block)
96
+ end
91
97
  end
92
98
 
93
99
  def html_safe?
@@ -114,12 +114,15 @@ module ViewComponent
114
114
  # @param path [String] The path to set for the current request.
115
115
  def with_request_url(path)
116
116
  old_request_path_parameters = request.path_parameters
117
+ old_request_query_parameters = request.query_parameters
117
118
  old_controller = defined?(@controller) && @controller
118
119
 
119
120
  request.path_parameters = Rails.application.routes.recognize_path(path)
121
+ request.set_header("action_dispatch.request.query_parameters", Rack::Utils.parse_query(path.split("?")[1]))
120
122
  yield
121
123
  ensure
122
124
  request.path_parameters = old_request_path_parameters
125
+ request.set_header("action_dispatch.request.query_parameters", old_request_query_parameters)
123
126
  @controller = old_controller
124
127
  end
125
128
 
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 40
6
+ MINOR = 41
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.40.0
4
+ version: 2.41.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: 2021-09-09 00:00:00.000000000 Z
11
+ date: 2021-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -226,6 +226,20 @@ dependencies:
226
226
  - - "~>"
227
227
  - !ruby/object:Gem::Version
228
228
  version: '4.0'
229
+ - !ruby/object:Gem::Dependency
230
+ name: sprockets-rails
231
+ requirement: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - "~>"
234
+ - !ruby/object:Gem::Version
235
+ version: 3.2.2
236
+ type: :development
237
+ prerelease: false
238
+ version_requirements: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - "~>"
241
+ - !ruby/object:Gem::Version
242
+ version: 3.2.2
229
243
  - !ruby/object:Gem::Dependency
230
244
  name: yard
231
245
  requirement: !ruby/object:Gem::Requirement