Class: Www::VideoPresenter

Inherits:
VideoBasePresenter show all
Defined in:
app/presenters/www/video_presenter.rb

Overview

Presenter: video presenter.

Instance Attribute Summary

Attributes inherited from BasePresenter

#current_account, #options, #url_helper

Instance Method Summary collapse

Methods inherited from VideoBasePresenter

#build_transcript_schema, #cf_poster_url, #chapter_clips, #cloudflare_embed_url, #cloudflare_mp4_url, #cloudflare_video_url, #created_at, #format_duration, #format_duration_for_display, #format_paragraphs_as_text, #format_sentences_as_text, #format_structured_paragraphs_as_text, #format_timestamp, #has_assemblyai_transcript_id?, #has_audio_extraction?, #has_cloudflare_captions?, #has_html_transcript?, #has_structured_transcript_json?, #published_on, #schema_dot_org_structure, #title, #transcript_display, #transcript_duration, #transcript_language, #video_medias_url

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(model, view = nil, options = nil) ⇒ VideoPresenter

Returns a new instance of VideoPresenter.

Parameters:

  • model (Video)

    the wrapped video

  • view (Object, nil) (defaults to: nil)

    view context

  • options (Hash, nil) (defaults to: nil)

    passed through to the parent initializer

Options Hash (options):

  • current_account (Account)

    current account



9
10
11
12
# File 'app/presenters/www/video_presenter.rb', line 9

def initialize(model, view = nil, options = nil)
  @url_helper = Www::Router.new
  super
end

Instance Method Details

Breadcrumb trail entries for the video page.

Parameters:

  • _params (Hash)

    unused request params

Returns:

  • (Array<Hash>)

    breadcrumb entries (:name, :url)



23
24
25
26
27
28
# File 'app/presenters/www/video_presenter.rb', line 23

def breadcrumb_links_array(_params)
  b_arr = [{ name: 'Video Library', url: h.cms_link('/videos') }]
  b_arr += h.catalog_breadcrumb_links(primary_product_line) if primary_product_line
  b_arr << { name: video.title }
  b_arr
end

#cloudflare_stream_urlString?

Cloudflare Stream playback URL for the video.

Returns:

  • (String, nil)

    stream URL



63
64
65
# File 'app/presenters/www/video_presenter.rb', line 63

def cloudflare_stream_url
  cloudflare_video_url
end

#expanded_descriptionString?

Localized expanded description.

Returns:

  • (String, nil)

    localized HTML



32
33
34
# File 'app/presenters/www/video_presenter.rb', line 32

def expanded_description
  h.localize_content video.expanded_description
end

#id_iriString

Provide a stable @id IRI for the VideoObject so WebPage mainEntity can reference it

Returns:

  • (String)

    the canonical URL as IRI



94
95
96
# File 'app/presenters/www/video_presenter.rb', line 94

def id_iri
  path
end

#page_descriptionString?

Localized meta description.

Returns:

  • (String, nil)

    localized page description



57
58
59
# File 'app/presenters/www/video_presenter.rb', line 57

def page_description
  h.localize_content(super)
end

#page_titleString

HTML title for the video page.

Returns:

  • (String)

    title with 'Video:' prefix and locale suffix



69
70
71
72
73
74
75
76
# File 'app/presenters/www/video_presenter.rb', line 69

def page_title
  t = +''
  t << (video.meta_title.presence || video.title.presence)
  # We append the company locale, unless the company name is already in the title
  t << " | #{h.company_locale}" unless t.include?(h.company_locale)
  t.prepend('Video: ') unless t.start_with?('Video:')
  t
end

#pathString

Absolute canonical URL. Used as the VideoObject/WebPage @id and in schema
URLs (Clip #t= links), which must be absolute IRIs — not a relative
cms_link path — so cross-node entity-graph references resolve.

Returns:

  • (String)

    canonical video URL



88
89
90
# File 'app/presenters/www/video_presenter.rb', line 88

def path
  video.cms_url
end

#primary_product_lineProductLine?

First product line associated with the video.

Returns:



16
17
18
# File 'app/presenters/www/video_presenter.rb', line 16

def primary_product_line
  video.product_lines.first
end

#render_transcriptActiveSupport::SafeBuffer, String

Transcript rendering methods for public pages

Returns:

  • (ActiveSupport::SafeBuffer, String)

    transcript block HTML



100
101
102
103
104
105
106
107
108
109
# File 'app/presenters/www/video_presenter.rb', line 100

def render_transcript
  return '' if video.transcript.blank?

  h.(:div, class: 'transcript') do
    h.safe_join([
                  render_transcript_header,
                  render_transcript_content
                ])
  end
end

#sub_headerString?

Localized sub-header.

Returns:

  • (String, nil)

    localized sub-header



44
45
46
# File 'app/presenters/www/video_presenter.rb', line 44

def sub_header
  h.localize_content video.sub_header
end

#text_descriptionString

Best available plain-text description for the video.

Returns:

  • (String)

    localized, whitespace-collapsed description



50
51
52
53
# File 'app/presenters/www/video_presenter.rb', line 50

def text_description
  d = video.meta_description.presence || (Nokogiri::HTML(video.expanded_description).text if video.expanded_description.present?) || video.sub_header.presence || video.meta_title.presence || video.title.presence
  h.localize_content(d.squeeze(' ').strip)
end

#to_json_ldString

JSON-LD serialization of the video schema.

Returns:

  • (String)

    JSON-LD markup



80
81
82
# File 'app/presenters/www/video_presenter.rb', line 80

def to_json_ld
  schema_dot_org_structure.to_s
end

#transcriptString?

Localized transcript HTML.

Returns:

  • (String, nil)

    localized transcript



38
39
40
# File 'app/presenters/www/video_presenter.rb', line 38

def transcript
  h.localize_content video.transcript
end