Files
old-holivud2/app/helpers/contact_info_helper.rb
2020-05-31 22:38:19 +02:00

51 lines
1.1 KiB
Ruby

module ContactInfoHelper
def contact_info_for(contactable)
contact_info(
name: contactable.name,
address: contactable.address,
phone: contactable.phone,
email: contactable.email,
)
end
def contact_info(name: nil, address: nil, phone: nil, email: nil)
content_tag :address do
if name.present?
concat content_tag(:strong, name)
concat tag(:br)
end
if address.present?
concat format_address(address)
concat tag(:br)
end
if phone.present?
concat phone_abbr(phone)
concat tag(:br)
end
if email.present?
concat email_abbr(email)
concat tag(:br)
end
end
end
private
def format_address(address)
case address
when Address
simple_format address.to_s(format: :condensed), {}, wrapper_tag: "span"
else
address.to_s
end
end
def email_abbr(email)
content_tag(:abbr, "E: ", title: "Email") + mail_to(email)
end
def phone_abbr(phone)
content_tag(:abbr, "P: ", title: "Phone") + phone
end
end