view_component 2.78.0 → 2.79.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: 816041da43cddd9b2b791c005c7122781da97d7b38c068d3d587b8b66665759e
4
+ data.tar.gz: 4afc380c903978336d80842509d1c9082709686cb4e1361674ce1793220e7db9
5
5
  SHA512:
6
- metadata.gz: a702c2c57c6763340ae79be1eb454c4d451601eb8c7007257318bfe87bd88710e53c5875e7308440008c9c32b55038d6691d58217f6f1c5390e4b643b0c91f11
7
- data.tar.gz: 0d38198fe331e12a2d2b250888980d09d059dc6f1d5a392e5646ee3c834f71fb856cfd8cd4b9eaf02ce6facec836aa849fcb18af95f6239a0dc1396c96d7faf4
6
+ metadata.gz: 818a443353202ce4d3c63cdf3cb67ad2e1b35065f1961dac48dc5de0095331492a5ab886845f908fa7c5ca89d4ee8e02382c35973166086d3177a081720aa3c7
7
+ data.tar.gz: eeae1fb4978a03e2cc2da23af48bd035b43a6dc6b9408c3b5b318f45ff2a2f3b4c9f6f83386e62d8fdad802693c6a6d42b9c222c7e3974ba58a498b75cd6e78a
@@ -39,6 +39,12 @@ module ViewComponent
39
39
  end
40
40
  end
41
41
 
42
+ if Rails.env.test?
43
+ def system_test_entrypoint
44
+ render file: "./tmp/view_components/#{params.permit(:file)[:file]}"
45
+ end
46
+ end
47
+
42
48
  private
43
49
 
44
50
  # :doc:
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
- 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
 
@@ -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.warn("Support for Ruby versions < 2.7.0 will be removed in v3.0.0.")
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.warn(
55
- "`#before_render_check` will be removed in v3.0.0.\n\n" \
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: 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
@@ -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.warn(
145
- "This manually engine loading is deprecated and will be removed in v3.0.0. " \
146
- 'Remove `require "view_component/engine"`.'
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.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 = 79
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.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-28 00:00:00.000000000 Z
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