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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38891bd3b2a3b00b7da81feb7e78fa55e5efbbf5f4bcf25abd47cf68893e7725
4
- data.tar.gz: d53bc1d826b6504ea9b4fd4d5aa91362995fec79e12471c12466ea62a31c59b6
3
+ metadata.gz: 3ba3d4977df1eebf5c9302cd205026c2c24171573ac3e773e7842d7951a3dba3
4
+ data.tar.gz: 8b304a5e95a8483fa76227c6949a5d97a645ed70e7529bec41d21faee6a1b5f0
5
5
  SHA512:
6
- metadata.gz: 3b3c2bfa37f043f19b52d9dcca5e07c8ecd7cdc3c4e06edaf775eedf5b1ced6e1a32bec284116a39222f2e67249928a175f72a75d33e84f81eb00cc918f40015
7
- data.tar.gz: 626cf782c789aef2e982f13a2f8f313a3f9bf37e0bcaefc1010e9ee4f70335a6fc6062a48ca7e2d49ef4c9f0a8f4f3a9a1ed493fb5440d40da5253bf9393fb86
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- actionview-component (1.15.0)
4
+ actionview-component (1.16.0)
5
5
  capybara (>= 3)
6
6
 
7
7
  GEM
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:
@@ -132,7 +132,9 @@ module ViewComponent
132
132
 
133
133
  class << self
134
134
  def inherited(child)
135
- child.include Rails.application.routes.url_helpers unless child < Rails.application.routes.url_helpers
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
 
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 1
6
- MINOR = 15
6
+ MINOR = 16
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: actionview-component
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.15.0
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-09 00:00:00.000000000 Z
11
+ date: 2020-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara