Sha256: e16dc10fdd8f3a3bfdd491237dbca63e5d70dcb427d801d2de668c1207aefc82

Contents?: true

Size: 1.4 KB

Versions: 9

Compression:

Stored size: 1.4 KB

Contents

module GovukPublishingComponents
  module Presenters
    class Page
      attr_reader :local_assigns

      def initialize(local_assigns)
        @local_assigns = local_assigns
      end

      def schema
        local_assigns.fetch(:schema)
      end

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

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

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

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

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

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

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

      def image_placeholders
        local_assigns[:image_placeholders]
      end

      def document_type
        content_item["document_type"]
      end

      def base_path
        content_item["base_path"]
      end

      def content_item
        local_assigns[:content_item]
      end

      def logo_url
        local_assigns[:logo_url]
      end

      def parts
        content_item.dig("details", "parts") || []
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
govuk_publishing_components-20.5.2 lib/govuk_publishing_components/presenters/machine_readable/page.rb
govuk_publishing_components-20.5.1 lib/govuk_publishing_components/presenters/machine_readable/page.rb
govuk_publishing_components-20.5.0 lib/govuk_publishing_components/presenters/machine_readable/page.rb
govuk_publishing_components-20.4.0 lib/govuk_publishing_components/presenters/machine_readable/page.rb
govuk_publishing_components-20.3.0 lib/govuk_publishing_components/presenters/machine_readable/page.rb
govuk_publishing_components-20.2.2 lib/govuk_publishing_components/presenters/machine_readable/page.rb
govuk_publishing_components-20.2.1 lib/govuk_publishing_components/presenters/machine_readable/page.rb
govuk_publishing_components-20.2.0 lib/govuk_publishing_components/presenters/machine_readable/page.rb
govuk_publishing_components-20.1.0 lib/govuk_publishing_components/presenters/machine_readable/page.rb