Class: GovukPublishingComponents::Presenters::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_publishing_components/presenters/machine_readable/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(local_assigns) ⇒ Page

Returns a new instance of Page.



6
7
8
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 6

def initialize(local_assigns)
  @local_assigns = local_assigns
end

Instance Attribute Details

#local_assignsObject (readonly)

Returns the value of attribute local_assigns.



4
5
6
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 4

def local_assigns
  @local_assigns
end

Instance Method Details

#attachmentsObject



54
55
56
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 54

def attachments
  content_item.dig("details", "attachments")
end

#base_pathObject



50
51
52
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 50

def base_path
  content_item["base_path"]
end

#bodyObject



18
19
20
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 18

def body
  local_assigns[:body] || content_item.dig("details", "body")
end

#canonical_urlObject



14
15
16
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 14

def canonical_url
  local_assigns[:canonical_url] || (Plek.new.website_root + content_item["base_path"])
end

#content_itemObject



58
59
60
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 58

def content_item
  local_assigns[:content_item]
end

#descriptionObject



26
27
28
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 26

def description
  local_assigns[:description] || content_item["description"]
end

#document_typeObject



46
47
48
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 46

def document_type
  content_item["document_type"]
end

#has_image?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 30

def has_image?
  content_item.dig("details", "image").present?
end

#image_alt_textObject



38
39
40
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 38

def image_alt_text
  content_item.dig("details", "image", "alt_text")
end

#image_placeholdersObject



42
43
44
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 42

def image_placeholders
  local_assigns[:image_placeholders]
end

#image_urlObject



34
35
36
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 34

def image_url
  content_item.dig("details", "image", "high_resolution_url") || content_item.dig("details", "image", "url")
end

#logo_urlObject



62
63
64
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 62

def logo_url
  local_assigns[:logo_url]
end

#requested_pathObject



66
67
68
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 66

def requested_path
  local_assigns[:request_path]
end

#schemaObject



10
11
12
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 10

def schema
  local_assigns.fetch(:schema)
end

#titleObject



22
23
24
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 22

def title
  local_assigns[:title] || content_item["title"]
end

#withdrawn?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/govuk_publishing_components/presenters/machine_readable/page.rb', line 70

def withdrawn?
  content_item["withdrawn_notice"].present?
end