Class: ViewComponent::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/view_component/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



8
9
10
# File 'lib/view_component/collection.rb', line 8

def component
  @component
end

Instance Method Details

#each(&block) ⇒ Object



18
19
20
# File 'lib/view_component/collection.rb', line 18

def each(&block)
  components.each(&block)
end

#formatObject

Rails expects us to define ‘format` on all renderables, but we do not know the `format` of a ViewComponent until runtime.



25
26
27
# File 'lib/view_component/collection.rb', line 25

def format
  nil
end

#render_in(view_context, &block) ⇒ Object



12
13
14
15
16
# File 'lib/view_component/collection.rb', line 12

def render_in(view_context, &block)
  components.map do |component|
    component.render_in(view_context, &block)
  end.join(rendered_spacer(view_context)).html_safe
end