view_component_helper 0.4.4 → 0.4.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b14cab38b32ee81aa0cc440c6ace3233c681bf567d3af063b260cc10d7ffd68
4
- data.tar.gz: 33eec3e87d67cdf41fe9c7741ebedd3583f0dd0b6cd4fe22c8f4d17c7d31da0c
3
+ metadata.gz: 57701718d039ac056f76dc09a6ad26114b495067fcbf6af07b9b0ffd30f3fbaf
4
+ data.tar.gz: 9686baee018175896e73771ba436427183d8bba00e976441608e912e88515b4d
5
5
  SHA512:
6
- metadata.gz: 6110fdd56c17863aa506f5268037482f6727c600acc901e4deb6e20a219c98bafda4eb6a0ce9a5d3b4ad69622896397cc088614204c7ae339e8ee00039f44433
7
- data.tar.gz: 5d86f6a095be702ede49c7c39606748103527f3881a0e16ea984a494103dbbcd594e4b8f11170b6a085223cbd97cf6c430bb342453bd75ad4e3e56309a96c57c
6
+ metadata.gz: 9d765d480b9be81327db65955ffc028f2bd021bf66484344626e1d823690b92023dcbfcbb2834f463bf743ab9077dcf25d02700706872f0b62ecdd58cdb31a42
7
+ data.tar.gz: 50a5cf227fbff3fb388e83e8c960df0ec52b7d616d7855a1433d6eb4fbd4246de5fbf6f65cbe19b194a32cb42dfb7dbe73ccea68d9d2072b55c1f69684a9b32a
data/Gemfile.lock CHANGED
@@ -1,88 +1,90 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- view_component_helper (0.4.3)
4
+ view_component_helper (0.4.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actioncable (7.0.6)
10
- actionpack (= 7.0.6)
11
- activesupport (= 7.0.6)
9
+ actioncable (7.0.8)
10
+ actionpack (= 7.0.8)
11
+ activesupport (= 7.0.8)
12
12
  nio4r (~> 2.0)
13
13
  websocket-driver (>= 0.6.1)
14
- actionmailbox (7.0.6)
15
- actionpack (= 7.0.6)
16
- activejob (= 7.0.6)
17
- activerecord (= 7.0.6)
18
- activestorage (= 7.0.6)
19
- activesupport (= 7.0.6)
14
+ actionmailbox (7.0.8)
15
+ actionpack (= 7.0.8)
16
+ activejob (= 7.0.8)
17
+ activerecord (= 7.0.8)
18
+ activestorage (= 7.0.8)
19
+ activesupport (= 7.0.8)
20
20
  mail (>= 2.7.1)
21
21
  net-imap
22
22
  net-pop
23
23
  net-smtp
24
- actionmailer (7.0.6)
25
- actionpack (= 7.0.6)
26
- actionview (= 7.0.6)
27
- activejob (= 7.0.6)
28
- activesupport (= 7.0.6)
24
+ actionmailer (7.0.8)
25
+ actionpack (= 7.0.8)
26
+ actionview (= 7.0.8)
27
+ activejob (= 7.0.8)
28
+ activesupport (= 7.0.8)
29
29
  mail (~> 2.5, >= 2.5.4)
30
30
  net-imap
31
31
  net-pop
32
32
  net-smtp
33
33
  rails-dom-testing (~> 2.0)
34
- actionpack (7.0.6)
35
- actionview (= 7.0.6)
36
- activesupport (= 7.0.6)
34
+ actionpack (7.0.8)
35
+ actionview (= 7.0.8)
36
+ activesupport (= 7.0.8)
37
37
  rack (~> 2.0, >= 2.2.4)
38
38
  rack-test (>= 0.6.3)
39
39
  rails-dom-testing (~> 2.0)
40
40
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
41
- actiontext (7.0.6)
42
- actionpack (= 7.0.6)
43
- activerecord (= 7.0.6)
44
- activestorage (= 7.0.6)
45
- activesupport (= 7.0.6)
41
+ actiontext (7.0.8)
42
+ actionpack (= 7.0.8)
43
+ activerecord (= 7.0.8)
44
+ activestorage (= 7.0.8)
45
+ activesupport (= 7.0.8)
46
46
  globalid (>= 0.6.0)
47
47
  nokogiri (>= 1.8.5)
48
- actionview (7.0.6)
49
- activesupport (= 7.0.6)
48
+ actionview (7.0.8)
49
+ activesupport (= 7.0.8)
50
50
  builder (~> 3.1)
51
51
  erubi (~> 1.4)
52
52
  rails-dom-testing (~> 2.0)
53
53
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
54
- activejob (7.0.6)
55
- activesupport (= 7.0.6)
54
+ activejob (7.0.8)
55
+ activesupport (= 7.0.8)
56
56
  globalid (>= 0.3.6)
57
- activemodel (7.0.6)
58
- activesupport (= 7.0.6)
59
- activerecord (7.0.6)
60
- activemodel (= 7.0.6)
61
- activesupport (= 7.0.6)
62
- activestorage (7.0.6)
63
- actionpack (= 7.0.6)
64
- activejob (= 7.0.6)
65
- activerecord (= 7.0.6)
66
- activesupport (= 7.0.6)
57
+ activemodel (7.0.8)
58
+ activesupport (= 7.0.8)
59
+ activerecord (7.0.8)
60
+ activemodel (= 7.0.8)
61
+ activesupport (= 7.0.8)
62
+ activestorage (7.0.8)
63
+ actionpack (= 7.0.8)
64
+ activejob (= 7.0.8)
65
+ activerecord (= 7.0.8)
66
+ activesupport (= 7.0.8)
67
67
  marcel (~> 1.0)
68
68
  mini_mime (>= 1.1.0)
69
- activesupport (7.0.6)
69
+ activesupport (7.0.8)
70
70
  concurrent-ruby (~> 1.0, >= 1.0.2)
71
71
  i18n (>= 1.6, < 2)
72
72
  minitest (>= 5.1)
73
73
  tzinfo (~> 2.0)
74
74
  ast (2.4.2)
75
+ base64 (0.1.1)
75
76
  builder (3.2.4)
76
77
  concurrent-ruby (1.2.2)
77
78
  crass (1.0.6)
78
79
  date (3.3.3)
79
80
  diff-lcs (1.5.0)
80
81
  erubi (1.12.0)
81
- globalid (1.1.0)
82
- activesupport (>= 5.0)
82
+ globalid (1.2.1)
83
+ activesupport (>= 6.1)
83
84
  i18n (1.14.1)
84
85
  concurrent-ruby (~> 1.0)
85
86
  json (2.6.3)
87
+ language_server-protocol (3.17.0.3)
86
88
  loofah (2.21.3)
87
89
  crass (~> 1.0.2)
88
90
  nokogiri (>= 1.12.0)
@@ -93,56 +95,54 @@ GEM
93
95
  net-smtp
94
96
  marcel (1.0.2)
95
97
  method_source (1.0.0)
96
- mini_mime (1.1.2)
97
- mini_portile2 (2.8.4)
98
- minitest (5.18.1)
99
- net-imap (0.3.6)
98
+ mini_mime (1.1.5)
99
+ minitest (5.20.0)
100
+ net-imap (0.3.7)
100
101
  date
101
102
  net-protocol
102
103
  net-pop (0.1.2)
103
104
  net-protocol
104
105
  net-protocol (0.2.1)
105
106
  timeout
106
- net-smtp (0.3.3)
107
+ net-smtp (0.4.0)
107
108
  net-protocol
108
109
  nio4r (2.5.9)
109
- nokogiri (1.15.3)
110
- mini_portile2 (~> 2.8.2)
110
+ nokogiri (1.15.4-x86_64-darwin)
111
111
  racc (~> 1.4)
112
- nokogiri (1.15.3-x86_64-darwin)
112
+ nokogiri (1.15.4-x86_64-linux)
113
113
  racc (~> 1.4)
114
114
  parallel (1.23.0)
115
115
  parser (3.2.2.3)
116
116
  ast (~> 2.4.1)
117
117
  racc
118
118
  racc (1.7.1)
119
- rack (2.2.7)
119
+ rack (2.2.8)
120
120
  rack-test (2.1.0)
121
121
  rack (>= 1.3)
122
- rails (7.0.6)
123
- actioncable (= 7.0.6)
124
- actionmailbox (= 7.0.6)
125
- actionmailer (= 7.0.6)
126
- actionpack (= 7.0.6)
127
- actiontext (= 7.0.6)
128
- actionview (= 7.0.6)
129
- activejob (= 7.0.6)
130
- activemodel (= 7.0.6)
131
- activerecord (= 7.0.6)
132
- activestorage (= 7.0.6)
133
- activesupport (= 7.0.6)
122
+ rails (7.0.8)
123
+ actioncable (= 7.0.8)
124
+ actionmailbox (= 7.0.8)
125
+ actionmailer (= 7.0.8)
126
+ actionpack (= 7.0.8)
127
+ actiontext (= 7.0.8)
128
+ actionview (= 7.0.8)
129
+ activejob (= 7.0.8)
130
+ activemodel (= 7.0.8)
131
+ activerecord (= 7.0.8)
132
+ activestorage (= 7.0.8)
133
+ activesupport (= 7.0.8)
134
134
  bundler (>= 1.15.0)
135
- railties (= 7.0.6)
136
- rails-dom-testing (2.1.1)
135
+ railties (= 7.0.8)
136
+ rails-dom-testing (2.2.0)
137
137
  activesupport (>= 5.0.0)
138
138
  minitest
139
139
  nokogiri (>= 1.6)
140
140
  rails-html-sanitizer (1.6.0)
141
141
  loofah (~> 2.21)
142
142
  nokogiri (~> 1.14)
143
- railties (7.0.6)
144
- actionpack (= 7.0.6)
145
- activesupport (= 7.0.6)
143
+ railties (7.0.8)
144
+ actionpack (= 7.0.8)
145
+ activesupport (= 7.0.8)
146
146
  method_source
147
147
  rake (>= 12.2)
148
148
  thor (~> 1.0)
@@ -150,28 +150,30 @@ GEM
150
150
  rainbow (3.1.1)
151
151
  rake (13.0.6)
152
152
  regexp_parser (2.8.1)
153
- rexml (3.2.5)
154
- rspec (3.11.0)
155
- rspec-core (~> 3.11.0)
156
- rspec-expectations (~> 3.11.0)
157
- rspec-mocks (~> 3.11.0)
158
- rspec-core (3.11.0)
159
- rspec-support (~> 3.11.0)
160
- rspec-expectations (3.11.1)
153
+ rexml (3.2.6)
154
+ rspec (3.12.0)
155
+ rspec-core (~> 3.12.0)
156
+ rspec-expectations (~> 3.12.0)
157
+ rspec-mocks (~> 3.12.0)
158
+ rspec-core (3.12.2)
159
+ rspec-support (~> 3.12.0)
160
+ rspec-expectations (3.12.3)
161
161
  diff-lcs (>= 1.2.0, < 2.0)
162
- rspec-support (~> 3.11.0)
163
- rspec-mocks (3.11.1)
162
+ rspec-support (~> 3.12.0)
163
+ rspec-mocks (3.12.6)
164
164
  diff-lcs (>= 1.2.0, < 2.0)
165
- rspec-support (~> 3.11.0)
166
- rspec-support (3.11.1)
167
- rubocop (1.52.1)
165
+ rspec-support (~> 3.12.0)
166
+ rspec-support (3.12.1)
167
+ rubocop (1.56.3)
168
+ base64 (~> 0.1.1)
168
169
  json (~> 2.3)
170
+ language_server-protocol (>= 3.17.0)
169
171
  parallel (~> 1.10)
170
172
  parser (>= 3.2.2.3)
171
173
  rainbow (>= 2.2.2, < 4.0)
172
174
  regexp_parser (>= 1.8, < 3.0)
173
175
  rexml (>= 3.2.5, < 4.0)
174
- rubocop-ast (>= 1.28.0, < 2.0)
176
+ rubocop-ast (>= 1.28.1, < 2.0)
175
177
  ruby-progressbar (~> 1.7)
176
178
  unicode-display_width (>= 2.4.0, < 3.0)
177
179
  rubocop-ast (1.29.0)
@@ -182,17 +184,18 @@ GEM
182
184
  tzinfo (2.0.6)
183
185
  concurrent-ruby (~> 1.0)
184
186
  unicode-display_width (2.4.2)
185
- view_component (2.82.0)
187
+ view_component (3.6.0)
186
188
  activesupport (>= 5.2.0, < 8.0)
187
189
  concurrent-ruby (~> 1.0)
188
190
  method_source (~> 1.0)
189
- websocket-driver (0.7.5)
191
+ websocket-driver (0.7.6)
190
192
  websocket-extensions (>= 0.1.0)
191
193
  websocket-extensions (0.1.5)
192
- zeitwerk (2.6.8)
194
+ zeitwerk (2.6.11)
193
195
 
194
196
  PLATFORMS
195
- ruby
197
+ x86_64-darwin-21
198
+ x86_64-linux
196
199
 
197
200
  DEPENDENCIES
198
201
  rails
@@ -1,9 +1,16 @@
1
- require 'rails/railtie'
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/railtie"
2
4
 
3
5
  module ViewComponentHelper
6
+ # Railtie for the ViewComponentHelper module.
7
+ #
8
+ # This Railtie ensures that the components in the Rails application
9
+ # are loaded and available for use during the app's initialization process.
10
+ #
4
11
  class Railtie < Rails::Railtie
5
12
  config.to_prepare do
6
13
  ViewComponentHelper.load_components
7
14
  end
8
15
  end
9
- end
16
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ViewComponentHelper
4
- VERSION = "0.4.4"
4
+ VERSION = "0.4.5"
5
5
  end
@@ -1,31 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ViewComponentHelper Module
1
4
  #
2
- #
5
+ # This module provides utility methods to assist with rendering ViewComponents
6
+ # within a Rails application. It aims to simplify the process of invoking
7
+ # and displaying components based on their file paths and additional arguments.
3
8
  #
4
9
  module ViewComponentHelper
5
- def render_view_component(path, *args, **kwargs, &block)
6
- render path.classify.constantize.new(*args, **kwargs, &block)
10
+ def render_view_component(path, *args, collection: nil, **kwargs, &block)
11
+ component_klass = path.classify.constantize
12
+
13
+ if collection
14
+ render component_klass.with_collection(collection, *args, **kwargs, &block)
15
+ else
16
+ render component_klass.new(*args, **kwargs, &block)
17
+ end
7
18
  end
8
19
 
9
20
  alias render_vc render_view_component
10
21
  alias vc render_view_component
11
22
 
12
- def self.load_components
13
- Dir[Rails.root.join('app/components/**/*.rb')].each do |file|
14
- require file
23
+ def self.default_component_loader
24
+ -> { Dir[Rails.root.join("app/components/**/*.rb")] }
25
+ end
26
+
27
+ def self.load_components(component_loader = default_component_loader)
28
+ component_loader.call.each do |file|
29
+ component_path = extract_component_path(file)
30
+ component_class_name = component_path.camelize
31
+ method_name = component_path.gsub("/", "_")
32
+
33
+ define_render_method_for(component_class_name, method_name) if valid_component_class?(component_class_name)
34
+ end
35
+ end
15
36
 
16
- component_path = file.gsub("#{Rails.root.join('app/components')}/", '').gsub('.rb', '')
17
- component_class_name = component_path.camelize # don't use classify
18
- method_name = component_path.gsub('/', '_')
37
+ def self.extract_component_path(file)
38
+ file.gsub("#{Rails.root.join("app/components")}/", "").gsub(".rb", "")
39
+ end
19
40
 
20
- next unless Object.const_defined?(component_class_name) && component_class_name.constantize < ViewComponent::Base
41
+ def self.valid_component_class?(component_class_name)
42
+ Object.const_defined?(component_class_name) && component_class_name.constantize < ViewComponent::Base
43
+ end
21
44
 
22
- define_method(method_name) do |*args, **kwargs, &block|
23
- render component_class_name.constantize.new(*args, **kwargs, &block)
45
+ def self.define_render_method_for(component_class_name, method_name)
46
+ define_method(method_name) do |*args, collection: nil, **kwargs, &block|
47
+ component_klass = component_class_name.constantize
48
+
49
+ if collection
50
+ render component_klass.with_collection(collection, *args, **kwargs, &block)
51
+ else
52
+ render component_klass.new(*args, **kwargs, &block)
24
53
  end
25
54
  end
26
55
  end
27
56
  end
28
57
 
29
- ActiveSupport.on_load :action_view do
30
- include ViewComponentHelper
31
- end if defined?(ActiveSupport)
58
+ if defined?(ActiveSupport)
59
+ ActiveSupport.on_load :action_view do
60
+ include ViewComponentHelper
61
+ end
62
+ end
@@ -2,4 +2,4 @@
2
2
 
3
3
  require "view_component_helper/view_helper"
4
4
  require "view_component_helper/railtie" if defined?(Rails)
5
- require "view_component_helper/version"
5
+ require "view_component_helper/version"
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["yamitake"]
9
9
  spec.email = ["take.yapr@gmail.com"]
10
10
 
11
- spec.summary = "This gem enables easy invocation of View helper methods for view_component, simplifying their integration."
12
- spec.description = "The 'view_component_helper' gem streamlines View helper method invocation for view_component. Simplify integration and boost productivity. "
11
+ spec.summary = "This gem enables easy invocation of View helper methods for view_component."
12
+ spec.description = "Simplify integration and boost productivity. "
13
13
  spec.homepage = "https://github.com/yapr/view_component_helper"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = ">= 2.6.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - yamitake
@@ -10,8 +10,7 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2023-09-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: 'The ''view_component_helper'' gem streamlines View helper method invocation
14
- for view_component. Simplify integration and boost productivity. '
13
+ description: 'Simplify integration and boost productivity. '
15
14
  email:
16
15
  - take.yapr@gmail.com
17
16
  executables: []
@@ -57,6 +56,5 @@ requirements: []
57
56
  rubygems_version: 3.3.7
58
57
  signing_key:
59
58
  specification_version: 4
60
- summary: This gem enables easy invocation of View helper methods for view_component,
61
- simplifying their integration.
59
+ summary: This gem enables easy invocation of View helper methods for view_component.
62
60
  test_files: []