Class: Www::AuthorPresenter
- Inherits:
-
BasePresenter
- Object
- SimpleDelegator
- BasePresenter
- BasePresenter
- Www::AuthorPresenter
- Defined in:
- app/presenters/www/author_presenter.rb
Overview
Presenter responsible for emitting Schema.org Person for public author pages
Instance Attribute Summary
Attributes inherited from BasePresenter
#current_account, #options, #url_helper
Instance Method Summary collapse
-
#combined_social_links ⇒ Object
Combined social links with company fallbacks (for author show page).
- #department ⇒ Object
- #employee_name ⇒ Object
- #formatted_post_date(post) ⇒ Object
- #hire_year ⇒ Object
- #job_title ⇒ Object
-
#latest_post ⇒ Object
Latest published post for this author.
-
#personal_social_links ⇒ Object
Personal social links only.
- #profile_image ⇒ Object
-
#profile_image_url(width: 600, height: 600, thumbnail: true) ⇒ Object
Profile image URL.
-
#profile_url ⇒ Object
Public profile URL for the author page.
- #published_posts_count ⇒ Object
-
#schema_dot_org_structure ⇒ Object
Build full Schema.org Person including profile URL, image and sameAs links.
Methods inherited from BasePresenter
Methods inherited from BasePresenter
#can?, #capture, #concat, #content_tag, #fa_icon, #h, #initialize, #link_to, #number_to_currency, #present, presents, #r, #safe_present, #simple_format, #u
Constructor Details
This class inherits a constructor from Www::BasePresenter
Instance Method Details
#combined_social_links ⇒ Object
Combined social links with company fallbacks (for author show page)
114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/presenters/www/author_presenter.rb', line 114 def personal = company = h. { facebook: personal['facebook'] || company[:facebook], instagram: personal['instagram'] || company[:instagram], twitter: personal['twitter'] || company[:twitter], linkedin: personal['linkedin'] || company[:linkedin], website: personal['website'] }.compact end |
#department ⇒ Object
89 90 91 |
# File 'app/presenters/www/author_presenter.rb', line 89 def department employee.employee_record&.department end |
#employee_name ⇒ Object
81 82 83 |
# File 'app/presenters/www/author_presenter.rb', line 81 def employee_name employee.full_name end |
#formatted_post_date(post) ⇒ Object
143 144 145 |
# File 'app/presenters/www/author_presenter.rb', line 143 def formatted_post_date(post) post.effective_revised_date&.to_date&.to_fs(:long) end |
#hire_year ⇒ Object
93 94 95 |
# File 'app/presenters/www/author_presenter.rb', line 93 def hire_year employee.employee_record&.hire_date&.year end |
#job_title ⇒ Object
85 86 87 |
# File 'app/presenters/www/author_presenter.rb', line 85 def job_title employee.employee_record&.job_title end |
#latest_post ⇒ Object
Latest published post for this author
127 128 129 130 131 132 133 134 135 |
# File 'app/presenters/www/author_presenter.rb', line 127 def latest_post return employee.latest_post if employee.respond_to?(:latest_post) && employee.latest_post Post.published .where(original_author_id: employee.id) .order(published_at: :desc, created_at: :desc) .select(:id, :slug, :subject, :published_at, :revised_at, :created_at) .first end |
#personal_social_links ⇒ Object
Personal social links only
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/presenters/www/author_presenter.rb', line 98 def employee.contact_points .by_category([ ContactPoint::LINKEDIN, ContactPoint::TWITTER, ContactPoint::FACEBOOK, ContactPoint::INSTAGRAM, ContactPoint::WEBSITE ]) .pluck(:category, :detail) .to_h rescue StandardError {} end |
#profile_image ⇒ Object
69 70 71 |
# File 'app/presenters/www/author_presenter.rb', line 69 def profile_image employee.profile_image end |
#profile_image_url(width: 600, height: 600, thumbnail: true) ⇒ Object
Profile image URL
74 75 76 77 78 79 |
# File 'app/presenters/www/author_presenter.rb', line 74 def profile_image_url(width: 600, height: 600, thumbnail: true) pp = profile_image return unless pp pp.image_url(width: width, height: height, thumbnail: thumbnail) end |
#profile_url ⇒ Object
Public profile URL for the author page
63 64 65 66 67 |
# File 'app/presenters/www/author_presenter.rb', line 63 def profile_url return unless employee.employee_record&. "#{WEB_URL}/authors/#{employee.employee_record.slug}" end |
#published_posts_count ⇒ Object
137 138 139 140 141 |
# File 'app/presenters/www/author_presenter.rb', line 137 def published_posts_count return employee.published_posts_count if employee.respond_to?(:published_posts_count) Post.published.where(original_author_id: employee.id).count end |
#schema_dot_org_structure ⇒ Object
Build full Schema.org Person including profile URL, image and sameAs links
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/presenters/www/author_presenter.rb', line 9 def schema_dot_org_structure SchemaDotOrg::Person.new.tap do |p| p.givenName = employee.first_name p.familyName = employee.last_name p.name = employee.full_name begin p.url = h.(employee.employee_record) rescue StandardError # ignore URL errors in presenter end if (pp = employee.profile_image) p.image = SchemaDotOrg::ImageObject.new(url: pp.image_url(width: 800)) end links = begin employee.contact_points .by_category([ ContactPoint::LINKEDIN, ContactPoint::TWITTER, ContactPoint::FACEBOOK, ContactPoint::INSTAGRAM, ContactPoint::WEBSITE ]) .pluck(:detail) .compact .uniq rescue StandardError [] end p.sameAs = links if links.present? # Include work address from associated company if (addr = employee.company&.address) p.address = SchemaDotOrg::PostalAddress.new( streetAddress: [addr.street1, addr.street2, addr.street3].compact_blank.join(' '), addressLocality: addr.city, addressRegion: addr.state_code, postalCode: addr.zip_compact, addressCountry: addr.country&.iso ) end # Company association for active employees begin p.worksFor = h.online_store_schema unless employee.inactive rescue StandardError # ignore if helper not available in this context end end end |