Class: Refinery::Pages::SectionPresenter

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::SanitizeHelper, ActionView::Helpers::TagHelper
Defined in:
pages/app/presenters/refinery/pages/section_presenter.rb

Overview

Knows how to build the html for a section. A section is part of the visible html, that has content wrapped in some particular markup. Construct with the relevant options, and then call wrapped_html to get the resultant html.

The content rendered will usually be the value of fallback_html, unless an override_html is specified. However, on rendering, you can elect not display sections that have no override_html by passing in false for can_use_fallback.

Sections may be hidden, in which case they wont display at all.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_hash = {}) ⇒ SectionPresenter

Returns a new instance of SectionPresenter



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

def initialize(initial_hash = {})
  { logger: Rails.logger }.merge(initial_hash).map do |key, value|
    send("#{key}=", value)
  end
end

Instance Attribute Details

#fallback_htmlObject

Returns the value of attribute fallback_html



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

def fallback_html
  @fallback_html
end

#hiddenObject Also known as: hidden?

Returns the value of attribute hidden



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

def hidden
  @hidden
end

#idObject

Returns the value of attribute id



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

def id
  @id
end

#override_htmlObject

Returns the value of attribute override_html



26
27
28
# File 'pages/app/presenters/refinery/pages/section_presenter.rb', line 26

def override_html
  @override_html
end

Instance Method Details

#has_content?(can_use_fallback = true) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'pages/app/presenters/refinery/pages/section_presenter.rb', line 32

def has_content?(can_use_fallback = true)
  visible? && content_html(can_use_fallback).present?
end

#hideObject



45
46
47
# File 'pages/app/presenters/refinery/pages/section_presenter.rb', line 45

def hide
  self.hidden = true
end

#not_present_css_classObject



49
50
51
# File 'pages/app/presenters/refinery/pages/section_presenter.rb', line 49

def not_present_css_class
  "no_#{id}"
end

#visible?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'pages/app/presenters/refinery/pages/section_presenter.rb', line 28

def visible?
  !hidden?
end

#wrapped_html(can_use_fallback = true) ⇒ Object



36
37
38
39
40
41
42
43
# File 'pages/app/presenters/refinery/pages/section_presenter.rb', line 36

def wrapped_html(can_use_fallback = true)
  return if hidden?

  content = content_html(can_use_fallback)
  if content.present?
    wrap_content_in_tag(content)
  end
end