actionview-component 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59f02a9bdd999da01d26a2f7a9c80d0ec6cd1cf96d0195f8d2aa983f504d9908
4
- data.tar.gz: ea36b326f6c565cf64acc827449dc11372a2bf10c49a77b5e994d9597234e926
3
+ metadata.gz: ddf5bf315652aa562e2539e334b61b97504cc05d37dd8580929dc0427d4ef44a
4
+ data.tar.gz: 2c7310fec9eca98c28d6dc1b547959a8f4581026a59afe66f927df4c630b4ded
5
5
  SHA512:
6
- metadata.gz: e87095b78618384e60884166c0a6eb9d024c94afe0f5e4d44b1295dd5fbdf8a84000e304d8c4b56e51e8c6112f6416718fe04667b9e13bca4b2a5283c6346b49
7
- data.tar.gz: '08dc5a1408d730948c08239a90edea25cfde9cc144a7e4b24ecfd4ee6817f7a49c19df7acec9fdfd58b26545c8fe182080dc436f3ac9aa14b17479365a40166b'
6
+ metadata.gz: 38c43b346608924c4ee5977c99760acebbb055392acbb276b8dbe1f0ce92b2c020b6ff2a9c5c63ac9b9025e4d1cc9a24fd86bf428a5ba375f11fa7b12a8fc149
7
+ data.tar.gz: 7ed9efc6148a03dcaafcbec7a77467b17690e2c71e5afb133855a4924b91a771c0980cd7e0b4373f9deea8909be74e675a3a579e39eb78391cfbce8ab4db01af
@@ -1,7 +1,25 @@
1
- * Components now inherit from ActionView::Component::base
1
+ * The `render_component` test helper has been renamed to `render_inline`. `render_component` has been deprecated and will be removed in v2.0.0.
2
2
 
3
3
  *Joel Hawksley*
4
4
 
5
+ * Components are now rendered with `render MyComponent, foo: :bar` syntax. The existing `render MyComponent.new(foo: :bar)` syntax has been deprecated and will be removed in v2.0.0.
6
+
7
+ *Joel Hawksley*
8
+
9
+ # v1.1.0
10
+
11
+ * Components now inherit from ActionView::Component::Base
12
+
13
+ *Joel Hawksley*
14
+
15
+ # v1.0.1
16
+
5
17
  * Always recompile component templates outside production.
6
18
 
7
19
  *Joel Hawksley, John Hawthorn*
20
+
21
+ # v1.0.0
22
+
23
+ This release extracts the `ActionView::Component` library from the GitHub application.
24
+
25
+ It will be published on RubyGems under the existing `actionview-component` gem name, as @chancancode has passed us ownership of the gem.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- actionview-component (1.0.1)
4
+ actionview-component (1.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -124,7 +124,7 @@ end
124
124
  We can render it in a view as:
125
125
 
126
126
  ```erb
127
- <%= render(TestComponent.new(title: "my title")) do %>
127
+ <%= render(TestComponent, title: "my title") do %>
128
128
  Hello, World!
129
129
  <% end %>
130
130
  ```
@@ -135,12 +135,24 @@ Which returns:
135
135
  <span title="my title">Hello, World!</span>
136
136
  ```
137
137
 
138
+ ##### Supported `render` syntaxes
139
+
140
+ Components can be rendered via:
141
+
142
+ `render(TestComponent, foo: :bar)`
143
+
144
+ `render(component: TestComponent, locals: { foo: :bar })`
145
+
146
+ The following syntax has been deprecated and will be removed in v2.0.0:
147
+
148
+ `render(TestComponent.new(foo: :bar)`
149
+
138
150
  #### Error case
139
151
 
140
152
  If the component is rendered with a blank title:
141
153
 
142
154
  ```erb
143
- <%= render(TestComponent.new(title: "")) do %>
155
+ <%= render(TestComponent, title: "") do %>
144
156
  Hello, World!
145
157
  <% end %>
146
158
  ```
@@ -151,7 +163,7 @@ An error will be raised:
151
163
 
152
164
  ### Testing
153
165
 
154
- Components are unit tested directly. The `render_component` test helper renders a component and wraps the result in `Nokogiri.HTML`, allowing us to test the component above as:
166
+ Components are unit tested directly. The `render_inline` test helper wraps the result in `Nokogiri.HTML`, allowing us to test the component above as:
155
167
 
156
168
  ```ruby
157
169
  require "action_view/component/test_helpers"
@@ -162,7 +174,7 @@ class MyComponentTest < Minitest::Test
162
174
  def test_render_component
163
175
  assert_equal(
164
176
  %(<span title="my title">Hello, World!</span>),
165
- render_component(TestComponent.new(title: "my title")) { "Hello, World!" }.css("span").to_html
177
+ render_inline(TestComponent, title: "my title") { "Hello, World!" }.css("span").to_html
166
178
  )
167
179
  end
168
180
  end
@@ -6,7 +6,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = "actionview-component"
9
- spec.version = "1.1.0"
9
+ spec.version = "1.2.0"
10
10
  spec.authors = ["GitHub Open Source"]
11
11
  spec.email = ["opensource+actionview-component@github.com"]
12
12
 
@@ -2,18 +2,28 @@
2
2
 
3
3
  # Monkey patch ActionView::Base#render to support ActionView::Component
4
4
  #
5
- # Upstreamed in https://github.com/rails/rails/pull/36388
6
- # Necessary for Rails versions < 6.1.0.alpha
5
+ # A version of this monkey patch was upstreamed in https://github.com/rails/rails/pull/36388
6
+ # We'll need to upstream an updated version of this eventually.
7
7
  class ActionView::Base
8
8
  module RenderMonkeyPatch
9
- def render(component, _ = nil, &block)
10
- return super unless component.respond_to?(:render_in)
11
-
12
- component.render_in(self, &block)
9
+ def render(options = {}, args = {}, &block)
10
+ if options.respond_to?(:render_in)
11
+ ActiveSupport::Deprecation.warn(
12
+ "passing component instances to `render` has been deprecated and will be removed in v2.0.0. Use `render MyComponent, foo: :bar` instead."
13
+ )
14
+
15
+ options.render_in(self, &block)
16
+ elsif options.is_a?(Class) && options < ActionView::Component::Base
17
+ options.new(args).render_in(self, &block)
18
+ elsif options.is_a?(Hash) && options.has_key?(:component)
19
+ options[:component].new(options[:locals]).render_in(self, &block)
20
+ else
21
+ super
22
+ end
13
23
  end
14
24
  end
15
25
 
16
- prepend RenderMonkeyPatch unless Rails::VERSION::MINOR > 0 && Rails::VERSION::MAJOR == 6
26
+ prepend RenderMonkeyPatch
17
27
  end
18
28
 
19
29
  module ActionView
@@ -42,7 +52,7 @@ module ActionView
42
52
  # <span title="<%= @title %>">Hello, <%= content %>!</span>
43
53
  #
44
54
  # In use:
45
- # <%= render MyComponent.new(title: "greeting") do %>world<% end %>
55
+ # <%= render MyComponent, title: "greeting" do %>world<% end %>
46
56
  # returns:
47
57
  # <span title="greeting">Hello, world!</span>
48
58
  #
@@ -3,8 +3,16 @@
3
3
  module ActionView
4
4
  module Component
5
5
  module TestHelpers
6
- def render_component(component, &block)
7
- Nokogiri::HTML(component.render_in(ApplicationController.new.view_context, &block))
6
+ def render_inline(component, **args, &block)
7
+ Nokogiri::HTML(ApplicationController.new.view_context.render(component, args, &block))
8
+ end
9
+
10
+ def render_component(component, **args, &block)
11
+ ActiveSupport::Deprecation.warn(
12
+ "`render_component` has been deprecated in favor of `render_inline`, and will be removed in v2.0.0."
13
+ )
14
+
15
+ render_inline(component, args, &block)
8
16
  end
9
17
  end
10
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionview-component
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-27 00:00:00.000000000 Z
11
+ date: 2019-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler