Class: Refinery::Pages::ContentPresenter

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
pages/app/presenters/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



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

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

Instance Method Details

#add_section(new_section) ⇒ Object



34
35
36
# File 'pages/app/presenters/refinery/pages/content_presenter.rb', line 34

def add_section(new_section)
  @sections << new_section
end

#blank_section_css_classes(can_use_fallback = true) ⇒ Object



14
15
16
17
# File 'pages/app/presenters/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



28
29
30
31
32
# File 'pages/app/presenters/refinery/pages/content_presenter.rb', line 28

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

#get_section(index) ⇒ Object



38
39
40
# File 'pages/app/presenters/refinery/pages/content_presenter.rb', line 38

def get_section(index)
  @sections[index]
end

#hidden_sectionsObject



24
25
26
# File 'pages/app/presenters/refinery/pages/content_presenter.rb', line 24

def hidden_sections
  @sections.select(&:hidden?)
end

#hide_sections(*ids_to_hide) ⇒ Object



19
20
21
22
# File 'pages/app/presenters/refinery/pages/content_presenter.rb', line 19

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



42
43
44
45
46
# File 'pages/app/presenters/refinery/pages/content_presenter.rb', line 42

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