Class: ViewComponent::Collection
- Inherits:
-
Object
- Object
- ViewComponent::Collection
- Includes:
- Enumerable
- Defined in:
- lib/view_component/collection.rb
Instance Attribute Summary collapse
-
#component ⇒ Object
readonly
Returns the value of attribute component.
Instance Method Summary collapse
Instance Attribute Details
#component ⇒ Object (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
#components ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/view_component/collection.rb', line 19 def components return @components if defined? @components iterator = ActionView::PartialIteration.new(@collection.size) component.validate_collection_parameter!(validate_default: true) @components = @collection.map do |item| component.new(**(item, iterator)).tap do |component| iterator.iterate! end end end |
#each(&block) ⇒ Object
33 34 35 |
# File 'lib/view_component/collection.rb', line 33 def each(&block) components.each(&block) end |
#render_in(view_context, &block) ⇒ Object
13 14 15 16 17 |
# File 'lib/view_component/collection.rb', line 13 def render_in(view_context, &block) components.map do |component| component.render_in(view_context, &block) end.join.html_safe # rubocop:disable Rails/OutputSafety end |