view_component 2.25.1 → 2.26.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 +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/rails/generators/erb/component_generator.rb +7 -7
- data/lib/rails/generators/haml/component_generator.rb +3 -1
- data/lib/rails/generators/slim/component_generator.rb +3 -1
- data/lib/view_component/base.rb +24 -4
- data/lib/view_component/collection.rb +0 -1
- data/lib/view_component/slotable.rb +7 -1
- data/lib/view_component/slotable_v2.rb +2 -0
- data/lib/view_component/version.rb +2 -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: 5a1fb023bfaa4a1ea26166ddd22b5fcd4a7e5f5da1bc7f10039c2bc557f1a94c
|
4
|
+
data.tar.gz: 5274b49f0e18f521b15181c70aeb4edcf3458cba13dc8c8ea59b9331d26681c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc60826197c5dbd54ebd53517ff59eab097449913802a4e17df9db33ab54d1daf8ff2e00d1629058962c267274ec7fe6e362aa036206d379e27c7c832db7d05c
|
7
|
+
data.tar.gz: b3a65f7a829d9e9fc675904d61c6d1c1015c194c5a7abe596961b3cb20a3a4c2045f1ce49b1b98a551c4b745688c38610d3a86040c1f7f0229c3b247a51f9c65
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,20 @@
|
|
2
2
|
|
3
3
|
## main
|
4
4
|
|
5
|
+
## 2.26.0
|
6
|
+
|
7
|
+
* Lazily evaluate component `content` in `render?`, preventing the `content` block from being evaluated when `render?` returns false.
|
8
|
+
|
9
|
+
*Blake Williams*
|
10
|
+
|
11
|
+
* Do not generate template when using `--inline` flag.
|
12
|
+
|
13
|
+
*Hans Lemuet*
|
14
|
+
|
15
|
+
* Add `--inline` option to the Haml and Slim generators
|
16
|
+
|
17
|
+
*Hans Lemuet*
|
18
|
+
|
5
19
|
## 2.25.1
|
6
20
|
|
7
21
|
* Experimental: call `._after_compile` class method after a component is compiled.
|
@@ -10,18 +10,18 @@ module Erb
|
|
10
10
|
class_option :inline, type: :boolean, default: false
|
11
11
|
|
12
12
|
def copy_view_file
|
13
|
-
|
13
|
+
unless options["inline"]
|
14
|
+
template "component.html.erb", destination
|
15
|
+
end
|
14
16
|
end
|
15
17
|
|
16
18
|
private
|
17
19
|
|
18
20
|
def destination
|
19
|
-
if
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
File.join("app/components", class_path, "#{file_name}_component.html.erb")
|
24
|
-
end
|
21
|
+
if options["sidecar"]
|
22
|
+
File.join("app/components", class_path, "#{file_name}_component", "#{file_name}_component.html.erb")
|
23
|
+
else
|
24
|
+
File.join("app/components", class_path, "#{file_name}_component.html.erb")
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
data/lib/view_component/base.rb
CHANGED
@@ -78,8 +78,8 @@ module ViewComponent
|
|
78
78
|
old_current_template = @current_template
|
79
79
|
@current_template = self
|
80
80
|
|
81
|
-
|
82
|
-
@
|
81
|
+
@_content_evaluated = false
|
82
|
+
@_render_in_block = block
|
83
83
|
|
84
84
|
before_render
|
85
85
|
|
@@ -177,7 +177,20 @@ module ViewComponent
|
|
177
177
|
@request ||= controller.request
|
178
178
|
end
|
179
179
|
|
180
|
-
attr_reader :
|
180
|
+
attr_reader :view_context
|
181
|
+
|
182
|
+
def content
|
183
|
+
return @_content if defined?(@_content)
|
184
|
+
@_content_evaluated = true
|
185
|
+
|
186
|
+
@_content = if @view_context && @_render_in_block
|
187
|
+
view_context.capture(self, &@_render_in_block)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def content_evaluated?
|
192
|
+
@_content_evaluated
|
193
|
+
end
|
181
194
|
|
182
195
|
# The controller used for testing components.
|
183
196
|
# Defaults to ApplicationController. This should be set early
|
@@ -256,7 +269,14 @@ module ViewComponent
|
|
256
269
|
if areas.include?(:content)
|
257
270
|
raise ArgumentError.new ":content is a reserved content area name. Please use another name, such as ':body'"
|
258
271
|
end
|
259
|
-
|
272
|
+
|
273
|
+
areas.each do |area|
|
274
|
+
define_method area.to_sym do
|
275
|
+
content unless content_evaluated? # ensure content is loaded so content_areas will be defined
|
276
|
+
instance_variable_get(:"@#{area}") if instance_variable_defined?(:"@#{area}")
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
260
280
|
self.content_areas = areas
|
261
281
|
end
|
262
282
|
|
@@ -10,7 +10,6 @@ module ViewComponent
|
|
10
10
|
def render_in(view_context, &block)
|
11
11
|
iterator = ActionView::PartialIteration.new(@collection.size)
|
12
12
|
|
13
|
-
component.compile(raise_errors: true)
|
14
13
|
component.validate_collection_parameter!(validate_default: true)
|
15
14
|
|
16
15
|
@collection.map do |item|
|
@@ -51,11 +51,17 @@ module ViewComponent
|
|
51
51
|
if collection
|
52
52
|
class_eval <<-RUBY
|
53
53
|
def #{accessor_name}
|
54
|
+
content unless content_evaluated? # ensure content is loaded so slots will be defined
|
54
55
|
#{instance_variable_name} ||= []
|
55
56
|
end
|
56
57
|
RUBY
|
57
58
|
else
|
58
|
-
|
59
|
+
class_eval <<-RUBY
|
60
|
+
def #{accessor_name}
|
61
|
+
content unless content_evaluated? # ensure content is loaded so slots will be defined
|
62
|
+
#{instance_variable_name} if defined?(#{instance_variable_name})
|
63
|
+
end
|
64
|
+
RUBY
|
59
65
|
end
|
60
66
|
|
61
67
|
# Default class_name to ViewComponent::Slot
|
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.
|
4
|
+
version: 2.26.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: 2021-02-
|
11
|
+
date: 2021-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|