module SpudBannersHelper def spud_banners_for_set(set_or_identifier, options = {}) if set_or_identifier.is_a?(SpudBannerSet) banner_set = set_or_identifier else banner_set = SpudBannerSet.find_by_identifier(set_or_identifier) end return '' if banner_set.blank? cache(banner_set) do concat spud_banners_set_tag(banner_set, options) end end def spud_banners_set_tag(banner_set, options = {}) limit = options[:limit] || false if block_given? banner_set.banners.limit(limit).each do |banner| yield(banner) end else content_tag(:div, :class => 'spud_banner_set', 'data-id' => banner_set.id) do banner_set.banners.limit(limit).map do |banner| concat(content_tag(:div, :class => 'spud_banner_set_banner', 'data-id' => banner.id){ spud_banner_tag(banner) }) end end end end def spud_banner_tag(banner) if banner.link_to.blank? spud_banner_image_tag(banner) else link_to(banner.link_to, :target => banner.link_target) do spud_banner_image_tag(banner) end end end def spud_banner_image_tag(banner) image_tag(banner.banner.url(:banner), :alt => banner.alt, :title => banner.title) end end