inline_view_component

Installs the inline_view_component gem
Icons/chart bar
Used 12 times
Created by
R Rafe Rosen

Usage
after installing this railsbyte, you can define templates in your view_component class definitions like this:

class HelloComponent < ApplicationComponent
  template <<~ERB, :erb
    <h1>Hello World!</h1>
  ERB
end

If you have other templating engines installed, you can replace :erb with :haml, :slim, or any other template format your rails app supports.

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/Vp7slZ"
Template Source

Review the code before running this template on your machine.

gem "inline_view_component"

file = "app/components/application_component.rb"

if File.exist?(file)
  inject_into_class(file, "ApplicationComponent") { "  include InlineViewComponent\n" } 
else
  create_file file, <<~RUBY
    class ApplicationComponent < ViewComponent::Base
      include InlineViewComponent
    end
  RUBY
end
Comments

Sign up or Login to leave a comment.