view_component 2.78.0 → 2.80.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: 7fbd11387f1d91c630d91d12ce292fe85f3ac95063d32cb5fef898012f098dc8
4
- data.tar.gz: a54372810de68fdfe4d863437ace9a4ab9f930e4255c16d1b696053ecaae2c96
3
+ metadata.gz: 35801e5fcaab65f2242b92370229ab3b1bb687db3b36c92b74f0e515cfe258b1
4
+ data.tar.gz: 4f4d7adfcbe6ec3e4af0b3cfed05d80976a9fb31dd47fa77f5a48d8def5cb489
5
5
  SHA512:
6
- metadata.gz: a702c2c57c6763340ae79be1eb454c4d451601eb8c7007257318bfe87bd88710e53c5875e7308440008c9c32b55038d6691d58217f6f1c5390e4b643b0c91f11
7
- data.tar.gz: 0d38198fe331e12a2d2b250888980d09d059dc6f1d5a392e5646ee3c834f71fb856cfd8cd4b9eaf02ce6facec836aa849fcb18af95f6239a0dc1396c96d7faf4
6
+ metadata.gz: 21367aa3c40f5004a2479842db12460ea7939a189921f97dfe3ffbfba12acc327bc828a1d96be9b96816ecfc6952ce07ddf3549a858775934d83da3111bf09c4
7
+ data.tar.gz: 215cc4ef718e34ce4753bbfef12aee750f73193643af09b05699dff36711f46f0f2821fc6410c639bde87576d911a019d011677bf97620eb103bac4550130439
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/application_controller"
4
+
5
+ class ViewComponentsSystemTestController < Rails::ApplicationController # :nodoc:
6
+ def system_test_entrypoint
7
+ render file: "./tmp/view_components/#{params.permit(:file)[:file]}"
8
+ end
9
+ end
data/docs/CHANGELOG.md CHANGED
@@ -10,6 +10,38 @@ nav_order: 5
10
10
 
11
11
  ## main
12
12
 
13
+ ## 2.80.0
14
+
15
+ * Move system test endpoint out of the unrelated previews controller.
16
+
17
+ *Edwin Mak*
18
+
19
+ * Display Ruby 2.7 deprecation notice only once, when starting the application.
20
+
21
+ *Henrik Hauge Bjørnskov*
22
+
23
+ * Require Rails 5.2+ in gemspec and update documentation.
24
+
25
+ *Drew Bragg*
26
+
27
+ * Add documentation for using `with_rendered_component_path` with RSpec.
28
+
29
+ *Edwin Mak*
30
+
31
+ ## 2.79.0
32
+
33
+ * Add ability to pass explicit `preview_path` to preview generator.
34
+
35
+ *Erinna Chen*
36
+
37
+ * Add `with_rendered_component_path` helper for writing component system tests.
38
+
39
+ *Edwin Mak*
40
+
41
+ * Include gem name and deprecation horizon in every deprecation message.
42
+
43
+ *Jan Klimo*
44
+
13
45
  ## 2.78.0
14
46
 
15
47
  * 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
- return if preview_paths.count > 1
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
 
@@ -30,10 +30,6 @@ module ViewComponent
30
30
  return if compiled? && !force
31
31
  return if component_class == ViewComponent::Base
32
32
 
33
- if RUBY_VERSION < "2.7.0"
34
- ViewComponent::Deprecation.warn("Support for Ruby versions < 2.7.0 will be removed in v3.0.0.")
35
- end
36
-
37
33
  component_class.superclass.compile(raise_errors: raise_errors) if should_compile_superclass?
38
34
  subclass_instance_methods = component_class.instance_methods(false)
39
35
 
@@ -51,9 +47,8 @@ module ViewComponent
51
47
  end
52
48
 
53
49
  if subclass_instance_methods.include?(:before_render_check)
54
- ViewComponent::Deprecation.warn(
55
- "`#before_render_check` will be removed in v3.0.0.\n\n" \
56
- "To fix this issue, use `#before_render` instead."
50
+ ViewComponent::Deprecation.deprecation_warning(
51
+ "`before_render_check`", :"`before_render`"
57
52
  )
58
53
  end
59
54
 
@@ -12,7 +12,7 @@ module ViewComponent
12
12
 
13
13
  def defaults
14
14
  ActiveSupport::OrderedOptions.new.merge!({
15
- generate: ActiveSupport::OrderedOptions.new(false),
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.warn("`preview_path` will be removed in v3.0.0. Use `preview_paths` instead.")
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.warn(
35
- "`with_content_areas` is deprecated and will be removed in ViewComponent v3.0.0.\n\n" \
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.to_s, "ViewComponent")
6
+ DEPRECATION_HORIZON = "3.0.0"
7
+ Deprecation = ActiveSupport::Deprecation.new(DEPRECATION_HORIZON, "ViewComponent")
8
8
  end
@@ -130,6 +130,12 @@ module ViewComponent
130
130
  end
131
131
  end
132
132
 
133
+ if Rails.env.test?
134
+ app.routes.prepend do
135
+ get("_system_test_entrypoint", to: "view_components_system_test#system_test_entrypoint")
136
+ end
137
+ end
138
+
133
139
  app.executor.to_run :before do
134
140
  CompileCache.invalidate! unless ActionView::Base.cache_template_loading
135
141
  end
@@ -137,13 +143,17 @@ module ViewComponent
137
143
  end
138
144
  end
139
145
 
146
+ if RUBY_VERSION < "2.7.0"
147
+ ViewComponent::Deprecation.deprecation_warning("Support for Ruby versions < 2.7.0")
148
+ end
149
+
140
150
  # :nocov:
141
151
  unless defined?(ViewComponent::Base)
142
152
  require "view_component/deprecation"
143
153
 
144
- ViewComponent::Deprecation.warn(
145
- "This manually engine loading is deprecated and will be removed in v3.0.0. " \
146
- 'Remove `require "view_component/engine"`.'
154
+ ViewComponent::Deprecation.deprecation_warning(
155
+ "Manually loading the engine",
156
+ "remove `require \"view_component/engine\"`"
147
157
  )
148
158
 
149
159
  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.warn(
66
- "polymorphic slot setters like `#{setter_name}` are deprecated and will be removed in " \
67
- "ViewComponent v3.0.0.\n\nUse `with_#{setter_name}` instead."
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.warn(
27
- "`with_slot` is deprecated and will be removed in ViewComponent v3.0.0.\n" \
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.warn(msg, stack)
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.warn(
163
- "Setting a slot with `##{singular_name}` is deprecated and will be removed in ViewComponent v3.0.0. " \
164
- "Use `#with_#{singular_name}` to set the slot instead."
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.warn(
191
- "Setting a slot with `##{slot_name}` is deprecated and will be removed in ViewComponent v3.0.0. " \
192
- "Use `#with_#{slot_name}` to set the slot instead."
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,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/test_case"
4
+
5
+ module ViewComponent
6
+ class SystemTestCase < ActionDispatch::SystemTestCase
7
+ include ViewComponent::SystemTestHelpers
8
+
9
+ def page
10
+ Capybara.current_session
11
+ end
12
+ end
13
+ end
@@ -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.warn(
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
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 78
6
+ MINOR = 80
7
7
  PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
@@ -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.warn(
27
- "Manually loading the engine is deprecated and will be removed in v3.0.0. " \
28
- "Remove `require \"view_component/engine\"`."
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.78.0
4
+ version: 2.80.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-28 00:00:00.000000000 Z
11
+ date: 2022-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.0
19
+ version: 5.2.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '8.0'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 5.0.0
29
+ version: 5.2.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '8.0'
@@ -322,6 +322,7 @@ files:
322
322
  - app/assets/vendor/prism.min.js
323
323
  - app/controllers/concerns/view_component/preview_actions.rb
324
324
  - app/controllers/view_components_controller.rb
325
+ - app/controllers/view_components_system_test_controller.rb
325
326
  - app/helpers/preview_helper.rb
326
327
  - app/views/test_mailer/test_email.html.erb
327
328
  - app/views/view_components/_preview_source.html.erb
@@ -377,6 +378,8 @@ files:
377
378
  - lib/view_component/slot_v2.rb
378
379
  - lib/view_component/slotable.rb
379
380
  - lib/view_component/slotable_v2.rb
381
+ - lib/view_component/system_test_case.rb
382
+ - lib/view_component/system_test_helpers.rb
380
383
  - lib/view_component/template_error.rb
381
384
  - lib/view_component/test_case.rb
382
385
  - lib/view_component/test_helpers.rb