view_component_helper 0.4.5 → 0.9.1

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: 57701718d039ac056f76dc09a6ad26114b495067fcbf6af07b9b0ffd30f3fbaf
4
- data.tar.gz: 9686baee018175896e73771ba436427183d8bba00e976441608e912e88515b4d
3
+ metadata.gz: 5966bd782f29a9d3e10a9bd583c6d79d7239f2f767de4cd3e4e5a13b302e0e81
4
+ data.tar.gz: 7c6fc694458ae9dd2d583b6d7df13c482399b81f3c4c618c979bc6d7288baf84
5
5
  SHA512:
6
- metadata.gz: 9d765d480b9be81327db65955ffc028f2bd021bf66484344626e1d823690b92023dcbfcbb2834f463bf743ab9077dcf25d02700706872f0b62ecdd58cdb31a42
7
- data.tar.gz: 50a5cf227fbff3fb388e83e8c960df0ec52b7d616d7855a1433d6eb4fbd4246de5fbf6f65cbe19b194a32cb42dfb7dbe73ccea68d9d2072b55c1f69684a9b32a
6
+ metadata.gz: 70c4004614931d4caa0f88de8f07fd9dd312c9e456450b4c8094225aeb760c3d876be8339cc6daa22c92e8dde428f038e37876a24ccab61fc0be2f2c51033eff
7
+ data.tar.gz: d75ee370dfc30a75114c4012f55c6ff0b6d89f370678957ca04b0d1a07e570db6d6a88e223d21a482df022f525883c876b8a8f3f3e9709f36c8f0f02f87cedf3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- view_component_helper (0.4.5)
4
+ view_component_helper (0.9.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # ViewComponentHelper
2
+ [![Gem Version](https://badge.fury.io/rb/view_component_helper.svg)](https://badge.fury.io/rb/view_component_helper)
2
3
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/view_component_helper`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+ `ViewComponentHelper` is a simple gem designed to enhance the functionality provided by [ViewComponent](https://github.com/ViewComponent/view_component). It offers shortcuts to access generated ViewComponents, making your Rails development experience smoother and more efficient.
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
6
 
7
7
  ## Installation
8
8
 
@@ -30,15 +30,40 @@ or
30
30
  <%= vc("messageComponent", name: "World") %>
31
31
  ```
32
32
 
33
- Make sure to incorporate ViewComponent as described in the reference link to enhance your application's functionality.
33
+ ## Usage
34
+ For more information on ViewComponents, please refer to the [official documentation](https://viewcomponent.org/).
35
+
36
+ `ViewComponentHelper` allows for easier referencing of `ViewComponent` classes located under the `app/components` directory by providing you with intuitive shortcut methods.
37
+
38
+ ### How it works
39
+ For every `ViewComponent` you define within the `app/components` directory, `ViewComponentHelper` automatically provides a shortcut method to render it.
40
+
41
+ ### Examples
34
42
 
43
+ 1. For a component located at `app/components/title_component.rb`:
35
44
 
45
+ You can utilize the following shortcut:
46
+ ```ruby
47
+ title_component(title: "test title")
48
+ ```
49
+
50
+ 2. For a component located at `app/components/button.rb`:
36
51
 
37
- ## Development
52
+ ```erb
53
+ <%= button %>
54
+ ```
38
55
 
39
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+ 3. For a component located at `app/components/dialog/component.rb`
40
57
 
41
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+ ```erb
59
+ <%= dialog_component do |c| %>
60
+ <% c.with_title { "dialog title" } %>
61
+ <% c.with_body do %>
62
+ <p>this is dialog body</p>
63
+ <% end %>
64
+ <div>content</div>
65
+ <% end %>
66
+ ```
42
67
 
43
68
  ## Contributing
44
69
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ViewComponentHelper
4
- VERSION = "0.4.5"
4
+ VERSION = "0.9.1"
5
5
  end
@@ -7,26 +7,26 @@
7
7
  # and displaying components based on their file paths and additional arguments.
8
8
  #
9
9
  module ViewComponentHelper
10
+ require "active_support/core_ext/string/inflections"
11
+
10
12
  def render_view_component(path, *args, collection: nil, **kwargs, &block)
11
13
  component_klass = path.classify.constantize
12
14
 
13
15
  if collection
14
16
  render component_klass.with_collection(collection, *args, **kwargs, &block)
15
17
  else
16
- render component_klass.new(*args, **kwargs, &block)
18
+ component_instance = component_klass.new(*args, **kwargs)
19
+ component_instance.instance_exec(&block) if block_given?
20
+ render(component_instance)
17
21
  end
18
22
  end
19
23
 
20
24
  alias render_vc render_view_component
21
25
  alias vc render_view_component
22
26
 
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)
27
+ def self.load_components(component_loader = -> { Dir[Rails.root.join("app/components/**/*.rb")] })
28
28
  component_loader.call.each do |file|
29
- component_path = extract_component_path(file)
29
+ component_path = file[%r{components/(.*)\.rb$}, 1]
30
30
  component_class_name = component_path.camelize
31
31
  method_name = component_path.gsub("/", "_")
32
32
 
@@ -34,10 +34,6 @@ module ViewComponentHelper
34
34
  end
35
35
  end
36
36
 
37
- def self.extract_component_path(file)
38
- file.gsub("#{Rails.root.join("app/components")}/", "").gsub(".rb", "")
39
- end
40
-
41
37
  def self.valid_component_class?(component_class_name)
42
38
  Object.const_defined?(component_class_name) && component_class_name.constantize < ViewComponent::Base
43
39
  end
@@ -49,7 +45,8 @@ module ViewComponentHelper
49
45
  if collection
50
46
  render component_klass.with_collection(collection, *args, **kwargs, &block)
51
47
  else
52
- render component_klass.new(*args, **kwargs, &block)
48
+ component_instance = component_klass.new(*args, **kwargs, &block)
49
+ render component_instance
53
50
  end
54
51
  end
55
52
  end
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.5
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yamitake
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-21 00:00:00.000000000 Z
11
+ date: 2023-11-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'Simplify integration and boost productivity. '
14
14
  email: