view_component 2.39.0 → 2.40.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: e5f28b38a232a62dbe80033fe0ac5a7b0ee717f933afc76a1e991396ff51a8d6
4
- data.tar.gz: ed6610e4fc417a876aeac464439cc627c5ce6e242a65faa0d7db001e2249035a
3
+ metadata.gz: a6b59c1dbd53f3cb893d36ca15cb6838e6b127a36c895d2e062f961929f03bb9
4
+ data.tar.gz: b32e3ecaa9f9734eded75141a75baeaa4396652e475827ff9db29dcf647e36c7
5
5
  SHA512:
6
- metadata.gz: d7e130233a0699c54a1a9664c9a893afc6df8e45795d397ce6592e2edbd719c61ed6ef9fb373b3dc8d8285bc3a2d712c013579303138fb466806e646c2480465
7
- data.tar.gz: 25001a6bff37068aceccfb029d5829cd759f4662f7f0b8eb4ab76a42bf0a31ba55f1ceb97480c4a285dc3e9d9da62e746194f623f6b443c647fdb17bb21b3963
6
+ metadata.gz: e1e2312bb9dda96f1f52d6fa513514e461b2c3f9880ffa8321fcba69aabeaf1d87fc5199a7cf190c2596184051c0db30539b4600dbe2a15b5a560f76dc04240f
7
+ data.tar.gz: fc65722d4b20457c22de5d0603b80b171777c18bbae19c579f841b4aa092e6feb8e821da8832b6c2fb283d6a2fbca8929967f379b96d68d8ad94c8b171fa2293
data/docs/CHANGELOG.md CHANGED
@@ -7,6 +7,24 @@ title: Changelog
7
7
 
8
8
  ## main
9
9
 
10
+ ## 2.40.0
11
+
12
+ * Replace antipatterns section in the documentation with best practices.
13
+
14
+ *Blake Williams*
15
+
16
+ * Add components to `rails stats` task.
17
+
18
+ *Nicolas Brousse*
19
+
20
+ * Fix bug when using Slim and writing a slot whose block evaluates to `nil`.
21
+
22
+ *Yousuf Jukaku*
23
+
24
+ * Add documentation for test helpers.
25
+
26
+ *Joel Hawksley*
27
+
10
28
  ## 2.39.0
11
29
 
12
30
  * Clarify documentation of `with_variant` as an override of Action Pack.
@@ -8,6 +8,10 @@ module ViewComponent
8
8
  config.view_component = ActiveSupport::OrderedOptions.new
9
9
  config.view_component.preview_paths ||= []
10
10
 
11
+ rake_tasks do
12
+ load "view_component/rails/tasks/view_component.rake"
13
+ end
14
+
11
15
  initializer "view_component.set_configs" do |app|
12
16
  options = app.config.view_component
13
17
 
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ task stats: "view_component:statsetup"
4
+
5
+ namespace :view_component do
6
+ task statsetup: :environment do
7
+ require "rails/code_statistics"
8
+
9
+ ::STATS_DIRECTORIES << ["ViewComponents", ViewComponent::Base.view_component_path]
10
+ end
11
+ end
@@ -64,7 +64,7 @@ module ViewComponent
64
64
  @__vc_content_set_by_with_content
65
65
  end
66
66
 
67
- @content
67
+ @content = @content.to_s
68
68
  end
69
69
 
70
70
  # Allow access to public component methods via the wrapper
@@ -27,8 +27,19 @@ module ViewComponent
27
27
  # :nocov:
28
28
  end
29
29
 
30
+ # @private
30
31
  attr_reader :rendered_component
31
32
 
33
+ # Render a component inline. Internally sets `page` to be a `Capybara::Node::Simple`,
34
+ # allowing for Capybara assertions to be used:
35
+ #
36
+ # ```ruby
37
+ # render_inline(MyComponent.new)
38
+ # assert_text("Hello, World!")
39
+ # ```
40
+ #
41
+ # @param component [ViewComponent::Base] The instance of the component to be rendered.
42
+ # @return [Nokogiri::HTML]
32
43
  def render_inline(component, **args, &block)
33
44
  @rendered_component =
34
45
  if Rails.version.to_f >= 6.1
@@ -40,10 +51,12 @@ module ViewComponent
40
51
  Nokogiri::HTML.fragment(@rendered_component)
41
52
  end
42
53
 
54
+ # @private
43
55
  def controller
44
56
  @controller ||= build_controller(Base.test_controller.constantize)
45
57
  end
46
58
 
59
+ # @private
47
60
  def request
48
61
  @request ||=
49
62
  begin
@@ -53,6 +66,15 @@ module ViewComponent
53
66
  end
54
67
  end
55
68
 
69
+ # Set the Action Pack request variant for the given block:
70
+ #
71
+ # ```ruby
72
+ # with_variant(:phone) do
73
+ # render_inline(MyComponent.new)
74
+ # end
75
+ # ```
76
+ #
77
+ # @param variant [Symbol] The variant to be set for the provided block.
56
78
  def with_variant(variant)
57
79
  old_variants = controller.view_context.lookup_context.variants
58
80
 
@@ -62,6 +84,16 @@ module ViewComponent
62
84
  controller.view_context.lookup_context.variants = old_variants
63
85
  end
64
86
 
87
+ # Set the controller to be used while executing the given block,
88
+ # allowing access to controller-specific methods:
89
+ #
90
+ # ```ruby
91
+ # with_controller_class(UsersController) do
92
+ # render_inline(MyComponent.new)
93
+ # end
94
+ # ```
95
+ #
96
+ # @param klass [ActionController::Base] The controller to be used.
65
97
  def with_controller_class(klass)
66
98
  old_controller = defined?(@controller) && @controller
67
99
 
@@ -71,6 +103,15 @@ module ViewComponent
71
103
  @controller = old_controller
72
104
  end
73
105
 
106
+ # Set the URL for the current request (such as when using request-dependent path helpers):
107
+ #
108
+ # ```ruby
109
+ # with_request_url("/users/42") do
110
+ # render_inline(MyComponent.new)
111
+ # end
112
+ # ```
113
+ #
114
+ # @param path [String] The path to set for the current request.
74
115
  def with_request_url(path)
75
116
  old_request_path_parameters = request.path_parameters
76
117
  old_controller = defined?(@controller) && @controller
@@ -82,6 +123,7 @@ module ViewComponent
82
123
  @controller = old_controller
83
124
  end
84
125
 
126
+ # @private
85
127
  def build_controller(klass)
86
128
  klass.new.tap { |c| c.request = request }.extend(Rails.application.routes.url_helpers)
87
129
  end
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 39
6
+ MINOR = 40
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.39.0
4
+ version: 2.40.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-08-31 00:00:00.000000000 Z
11
+ date: 2021-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -303,6 +303,7 @@ files:
303
303
  - lib/view_component/preview.rb
304
304
  - lib/view_component/preview_template_error.rb
305
305
  - lib/view_component/previewable.rb
306
+ - lib/view_component/rails/tasks/view_component.rake
306
307
  - lib/view_component/render_component_helper.rb
307
308
  - lib/view_component/render_component_to_string_helper.rb
308
309
  - lib/view_component/render_monkey_patch.rb