Skip to content

Commit

Permalink
Show partner info page
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankocienski committed Aug 26, 2024
1 parent 76b559d commit 1e8b261
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
17 changes: 17 additions & 0 deletions app/helpers/partners_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
module PartnersHelper
def partner_contact_info(partner)
contact = partner.contact

parts = []
parts << link_to(contact.email, "mailto:#{contact.email}") if contact.email.present?
parts << link_to(contact.telephone, "tel:#{contact.telephone}") if contact.telephone.present?

parts.join(', ').html_safe
end

def partner_address_info(partner)
parts = []
parts << link_to(partner.url, partner.url, target: '_blank' ) if partner.url.present?
parts << partner.address.to_s if partner.address.present?

parts.join(' | ').html_safe
end
end
12 changes: 10 additions & 2 deletions app/models/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class Partner
attr_reader :description
attr_reader :url
attr_reader :logo_url
attr_reader :organiser_id

attr_reader :address
attr_reader :contact
Expand All @@ -20,6 +19,14 @@ def initialize(from)
@street_address = from['streetAddress']
@post_code = from['postalCode']
end

def present?
@street_address.present? || @post_code.present?
end

def to_s
[ @street_address, @post_code ].keep_if(&:present?).join(', ')
end
end

class PartnerContact
Expand All @@ -39,7 +46,8 @@ def initialize(data)
@name = data['name']
@summary = data['summary']
@description = data['description']
@logo_url = data['logo_url']
@logo_url = data['logo']
@url = data['url']

@address = PartnerAddress.new(data['address'])
@contact = PartnerContact.new(data['contact'])
Expand Down
20 changes: 16 additions & 4 deletions app/views/partners/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
%h1= @partner.name
- if @partner.url.present?
%p
%a{ href: @partner.url, target: '_blank' }= @partner.url

%p= @partner.description
- if @partner.logo_url.present?
%img{ src: @partner.logo_url, height: '100px' }

- if @partner.address.present? || @partner.url.present?
%p= partner_address_info(@partner)

- if @partner.contact.present?
%p Contact #{partner_contact_info(@partner)}

- if @partner.summary.present?
%p= @partner.summary

- if @partner.description.present?
%h2 Description
%p= @partner.description

2 changes: 1 addition & 1 deletion spec/requests/partners_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

describe "/partners/:id" do
it "returns http success" do
get "/partners/123"
get "/partners/192"
expect(response).to have_http_status(:success)
end
end
Expand Down

0 comments on commit 1e8b261

Please sign in to comment.