actionview-component 1.15.0 → 1.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +1 -1
- data/README.md +20 -0
- data/lib/view_component/base.rb +8 -2
- data/lib/view_component/test_helpers.rb +4 -0
- data/lib/view_component/version.rb +1 -1
- 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: 3ba3d4977df1eebf5c9302cd205026c2c24171573ac3e773e7842d7951a3dba3
|
4
|
+
data.tar.gz: 8b304a5e95a8483fa76227c6949a5d97a645ed70e7529bec41d21faee6a1b5f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96cb83f9aa25bfc9e363b0d9fca3e62b84829514f5340f4a531b4f8709563fc85fd2990b2175c912938993a09dc9d834396589daec8839b30523156eb21250d1
|
7
|
+
data.tar.gz: 9e03e678effd5b1716d24f23f7c16c0b4342ba18a4c480ac93ac5bdd3e7d049285e15974642c363b8d4e3b085108ae1b5a16ccf20bd3ed553472edc70fd4a722
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# master
|
2
2
|
|
3
|
+
# v1.16.0
|
4
|
+
|
5
|
+
* Add `refute_component_rendered` test helper.
|
6
|
+
|
7
|
+
*Joel Hawksley*
|
8
|
+
|
9
|
+
* Check for Rails before invocation.
|
10
|
+
|
11
|
+
*Dave Paola*
|
12
|
+
|
13
|
+
* Allow components to be rendered without a template file (aka inline component).
|
14
|
+
|
15
|
+
*Rainer Borene*
|
16
|
+
|
3
17
|
# v1.15.0
|
4
18
|
|
5
19
|
* Re-introduce ActionView::Component::TestHelpers.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -197,6 +197,24 @@ Which returns:
|
|
197
197
|
</div>
|
198
198
|
```
|
199
199
|
|
200
|
+
### Inline Component
|
201
|
+
|
202
|
+
A component can be rendered without any template file as well.
|
203
|
+
|
204
|
+
`app/components/inline_component.rb`:
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
class InlineComponent < ViewComponent::Base
|
208
|
+
def call
|
209
|
+
if active?
|
210
|
+
link_to "Cancel integration", integration_path, method: :delete
|
211
|
+
else
|
212
|
+
link_to "Integrate now!", integration_path
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
```
|
217
|
+
|
200
218
|
### Conditional Rendering
|
201
219
|
|
202
220
|
Components can implement a `#render?` method to determine if they should be rendered.
|
@@ -248,6 +266,8 @@ end
|
|
248
266
|
<%= render(ConfirmEmailComponent.new(user: current_user)) %>
|
249
267
|
```
|
250
268
|
|
269
|
+
To assert that a component has not been rendered, use `refute_component_rendered` from `ViewComponent::TestHelpers`.
|
270
|
+
|
251
271
|
### Testing
|
252
272
|
|
253
273
|
Unit test components directly, using the `render_inline` test helper and Capybara matchers:
|
data/lib/view_component/base.rb
CHANGED
@@ -132,7 +132,9 @@ module ViewComponent
|
|
132
132
|
|
133
133
|
class << self
|
134
134
|
def inherited(child)
|
135
|
-
|
135
|
+
if defined?(Rails)
|
136
|
+
child.include Rails.application.routes.url_helpers unless child < Rails.application.routes.url_helpers
|
137
|
+
end
|
136
138
|
|
137
139
|
super
|
138
140
|
end
|
@@ -159,6 +161,10 @@ module ViewComponent
|
|
159
161
|
@compiled && ActionView::Base.cache_template_loading
|
160
162
|
end
|
161
163
|
|
164
|
+
def inlined?
|
165
|
+
instance_methods(false).grep(/^call/).present? && templates.empty?
|
166
|
+
end
|
167
|
+
|
162
168
|
def compile!
|
163
169
|
compile(raise_template_errors: true)
|
164
170
|
end
|
@@ -167,7 +173,7 @@ module ViewComponent
|
|
167
173
|
# We could in theory do this on app boot, at least in production environments.
|
168
174
|
# Right now this just compiles the first time the component is rendered.
|
169
175
|
def compile(raise_template_errors: false)
|
170
|
-
return if compiled?
|
176
|
+
return if compiled? || inlined?
|
171
177
|
|
172
178
|
if template_errors.present?
|
173
179
|
raise ViewComponent::TemplateError.new(template_errors) if raise_template_errors
|
@@ -10,6 +10,10 @@ module ViewComponent
|
|
10
10
|
Capybara::Node::Simple.new(@raw)
|
11
11
|
end
|
12
12
|
|
13
|
+
def refute_component_rendered
|
14
|
+
assert_no_selector("body")
|
15
|
+
end
|
16
|
+
|
13
17
|
def render_inline(component, **args, &block)
|
14
18
|
@raw = controller.view_context.render(component, args, &block)
|
15
19
|
|
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.16.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: 2020-03-
|
11
|
+
date: 2020-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|