Module: ViewComponents::ComponentsBuilder

Included in:
ApplicationHelper
Defined in:
lib/view_components/components_builder.rb

Defined Under Namespace

Classes: Component

Instance Method Summary collapse

Instance Method Details

#define_component(name, options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/view_components/components_builder.rb', line 30

def define_component(name, options)
  Component.create!(name, options[:sections], options[:attributes])

  class_eval %(
    def #{name}(attributes, &block)
      component = Component.classes[:#{name}].new(self, attributes)
      block.call(component)
      render partial: "components/#{name}", locals: { :#{name} => component.to_h }
    end
  )
end