Class: FaqPresenter

Inherits:
BasePresenter show all
Defined in:
app/presenters/faq_presenter.rb

Overview

Presenter for FAQ sections using Schema.org models

Constant Summary collapse

ALLOWED_FAQ_TAGS =
%w[a p br ol ul li b strong i em h1 h2 h3 h4 h5 h6 div].freeze
ALLOWED_FAQ_ATTRIBUTES =
%w[href].freeze
SANITIZER =

One sanitizer per process — Rails::HTML5::SafeListSanitizer is thread-safe
and stateless between calls. Allocating a new instance per FAQ was the
previous behaviour and created unnecessary object churn on every schema build.

Rails::HTML5::SafeListSanitizer.new.freeze

Instance Attribute Summary

Attributes inherited from BasePresenter

#current_account, #options, #url_helper

Instance Method Summary collapse

Methods inherited from BasePresenter

#can?, #capture, #concat, #content_tag, #fa_icon, #h, #link_to, #number_to_currency, #present, presents, #r, #safe_present, #simple_format, #u

Constructor Details

#initialize(data, view_context = nil, options = {}) ⇒ FaqPresenter

Returns a new instance of FaqPresenter.



15
16
17
18
19
# File 'app/presenters/faq_presenter.rb', line 15

def initialize(data, view_context = nil, options = {})
  @data = data
  @product_url = options[:product_url]
  super(data, view_context)
end

Instance Method Details

#schema_dot_org_structureObject



21
22
23
24
25
# File 'app/presenters/faq_presenter.rb', line 21

def schema_dot_org_structure
  SchemaDotOrg::FaqPage.new(
    mainEntity: build_questions_array
  )
end

#to_json_ldObject



27
28
29
# File 'app/presenters/faq_presenter.rb', line 27

def to_json_ld
  schema_dot_org_structure.to_s
end