view_component 2.78.0 → 2.79.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 +6 -0
- data/docs/CHANGELOG.md +14 -0
- data/lib/rails/generators/preview/component_generator.rb +9 -2
- data/lib/view_component/compiler.rb +3 -4
- data/lib/view_component/config.rb +19 -2
- data/lib/view_component/content_areas.rb +2 -3
- data/lib/view_component/deprecation.rb +2 -2
- data/lib/view_component/engine.rb +7 -3
- data/lib/view_component/polymorphic_slots.rb +3 -3
- data/lib/view_component/slotable.rb +2 -3
- data/lib/view_component/slotable_v2.rb +11 -9
- data/lib/view_component/system_test_case.rb +13 -0
- data/lib/view_component/system_test_helpers.rb +27 -0
- data/lib/view_component/test_helpers.rb +1 -4
- data/lib/view_component/version.rb +1 -1
- data/lib/view_component.rb +5 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 816041da43cddd9b2b791c005c7122781da97d7b38c068d3d587b8b66665759e
|
4
|
+
data.tar.gz: 4afc380c903978336d80842509d1c9082709686cb4e1361674ce1793220e7db9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 818a443353202ce4d3c63cdf3cb67ad2e1b35065f1961dac48dc5de0095331492a5ab886845f908fa7c5ca89d4ee8e02382c35973166086d3177a081720aa3c7
|
7
|
+
data.tar.gz: eeae1fb4978a03e2cc2da23af48bd035b43a6dc6b9408c3b5b318f45ff2a2f3b4c9f6f83386e62d8fdad802693c6a6d42b9c222c7e3974ba58a498b75cd6e78a
|
data/docs/CHANGELOG.md
CHANGED
@@ -10,6 +10,20 @@ nav_order: 5
|
|
10
10
|
|
11
11
|
## main
|
12
12
|
|
13
|
+
## 2.79.0
|
14
|
+
|
15
|
+
* Add ability to pass explicit `preview_path` to preview generator.
|
16
|
+
|
17
|
+
*Erinna Chen*
|
18
|
+
|
19
|
+
* Add `with_rendered_component_path` helper for writing component system tests.
|
20
|
+
|
21
|
+
*Edwin Mak*
|
22
|
+
|
23
|
+
* Include gem name and deprecation horizon in every deprecation message.
|
24
|
+
|
25
|
+
*Jan Klimo*
|
26
|
+
|
13
27
|
## 2.78.0
|
14
28
|
|
15
29
|
* Support variants with dots in their names.
|
@@ -4,15 +4,22 @@ module Preview
|
|
4
4
|
module Generators
|
5
5
|
class ComponentGenerator < ::Rails::Generators::NamedBase
|
6
6
|
source_root File.expand_path("templates", __dir__)
|
7
|
+
class_option :preview_path, type: :string, desc: "Path for previews, required when multiple preview paths are configured", default: ViewComponent::Base.config.generate.preview_path
|
7
8
|
|
8
9
|
argument :attributes, type: :array, default: [], banner: "attribute"
|
9
10
|
check_class_collision suffix: "ComponentPreview"
|
10
11
|
|
11
12
|
def create_preview_file
|
12
13
|
preview_paths = ViewComponent::Base.config.preview_paths
|
13
|
-
|
14
|
+
optional_path = options[:preview_path]
|
15
|
+
return if preview_paths.count > 1 && optional_path.blank?
|
16
|
+
|
17
|
+
path_prefix = if optional_path.present?
|
18
|
+
optional_path
|
19
|
+
else
|
20
|
+
preview_paths.one? ? preview_paths.first : "test/components/previews"
|
21
|
+
end
|
14
22
|
|
15
|
-
path_prefix = preview_paths.one? ? preview_paths.first : "test/components/previews"
|
16
23
|
template "component_preview.rb", File.join(path_prefix, class_path, "#{file_name}_component_preview.rb")
|
17
24
|
end
|
18
25
|
|
@@ -31,7 +31,7 @@ module ViewComponent
|
|
31
31
|
return if component_class == ViewComponent::Base
|
32
32
|
|
33
33
|
if RUBY_VERSION < "2.7.0"
|
34
|
-
ViewComponent::Deprecation.
|
34
|
+
ViewComponent::Deprecation.deprecation_warning("Support for Ruby versions < 2.7.0")
|
35
35
|
end
|
36
36
|
|
37
37
|
component_class.superclass.compile(raise_errors: raise_errors) if should_compile_superclass?
|
@@ -51,9 +51,8 @@ module ViewComponent
|
|
51
51
|
end
|
52
52
|
|
53
53
|
if subclass_instance_methods.include?(:before_render_check)
|
54
|
-
ViewComponent::Deprecation.
|
55
|
-
"
|
56
|
-
"To fix this issue, use `#before_render` instead."
|
54
|
+
ViewComponent::Deprecation.deprecation_warning(
|
55
|
+
"`before_render_check`", :"`before_render`"
|
57
56
|
)
|
58
57
|
end
|
59
58
|
|
@@ -12,7 +12,7 @@ module ViewComponent
|
|
12
12
|
|
13
13
|
def defaults
|
14
14
|
ActiveSupport::OrderedOptions.new.merge!({
|
15
|
-
generate:
|
15
|
+
generate: default_generate_options,
|
16
16
|
preview_controller: "ViewComponentsController",
|
17
17
|
preview_route: "/rails/view_components",
|
18
18
|
show_previews_source: false,
|
@@ -66,6 +66,17 @@ module ViewComponent
|
|
66
66
|
# Always generate a preview alongside the component:
|
67
67
|
#
|
68
68
|
# config.view_component.generate.preview = true
|
69
|
+
#
|
70
|
+
# #### #preview_path
|
71
|
+
#
|
72
|
+
# Path to generate preview:
|
73
|
+
#
|
74
|
+
# config.view_component.generate.preview_path = "test/components/previews"
|
75
|
+
#
|
76
|
+
# Required when there is more than one path defined in preview_paths.
|
77
|
+
# Defaults to `""`. If this is blank, the generator will use
|
78
|
+
# `ViewComponent.config.preview_paths` if defined,
|
79
|
+
# `"test/components/previews"` otherwise
|
69
80
|
|
70
81
|
# @!attribute preview_controller
|
71
82
|
# @return [String]
|
@@ -135,6 +146,12 @@ module ViewComponent
|
|
135
146
|
|
136
147
|
["#{Rails.root}/test/components/previews"]
|
137
148
|
end
|
149
|
+
|
150
|
+
def default_generate_options
|
151
|
+
options = ActiveSupport::OrderedOptions.new(false)
|
152
|
+
options.preview_path = ""
|
153
|
+
options
|
154
|
+
end
|
138
155
|
end
|
139
156
|
|
140
157
|
def initialize
|
@@ -146,7 +163,7 @@ module ViewComponent
|
|
146
163
|
end
|
147
164
|
|
148
165
|
def preview_path=(new_value)
|
149
|
-
ViewComponent::Deprecation.
|
166
|
+
ViewComponent::Deprecation.deprecation_warning("`preview_path`", :"`preview_paths`")
|
150
167
|
self.preview_paths = Array.wrap(new_value)
|
151
168
|
end
|
152
169
|
|
@@ -31,9 +31,8 @@ module ViewComponent
|
|
31
31
|
|
32
32
|
class_methods do
|
33
33
|
def with_content_areas(*areas)
|
34
|
-
ViewComponent::Deprecation.
|
35
|
-
"`with_content_areas`
|
36
|
-
"Use slots (https://viewcomponent.org/guide/slots.html) instead."
|
34
|
+
ViewComponent::Deprecation.deprecation_warning(
|
35
|
+
"`with_content_areas`", "use slots (https://viewcomponent.org/guide/slots.html) instead"
|
37
36
|
)
|
38
37
|
|
39
38
|
if areas.include?(:content)
|
@@ -3,6 +3,6 @@
|
|
3
3
|
require "active_support/deprecation"
|
4
4
|
|
5
5
|
module ViewComponent
|
6
|
-
DEPRECATION_HORIZON = 3
|
7
|
-
Deprecation = ActiveSupport::Deprecation.new(DEPRECATION_HORIZON
|
6
|
+
DEPRECATION_HORIZON = "3.0.0"
|
7
|
+
Deprecation = ActiveSupport::Deprecation.new(DEPRECATION_HORIZON, "ViewComponent")
|
8
8
|
end
|
@@ -121,6 +121,10 @@ module ViewComponent
|
|
121
121
|
internal: true
|
122
122
|
)
|
123
123
|
|
124
|
+
if Rails.env.test?
|
125
|
+
get("_system_test_entrypoint", to: "#{preview_controller}#system_test_entrypoint")
|
126
|
+
end
|
127
|
+
|
124
128
|
get(
|
125
129
|
"#{options.preview_route}/*path",
|
126
130
|
to: "#{preview_controller}#previews",
|
@@ -141,9 +145,9 @@ end
|
|
141
145
|
unless defined?(ViewComponent::Base)
|
142
146
|
require "view_component/deprecation"
|
143
147
|
|
144
|
-
ViewComponent::Deprecation.
|
145
|
-
"
|
146
|
-
|
148
|
+
ViewComponent::Deprecation.deprecation_warning(
|
149
|
+
"Manually loading the engine",
|
150
|
+
"remove `require \"view_component/engine\"`"
|
147
151
|
)
|
148
152
|
|
149
153
|
require "view_component"
|
@@ -62,9 +62,9 @@ module ViewComponent
|
|
62
62
|
|
63
63
|
define_method(setter_name) do |*args, &block|
|
64
64
|
if _warn_on_deprecated_slot_setter
|
65
|
-
ViewComponent::Deprecation.
|
66
|
-
"polymorphic slot setters like `#{setter_name}`
|
67
|
-
"
|
65
|
+
ViewComponent::Deprecation.deprecation_warning(
|
66
|
+
"Using polymorphic slot setters like `#{setter_name}`",
|
67
|
+
:"`with_#{setter_name}`"
|
68
68
|
)
|
69
69
|
end
|
70
70
|
|
@@ -23,9 +23,8 @@ module ViewComponent
|
|
23
23
|
# class_name: "Header" # class name string, used to instantiate Slot
|
24
24
|
# )
|
25
25
|
def with_slot(*slot_names, collection: false, class_name: nil)
|
26
|
-
ViewComponent::Deprecation.
|
27
|
-
"`with_slot`
|
28
|
-
"Use the new slots API (https://viewcomponent.org/guide/slots.html) instead."
|
26
|
+
ViewComponent::Deprecation.deprecation_warning(
|
27
|
+
"`with_slot`", "use the new slots API (https://viewcomponent.org/guide/slots.html) instead"
|
29
28
|
)
|
30
29
|
|
31
30
|
slot_names.each do |slot_name|
|
@@ -93,10 +93,12 @@ module ViewComponent
|
|
93
93
|
else
|
94
94
|
if _warn_on_deprecated_slot_setter
|
95
95
|
stack = caller_locations(3)
|
96
|
-
msg = "Setting a slot with `##{slot_name}` is deprecated and will be removed in ViewComponent v3.0.0. " \
|
97
|
-
"Use `#with_#{slot_name}` to set the slot instead."
|
98
96
|
|
99
|
-
ViewComponent::Deprecation.
|
97
|
+
ViewComponent::Deprecation.deprecation_warning(
|
98
|
+
"Setting a slot with `##{slot_name}`",
|
99
|
+
"use `#with_#{slot_name}` to set the slot instead",
|
100
|
+
stack
|
101
|
+
)
|
100
102
|
end
|
101
103
|
|
102
104
|
set_slot(slot_name, nil, *args, &block)
|
@@ -159,9 +161,9 @@ module ViewComponent
|
|
159
161
|
|
160
162
|
define_method singular_name do |*args, &block|
|
161
163
|
if _warn_on_deprecated_slot_setter
|
162
|
-
ViewComponent::Deprecation.
|
163
|
-
"Setting a slot with `##{singular_name}`
|
164
|
-
"
|
164
|
+
ViewComponent::Deprecation.deprecation_warning(
|
165
|
+
"Setting a slot with `##{singular_name}`",
|
166
|
+
"use `#with_#{singular_name}` to set the slot instead"
|
165
167
|
)
|
166
168
|
end
|
167
169
|
|
@@ -187,9 +189,9 @@ module ViewComponent
|
|
187
189
|
get_slot(slot_name)
|
188
190
|
else
|
189
191
|
if _warn_on_deprecated_slot_setter
|
190
|
-
ViewComponent::Deprecation.
|
191
|
-
"Setting a slot with `##{slot_name}`
|
192
|
-
"
|
192
|
+
ViewComponent::Deprecation.deprecation_warning(
|
193
|
+
"Setting a slot with `##{slot_name}`",
|
194
|
+
"use `#with_#{slot_name}` to set the slot instead"
|
193
195
|
)
|
194
196
|
end
|
195
197
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ViewComponent
|
4
|
+
module SystemTestHelpers
|
5
|
+
include TestHelpers
|
6
|
+
|
7
|
+
#
|
8
|
+
# Returns a block that can be used to visit the path of the inline rendered component.
|
9
|
+
# @param fragment [Nokogiri::Fragment] The fragment returned from `render_inline`.
|
10
|
+
# @param layout [String] The (optional) layout to use.
|
11
|
+
# @return [Proc] A block that can be used to visit the path of the inline rendered component.
|
12
|
+
def with_rendered_component_path(fragment, layout: false, &block)
|
13
|
+
# Add './tmp/view_components/' directory if it doesn't exist to store the rendered component HTML
|
14
|
+
FileUtils.mkdir_p("./tmp/view_components/") unless Dir.exist?("./tmp/view_components/")
|
15
|
+
|
16
|
+
file = Tempfile.new(["rendered_#{fragment.class.name}", ".html"], "tmp/view_components/")
|
17
|
+
begin
|
18
|
+
file.write(controller.render_to_string(html: fragment.to_html.html_safe, layout: layout))
|
19
|
+
file.rewind
|
20
|
+
|
21
|
+
block.call("/_system_test_entrypoint?file=#{file.path.split("/").last}")
|
22
|
+
ensure
|
23
|
+
file.unlink
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -35,10 +35,7 @@ module ViewComponent
|
|
35
35
|
#
|
36
36
|
# @return [String]
|
37
37
|
def rendered_component
|
38
|
-
ViewComponent::Deprecation.
|
39
|
-
"`rendered_component` is deprecated and will be removed in v3.0.0. " \
|
40
|
-
"Use `page` instead."
|
41
|
-
)
|
38
|
+
ViewComponent::Deprecation.deprecation_warning("`rendered_component`", :"`page`")
|
42
39
|
|
43
40
|
rendered_content
|
44
41
|
end
|
data/lib/view_component.rb
CHANGED
@@ -16,16 +16,18 @@ module ViewComponent
|
|
16
16
|
autoload :Preview
|
17
17
|
autoload :PreviewTemplateError
|
18
18
|
autoload :TestHelpers
|
19
|
+
autoload :SystemTestHelpers
|
19
20
|
autoload :TestCase
|
21
|
+
autoload :SystemTestCase
|
20
22
|
autoload :TemplateError
|
21
23
|
autoload :Translatable
|
22
24
|
end
|
23
25
|
|
24
26
|
# :nocov:
|
25
27
|
if defined?(ViewComponent::Engine)
|
26
|
-
ViewComponent::Deprecation.
|
27
|
-
"Manually loading the engine
|
28
|
-
"
|
28
|
+
ViewComponent::Deprecation.deprecation_warning(
|
29
|
+
"Manually loading the engine",
|
30
|
+
"remove `require \"view_component/engine\"`"
|
29
31
|
)
|
30
32
|
elsif defined?(Rails::Engine)
|
31
33
|
require "view_component/engine"
|
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.
|
4
|
+
version: 2.79.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: 2022-
|
11
|
+
date: 2022-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -377,6 +377,8 @@ files:
|
|
377
377
|
- lib/view_component/slot_v2.rb
|
378
378
|
- lib/view_component/slotable.rb
|
379
379
|
- lib/view_component/slotable_v2.rb
|
380
|
+
- lib/view_component/system_test_case.rb
|
381
|
+
- lib/view_component/system_test_helpers.rb
|
380
382
|
- lib/view_component/template_error.rb
|
381
383
|
- lib/view_component/test_case.rb
|
382
384
|
- lib/view_component/test_helpers.rb
|