From 9ff89068ae2d2b1a58031048e870b7a361dfbc4b Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Tue, 17 Jan 2023 18:21:48 +0100 Subject: [PATCH] Better contact details --- app/services/contact_details/base.rb | 19 +++++++++++++++++++ app/services/contact_details/linkedin.rb | 11 +++++++++++ app/services/contact_details/twitter.rb | 10 ++++++++++ app/services/contact_details/website.rb | 14 ++++++++++++++ .../admin/university/people/static.html.erb | 11 +++++++++++ 5 files changed, 65 insertions(+) create mode 100644 app/services/contact_details/base.rb create mode 100644 app/services/contact_details/linkedin.rb create mode 100644 app/services/contact_details/twitter.rb create mode 100644 app/services/contact_details/website.rb diff --git a/app/services/contact_details/base.rb b/app/services/contact_details/base.rb new file mode 100644 index 000000000..62d6fb679 --- /dev/null +++ b/app/services/contact_details/base.rb @@ -0,0 +1,19 @@ +class ContactDetails::Base + attr_accessor :url, :label + + def initialize(string) + @string = string + prepare_url + prepare_label + end + + protected + + def prepare_label + @label = @string + end + + def prepare_url + @url = @string + end +end \ No newline at end of file diff --git a/app/services/contact_details/linkedin.rb b/app/services/contact_details/linkedin.rb new file mode 100644 index 000000000..bcedeed09 --- /dev/null +++ b/app/services/contact_details/linkedin.rb @@ -0,0 +1,11 @@ +class ContactDetails::Linkedin < ContactDetails::Website + ROOT = 'www.linkedin.com/in/' + + protected + + def prepare_label + super + @label.remove! ROOT + @label.chomp! '/' + end +end \ No newline at end of file diff --git a/app/services/contact_details/twitter.rb b/app/services/contact_details/twitter.rb new file mode 100644 index 000000000..ccc59c045 --- /dev/null +++ b/app/services/contact_details/twitter.rb @@ -0,0 +1,10 @@ +class ContactDetails::Twitter < ContactDetails::Website + ROOT = 'twitter.com/' + + protected + + def prepare_label + super + @label.remove! ROOT + end +end \ No newline at end of file diff --git a/app/services/contact_details/website.rb b/app/services/contact_details/website.rb new file mode 100644 index 000000000..d1f4fd8f1 --- /dev/null +++ b/app/services/contact_details/website.rb @@ -0,0 +1,14 @@ +class ContactDetails::Website < ContactDetails::Base + PROTOCOL = 'https://' + + protected + + def prepare_url + @url = @string + @url = "#{PROTOCOL}#{@url}" unless @url.start_with? PROTOCOL + end + + def prepare_label + @label = @url.remove PROTOCOL + end +end \ No newline at end of file diff --git a/app/views/admin/university/people/static.html.erb b/app/views/admin/university/people/static.html.erb index 8e58f1a9e..07d8a5122 100644 --- a/app/views/admin/university/people/static.html.erb +++ b/app/views/admin/university/people/static.html.erb @@ -19,6 +19,17 @@ linkedin: >- <%= @about.linkedin %> website: >- <%= @about.url %> +contact_details: + website: <% detail = ContactDetails::Website.new @about.url %> + label: <%= detail.label %> + url: <%= detail.url %> + linkedin: <% detail = ContactDetails::Linkedin.new @about.linkedin %> + label: <%= detail.label %> + url: <%= detail.url %> + twitter: <% detail = ContactDetails::Twitter.new @about.twitter %> + label: <%= detail.label %> + url: <%= detail.url %> + <% if @about.best_picture.attached? %> image: "<%= @about.best_picture.blob.id %>" <% end %> -- GitLab