view_component 2.7.0 → 2.8.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.

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: 5c62fe72fd9c16275ff15c18684090a2678dfba28d585da3133b430431a672e7
4
- data.tar.gz: b05a979440d506690105a9a8c0f501a914bb0db30d3c56303dd145b5d4aad208
3
+ metadata.gz: 7ac6dfbc2cb2fb7bbad0aac55de41cfbdc782dac0eb14f1e4b18784e15db02a9
4
+ data.tar.gz: 294bd6faac8d95b0db842ab67139e141117058148c24d503647960e31c19ef21
5
5
  SHA512:
6
- metadata.gz: f47750eee5ae067e03b3945ae696eccf5c14bd5677a9a65854eb15ccd060ae3d5d08591424c922097c4596546b007958b2f04bf0c14360939c44f200153ff9dc
7
- data.tar.gz: 4098da390547ba5d915d7eb887b22d9d932e860a079ab8a04f54f2fd8d437aa7830462e116f2ef0efdf078b73dc70f05e64380747acbbd736a99fc4117c462c6
6
+ metadata.gz: 4d2da7f6d4ff599ea9b92408dc632eecb7629d7bf7cda9484eab20b0f02dd1a78ba3669fc5f9107f2b6388d2f5634258a14b806d58327c716a8339b819ef8aa7
7
+ data.tar.gz: 50b86ff9e697608ae063352c8a55430763b5762016c3512dfa103f5df7a2fbb4875a993e319783f2e1e077c4ca157152a4314d3a106b0fc0a84186926044f917
@@ -1,5 +1,11 @@
1
1
  # master
2
2
 
3
+ # 2.8.0
4
+
5
+ * Add `before_render`, deprecating `before_render_check`.
6
+
7
+ *Joel Hawksley*
8
+
3
9
  # 2.7.0
4
10
 
5
11
  * Add `rendered_component` method to `ViewComponent::TestHelpers` which exposes the raw output of the rendered component.
data/README.md CHANGED
@@ -193,7 +193,7 @@ end
193
193
 
194
194
  ### Sidecar Assets
195
195
 
196
- ViewComponents supports two options for defining view files.
196
+ ViewComponents supports two options for defining view files.
197
197
 
198
198
  #### Sidecar view
199
199
 
@@ -274,6 +274,19 @@ end
274
274
 
275
275
  _To assert that a component has not been rendered, use `refute_component_rendered` from `ViewComponent::TestHelpers`._
276
276
 
277
+ ### `before_render`
278
+
279
+ Components can define a `before_render` method to be called before a component is rendered, when `helpers` is able to be used:
280
+
281
+ `app/components/confirm_email_component.rb`
282
+ ```ruby
283
+ class MyComponent < ViewComponent::Base
284
+ def before_render
285
+ @my_icon = helpers.star_icon
286
+ end
287
+ end
288
+ ```
289
+
277
290
  ### Rendering collections
278
291
 
279
292
  Use `with_collection` to render a ViewComponent with a collection:
@@ -439,6 +452,21 @@ test "render component" do
439
452
  end
440
453
  ```
441
454
 
455
+ To test components that use `with_content_areas`:
456
+
457
+ ```ruby
458
+ test "renders content_areas template with content " do
459
+ render_inline(ContentAreasComponent.new(footer: "Bye!")) do |component|
460
+ component.with(:title, "Hello!")
461
+ component.with(:body) { "Have a nice day." }
462
+ end
463
+
464
+ assert_selector(".title", text: "Hello!")
465
+ assert_selector(".body", text: "Have a nice day.")
466
+ assert_selector(".footer", text: "Bye!")
467
+ end
468
+ ```
469
+
442
470
  #### Action Pack Variants
443
471
 
444
472
  Use the `with_variant` helper to test specific variants:
@@ -66,7 +66,7 @@ module ViewComponent
66
66
  # Assign captured content passed to component as a block to @content
67
67
  @content = view_context.capture(self, &block) if block_given?
68
68
 
69
- before_render_check
69
+ before_render
70
70
 
71
71
  if render?
72
72
  send(self.class.call_method_name(@variant))
@@ -77,6 +77,10 @@ module ViewComponent
77
77
  @current_template = old_current_template
78
78
  end
79
79
 
80
+ def before_render
81
+ before_render_check
82
+ end
83
+
80
84
  def before_render_check
81
85
  # noop
82
86
  end
@@ -205,6 +209,12 @@ module ViewComponent
205
209
  return false
206
210
  end
207
211
 
212
+ if instance_methods(false).include?(:before_render_check)
213
+ ActiveSupport::Deprecation.warn(
214
+ "`before_render_check` will be removed in v3.0.0. Use `before_render` instead."
215
+ )
216
+ end
217
+
208
218
  # Remove any existing singleton methods,
209
219
  # as Ruby warns when redefining a method.
210
220
  remove_possible_singleton_method(:variants)
@@ -239,8 +249,8 @@ module ViewComponent
239
249
  # starting line number so errors that are raised will point to the
240
250
  # correct line in the component template.
241
251
  line_number =
242
- if ActionView::Base.respond_to?(:annotate_template_file_names) &&
243
- ActionView::Base.annotate_template_file_names
252
+ if ActionView::Base.respond_to?(:annotate_rendered_view_with_filenames) &&
253
+ ActionView::Base.annotate_rendered_view_with_filenames
244
254
  -2
245
255
  else
246
256
  -1
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 7
6
+ MINOR = 8
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.7.0
4
+ version: 2.8.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-05-19 00:00:00.000000000 Z
11
+ date: 2020-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -142,6 +142,34 @@ dependencies:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
144
  version: 0.13.0
145
+ - !ruby/object:Gem::Dependency
146
+ name: simplecov
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: 0.18.0
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: 0.18.0
159
+ - !ruby/object:Gem::Dependency
160
+ name: simplecov-erb
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '0.1'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: '0.1'
145
173
  description:
146
174
  email:
147
175
  - opensource+view_component@github.com