Skip to content

This gem enables easy invocation of View helper methods for view_component, simplifying their integration.

License

Notifications You must be signed in to change notification settings

yapr/view_component_helper

Repository files navigation

ViewComponentHelper

Gem Version

ViewComponentHelper is a simple gem designed to enhance the functionality provided by ViewComponent. It offers shortcuts to access generated ViewComponents, making your Rails development experience smoother and more efficient.

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add view_component_helper

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install view_component_helper

Usage

Please refer to ViewComponent website for more details.

To use ViewComponent, you'll need to follow the example below. By utilizing this gem, you can make calls like the following:

# Before
<%= render(MessageComponent.new(name: "World")) %>

# After
<%= render_vc("messageComponent", name: "World") %>
or
<%= vc("messageComponent", name: "World") %>

Usage

For more information on ViewComponents, please refer to the official documentation.

ViewComponentHelper allows for easier referencing of ViewComponent classes located under the app/components directory by providing you with intuitive shortcut methods.

How it works

For every ViewComponent you define within the app/components directory, ViewComponentHelper automatically provides a shortcut method to render it.

Examples

  1. For a component located at app/components/title_component.rb:

You can utilize the following shortcut:

title_component(title: "test title")
  1. For a component located at app/components/button.rb:
<%= button %>
  1. For a component located at app/components/dialog/component.rb
<%= dialog_component do |c| %>
  <% c.with_title { "dialog title" } %>
  <% c.with_body do %>
    <p>this is dialog body</p>
  <% end %>
  <div>content</div>
<% end %>

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/yapr/view_component_helper.

License

The gem is available as open source under the terms of the MIT License.

About

This gem enables easy invocation of View helper methods for view_component, simplifying their integration.

Resources

License

Stars

Watchers

Forks

Packages

No packages published