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 +4 -4
- data/CHANGELOG.md +19 -1
- data/Gemfile.lock +1 -1
- data/README.md +16 -4
- data/actionview-component.gemspec +1 -1
- data/lib/action_view/component/base.rb +18 -8
- data/lib/action_view/component/test_helpers.rb +10 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddf5bf315652aa562e2539e334b61b97504cc05d37dd8580929dc0427d4ef44a
|
4
|
+
data.tar.gz: 2c7310fec9eca98c28d6dc1b547959a8f4581026a59afe66f927df4c630b4ded
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38c43b346608924c4ee5977c99760acebbb055392acbb276b8dbe1f0ce92b2c020b6ff2a9c5c63ac9b9025e4d1cc9a24fd86bf428a5ba375f11fa7b12a8fc149
|
7
|
+
data.tar.gz: 7ed9efc6148a03dcaafcbec7a77467b17690e2c71e5afb133855a4924b91a771c0980cd7e0b4373f9deea8909be74e675a3a579e39eb78391cfbce8ab4db01af
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,25 @@
|
|
1
|
-
*
|
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.
|
data/Gemfile.lock
CHANGED
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
|
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
|
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 `
|
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
|
-
|
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.
|
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
|
-
#
|
6
|
-
#
|
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(
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
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
|
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
|
7
|
-
Nokogiri::HTML(
|
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.
|
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-
|
11
|
+
date: 2019-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|