view_component 3.1.0 → 3.3.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: ca112c2d340e4ade9bd258d515edafbd1cc66e0b19097acd12d3eab53b9ae4a4
4
- data.tar.gz: 173223c31abaf369bbfb455eff47137dfa6b7ac98485b17ba58c8317d6f5c3e5
3
+ metadata.gz: dfae7c952ad3086e6df45516e19bdbf8699b3c87209675dbe6e98d07d7457678
4
+ data.tar.gz: 11b457c1aa7784e98b4e09913e6206083ad8e6e6c0bb66832ee7b91f097a481a
5
5
  SHA512:
6
- metadata.gz: 7d63eac1f6f698a44ae621b107194d5ae2e0f4ef16da352e8fbb4ee5514f61fadd70e596582d6f78fcbc5738be3046013846a8541d0e845a85a4d1257262d8ad
7
- data.tar.gz: f7a415d645e7dc45cbd0300fed91c3356d10c543ea9331a24b7beb8e67efe0f3f05d09148a66a4dbecd14149861c884ea0481c033c9c32da5f398b3744c02b60
6
+ metadata.gz: d90880b28c40393b2d198e71df13a12fe078069aeeb8c629fd34b96e636b67120017cb9d49948fe4f73f2a41dbd2d345ba5465728d940668a895ce5ca6407ee5
7
+ data.tar.gz: da53115421cdad2b9522bb6db4d518c0851dde9d5e6191a677316bd1a8fe56945be99ac3632e3a9b2f069f69141f32fa77797c6d8d3f056a4bb7e8323a465b71
@@ -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,34 @@ nav_order: 5
10
10
 
11
11
  ## main
12
12
 
13
+ ## 3.3.0
14
+
15
+ * Include InlineTemplate by default in Base. **Note:** It's no longer necessary to include `ViewComponent::InlineTemplate` to use inline templates.
16
+
17
+ *Joel Hawksley*
18
+
19
+ * Allow Setting host when using the `with_request_url` test helper.
20
+
21
+ *Daniel Alfaro*
22
+
23
+ * Resolve ambiguous preview paths when using components without the Component suffix.
24
+
25
+ *Reed Law*
26
+
27
+ ## 3.2.0
28
+
29
+ * Fix viewcomponent.org Axe violations.
30
+
31
+ *Joel Hawksley*
32
+
33
+ * Fix example of RSpec configuration in docs
34
+
35
+ *Pasha Kalashnikov*
36
+
37
+ * Add URL helpers to previews
38
+
39
+ *Reegan Viljoen*
40
+
13
41
  ## 3.1.0
14
42
 
15
43
  * Check `defined?(Rails) && Rails.application` before using `ViewComponent::Base.config.view_component_path`.
@@ -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
@@ -39,7 +39,7 @@ module ViewComponent # :nodoc:
39
39
  end
40
40
 
41
41
  def inline_template
42
- @__vc_inline_template
42
+ @__vc_inline_template if defined?(@__vc_inline_template)
43
43
  end
44
44
 
45
45
  def inline_template_language
@@ -4,6 +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
8
  include ActionView::Helpers::TagHelper
8
9
  include ActionView::Helpers::AssetTagHelper
9
10
  extend ActiveSupport::DescendantsTracker
@@ -4,8 +4,10 @@ task stats: "view_component:statsetup"
4
4
 
5
5
  namespace :view_component do
6
6
  task :statsetup do
7
+ # :nocov:
7
8
  require "rails/code_statistics"
8
9
 
9
10
  ::STATS_DIRECTORIES << ["ViewComponents", ViewComponent::Base.view_component_path]
11
+ # :nocov:
10
12
  end
11
13
  end
@@ -156,7 +156,9 @@ module ViewComponent
156
156
  # ```
157
157
  #
158
158
  # @param path [String] The path to set for the current request.
159
- def with_request_url(path)
159
+ # @param host [String] The host to set for the current request.
160
+ def with_request_url(path, host: nil)
161
+ old_request_host = vc_test_request.host
160
162
  old_request_path_info = vc_test_request.path_info
161
163
  old_request_path_parameters = vc_test_request.path_parameters
162
164
  old_request_query_parameters = vc_test_request.query_parameters
@@ -164,12 +166,14 @@ module ViewComponent
164
166
  old_controller = defined?(@vc_test_controller) && @vc_test_controller
165
167
 
166
168
  path, query = path.split("?", 2)
169
+ vc_test_request.host = host if host
167
170
  vc_test_request.path_info = path
168
171
  vc_test_request.path_parameters = Rails.application.routes.recognize_path_with_request(vc_test_request, path, {})
169
172
  vc_test_request.set_header("action_dispatch.request.query_parameters", Rack::Utils.parse_nested_query(query))
170
173
  vc_test_request.set_header(Rack::QUERY_STRING, query)
171
174
  yield
172
175
  ensure
176
+ vc_test_request.host = old_request_host
173
177
  vc_test_request.path_info = old_request_path_info
174
178
  vc_test_request.path_parameters = old_request_path_parameters
175
179
  vc_test_request.set_header("action_dispatch.request.query_parameters", old_request_query_parameters)
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 3
6
- MINOR = 1
6
+ MINOR = 3
7
7
  PATCH = 0
8
8
  PRE = nil
9
9
 
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.1.0
4
+ version: 3.3.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-05-31 00:00:00.000000000 Z
11
+ date: 2023-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport