view_component_helper 0.4.3 → 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: a915d8e179ad5dc827c3d16b10321d6aa1786cc5962fc3f996e2a3486c95a8a2
4
- data.tar.gz: f8aeacbbde5ab6eb1f97bf66aaa256b08d989d67c2b0e786744f301d9364def5
3
+ metadata.gz: 9b14cab38b32ee81aa0cc440c6ace3233c681bf567d3af063b260cc10d7ffd68
4
+ data.tar.gz: 33eec3e87d67cdf41fe9c7741ebedd3583f0dd0b6cd4fe22c8f4d17c7d31da0c
5
5
  SHA512:
6
- metadata.gz: e230c9bc9621db75c80bbd5b44722bbdbde335de06f10ea065a952e8887e671b3703929ae25df8d539933188867a3dadf408fc332db87c2f56b0f9a278b243cc
7
- data.tar.gz: c858e698106588bad51d7ed29ff88a074b593df7ffa0093c3ff420259373e6e700b943e21265e00449644639d287fb592da0081dcadcb3cb92e9bb65fdba653a
6
+ metadata.gz: 6110fdd56c17863aa506f5268037482f6727c600acc901e4deb6e20a219c98bafda4eb6a0ce9a5d3b4ad69622896397cc088614204c7ae339e8ee00039f44433
7
+ data.tar.gz: 5d86f6a095be702ede49c7c39606748103527f3881a0e16ea984a494103dbbcd594e4b8f11170b6a085223cbd97cf6c430bb342453bd75ad4e3e56309a96c57c
@@ -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.3"
4
+ VERSION = "0.4.4"
5
5
  end
@@ -1,18 +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
7
10
  alias vc render_view_component
8
11
 
9
- private
12
+ def self.load_components
13
+ Dir[Rails.root.join('app/components/**/*.rb')].each do |file|
14
+ require file
10
15
 
11
- def component_class_for(name)
12
- 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
13
26
  end
14
27
  end
15
28
 
16
29
  ActiveSupport.on_load :action_view do
17
30
  include ViewComponentHelper
18
- 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.3
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-19 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