view_component 3.12.0 → 3.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9624272c360c4807dd67cd51f1ac1c1ffa9eab79cfb77994768ef32c8cb6af0
4
- data.tar.gz: f393224b193af373eef5333a35fc20ac8ca8d5501716d0c3a58aeea0ad56de61
3
+ metadata.gz: 7355cbed890e04169fee1c12513cd045bee0e912838c9d368be9317ee801bfcc
4
+ data.tar.gz: 76b95e2aab1e097356e06c4c6695a12a1fc0cc3344f3657c1bf42bcb587157cc
5
5
  SHA512:
6
- metadata.gz: dfa57ba053fac0733672492bee096d2b009dea6e5931e38ecb300d7eabe4d90a73966d81373dc7bbc1f61bcf074fc2e803611eb6602554b649b9f54a9a4ea471
7
- data.tar.gz: c8bf7fbbc161ce4030e7529bd7c5c7053d3c16f6c7f92a2816abce0727ceeacbce12d6b757faa107b3e24b92f6c423875afce3c50008d049aca45716c5be2dff
6
+ metadata.gz: f3f7b42ee9a138203348eb6a6560e0d67f041c0d66aaf5eb8465ac6f2ef506eab543a5c408f2a879c70228ae6bef029fc3a916f36344a8835bb8e9d29c4bf89b
7
+ data.tar.gz: cd8d3a36c04d72941503a255f0143d7ea6f5178364e20e1fac834a7e5ac683b0915588b14cda7c9025bc4ac4cba476c184780940606a968b5449167a9428440f
data/docs/CHANGELOG.md CHANGED
@@ -10,6 +10,34 @@ nav_order: 5
10
10
 
11
11
  ## main
12
12
 
13
+ ## 3.13.0
14
+
15
+ * Add ruby head and YJIT to CI.
16
+
17
+ *Reegan Viljoen*
18
+
19
+ * Fixed a bug where inline templates where unable to remove trailing whitespace without throwing an error.
20
+
21
+ *Reegan Viljoen*
22
+
23
+ * Fixed CI for Rails main.
24
+
25
+ *Reegan Viljoen*
26
+
27
+ * Add `from:` option to `use_helpers` to allow for more flexible helper inclusion from modules.
28
+
29
+ *Reegan Viljoen*
30
+
31
+ * Fixed ruby head matcher issue.
32
+
33
+ *Reegan Viljoen*
34
+
35
+ ## 3.12.1
36
+
37
+ * Ensure content is rendered correctly for forwarded slots.
38
+
39
+ *Cameron Dutro*
40
+
13
41
  ## 3.12.0
14
42
 
15
43
  * Remove offline links from resources.
@@ -18,15 +46,15 @@ nav_order: 5
18
46
 
19
47
  * Fix templates not being correctly populated when caller location label has a prefix.
20
48
 
21
- On the upstream version of Ruby, method owners are now included in backtraces as prefixes. This caused the call stack filtering to not work as intended and thus `source_location` to be incorrect for child ViewComponents, consequently not populating templates correctly.
49
+ On the upstream version of Ruby, method owners are now included in backtraces as prefixes. This caused the call stack filtering to not work as intended and thus `source_location` to be incorrect for child ViewComponents, consequently not populating templates correctly.
22
50
 
23
51
  *Allan Pires, Jason Kim*
24
52
 
25
53
  * Use component path for generating RSpec files.
26
54
 
27
- When generating new RSpec files for components, the generator will use the `view_component_path` value in the config to decide where to put the new spec file. For instance, if the `view_component_path` option has been changed to `app/views/components`, the generator will put the spec file in `spec/views/components`. **If the `view_component_path` doesn't start with `app/`, then the generator will fall back to `spec/components/`.**
55
+ When generating new RSpec files for components, the generator will use the `view_component_path` value in the config to decide where to put the new spec file. For instance, if the `view_component_path` option has been changed to `app/views/components`, the generator will put the spec file in `spec/views/components`. **If the `view_component_path` doesn't start with `app/`, then the generator will fall back to `spec/components/`.**
28
56
 
29
- This feature is enabled via the `config.view_component.generate.use_component_path_for_rspec_tests` option, defaulting to `false`. The default will change to `true` in ViewComponent v4.
57
+ This feature is enabled via the `config.view_component.generate.use_component_path_for_rspec_tests` option, defaulting to `false`. The default will change to `true` in ViewComponent v4.
30
58
 
31
59
  *William Mathewson*
32
60
 
@@ -50,7 +78,7 @@ This feature is enabled via the `config.view_component.generate.use_component_pa
50
78
 
51
79
  * Include ViewComponent::UseHelpers by default.
52
80
 
53
- *Reegan Viljoen*
81
+ *Reegan Viljoen*
54
82
 
55
83
  * Bump `puma` in Gemfile.lock.
56
84
 
@@ -247,9 +247,9 @@ module ViewComponent
247
247
 
248
248
  def compiled_inline_template(template)
249
249
  handler = ActionView::Template.handler_for_extension(template.language)
250
- template.rstrip! if component_class.strip_trailing_whitespace?
250
+ template = template.source.dup
251
251
 
252
- compile_template(template.source, handler)
252
+ compile_template(template, handler)
253
253
  end
254
254
 
255
255
  def compiled_template(file_path)
@@ -16,7 +16,7 @@ module ViewComponent # :nodoc:
16
16
  identifier: self.class.identifier
17
17
  }
18
18
  ) do
19
- super(view_context, &block)
19
+ super
20
20
  end
21
21
  end
22
22
 
@@ -57,7 +57,17 @@ module ViewComponent
57
57
 
58
58
  if defined?(@__vc_content_block)
59
59
  # render_in is faster than `parent.render`
60
- @__vc_component_instance.render_in(view_context, &@__vc_content_block)
60
+ @__vc_component_instance.render_in(view_context) do |*args|
61
+ return @__vc_content_block.call(*args) if @__vc_content_block&.source_location.nil?
62
+
63
+ block_context = @__vc_content_block.binding.receiver
64
+
65
+ if block_context.class < ActionView::Base
66
+ block_context.capture(*args, &@__vc_content_block)
67
+ else
68
+ @__vc_content_block.call(*args)
69
+ end
70
+ end
61
71
  else
62
72
  @__vc_component_instance.render_in(view_context)
63
73
  end
@@ -4,17 +4,27 @@ module ViewComponent::UseHelpers
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  class_methods do
7
- def use_helpers(*args)
8
- args.each do |helper_method|
9
- class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
10
- def #{helper_method}(*args, &block)
11
- raise HelpersCalledBeforeRenderError if view_context.nil?
12
- __vc_original_view_context.#{helper_method}(*args, &block)
13
- end
14
- RUBY
7
+ def use_helpers(*args, from: nil)
8
+ args.each { |helper_method| use_helper(helper_method, from: from) }
9
+ end
10
+
11
+ def use_helper(helper_method, from: nil)
12
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
13
+ def #{helper_method}(*args, &block)
14
+ raise HelpersCalledBeforeRenderError if view_context.nil?
15
+
16
+ #{define_helper(helper_method: helper_method, source: from)}
17
+ end
18
+ RUBY
19
+ ruby2_keywords(helper_method) if respond_to?(:ruby2_keywords, true)
20
+ end
21
+
22
+ private
23
+
24
+ def define_helper(helper_method:, source:)
25
+ return "__vc_original_view_context.#{helper_method}(*args, &block)" unless source.present?
15
26
 
16
- ruby2_keywords(helper_method) if respond_to?(:ruby2_keywords, true)
17
- end
27
+ "#{source}.instance_method(:#{helper_method}).bind(self).call(*args, &block)"
18
28
  end
19
29
  end
20
30
  end
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 3
6
- MINOR = 12
6
+ MINOR = 13
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.12.0
4
+ version: 3.13.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: 2024-04-12 00:00:00.000000000 Z
11
+ date: 2024-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -561,7 +561,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
561
561
  - !ruby/object:Gem::Version
562
562
  version: '0'
563
563
  requirements: []
564
- rubygems_version: 3.5.4
564
+ rubygems_version: 3.5.3
565
565
  signing_key:
566
566
  specification_version: 4
567
567
  summary: A framework for building reusable, testable & encapsulated view components