diff --git a/app/services/contact_details/base.rb b/app/services/contact_details/base.rb new file mode 100644 index 0000000000000000000000000000000000000000..62d6fb67907fc837ee63e91b9a107350a584a4c1 --- /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 0000000000000000000000000000000000000000..bcedeed093aad63ed4856ac095516ba00181f22a --- /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 0000000000000000000000000000000000000000..ccc59c045ccddb7ee2b31b1f6c9e1504ec4e94cf --- /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 0000000000000000000000000000000000000000..d1f4fd8f11978f4a9cff7608e766936f7ac15cf7 --- /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 8e58f1a9edf61c3f56e0f18287ce10aa73d4278c..07d8a5122e41d35cc21c9a8245a21aacaecdd9ac 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 %>