view_component_helper 0.4.2 → 0.4.4

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: 39113fcb2c060a723b94fc5239da2333fdf0b79e510a536c41c9b0dd860c367a
4
- data.tar.gz: 690401de39489f12fdf78df6016205531bbba52643640755bebf9f77c3155847
3
+ metadata.gz: 9b14cab38b32ee81aa0cc440c6ace3233c681bf567d3af063b260cc10d7ffd68
4
+ data.tar.gz: 33eec3e87d67cdf41fe9c7741ebedd3583f0dd0b6cd4fe22c8f4d17c7d31da0c
5
5
  SHA512:
6
- metadata.gz: 70f3de26a9aa00724f6435d136646d359eda56fcfea75dbc7451eb71cb360f18290638b55c0424afc6834a28412513820be705a28d6aedbe41d395e130cbe4d5
7
- data.tar.gz: be103eefa27c4fea916e40e462f72d246819b6da2f4e7ada8d72f931d07aa74b513f9b45a79330c672e29f483ccbea4c8767744d9ffec20a00e0060b987bdb32
6
+ metadata.gz: 6110fdd56c17863aa506f5268037482f6727c600acc901e4deb6e20a219c98bafda4eb6a0ce9a5d3b4ad69622896397cc088614204c7ae339e8ee00039f44433
7
+ data.tar.gz: 5d86f6a095be702ede49c7c39606748103527f3881a0e16ea984a494103dbbcd594e4b8f11170b6a085223cbd97cf6c430bb342453bd75ad4e3e56309a96c57c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- view_component_helper (0.4.2)
4
+ view_component_helper (0.4.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -94,6 +94,7 @@ GEM
94
94
  marcel (1.0.2)
95
95
  method_source (1.0.0)
96
96
  mini_mime (1.1.2)
97
+ mini_portile2 (2.8.4)
97
98
  minitest (5.18.1)
98
99
  net-imap (0.3.6)
99
100
  date
@@ -105,6 +106,9 @@ GEM
105
106
  net-smtp (0.3.3)
106
107
  net-protocol
107
108
  nio4r (2.5.9)
109
+ nokogiri (1.15.3)
110
+ mini_portile2 (~> 2.8.2)
111
+ racc (~> 1.4)
108
112
  nokogiri (1.15.3-x86_64-darwin)
109
113
  racc (~> 1.4)
110
114
  parallel (1.23.0)
@@ -188,7 +192,7 @@ GEM
188
192
  zeitwerk (2.6.8)
189
193
 
190
194
  PLATFORMS
191
- x86_64-darwin-21
195
+ ruby
192
196
 
193
197
  DEPENDENCIES
194
198
  rails
data/README.md CHANGED
@@ -25,7 +25,9 @@ To use ViewComponent, you'll need to follow the example below. By utilizing this
25
25
  <%= render(MessageComponent.new(name: "World")) %>
26
26
 
27
27
  # After
28
- <%= render_rc("messageComponent", name: "World") %>
28
+ <%= render_vc("messageComponent", name: "World") %>
29
+ or
30
+ <%= vc("messageComponent", name: "World") %>
29
31
  ```
30
32
 
31
33
  Make sure to incorporate ViewComponent as described in the reference link to enhance your application's functionality.
@@ -0,0 +1,9 @@
1
+ require 'rails/railtie'
2
+
3
+ module ViewComponentHelper
4
+ class Railtie < Rails::Railtie
5
+ config.to_prepare do
6
+ ViewComponentHelper.load_components
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ViewComponentHelper
4
- VERSION = "0.4.2"
4
+ VERSION = "0.4.4"
5
5
  end
@@ -1,17 +1,31 @@
1
+ #
2
+ #
3
+ #
1
4
  module ViewComponentHelper
2
- def render_view_component(path, *args, **kwargs, &)
3
- render component_class_for(path).new(*args, **kwargs, &)
5
+ def render_view_component(path, *args, **kwargs, &block)
6
+ render path.classify.constantize.new(*args, **kwargs, &block)
4
7
  end
5
8
 
6
9
  alias render_vc render_view_component
10
+ alias vc render_view_component
7
11
 
8
- private
12
+ def self.load_components
13
+ Dir[Rails.root.join('app/components/**/*.rb')].each do |file|
14
+ require file
9
15
 
10
- def component_class_for(name)
11
- name.classify.constantize
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('/', '_')
19
+
20
+ next unless Object.const_defined?(component_class_name) && component_class_name.constantize < ViewComponent::Base
21
+
22
+ define_method(method_name) do |*args, **kwargs, &block|
23
+ render component_class_name.constantize.new(*args, **kwargs, &block)
24
+ end
25
+ end
12
26
  end
13
27
  end
14
28
 
15
29
  ActiveSupport.on_load :action_view do
16
30
  include ViewComponentHelper
17
- end
31
+ end if defined?(ActiveSupport)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "addressable/uri"
4
3
  require "view_component_helper/view_helper"
4
+ require "view_component_helper/railtie" if defined?(Rails)
5
5
  require "view_component_helper/version"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - yamitake
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-07 00:00:00.000000000 Z
11
+ date: 2023-09-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'The ''view_component_helper'' gem streamlines View helper method invocation
14
14
  for view_component. Simplify integration and boost productivity. '
@@ -27,6 +27,7 @@ files:
27
27
  - README.md
28
28
  - Rakefile
29
29
  - lib/view_component_helper.rb
30
+ - lib/view_component_helper/railtie.rb
30
31
  - lib/view_component_helper/version.rb
31
32
  - lib/view_component_helper/view_helper.rb
32
33
  - sig/view_component_helper.rbs