Class: Helios::Seo::ResourcePresenter
- Inherits:
-
Object
- Object
- Helios::Seo::ResourcePresenter
- Defined in:
- app/services/helios/seo/resource_presenter.rb
Overview
Wraps a content resource + configuration and exposes the resolved, render-ready SEO values. Shared by TagsHelper and SchemaBuilder so the two never disagree. Targets the resource contract:
name, slug, description, keywords, created_at, updated_at, published?
and degrades gracefully when optional methods are absent.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #canonical_url ⇒ Object
-
#description ⇒ Object
SERP-friendly plain-text description, falling back to the default.
-
#document_title ⇒ Object
The
tag: a resolver override, else the configured template. -
#faqs ⇒ Object
Normalized FAQ pairs; empty unless the host's resolver returns items.
-
#image_url ⇒ Object
Social-share image: resolver first, then the configured default.
-
#initialize(resource, config = Helios::Seo.configuration, view: nil) ⇒ ResourcePresenter
constructor
viewis the ActionView context (passed by TagsHelper). - #keywords ⇒ Object
- #modified_time ⇒ Object
-
#name ⇒ Object
(also: #headline)
The content title (used for og:title, twitter:title, schema headline).
- #published? ⇒ Boolean
-
#published_time ⇒ Object
ISO-8601 timestamps, emitted only for published resources.
- #robots ⇒ Object
Constructor Details
#initialize(resource, config = Helios::Seo.configuration, view: nil) ⇒ ResourcePresenter
view is the ActionView context (passed by TagsHelper). Resolvers that
need it to build URLs — e.g. an image_resolver generating an ActiveStorage
proxy URL — can declare a second argument and receive it.
14 15 16 17 18 |
# File 'app/services/helios/seo/resource_presenter.rb', line 14 def initialize(resource, config = Helios::Seo.configuration, view: nil) @resource = resource @config = config @view = view end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'app/services/helios/seo/resource_presenter.rb', line 9 def config @config end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
9 10 11 |
# File 'app/services/helios/seo/resource_presenter.rb', line 9 def resource @resource end |
Instance Method Details
#canonical_url ⇒ Object
49 50 51 |
# File 'app/services/helios/seo/resource_presenter.rb', line 49 def canonical_url resolve(config.canonical_url).presence || config.default_canonical_url(resource) end |
#description ⇒ Object
SERP-friendly plain-text description, falling back to the default.
37 38 39 40 41 42 43 |
# File 'app/services/helios/seo/resource_presenter.rb', line 37 def description text = value(:description).to_s.squish text = config.default_description.to_s if text.blank? return nil if text.blank? text.truncate(160) end |
#document_title ⇒ Object
The
27 28 29 30 31 32 33 34 |
# File 'app/services/helios/seo/resource_presenter.rb', line 27 def document_title override = resolve(config.title_resolver) return override.to_s if override.present? format(config.title_template.to_s, title: name.to_s, site_name: config.site_name.to_s) end |
#faqs ⇒ Object
Normalized FAQ pairs; empty unless the host's resolver returns items.
76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/services/helios/seo/resource_presenter.rb', line 76 def faqs Array(resolve(config.faq_resolver)).filter_map do |item| next unless item.respond_to?(:[]) question = item[:question] || item["question"] answer = item[:answer] || item["answer"] next if question.blank? || answer.blank? { question: question.to_s, answer: answer.to_s } end end |
#image_url ⇒ Object
Social-share image: resolver first, then the configured default.
58 59 60 |
# File 'app/services/helios/seo/resource_presenter.rb', line 58 def image_url resolve(config.image_resolver).presence || config.default_og_image.presence end |
#keywords ⇒ Object
45 46 47 |
# File 'app/services/helios/seo/resource_presenter.rb', line 45 def keywords value(:keywords).presence end |
#modified_time ⇒ Object
71 72 73 |
# File 'app/services/helios/seo/resource_presenter.rb', line 71 def modified_time published? ? iso8601(:updated_at) : nil end |
#name ⇒ Object Also known as: headline
The content title (used for og:title, twitter:title, schema headline).
21 22 23 |
# File 'app/services/helios/seo/resource_presenter.rb', line 21 def name value(:name) end |
#published? ⇒ Boolean
62 63 64 |
# File 'app/services/helios/seo/resource_presenter.rb', line 62 def published? resource.respond_to?(:published?) ? !!resource.published? : true end |
#published_time ⇒ Object
ISO-8601 timestamps, emitted only for published resources.
67 68 69 |
# File 'app/services/helios/seo/resource_presenter.rb', line 67 def published_time published? ? iso8601(:created_at) : nil end |
#robots ⇒ Object
53 54 55 |
# File 'app/services/helios/seo/resource_presenter.rb', line 53 def robots resolve(config.robots_resolver).presence || config.default_robots(resource) end |