view_component 2.50.0 → 2.51.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: 4ea90ad2ed037528865b7e6cf8b5850df938b624883a1508d85de52d8978c4fb
4
- data.tar.gz: f2c1e558a700b9f79b3939785f3ff6c2f812a6e03b697f9b60f4aa6f6eaf54a0
3
+ metadata.gz: 163414625d8e2df6f2afddc821a6c849aef71cc8cd1ba458a533d90840e545cc
4
+ data.tar.gz: 3518269c96d4e62d3bcedae22871c7b260d2abf42e0c1e32703115185e69eeea
5
5
  SHA512:
6
- metadata.gz: 9fd97f786e4382098f81e5ec6230b6ae550991641f83d74ecfd67d3eacea515cd899ab21264c8ac5b5de1caed7f35304eb9b6cba13f092e5abdb3a6dc45f6b06
7
- data.tar.gz: b70d4f308f47c6937d8aa2e518564ebbc6313366168e6382f4c296823ed07489c7be333f8f47822e65d3a5159753b5d3934ead8cd4323c3777d0c22dde9870f8
6
+ metadata.gz: 531785b833a4d1a83b6929095b6a6a34076cb6576820884487a247d70c37bde2fedc47914633674c59a888dc7270526660e121f4980f2bcb85625ed6009607c4
7
+ data.tar.gz: e4c8b2694c7f70c529d56dcced18f66d511e909e1f36abc604a58402d1332caecde59d40c065668454af8abf6d53578469539ac1f4366650ad286856b50776fa
data/docs/CHANGELOG.md CHANGED
@@ -7,6 +7,24 @@ title: Changelog
7
7
 
8
8
  ## main
9
9
 
10
+ ## 2.51.0
11
+
12
+ * Update the docs only when releasing a new version.
13
+
14
+ *Hans Lemuet*
15
+
16
+ * Alphabetize companies using ViewComponent and add Brightline to the list.
17
+
18
+ *Jack Schuss*
19
+
20
+ * Add CMYK value for ViewComponent Red color on logo page.
21
+
22
+ *Dylan Smith*
23
+
24
+ * Improve performance by moving template compilation from `#render_in` to `#render_template_for`.
25
+
26
+ *Cameron Dutro*
27
+
10
28
  ## 2.50.0
11
29
 
12
30
  * Add tests for `layout` usage when rendering via controller.
@@ -66,8 +66,6 @@ module ViewComponent
66
66
  #
67
67
  # @return [String]
68
68
  def render_in(view_context, &block)
69
- self.class.compile(raise_errors: true)
70
-
71
69
  @view_context = view_context
72
70
  self.__vc_original_view_context ||= view_context
73
71
 
@@ -112,6 +110,16 @@ module ViewComponent
112
110
  @current_template = old_current_template
113
111
  end
114
112
 
113
+ # :nocov:
114
+ def render_template_for(variant = nil)
115
+ # Force compilation here so the compiler always redefines render_template_for.
116
+ # This is mostly a safeguard to prevent infinite recursion.
117
+ self.class.compile(raise_errors: true, force: true)
118
+ # .compile replaces this method; call the new one
119
+ render_template_for(variant)
120
+ end
121
+ # :nocov:
122
+
115
123
  # EXPERIMENTAL: Optional content to be returned after the rendered template.
116
124
  #
117
125
  # @return [String]
@@ -445,8 +453,8 @@ module ViewComponent
445
453
  # Do as much work as possible in this step, as doing so reduces the amount
446
454
  # of work done each time a component is rendered.
447
455
  # @private
448
- def compile(raise_errors: false)
449
- compiler.compile(raise_errors: raise_errors)
456
+ def compile(raise_errors: false, force: false)
457
+ compiler.compile(raise_errors: raise_errors, force: force)
450
458
  end
451
459
 
452
460
  # @private
@@ -20,10 +20,11 @@ module ViewComponent
20
20
 
21
21
  def invalidate_class!(klass)
22
22
  cache.delete(klass)
23
+ klass.compiler.reset_render_template_for
23
24
  end
24
25
 
25
26
  def invalidate!
26
- cache.clear
27
+ cache.each { |klass| invalidate_class!(klass) }
27
28
  end
28
29
  end
29
30
  end
@@ -27,12 +27,11 @@ module ViewComponent
27
27
  self.class.mode == DEVELOPMENT_MODE
28
28
  end
29
29
 
30
- def compile(raise_errors: false)
31
- return if compiled?
30
+ def compile(raise_errors: false, force: false)
31
+ return if compiled? && !force
32
+ return if component_class == ViewComponent::Base
32
33
 
33
34
  with_lock do
34
- CompileCache.invalidate_class!(component_class)
35
-
36
35
  subclass_instance_methods = component_class.instance_methods(false)
37
36
 
38
37
  if subclass_instance_methods.include?(:with_content) && raise_errors
@@ -65,8 +64,8 @@ module ViewComponent
65
64
  # as Ruby warns when redefining a method.
66
65
  method_name = call_method_name(template[:variant])
67
66
 
68
- if component_class.instance_methods.include?(method_name.to_sym)
69
- component_class.send(:undef_method, method_name.to_sym)
67
+ if component_class.instance_methods(false).include?(method_name.to_sym)
68
+ component_class.send(:remove_method, method_name.to_sym)
70
69
  end
71
70
 
72
71
  component_class.class_eval <<-RUBY, template[:path], -1
@@ -93,14 +92,18 @@ module ViewComponent
93
92
  end
94
93
  end
95
94
 
95
+ def reset_render_template_for
96
+ if component_class.instance_methods(false).include?(:render_template_for)
97
+ component_class.send(:remove_method, :render_template_for)
98
+ end
99
+ end
100
+
96
101
  private
97
102
 
98
103
  attr_reader :component_class
99
104
 
100
105
  def define_render_template_for
101
- if component_class.instance_methods.include?(:render_template_for)
102
- component_class.send(:undef_method, :render_template_for)
103
- end
106
+ reset_render_template_for
104
107
 
105
108
  variant_elsifs = variants.compact.uniq.map do |variant|
106
109
  "elsif variant.to_sym == :#{variant}\n #{call_method_name(variant)}"
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 50
6
+ MINOR = 51
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.50.0
4
+ version: 2.51.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: 2022-03-10 00:00:00.000000000 Z
11
+ date: 2022-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport