view_component 3.11.0 → 3.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/CHANGELOG.md +20 -0
- data/lib/rails/generators/rspec/component_generator.rb +15 -3
- data/lib/view_component/base.rb +3 -1
- data/lib/view_component/config.rb +13 -0
- data/lib/view_component/slotable.rb +1 -1
- data/lib/view_component/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9624272c360c4807dd67cd51f1ac1c1ffa9eab79cfb77994768ef32c8cb6af0
|
4
|
+
data.tar.gz: f393224b193af373eef5333a35fc20ac8ca8d5501716d0c3a58aeea0ad56de61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfa57ba053fac0733672492bee096d2b009dea6e5931e38ecb300d7eabe4d90a73966d81373dc7bbc1f61bcf074fc2e803611eb6602554b649b9f54a9a4ea471
|
7
|
+
data.tar.gz: c8bf7fbbc161ce4030e7529bd7c5c7053d3c16f6c7f92a2816abce0727ceeacbce12d6b757faa107b3e24b92f6c423875afce3c50008d049aca45716c5be2dff
|
data/docs/CHANGELOG.md
CHANGED
@@ -10,6 +10,26 @@ nav_order: 5
|
|
10
10
|
|
11
11
|
## main
|
12
12
|
|
13
|
+
## 3.12.0
|
14
|
+
|
15
|
+
* Remove offline links from resources.
|
16
|
+
|
17
|
+
*Paulo Henrique Meneses*
|
18
|
+
|
19
|
+
* Fix templates not being correctly populated when caller location label has a prefix.
|
20
|
+
|
21
|
+
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.
|
22
|
+
|
23
|
+
*Allan Pires, Jason Kim*
|
24
|
+
|
25
|
+
* Use component path for generating RSpec files.
|
26
|
+
|
27
|
+
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/`.**
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
*William Mathewson*
|
32
|
+
|
13
33
|
## 3.11.0
|
14
34
|
|
15
35
|
* 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(
|
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
|
15
|
-
|
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
|
data/lib/view_component/base.rb
CHANGED
@@ -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
|
-
|
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]
|
@@ -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
|
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
|
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.
|
4
|
+
version: 3.12.0
|
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-
|
11
|
+
date: 2024-04-12 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.
|
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
|