view_component 2.66.0 → 2.67.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: 426a776552c0355ba0fb4ccc066c05a218b9998acb39489485375624b347c170
4
- data.tar.gz: d17d69cb6e1c08fe31545eb5cf878579dd4aaf11e803790130c83ec7b4c178d2
3
+ metadata.gz: 89e52bd1cf26dcf9a118635445255a0b6fe11d6d66947246af1df1df8b0ae867
4
+ data.tar.gz: eade5ea1be098f111d221bd3028764df7749f71d7639c49ef6ac99c43276119f
5
5
  SHA512:
6
- metadata.gz: 4b001cf58f8586b3e83cf8129c23d0bb5a499182189db4a99dfd747d6767f529a631eb2bf439a32f8a91dbb5861eb16ef637b514bffccacd476d577e2c5c27aa
7
- data.tar.gz: 24d147cfbb226ff11114631721507bfed5a73fe25e1963186fe106a9c0f485596b65349457685967e7df0edea4d78841646f36683764244673e4281ff56741fd
6
+ metadata.gz: 00ab6fe377ab39bf01db8942d36b131bd04d084bc0ab594f751728f47c501eb366caff3ff108aa1acdc17380cc581131d204907b1b0f59a33b0558f043a98ab1
7
+ data.tar.gz: f7d7923bbad729d18d4c53c348beb60afea0375cd95fd99ba82de0be993af2153d29742533e066a2fca49fb39b836992dd437a78de8aa59789b6c751d9a8d226
@@ -43,12 +43,12 @@ module ViewComponent
43
43
 
44
44
  # :doc:
45
45
  def default_preview_layout
46
- Rails.application.config.view_component.default_preview_layout
46
+ ViewComponent::Base.config.default_preview_layout
47
47
  end
48
48
 
49
49
  # :doc:
50
50
  def show_previews?
51
- Rails.application.config.view_component.show_previews
51
+ ViewComponent::Base.config.show_previews
52
52
  end
53
53
 
54
54
  # :doc:
@@ -22,7 +22,7 @@ module PreviewHelper
22
22
  # Fetch template source via finding it through preview paths
23
23
  # to accomodate source view when exclusively using templates
24
24
  # for previews for Rails < 6.1.
25
- all_template_paths = Rails.application.config.view_component.preview_paths.map do |preview_path|
25
+ all_template_paths = ViewComponent::Base.config.preview_paths.map do |preview_path|
26
26
  Dir.glob("#{preview_path}/**/*")
27
27
  end.flatten
28
28
 
@@ -1,5 +1,5 @@
1
1
  <% if @render_args[:component] %>
2
- <% if Rails.application.config.view_component.render_monkey_patch_enabled || Rails.version.to_f >= 6.1 %>
2
+ <% if ViewComponent::Base.config.render_monkey_patch_enabled || Rails.version.to_f >= 6.1 %>
3
3
  <%= render(@render_args[:component], @render_args[:args], &@render_args[:block]) %>
4
4
  <% else %>
5
5
  <%= render_component(@render_args[:component], &@render_args[:block]) %>
@@ -8,6 +8,6 @@
8
8
  <%= render template: @render_args[:template], locals: @render_args[:locals] || {} %>
9
9
  <% end %>
10
10
 
11
- <% if Rails.application.config.view_component.show_previews_source %>
11
+ <% if ViewComponent::Base.config.show_previews_source %>
12
12
  <%= preview_source %>
13
13
  <% end %>
data/docs/CHANGELOG.md CHANGED
@@ -9,6 +9,24 @@ title: Changelog
9
9
 
10
10
  ## main
11
11
 
12
+ ## 2.67.0
13
+
14
+ * Use ViewComponent::Base.config as the internal endpoint for config.
15
+
16
+ *Simon Fish*
17
+
18
+ * Fix bug where `#with_request_url`, when used with query string, set the incorrect `request.path` and `request.fullpath`.
19
+
20
+ *Franz Liedke*
21
+
22
+ * Add link to [ViewComponentAttributes](https://github.com/amba-Health/view_component_attributes) in Resources section of docs.
23
+
24
+ *Romaric Pascal*
25
+
26
+ * `render_preview` test helper is available by default. It is no longer necessary to include `ViewComponent::RenderPreviewHelper`.
27
+
28
+ *Joel Hawksley*
29
+
12
30
  ## 2.66.0
13
31
 
14
32
  * Add missing `generate.sidecar`, `generate.stimulus_controller`, `generate.locale`, `generate.distinct_locale_files`, `generate.preview` config options to `config.view_component`.
@@ -29,7 +29,7 @@ module ViewComponent
29
29
  end
30
30
 
31
31
  def component_path
32
- Rails.application.config.view_component.view_component_path
32
+ ViewComponent::Base.config.view_component_path
33
33
  end
34
34
 
35
35
  def stimulus_controller
@@ -42,7 +42,7 @@ module ViewComponent
42
42
  end
43
43
 
44
44
  def sidecar?
45
- options["sidecar"] || Rails.application.config.view_component.generate.sidecar
45
+ options["sidecar"] || ViewComponent::Base.config.generate.sidecar
46
46
  end
47
47
  end
48
48
  end
@@ -13,12 +13,12 @@ module Rails
13
13
  check_class_collision suffix: "Component"
14
14
 
15
15
  class_option :inline, type: :boolean, default: false
16
- class_option :locale, type: :boolean, default: Rails.application.config.view_component.generate.locale
16
+ class_option :locale, type: :boolean, default: ViewComponent::Base.config.generate.locale
17
17
  class_option :parent, type: :string, desc: "The parent class for the generated component"
18
- class_option :preview, type: :boolean, default: Rails.application.config.view_component.generate.preview
18
+ class_option :preview, type: :boolean, default: ViewComponent::Base.config.generate.preview
19
19
  class_option :sidecar, type: :boolean, default: false
20
20
  class_option :stimulus, type: :boolean,
21
- default: Rails.application.config.view_component.generate.stimulus_controller
21
+ default: ViewComponent::Base.config.generate.stimulus_controller
22
22
 
23
23
  def create_component_file
24
24
  template "component.rb", File.join(component_path, class_path, "#{file_name}_component.rb")
@@ -41,7 +41,7 @@ module Rails
41
41
  def parent_class
42
42
  return options[:parent] if options[:parent]
43
43
 
44
- Rails.application.config.view_component.component_parent_class || default_parent_class
44
+ ViewComponent::Base.config.component_parent_class || default_parent_class
45
45
  end
46
46
 
47
47
  def initialize_signature
@@ -12,7 +12,7 @@ module Locale
12
12
  class_option :sidecar, type: :boolean, default: false
13
13
 
14
14
  def create_locale_file
15
- if Rails.application.config.view_component.generate.distinct_locale_files
15
+ if ViewComponent::Base.config.generate.distinct_locale_files
16
16
  I18n.available_locales.each do |locale|
17
17
  create_file destination(locale), translations_hash([locale]).to_yaml
18
18
  end
@@ -9,7 +9,7 @@ module Preview
9
9
  check_class_collision suffix: "ComponentPreview"
10
10
 
11
11
  def create_preview_file
12
- preview_paths = Rails.application.config.view_component.preview_paths
12
+ preview_paths = ViewComponent::Base.config.preview_paths
13
13
  return if preview_paths.count > 1
14
14
 
15
15
  path_prefix = preview_paths.one? ? preview_paths.first : "test/components/previews"
@@ -18,7 +18,7 @@ module ViewComponent
18
18
  delegate(*ViewComponent::Config.defaults.keys, to: :config)
19
19
 
20
20
  def config
21
- Rails.application.config.view_component
21
+ @config ||= ViewComponent::Config.defaults
22
22
  end
23
23
  end
24
24
 
@@ -496,7 +496,7 @@ module ViewComponent
496
496
 
497
497
  # Removes the first part of the path and the extension.
498
498
  child.virtual_path = child.source_location.gsub(
499
- /(.*#{Regexp.quote(Rails.application.config.view_component.view_component_path)})|(\.rb)/, ""
499
+ /(.*#{Regexp.quote(ViewComponent::Base.config.view_component_path)})|(\.rb)/, ""
500
500
  )
501
501
 
502
502
  # Set collection parameter to the extended component
@@ -5,7 +5,7 @@ require "view_component/base"
5
5
 
6
6
  module ViewComponent
7
7
  class Engine < Rails::Engine # :nodoc:
8
- config.view_component = ViewComponent::Config.default
8
+ config.view_component = ViewComponent::Base.config
9
9
 
10
10
  rake_tasks do
11
11
  load "view_component/rails/tasks/view_component.rake"
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "view_component/render_preview_helper"
4
-
5
3
  module ViewComponent
6
4
  module TestHelpers
7
5
  begin
@@ -67,6 +65,47 @@ module ViewComponent
67
65
  Nokogiri::HTML.fragment(@rendered_content)
68
66
  end
69
67
 
68
+ # Render a preview inline. Internally sets `page` to be a `Capybara::Node::Simple`,
69
+ # allowing for Capybara assertions to be used:
70
+ #
71
+ # ```ruby
72
+ # render_preview(:default)
73
+ # assert_text("Hello, World!")
74
+ # ```
75
+ #
76
+ # Note: `#rendered_preview` expects a preview to be defined with the same class
77
+ # name as the calling test, but with `Test` replaced with `Preview`:
78
+ #
79
+ # MyComponentTest -> MyComponentPreview etc.
80
+ #
81
+ # In RSpec, `Preview` is appended to `described_class`.
82
+ #
83
+ # @param preview [String] The name of the preview to be rendered.
84
+ # @return [Nokogiri::HTML]
85
+ def render_preview(name)
86
+ begin
87
+ preview_klass = if respond_to?(:described_class)
88
+ raise "`render_preview` expected a described_class, but it is nil." if described_class.nil?
89
+
90
+ "#{described_class}Preview"
91
+ else
92
+ self.class.name.gsub("Test", "Preview")
93
+ end
94
+ preview_klass = preview_klass.constantize
95
+ rescue NameError
96
+ raise NameError, "`render_preview` expected to find #{preview_klass}, but it does not exist."
97
+ end
98
+
99
+ previews_controller = build_controller(Rails.application.config.view_component.preview_controller.constantize)
100
+ previews_controller.request.params[:path] = "#{preview_klass.preview_name}/#{name}"
101
+ previews_controller.response = ActionDispatch::Response.new
102
+ result = previews_controller.previews
103
+
104
+ @rendered_content = result
105
+
106
+ Nokogiri::HTML.fragment(@rendered_content)
107
+ end
108
+
70
109
  # Execute the given block in the view context. Internally sets `page` to be a
71
110
  # `Capybara::Node::Simple`, allowing for Capybara assertions to be used:
72
111
  #
@@ -151,10 +190,11 @@ module ViewComponent
151
190
  old_request_query_string = request.query_string
152
191
  old_controller = defined?(@controller) && @controller
153
192
 
193
+ path, query = path.split("?", 2)
154
194
  request.path_info = path
155
195
  request.path_parameters = Rails.application.routes.recognize_path(path)
156
- request.set_header("action_dispatch.request.query_parameters", Rack::Utils.parse_nested_query(path.split("?")[1]))
157
- request.set_header(Rack::QUERY_STRING, path.split("?")[1])
196
+ request.set_header("action_dispatch.request.query_parameters", Rack::Utils.parse_nested_query(query))
197
+ request.set_header(Rack::QUERY_STRING, query)
158
198
  yield
159
199
  ensure
160
200
  request.path_info = old_request_path_info
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 66
6
+ MINOR = 67
7
7
  PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
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.66.0
4
+ version: 2.67.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-09 00:00:00.000000000 Z
11
+ date: 2022-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -371,7 +371,6 @@ files:
371
371
  - lib/view_component/render_component_helper.rb
372
372
  - lib/view_component/render_component_to_string_helper.rb
373
373
  - lib/view_component/render_monkey_patch.rb
374
- - lib/view_component/render_preview_helper.rb
375
374
  - lib/view_component/render_to_string_monkey_patch.rb
376
375
  - lib/view_component/rendering_component_helper.rb
377
376
  - lib/view_component/rendering_monkey_patch.rb
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ViewComponent
4
- module RenderPreviewHelper
5
- # Render a preview inline. Internally sets `page` to be a `Capybara::Node::Simple`,
6
- # allowing for Capybara assertions to be used:
7
- #
8
- # ```ruby
9
- # render_preview(:default)
10
- # assert_text("Hello, World!")
11
- # ```
12
- #
13
- # Note: `#rendered_preview` expects a preview to be defined with the same class
14
- # name as the calling test, but with `Test` replaced with `Preview`:
15
- #
16
- # MyComponentTest -> MyComponentPreview etc.
17
- #
18
- # In RSpec, `Preview` is appended to `described_class`.
19
- #
20
- # @param preview [String] The name of the preview to be rendered.
21
- # @return [Nokogiri::HTML]
22
- def render_preview(name)
23
- begin
24
- preview_klass = if respond_to?(:described_class)
25
- raise "`render_preview` expected a described_class, but it is nil." if described_class.nil?
26
-
27
- "#{described_class}Preview"
28
- else
29
- self.class.name.gsub("Test", "Preview")
30
- end
31
- preview_klass = preview_klass.constantize
32
- rescue NameError
33
- raise NameError, "`render_preview` expected to find #{preview_klass}, but it does not exist."
34
- end
35
-
36
- previews_controller = build_controller(Rails.application.config.view_component.preview_controller.constantize)
37
- previews_controller.request.params[:path] = "#{preview_klass.preview_name}/#{name}"
38
- previews_controller.response = ActionDispatch::Response.new
39
- result = previews_controller.previews
40
-
41
- @rendered_content = result
42
-
43
- Nokogiri::HTML.fragment(@rendered_content)
44
- end
45
- end
46
- end