view_component 3.2.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of view_component might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/controllers/concerns/view_component/preview_actions.rb +1 -1
- data/docs/CHANGELOG.md +24 -0
- data/lib/view_component/base.rb +2 -0
- data/lib/view_component/config.rb +8 -0
- data/lib/view_component/engine.rb +8 -1
- data/lib/view_component/inline_template.rb +1 -1
- data/lib/view_component/instrumentation.rb +9 -1
- data/lib/view_component/preview.rb +1 -1
- data/lib/view_component/rails/tasks/view_component.rake +2 -0
- data/lib/view_component/test_helpers.rb +13 -1
- data/lib/view_component/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fda2b08a3a0e713feb6e1fc6c1fef238f886cc4ab1ddd23e3d181bda02ad9c27
|
4
|
+
data.tar.gz: e405fabfc3f12543caf45207f7222fdb9efcf9963dad10d3d37e47c131427e8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a8be926941021f58d66f8b8c29893e5bd682426483914f16f431783c2e230029755e137a434f535fd081f51d3d9a63c219174ce68af9202f8f5f42f0f7087bd
|
7
|
+
data.tar.gz: 4da3a061e16a87cc13440b4c1bf621da4d34a0b2443f28c34a132df0f4a85822b9f9ba12bea9b85c950e8b7991553c85a130eee75e1d7c84865feb30f66f17b5
|
@@ -59,7 +59,7 @@ module ViewComponent
|
|
59
59
|
def find_preview
|
60
60
|
candidates = []
|
61
61
|
params[:path].to_s.scan(%r{/|$}) { candidates << Regexp.last_match.pre_match }
|
62
|
-
preview = candidates.detect { |candidate| ViewComponent::Preview.exists?(candidate) }
|
62
|
+
preview = candidates.sort_by(&:length).reverse_each.detect { |candidate| ViewComponent::Preview.exists?(candidate) }
|
63
63
|
|
64
64
|
if preview
|
65
65
|
@preview = ViewComponent::Preview.find(preview)
|
data/docs/CHANGELOG.md
CHANGED
@@ -10,6 +10,30 @@ nav_order: 5
|
|
10
10
|
|
11
11
|
## main
|
12
12
|
|
13
|
+
## 3.4.0
|
14
|
+
|
15
|
+
* Avoid including Rails `url_helpers` into `Preview` class when they're not defined.
|
16
|
+
|
17
|
+
*Richard Macklin*
|
18
|
+
|
19
|
+
* Allow instrumentation to be automatically included in Server-Timing headers generated by Rails. To enable this set the config `config.use_deprecated_instrumentation_name = false`. The old key `!render.view_component` is deprecated: update ActiveSupport::Notification subscriptions to `render.view_component`.
|
20
|
+
|
21
|
+
*Travis Gaff*
|
22
|
+
|
23
|
+
## 3.3.0
|
24
|
+
|
25
|
+
* Include InlineTemplate by default in Base. **Note:** It's no longer necessary to include `ViewComponent::InlineTemplate` to use inline templates.
|
26
|
+
|
27
|
+
*Joel Hawksley*
|
28
|
+
|
29
|
+
* Allow Setting host when using the `with_request_url` test helper.
|
30
|
+
|
31
|
+
*Daniel Alfaro*
|
32
|
+
|
33
|
+
* Resolve ambiguous preview paths when using components without the Component suffix.
|
34
|
+
|
35
|
+
*Reed Law*
|
36
|
+
|
13
37
|
## 3.2.0
|
14
38
|
|
15
39
|
* Fix viewcomponent.org Axe violations.
|
data/lib/view_component/base.rb
CHANGED
@@ -7,6 +7,7 @@ require "view_component/compile_cache"
|
|
7
7
|
require "view_component/compiler"
|
8
8
|
require "view_component/config"
|
9
9
|
require "view_component/errors"
|
10
|
+
require "view_component/inline_template"
|
10
11
|
require "view_component/preview"
|
11
12
|
require "view_component/slotable"
|
12
13
|
require "view_component/translatable"
|
@@ -29,6 +30,7 @@ module ViewComponent
|
|
29
30
|
attr_writer :config
|
30
31
|
end
|
31
32
|
|
33
|
+
include ViewComponent::InlineTemplate
|
32
34
|
include ViewComponent::Slotable
|
33
35
|
include ViewComponent::Translatable
|
34
36
|
include ViewComponent::WithContentHelper
|
@@ -17,6 +17,7 @@ module ViewComponent
|
|
17
17
|
preview_route: "/rails/view_components",
|
18
18
|
show_previews_source: false,
|
19
19
|
instrumentation_enabled: false,
|
20
|
+
use_deprecated_instrumentation_name: true,
|
20
21
|
render_monkey_patch_enabled: true,
|
21
22
|
view_component_path: "app/components",
|
22
23
|
component_parent_class: nil,
|
@@ -99,6 +100,13 @@ module ViewComponent
|
|
99
100
|
# Whether ActiveSupport notifications are enabled.
|
100
101
|
# Defaults to `false`.
|
101
102
|
|
103
|
+
# @!attribute use_deprecated_instrumentation_name
|
104
|
+
# @return [Boolean]
|
105
|
+
# Whether ActiveSupport Notifications use the private name `"!render.view_component"`
|
106
|
+
# or are made more publicly available via `"render.view_component"`.
|
107
|
+
# Will default to `false` in next major version.
|
108
|
+
# Defaults to `true`.
|
109
|
+
|
102
110
|
# @!attribute render_monkey_patch_enabled
|
103
111
|
# @return [Boolean] Whether the #render method should be monkey patched.
|
104
112
|
# If this is disabled, use `#render_component` or
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require "rails"
|
4
4
|
require "view_component/config"
|
5
|
+
require "view_component/deprecation"
|
5
6
|
|
6
7
|
module ViewComponent
|
7
8
|
class Engine < Rails::Engine # :nodoc:
|
@@ -39,8 +40,14 @@ module ViewComponent
|
|
39
40
|
Base.config = app.config.view_component
|
40
41
|
|
41
42
|
if app.config.view_component.instrumentation_enabled.present?
|
42
|
-
# :nocov:
|
43
|
+
# :nocov: Re-executing the below in tests duplicates initializers and causes order-dependent failures.
|
43
44
|
ViewComponent::Base.prepend(ViewComponent::Instrumentation)
|
45
|
+
if app.config.view_component.use_deprecated_instrumentation_name
|
46
|
+
ViewComponent::Deprecation.deprecation_warning(
|
47
|
+
"!render.view_component",
|
48
|
+
"Use the new instrumentation key `render.view_component` instead. See https://viewcomponent.org/guide/instrumentation.html"
|
49
|
+
)
|
50
|
+
end
|
44
51
|
# :nocov:
|
45
52
|
end
|
46
53
|
end
|
@@ -10,7 +10,7 @@ module ViewComponent # :nodoc:
|
|
10
10
|
|
11
11
|
def render_in(view_context, &block)
|
12
12
|
ActiveSupport::Notifications.instrument(
|
13
|
-
|
13
|
+
notification_name,
|
14
14
|
{
|
15
15
|
name: self.class.name,
|
16
16
|
identifier: self.class.identifier
|
@@ -19,5 +19,13 @@ module ViewComponent # :nodoc:
|
|
19
19
|
super(view_context, &block)
|
20
20
|
end
|
21
21
|
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def notification_name
|
26
|
+
return "!render.view_component" if ViewComponent::Base.config.use_deprecated_instrumentation_name
|
27
|
+
|
28
|
+
"render.view_component"
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
@@ -4,7 +4,7 @@ require "active_support/descendants_tracker"
|
|
4
4
|
|
5
5
|
module ViewComponent # :nodoc:
|
6
6
|
class Preview
|
7
|
-
include Rails.application.routes.url_helpers
|
7
|
+
include Rails.application.routes.url_helpers if defined?(Rails.application.routes.url_helpers)
|
8
8
|
include ActionView::Helpers::TagHelper
|
9
9
|
include ActionView::Helpers::AssetTagHelper
|
10
10
|
extend ActiveSupport::DescendantsTracker
|
@@ -155,8 +155,18 @@ module ViewComponent
|
|
155
155
|
# end
|
156
156
|
# ```
|
157
157
|
#
|
158
|
+
# To use a specific host, pass the host param:
|
159
|
+
#
|
160
|
+
# ```ruby
|
161
|
+
# with_request_url("/users/42", host: "app.example.com") do
|
162
|
+
# render_inline(MyComponent.new)
|
163
|
+
# end
|
164
|
+
# ```
|
165
|
+
#
|
158
166
|
# @param path [String] The path to set for the current request.
|
159
|
-
|
167
|
+
# @param host [String] The host to set for the current request.
|
168
|
+
def with_request_url(path, host: nil)
|
169
|
+
old_request_host = vc_test_request.host
|
160
170
|
old_request_path_info = vc_test_request.path_info
|
161
171
|
old_request_path_parameters = vc_test_request.path_parameters
|
162
172
|
old_request_query_parameters = vc_test_request.query_parameters
|
@@ -164,12 +174,14 @@ module ViewComponent
|
|
164
174
|
old_controller = defined?(@vc_test_controller) && @vc_test_controller
|
165
175
|
|
166
176
|
path, query = path.split("?", 2)
|
177
|
+
vc_test_request.host = host if host
|
167
178
|
vc_test_request.path_info = path
|
168
179
|
vc_test_request.path_parameters = Rails.application.routes.recognize_path_with_request(vc_test_request, path, {})
|
169
180
|
vc_test_request.set_header("action_dispatch.request.query_parameters", Rack::Utils.parse_nested_query(query))
|
170
181
|
vc_test_request.set_header(Rack::QUERY_STRING, query)
|
171
182
|
yield
|
172
183
|
ensure
|
184
|
+
vc_test_request.host = old_request_host
|
173
185
|
vc_test_request.path_info = old_request_path_info
|
174
186
|
vc_test_request.path_parameters = old_request_path_parameters
|
175
187
|
vc_test_request.set_header("action_dispatch.request.query_parameters", old_request_query_parameters)
|
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.4.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: 2023-
|
11
|
+
date: 2023-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|