view_component 2.25.1 → 2.26.0

Sign up to get free protection for your applications and to get access to all the features.

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: c411f9f34b25054093f7abe23c5842c7523f083ecdb1ba586429545548eca423
4
- data.tar.gz: 744c27c0907544dfb93eb37ecf47c74dd7df86855c0e2b91f9619a77bd8eefc8
3
+ metadata.gz: 5a1fb023bfaa4a1ea26166ddd22b5fcd4a7e5f5da1bc7f10039c2bc557f1a94c
4
+ data.tar.gz: 5274b49f0e18f521b15181c70aeb4edcf3458cba13dc8c8ea59b9331d26681c5
5
5
  SHA512:
6
- metadata.gz: bee62ecbcfecbc53146b8a8e55207baf2d14769adda2bb2349494a82224acf12fa6584bfc32512e96474f28f011823f2c5712cbc021773d439c43fab8b090503
7
- data.tar.gz: 3f519b85b066d89fdf75afb17563cb868bb4fb673caa21326661f0738b9b4398af068421064ca6f77abf08b7b46bdc549c132252b111b8fb3009809d430b9682
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
- template "component.html.erb", destination
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 !options["inline"]
20
- if options["sidecar"]
21
- File.join("app/components", class_path, "#{file_name}_component", "#{file_name}_component.html.erb")
22
- else
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
 
@@ -9,7 +9,9 @@ module Haml
9
9
  class_option :sidecar, type: :boolean, default: false
10
10
 
11
11
  def copy_view_file
12
- template "component.html.haml", destination
12
+ if !options["inline"]
13
+ template "component.html.haml", destination
14
+ end
13
15
  end
14
16
 
15
17
  private
@@ -9,7 +9,9 @@ module Slim
9
9
  class_option :sidecar, type: :boolean, default: false
10
10
 
11
11
  def copy_view_file
12
- template "component.html.slim", destination
12
+ if !options["inline"]
13
+ template "component.html.slim", destination
14
+ end
13
15
  end
14
16
 
15
17
  private
@@ -78,8 +78,8 @@ module ViewComponent
78
78
  old_current_template = @current_template
79
79
  @current_template = self
80
80
 
81
- # Assign captured content passed to component as a block to @content
82
- @content = view_context.capture(self, &block) if block_given?
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 :content, :view_context
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
- attr_reader(*areas)
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
- attr_reader accessor_name
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
@@ -183,6 +183,8 @@ module ViewComponent
183
183
  end
184
184
 
185
185
  def get_slot(slot_name)
186
+ content unless content_evaluated? # ensure content is loaded so slots will be defined
187
+
186
188
  slot = self.class.registered_slots[slot_name]
187
189
  @_set_slots ||= {}
188
190
 
@@ -3,8 +3,8 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 25
7
- PATCH = 1
6
+ MINOR = 26
7
+ PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
10
10
  end
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.25.1
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-01 00:00:00.000000000 Z
11
+ date: 2021-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport