Class: ViewComponent::Collection
- Inherits:
-
Object
- Object
- ViewComponent::Collection
- Includes:
- Enumerable
- Defined in:
- lib/view_component/collection.rb
Instance Attribute Summary collapse
-
#__vc_original_view_context ⇒ Object
Returns the value of attribute __vc_original_view_context.
-
#component ⇒ Object
readonly
Returns the value of attribute component.
Instance Method Summary collapse
- #components ⇒ Object
- #each(&block) ⇒ Object
- #render_in(view_context, &block) ⇒ Object
- #set_original_view_context(view_context) ⇒ Object
Instance Attribute Details
#__vc_original_view_context ⇒ Object
Returns the value of attribute __vc_original_view_context.
13 14 15 |
# File 'lib/view_component/collection.rb', line 13 def __vc_original_view_context @__vc_original_view_context end |
#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
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/view_component/collection.rb', line 26 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
40 41 42 |
# File 'lib/view_component/collection.rb', line 40 def each(&block) components.each(&block) end |
#render_in(view_context, &block) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/view_component/collection.rb', line 19 def render_in(view_context, &block) components.map do |component| component.set_original_view_context(__vc_original_view_context) component.render_in(view_context, &block) end.join.html_safe end |
#set_original_view_context(view_context) ⇒ Object
15 16 17 |
# File 'lib/view_component/collection.rb', line 15 def set_original_view_context(view_context) self.__vc_original_view_context = view_context end |