Class: ContentBlockTools::Presenters::BlockPresenters::Contact::AddressPresenter

Inherits:
BasePresenter
  • Object
show all
Includes:
BlockLevelContactItem
Defined in:
lib/content_block_tools/presenters/block_presenters/contact/address_presenter.rb

Constant Summary

Constants included from BlockLevelContactItem

BlockLevelContactItem::BASE_TAG_TYPE

Constants inherited from BasePresenter

BasePresenter::BASE_TAG_TYPE

Instance Attribute Summary

Attributes inherited from BasePresenter

#item

Instance Method Summary collapse

Methods included from BlockLevelContactItem

#initialize, #title, #wrapper

Methods inherited from BasePresenter

#initialize

Methods included from Govspeak

#render_govspeak

Instance Method Details

#class_for_field_name(field_name) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/content_block_tools/presenters/block_presenters/contact/address_presenter.rb', line 28

def class_for_field_name(field_name)
  {
    recipient: "organization-name",
    street_address: "street-address",
    town_or_city: "locality",
    state_or_county: "region",
    postal_code: "postal-code",
    country: "country-name",
  }[field_name]
end

#renderObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/content_block_tools/presenters/block_presenters/contact/address_presenter.rb', line 10

def render
  wrapper do
    output = []

    output << (:p, class: "adr content-block__body") do
      %i[recipient street_address town_or_city state_or_county postal_code country].map { |field|
        next if item[field].blank?

        (:span, item[field], { class: class_for_field_name(field) })
      }.compact_blank.join(",<br/>").html_safe
    end

    output << render_govspeak(item[:description]) if item[:description].present?

    output.join.html_safe
  end
end