Method: ComponentHelper#component

Defined in:
app/helpers/component_helper.rb

#component(name, **kwargs, &block) ⇒ Object Also known as: comp

Create a component in a view.

other components inside this block. You can set locals inside this block.

Examples:


= component :header do |c|
  - c.title = "Hello"
  p My Extra Content

Parameters:

  • name (Symbol)

    The name of the component.

  • kwargs (Hash)

    The locals to pass to the component.

  • block (Proc)

    The block to pass to the component. You can use



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/component_helper.rb', line 16

def component name, **kwargs, &block
  component = Component.new(name, kwargs, lookup_context, nil, block)

  component._renderer = proc do |partial, locals, captured|
    render partial, locals do
      captured
    end
  end

  component._capture = proc do |component, block|
    if block
      capture do
        block.call(component)
      end
    end
  end

  component._capture_self
  component._yield_renderer
end