view_component 2.12.0 → 2.13.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: 8661a26312dc3649e30ee17fbc94f6fd73be410067f8a7fac8b6aaefc4338d11
4
- data.tar.gz: 1024034624c49bb65bfe1fc3466886ffa60cd9699a58c7427ea6dbedb9baa03b
3
+ metadata.gz: 3950532a26d2d6d1ddcf412383bfd9cde269c1f69c3d6f7f03dd4e51e7d638e2
4
+ data.tar.gz: ee2524ef62b335376287f30709e62f2d39a71e43c0f5ec9853db8142b6c8fb3c
5
5
  SHA512:
6
- metadata.gz: 24ddc5373c2fbb7cd81ef4f4077ea66a30ea797fbb9d4c444135d3d8590b5151596fddc18f5bc5e1f18fec65ca87572858513409385489524c11c1929cff3567
7
- data.tar.gz: cf63eb464e88e02310cb55f9c6c779c31622174777dbd1f39a24d0e9ac40407c555ac51012c5ea8c06bdeccac7aab880475c02c678c3fbff9ef22f5ca6cf797e
6
+ metadata.gz: c4cc6925445d3486e4c9a6ef915254cf3f28d973ad6a2876fca4fe3435b19ac273f18e89432622eaa38c8bba22ab9e9cafa07e417299dab8537848742175d1c8
7
+ data.tar.gz: 66d2a44a74a07e78f694adc4790218ee7a9d729e8cd8bb9546d154669a79d5abaa20e7d0bffa0801dfc276ef539b93d5a13dd2b4d3d3093cd8d806972d2dac81
@@ -1,5 +1,11 @@
1
1
  # master
2
2
 
3
+ # 2.13.0
4
+
5
+ * Add the ability to disable the render monkey patch with `config.view_component.render_monkey_patch_enabled`. In versions of Rails < 6.1, add `render_component` and `render_component_to_string` methods which can be used for rendering components instead of `render`.
6
+
7
+ *Johannes Engl*
8
+
3
9
  # 2.12.0
4
10
 
5
11
  * Implement Slots as potential successor to Content Areas.
data/README.md CHANGED
@@ -711,6 +711,18 @@ To use component previews:
711
711
  config.view_component.preview_path = "#{Rails.root}/spec/components/previews"
712
712
  ```
713
713
 
714
+ ### Disabling the render monkey patch (Rails < 6.1)
715
+
716
+ In order to [avoid conflicts](https://github.com/github/view_component/issues/288) between ViewComponent and other gems that also monkey patch the `render` method, it is possible to configure ViewComponent to not include the render monkey patch:
717
+
718
+ `config.view_component.render_monkey_patch_enabled = false # defaults to true`
719
+
720
+ With the monkey patch disabled, use `render_component` (or `render_component_to_string`) instead:
721
+
722
+ ```
723
+ <%= render_component Component.new(message: "bar") %>
724
+ ```
725
+
714
726
  ### Sidecar assets (experimental)
715
727
 
716
728
  It’s possible to include Javascript and CSS alongside components, sometimes called "sidecar" assets or files.
@@ -917,6 +929,11 @@ ViewComponent is built by:
917
929
  |@maxbeizer|@franco|@tbroad-ramsey|@jensljungblad|@bbugh|
918
930
  |Nashville, TN|Switzerland|Spring Hill, TN|New York, NY|Austin, TX|
919
931
 
932
+ |<img src="https://avatars.githubusercontent.com/johannesengl?s=256" alt="johannesengl" width="128" />|
933
+ |:---:|
934
+ |@johannesengl|
935
+ |Berlin, Germany|
936
+
920
937
  ## License
921
938
 
922
939
  ViewComponent is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -162,6 +162,9 @@ module ViewComponent
162
162
  mattr_accessor :test_controller
163
163
  @@test_controller = "ApplicationController"
164
164
 
165
+ # Configure if render monkey patches should be included or not in Rails <6.1.
166
+ mattr_accessor :render_monkey_patch_enabled, instance_writer: false, default: true
167
+
165
168
  class << self
166
169
  attr_accessor :source_location
167
170
 
@@ -10,6 +10,7 @@ module ViewComponent
10
10
  initializer "view_component.set_configs" do |app|
11
11
  options = app.config.view_component
12
12
 
13
+ options.render_monkey_patch_enabled = true if options.render_monkey_patch_enabled.nil?
13
14
  options.show_previews = Rails.env.development? if options.show_previews.nil?
14
15
  options.preview_route ||= ViewComponent::Base.preview_route
15
16
 
@@ -42,21 +43,35 @@ module ViewComponent
42
43
  end
43
44
  end
44
45
 
45
- initializer "view_component.monkey_patch_render" do
46
+ initializer "view_component.monkey_patch_render" do |app|
47
+ next if Rails.version.to_f >= 6.1 || !app.config.view_component.render_monkey_patch_enabled
48
+
46
49
  ActiveSupport.on_load(:action_view) do
47
- if Rails.version.to_f < 6.1
48
- require "view_component/render_monkey_patch"
49
- ActionView::Base.prepend ViewComponent::RenderMonkeyPatch
50
- end
50
+ require "view_component/render_monkey_patch"
51
+ ActionView::Base.prepend ViewComponent::RenderMonkeyPatch
51
52
  end
52
53
 
53
54
  ActiveSupport.on_load(:action_controller) do
54
- if Rails.version.to_f < 6.1
55
- require "view_component/rendering_monkey_patch"
56
- require "view_component/render_to_string_monkey_patch"
57
- ActionController::Base.prepend ViewComponent::RenderingMonkeyPatch
58
- ActionController::Base.prepend ViewComponent::RenderToStringMonkeyPatch
59
- end
55
+ require "view_component/rendering_monkey_patch"
56
+ require "view_component/render_to_string_monkey_patch"
57
+ ActionController::Base.prepend ViewComponent::RenderingMonkeyPatch
58
+ ActionController::Base.prepend ViewComponent::RenderToStringMonkeyPatch
59
+ end
60
+ end
61
+
62
+ initializer "view_component.include_render_component" do |app|
63
+ next if Rails.version.to_f >= 6.1
64
+
65
+ ActiveSupport.on_load(:action_view) do
66
+ require "view_component/render_component_helper"
67
+ ActionView::Base.include ViewComponent::RenderComponentHelper
68
+ end
69
+
70
+ ActiveSupport.on_load(:action_controller) do
71
+ require "view_component/rendering_component_helper"
72
+ require "view_component/render_component_to_string_helper"
73
+ ActionController::Base.include ViewComponent::RenderingComponentHelper
74
+ ActionController::Base.include ViewComponent::RenderComponentToStringHelper
60
75
  end
61
76
  end
62
77
 
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViewComponent
4
+ module RenderComponentHelper # :nodoc:
5
+ def render_component(component, &block)
6
+ component.render_in(self, &block)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViewComponent
4
+ module RenderComponentToStringHelper # :nodoc:
5
+ def render_component_to_string(component)
6
+ component.render_in(self.view_context)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViewComponent
4
+ module RenderingComponentHelper # :nodoc:
5
+ def render_component(component)
6
+ self.response_body = component.render_in(self.view_context)
7
+ end
8
+ end
9
+ end
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 12
6
+ MINOR = 13
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.12.0
4
+ version: 2.13.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: 2020-06-30 00:00:00.000000000 Z
11
+ date: 2020-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -204,8 +204,11 @@ files:
204
204
  - lib/view_component/engine.rb
205
205
  - lib/view_component/preview.rb
206
206
  - lib/view_component/previewable.rb
207
+ - lib/view_component/render_component_helper.rb
208
+ - lib/view_component/render_component_to_string_helper.rb
207
209
  - lib/view_component/render_monkey_patch.rb
208
210
  - lib/view_component/render_to_string_monkey_patch.rb
211
+ - lib/view_component/rendering_component_helper.rb
209
212
  - lib/view_component/rendering_monkey_patch.rb
210
213
  - lib/view_component/slot.rb
211
214
  - lib/view_component/slotable.rb