Class: ViewComponent::Collection

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::OutputSafetyHelper, 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.



11
12
13
# File 'lib/view_component/collection.rb', line 11

def component
  @component
end

Instance Method Details

#each(&block) ⇒ Object



22
23
24
# File 'lib/view_component/collection.rb', line 22

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.



29
30
31
# File 'lib/view_component/collection.rb', line 29

def format
  nil
end

#render_in(view_context, **_, &block) ⇒ Object



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

def render_in(view_context, **_, &block)
  rendered = components.map do |component|
    component.render_in(view_context, &block)
  end
  safe_join(rendered, rendered_spacer(view_context))
end