view_component 3.11.0 → 3.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dad3e67f83aa23cac53f816d751a652b229a1cbee327e753dbcdb9814549cf03
4
- data.tar.gz: 15e2fdafbb4132567a3b81bfeb7723704ffc5824aa82eb8083f2f79f48505ad3
3
+ metadata.gz: 875f47469a83b3b70de2e4271cc4af72542d88c6e12c373c8f6912d3c8c6d13e
4
+ data.tar.gz: 161671b627c087f227706c10e6ca7f900dcdd3d2ea49232024543bf78a3be14b
5
5
  SHA512:
6
- metadata.gz: 9fc84bada7187832e5cf4dba96b864e177260f6db88d9b9af78bee95b11ce7a3197d59d1f1171a9b4f473c62230e385b5b922b0536084c86ee73b80e6b9d293d
7
- data.tar.gz: 100e6e5e8f7d06848790906ee5b6ecc106a53d3c018c7bccfd303097ec2c126ee4511b409ff42513ae3b98ac7441cf6c0ecd1f0d0404b936529c78e8fdebef88
6
+ metadata.gz: aaa215e2aba616eca2ea0e1bd1e4ab76df2f6f4f34d1f3f225a5802a943b8e6c8e920b3821fda06353e52979345a8d941c2d3d2eaa24b71a6928502846224acc
7
+ data.tar.gz: f7da13dfa835866ac685d567f41549857ca40682e6f2beee269bf07b4b9bfaf942af62d03dbcc019cb72ef349ed8c601be24c1598efd0cb38e26397decb4e09a
data/docs/CHANGELOG.md CHANGED
@@ -10,6 +10,32 @@ nav_order: 5
10
10
 
11
11
  ## main
12
12
 
13
+ ## 3.12.1
14
+
15
+ * Ensure content is rendered correctly for forwarded slots.
16
+
17
+ *Cameron Dutro*
18
+
19
+ ## 3.12.0
20
+
21
+ * Remove offline links from resources.
22
+
23
+ *Paulo Henrique Meneses*
24
+
25
+ * Fix templates not being correctly populated when caller location label has a prefix.
26
+
27
+ On the upstream version of Ruby, method owners are now included in backtraces as prefixes. This caused the call stack filtering to not work as intended and thus `source_location` to be incorrect for child ViewComponents, consequently not populating templates correctly.
28
+
29
+ *Allan Pires, Jason Kim*
30
+
31
+ * Use component path for generating RSpec files.
32
+
33
+ When generating new RSpec files for components, the generator will use the `view_component_path` value in the config to decide where to put the new spec file. For instance, if the `view_component_path` option has been changed to `app/views/components`, the generator will put the spec file in `spec/views/components`. **If the `view_component_path` doesn't start with `app/`, then the generator will fall back to `spec/components/`.**
34
+
35
+ This feature is enabled via the `config.view_component.generate.use_component_path_for_rspec_tests` option, defaulting to `false`. The default will change to `true` in ViewComponent v4.
36
+
37
+ *William Mathewson*
38
+
13
39
  ## 3.11.0
14
40
 
15
41
  * Fix running non-integration tests under Rails main.
@@ -1,18 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rails/generators/abstract_generator"
4
+
3
5
  module Rspec
4
6
  module Generators
5
7
  class ComponentGenerator < ::Rails::Generators::NamedBase
8
+ include ViewComponent::AbstractGenerator
9
+
6
10
  source_root File.expand_path("templates", __dir__)
7
11
 
8
12
  def create_test_file
9
- template "component_spec.rb", File.join("spec/components", class_path, "#{file_name}_component_spec.rb")
13
+ template "component_spec.rb", File.join(spec_component_path, class_path, "#{file_name}_component_spec.rb")
10
14
  end
11
15
 
12
16
  private
13
17
 
14
- def file_name
15
- @_file_name ||= super.sub(/_component\z/i, "")
18
+ def spec_component_path
19
+ return "spec/components" unless ViewComponent::Base.config.generate.use_component_path_for_rspec_tests
20
+
21
+ configured_component_path = component_path
22
+ if configured_component_path.start_with?("app#{File::SEPARATOR}")
23
+ _app, *rest_of_path = Pathname.new(configured_component_path).each_filename.to_a
24
+ File.join("spec", *rest_of_path)
25
+ else
26
+ "spec/components"
27
+ end
16
28
  end
17
29
  end
18
30
  end
@@ -537,7 +537,9 @@ module ViewComponent
537
537
  # Derive the source location of the component Ruby file from the call stack.
538
538
  # We need to ignore `inherited` frames here as they indicate that `inherited`
539
539
  # has been re-defined by the consuming application, likely in ApplicationComponent.
540
- child.source_location = caller_locations(1, 10).reject { |l| l.label == "inherited" }[0].path
540
+ # We use `base_label` method here instead of `label` to avoid cases where the method
541
+ # owner is included in a prefix like `ApplicationComponent.inherited`.
542
+ child.source_location = caller_locations(1, 10).reject { |l| l.base_label == "inherited" }[0].path
541
543
 
542
544
  # If Rails application is loaded, removes the first part of the path and the extension.
543
545
  if defined?(Rails) && Rails.application
@@ -79,6 +79,19 @@ module ViewComponent
79
79
  # Defaults to `""`. If this is blank, the generator will use
80
80
  # `ViewComponent.config.preview_paths` if defined,
81
81
  # `"test/components/previews"` otherwise
82
+ #
83
+ # #### `#use_component_path_for_rspec_tests`
84
+ #
85
+ # Whether to use the `config.view_component_path` when generating new
86
+ # RSpec component tests:
87
+ #
88
+ # config.view_component.generate.use_component_path_for_rspec_tests = true
89
+ #
90
+ # When set to `true`, the generator will use the `view_component_path` to
91
+ # decide where to generate the new RSpec component test.
92
+ # For example, if the `view_component_path` is
93
+ # `app/views/components`, then the generator will create a new spec file
94
+ # in `spec/views/components/` rather than the default `spec/components/`.
82
95
 
83
96
  # @!attribute preview_controller
84
97
  # @return [String]
@@ -57,7 +57,17 @@ module ViewComponent
57
57
 
58
58
  if defined?(@__vc_content_block)
59
59
  # render_in is faster than `parent.render`
60
- @__vc_component_instance.render_in(view_context, &@__vc_content_block)
60
+ @__vc_component_instance.render_in(view_context) do |*args|
61
+ return @__vc_content_block.call(*args) if @__vc_content_block&.source_location.nil?
62
+
63
+ block_context = @__vc_content_block.binding.receiver
64
+
65
+ if block_context.class < ActionView::Base
66
+ block_context.capture(*args, &@__vc_content_block)
67
+ else
68
+ @__vc_content_block.call(*args)
69
+ end
70
+ end
61
71
  else
62
72
  @__vc_component_instance.render_in(view_context)
63
73
  end
@@ -366,7 +366,7 @@ module ViewComponent
366
366
  # 1. If this is a `content_area` style sub-component, we will render the
367
367
  # block via the `slot`
368
368
  #
369
- # 2. Since we've to pass block content to components when calling
369
+ # 2. Since we have to pass block content to components when calling
370
370
  # `render`, evaluating the block here would require us to call
371
371
  # `view_context.capture` twice, which is slower
372
372
  slot.__vc_content_block = block if block
@@ -3,8 +3,8 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 3
6
- MINOR = 11
7
- PATCH = 0
6
+ MINOR = 12
7
+ PATCH = 1
8
8
  PRE = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.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: 3.11.0
4
+ version: 3.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ViewComponent Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-21 00:00:00.000000000 Z
11
+ date: 2024-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -561,7 +561,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
561
561
  - !ruby/object:Gem::Version
562
562
  version: '0'
563
563
  requirements: []
564
- rubygems_version: 3.5.3
564
+ rubygems_version: 3.5.4
565
565
  signing_key:
566
566
  specification_version: 4
567
567
  summary: A framework for building reusable, testable & encapsulated view components