Sha256: 62b94e9afc06da9903566da46686a2d68c3d73663ae99aad1d7570c65919078f

Contents?: true

Size: 1.99 KB

Versions: 132

Compression:

Stored size: 1.99 KB

Contents

module GovukPublishingComponents
  module Presenters
    class ImageCardHelper
      include ActionView::Helpers
      include ActionView::Context

      attr_reader :href, :href_data_attributes, :extra_links, :large, :extra_links_no_indent, :heading_text, :metadata

      def initialize(local_assigns)
        @href = local_assigns[:href]
        @href_data_attributes = local_assigns[:href_data_attributes]
        @extra_links = local_assigns[:extra_links] || []
        @image_src = local_assigns[:image_src]
        @image_alt = local_assigns[:image_alt] || ""
        @context = local_assigns[:context]
        @description = local_assigns[:description]
        @large = local_assigns[:large]
        @heading_text = local_assigns[:heading_text]
        @extra_links_no_indent = local_assigns[:extra_links_no_indent]
        @metadata = local_assigns[:metadata]
      end

      def is_tracking?
        return true if @href_data_attributes

        if @extra_links
          @extra_links.each do |link|
            return true if link[:data_attributes]
          end
        end
        false
      end

      def image
        if @image_src
          content_tag(:figure, class: "gem-c-image-card__image-wrapper") do
            image_tag(@image_src, class: "gem-c-image-card__image", alt: @image_alt)
          end
        end
      end

      def context
        return unless @context

        content_tag(:p, class: 'gem-c-image-card__context') do
          if @context[:date]
            date = content_tag(:time, l(@context[:date], format: '%e %B %Y'), datetime: @context[:date].iso8601)
            dash = content_tag(:span, ' — ', 'aria-hidden': true)

            if @context[:text]
              date.concat(dash).concat(@context[:text])
            else
              date
            end
          else
            @context[:text]
          end
        end
      end

      def description
        content_tag(:div, @description, class: "gem-c-image-card__description") if @description
      end
    end
  end
end

Version data entries

132 entries across 132 versions & 1 rubygems

Version Path
govuk_publishing_components-17.13.0 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-17.12.2 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-17.12.1 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-17.12.0 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-17.11.0 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-17.10.0 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-17.9.0 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-17.8.0 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-17.7.0 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-17.6.1 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-17.6.0 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-17.5.0 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-17.4.0 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-17.3.0 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-17.2.0 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-17.1.1 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-17.1.0 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-17.0.0 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-16.29.0 lib/govuk_publishing_components/presenters/image_card_helper.rb
govuk_publishing_components-16.28.0 lib/govuk_publishing_components/presenters/image_card_helper.rb