Sha256: 57d5920a60c34aec0d21246930582d7d15b79c7c9e32648bc30b435daacc4255

Contents?: true

Size: 933 Bytes

Versions: 4

Compression:

Stored size: 933 Bytes

Contents

# frozen_string_literal: true

module FComponents
  module ComponentsHelper
    # Shorthand for rendering view_components from FComponents
    #
    # Usage:
    #
    #   <%= fcomponent :section, title: 'Greeting', classes: 'my--1' do %>
    #     <p class="Txt--center">Hello world</p>
    #   <% end %>
    def fcomponent(name, *args, &block)
      component_class = "FC::#{name.to_s.camelcase}::Component".constantize

      render(component_class.new(*args), &block)
    end
    ruby2_keywords :fcomponent

    # Shorthand for rendering view_components from your application
    #
    # Usage:
    #
    #   <%= component :card, classes: 'my--1' do %>
    #     <p class="Txt--center">Hello world</p>
    #   <% end %>
    def component(name, *args, &block)
      component_class = "#{name.to_s.camelcase}::Component".constantize

      render(component_class.new(*args), &block)
    end
    ruby2_keywords :component
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
f_components-0.5.0 app/helpers/f_components/components_helper.rb
f_components-1.0.0 app/helpers/f_components/components_helper.rb
f_components-0.3.0 app/helpers/f_components/components_helper.rb
f_components-0.2.1 app/helpers/f_components/components_helper.rb