Class: Www::CollectionPagePresenter

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

Overview

Presenter: collection page presenter.

Instance Attribute Summary collapse

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(page_title, page_description, page_url, items = [], request = nil) ⇒ CollectionPagePresenter

Returns a new instance of CollectionPagePresenter.

Parameters:

  • page_title (String)

    collection page title

  • page_description (String)

    collection page description

  • page_url (String)

    canonical collection page URL

  • items (Array) (defaults to: [])

    collection members (Schema.org types or name/url objects)

  • request (ActionDispatch::Request, nil) (defaults to: nil)

    current request



13
14
15
16
17
18
19
20
# File 'app/presenters/www/collection_page_presenter.rb', line 13

def initialize(page_title, page_description, page_url, items = [], request = nil)
  @page_title = page_title
  @page_description = page_description
  @page_url = page_url
  @items = items
  @request = request
  super(nil) # Pass nil since we don't need a model
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



6
7
8
# File 'app/presenters/www/collection_page_presenter.rb', line 6

def items
  @items
end

#page_descriptionObject (readonly)

Returns the value of attribute page_description.



6
7
8
# File 'app/presenters/www/collection_page_presenter.rb', line 6

def page_description
  @page_description
end

#page_titleObject (readonly)

Returns the value of attribute page_title.



6
7
8
# File 'app/presenters/www/collection_page_presenter.rb', line 6

def page_title
  @page_title
end

#page_urlObject (readonly)

Returns the value of attribute page_url.



6
7
8
# File 'app/presenters/www/collection_page_presenter.rb', line 6

def page_url
  @page_url
end

#requestObject (readonly)

Returns the value of attribute request.



6
7
8
# File 'app/presenters/www/collection_page_presenter.rb', line 6

def request
  @request
end

Instance Method Details

#schema_dot_org_structureSchemaDotOrg::CollectionPage

Schema.org CollectionPage structure for the collection.

Returns:



24
25
26
27
28
29
30
31
# File 'app/presenters/www/collection_page_presenter.rb', line 24

def schema_dot_org_structure
  SchemaDotOrg::CollectionPage.new(
    name: page_title,
    description: page_description,
    url: page_url,
    mainEntity: build_item_list
  )
end

#to_json_ldString

JSON-LD serialization of the collection page schema.

Returns:

  • (String)

    JSON-LD markup



35
36
37
# File 'app/presenters/www/collection_page_presenter.rb', line 35

def to_json_ld
  schema_dot_org_structure.to_s
end