Module: EffectivePageBannersHelper

Defined in:
app/helpers/effective_page_banners_helper.rb

Instance Method Summary collapse

Instance Method Details

#render_page_banner(page, opts = {}, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/helpers/effective_page_banners_helper.rb', line 5

def render_page_banner(page, opts = {}, &block)
  raise('expected a page') unless page.kind_of?(Effective::Page)

  return unless page.banner? || EffectivePages.banners_force_randomize

  # Always return a random banner if config.banners_force_randomize
  page_banner = Effective::PageBanner.deep.random.first if EffectivePages.banners_force_randomize
  page_banner ||= page.page_banner if page.banner? && page.page_banner.present?
  page_banner ||= Effective::PageBanner.deep.random.first if page.banner? && page.banner_random?

  return if page_banner.blank?

  if block_given?
    yield(page_banner); nil
  else
    image_tag(page_banner.file, alt: page_banner.caption, **opts)
  end
end