module Phlex::Collection
def initialize(collection: nil, item: nil)
def initialize(collection: nil, item: nil) unless collection || item raise ArgumentError, "You must pass a collection or an item as a keyword argument." end @collection = collection @item = item end
def template
def template @item ? item_template : collection_template { yield_items } end
def yield_items
def yield_items if @item raise ArgumentError, "You can only yield_items when rendering a collection. You are currently rendering an item." end @collection.each do |item| @item = item item_template end @item = nil end