Sha256: feb3bb57d9f757fcf66a555b038cf588f03131f4a443bc7a9671aa93f0f3a1fe
Contents?: true
Size: 639 Bytes
Versions: 4
Compression:
Stored size: 639 Bytes
Contents
# frozen_string_literal: true module Phlex module Collection 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 @item ? item_template : collection_template { yield_items } end private 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 end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
phlex-0.5.3 | lib/phlex/collection.rb |
phlex-0.5.2 | lib/phlex/collection.rb |
phlex-0.5.1 | lib/phlex/collection.rb |
phlex-0.5.0 | lib/phlex/collection.rb |