Class: Refinery::Pages::ContentPresenter

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
lib/refinery/pages/content_presenter.rb

Overview

Knows how to render a set of sections as html. This can be used in any Refinery view that is built from a group of sections. Pass the sections into the constructor or call add_section on the instance, then render by calling ‘to_html’.

Direct Known Subclasses

ContentPagePresenter

Instance Method Summary collapse

Constructor Details

#initialize(initial_sections = []) ⇒ ContentPresenter

Returns a new instance of ContentPresenter.



10
11
12
# File 'lib/refinery/pages/content_presenter.rb', line 10

def initialize(initial_sections = [])
  @sections = initial_sections
end

Instance Method Details

#add_section(new_section) ⇒ Object



33
34
35
# File 'lib/refinery/pages/content_presenter.rb', line 33

def add_section(new_section)
  @sections << new_section
end

#blank_section_css_classes(can_use_fallback = true) ⇒ Object



14
15
16
# File 'lib/refinery/pages/content_presenter.rb', line 14

def blank_section_css_classes(can_use_fallback = true)
  @sections.reject {|section| section.has_content?(can_use_fallback)}.map(&:not_present_css_class)
end

#fetch_template_overridesObject



27
28
29
30
31
# File 'lib/refinery/pages/content_presenter.rb', line 27

def fetch_template_overrides
  @sections.each do |section|
    section.override_html = yield section.id if section.id.present?
  end
end

#get_section(index) ⇒ Object



37
38
39
# File 'lib/refinery/pages/content_presenter.rb', line 37

def get_section(index)
  @sections[index]
end

#hidden_sectionsObject



23
24
25
# File 'lib/refinery/pages/content_presenter.rb', line 23

def hidden_sections
  @sections.select {|section| section.hidden? }
end

#hide_sections(*ids_to_hide) ⇒ Object



18
19
20
21
# File 'lib/refinery/pages/content_presenter.rb', line 18

def hide_sections(*ids_to_hide)
  ids_to_hide.flatten!
  @sections.select {|section| ids_to_hide.include?(section.id)}.each(&:hide) if ids_to_hide.any?
end

#to_html(can_use_fallback = true) ⇒ Object



41
42
43
44
45
# File 'lib/refinery/pages/content_presenter.rb', line 41

def to_html(can_use_fallback = true)
   :section, sections_html(can_use_fallback),
              :id => 'body_content',
              :class => blank_section_css_classes(can_use_fallback).join(' ')
end