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

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

Constant Summary

Constants inherited from BasePresenter

BasePresenter::BASE_TAG_TYPE

Instance Attribute Summary

Attributes inherited from BasePresenter

#item

Instance Method Summary collapse

Methods inherited from BasePresenter

#initialize

Constructor Details

This class inherits a constructor from ContentBlockTools::Presenters::BlockPresenters::BasePresenter

Instance Method Details

#class_for_field_name(field_name) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/content_block_tools/presenters/block_presenters/contact/address_presenter.rb', line 16

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

#renderObject



6
7
8
9
10
11
12
13
14
# File 'lib/content_block_tools/presenters/block_presenters/contact/address_presenter.rb', line 6

def render
  (:p, class: "adr") do
    %i[street_address locality region 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
end