Module: ActionComponent::ImporterHelper

Included in:
Component::ViewModel
Defined in:
lib/actioncomponent/importer_helper.rb

Overview

Exposes component rendering methods to Rails views

Instance Method Summary collapse

Instance Method Details

#create_component(component_path, view_model_data) ⇒ void



18
19
20
21
22
23
# File 'lib/actioncomponent/importer_helper.rb', line 18

def create_component(component_path, view_model_data)
  ActionComponent::Component.new(
    component_path: component_path,
    view_model_data: view_model_data.merge(c: controller, controller: controller)
  )
end

#import_action_component(local_component_name, opts = {}) ⇒ void

Description of #import_action_component

Parameters:

  • local_component_name (String)

    Local's component name (in the view scope)

  • opts (Hash) (defaults to: {})

    default: {} Options.



10
11
12
13
14
15
16
# File 'lib/actioncomponent/importer_helper.rb', line 10

def import_action_component(local_component_name, opts = {})
  raise "No path informed when importing component #{local_component_name}" if opts[:path].blank?

  define_singleton_method(local_component_name) do |**args|
    create_component(opts[:path], args).render
  end
end