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
Delegated Instance Attributes collapse
-
#profile_image ⇒ Object
Alias for Employee#profile_image.
Methods inherited from BasePresenter
#can?, #capture, #concat, #content_tag, #fa_icon, #link_to, #number_to_currency, #simple_format
Instance Method Summary collapse
-
#combined_social_links ⇒ Hash{Symbol => String}
Combined social links with company fallbacks (for author show page).
-
#department ⇒ String?
Department from the employee record.
-
#employee_name ⇒ String
Employee's full name.
-
#formatted_post_date(post) ⇒ String?
Post date formatted for display.
-
#hire_year ⇒ Integer?
Year the employee was hired.
-
#job_title ⇒ String?
Job title from the employee record.
-
#latest_post ⇒ Post?
Latest published post for this author.
-
#personal_social_links ⇒ Hash{String => String}
Personal social links only.
-
#profile_image_url(width: 600, height: 600, thumbnail: true) ⇒ String?
Profile image URL.
-
#profile_url ⇒ String?
Public profile URL for the author page.
-
#published_posts_count ⇒ Integer
Number of published posts by this author.
-
#schema_dot_org_structure ⇒ SchemaDotOrg::Person
Build full Schema.org Person including profile URL, image and sameAs links.
Methods inherited from BasePresenter
Methods inherited from BasePresenter
#h, #initialize, #present, presents, #r, #safe_present, #u
Constructor Details
This class inherits a constructor from Www::BasePresenter
Instance Method Details
#combined_social_links ⇒ Hash{Symbol => String}
Combined social links with company fallbacks (for author show page)
128 129 130 131 132 133 134 135 136 137 138 |
# File 'app/presenters/www/author_presenter.rb', line 128 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 ⇒ String?
Department from the employee record.
99 100 101 |
# File 'app/presenters/www/author_presenter.rb', line 99 def department employee.employee_record&.department end |
#employee_name ⇒ String
Employee's full name.
87 88 89 |
# File 'app/presenters/www/author_presenter.rb', line 87 def employee_name employee.full_name end |
#formatted_post_date(post) ⇒ String?
Post date formatted for display.
163 164 165 |
# File 'app/presenters/www/author_presenter.rb', line 163 def formatted_post_date(post) post.effective_revised_date&.to_date&.to_fs(:long) end |
#hire_year ⇒ Integer?
Year the employee was hired.
105 106 107 |
# File 'app/presenters/www/author_presenter.rb', line 105 def hire_year employee.employee_record&.hire_date&.year end |
#job_title ⇒ String?
Job title from the employee record.
93 94 95 |
# File 'app/presenters/www/author_presenter.rb', line 93 def job_title employee.employee_record&.job_title end |
#latest_post ⇒ Post?
Latest published post for this author
142 143 144 145 146 147 148 149 150 |
# File 'app/presenters/www/author_presenter.rb', line 142 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 ⇒ Hash{String => String}
Personal social links only
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/presenters/www/author_presenter.rb', line 111 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
Alias for Employee#profile_image
71 |
# File 'app/presenters/www/author_presenter.rb', line 71 delegate :profile_image, to: :employee |
#profile_image_url(width: 600, height: 600, thumbnail: true) ⇒ String?
Profile image URL
78 79 80 81 82 83 |
# File 'app/presenters/www/author_presenter.rb', line 78 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 ⇒ String?
Public profile URL for the author page
65 66 67 68 69 |
# File 'app/presenters/www/author_presenter.rb', line 65 def profile_url return unless employee.employee_record&. "#{WEB_URL}/authors/#{employee.employee_record.slug}" end |
#published_posts_count ⇒ Integer
Number of published posts by this author.
154 155 156 157 158 |
# File 'app/presenters/www/author_presenter.rb', line 154 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 ⇒ SchemaDotOrg::Person
Build full Schema.org Person including profile URL, image and sameAs links
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 61 |
# File 'app/presenters/www/author_presenter.rb', line 10 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 |