Class: GovukPublishingComponents::Presenters::ImageCardHelper

Inherits:
Object
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers
Defined in:
lib/govuk_publishing_components/presenters/image_card_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(local_assigns) ⇒ ImageCardHelper

Returns a new instance of ImageCardHelper.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 9

def initialize(local_assigns)
  @href = local_assigns[:href]
  @href_data_attributes = local_assigns[:href_data_attributes]
  @extra_details = local_assigns[:extra_details] || []
  @image_src = local_assigns[:image_src]
  @image_alt = local_assigns[:image_alt] || ""
  @image_loading = local_assigns[:image_loading] || "auto"
  @srcset = local_assigns[:srcset] || nil
  @sizes = local_assigns[:sizes] || nil
  @image_loading = local_assigns[:image_loading] || "auto"
  @context = local_assigns[:context]
  @description = local_assigns[:description]
  @large = local_assigns[:large]
  @heading_text = local_assigns[:heading_text]
  @extra_details_no_indent = local_assigns[:extra_details_no_indent]
  @metadata = local_assigns[:metadata]
  @lang = local_assigns[:lang]
end

Instance Attribute Details

#extra_detailsObject (readonly)

Returns the value of attribute extra_details.



7
8
9
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 7

def extra_details
  @extra_details
end

#extra_details_no_indentObject (readonly)

Returns the value of attribute extra_details_no_indent.



7
8
9
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 7

def extra_details_no_indent
  @extra_details_no_indent
end

#heading_textObject (readonly)

Returns the value of attribute heading_text.



7
8
9
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 7

def heading_text
  @heading_text
end

#hrefObject (readonly)

Returns the value of attribute href.



7
8
9
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 7

def href
  @href
end

#href_data_attributesObject (readonly)

Returns the value of attribute href_data_attributes.



7
8
9
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 7

def href_data_attributes
  @href_data_attributes
end

#image_loadingObject (readonly)

Returns the value of attribute image_loading.



7
8
9
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 7

def image_loading
  @image_loading
end

#langObject (readonly)

Returns the value of attribute lang.



7
8
9
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 7

def lang
  @lang
end

#largeObject (readonly)

Returns the value of attribute large.



7
8
9
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 7

def large
  @large
end

#metadataObject (readonly)

Returns the value of attribute metadata.



7
8
9
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 7

def 
  @metadata
end

Instance Method Details

#contextObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 56

def context
  return unless @context

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

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

#descriptionObject



75
76
77
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 75

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

#imageObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 39

def image
  if @image_src
    (:figure, class: "gem-c-image-card__image-wrapper") do
      image_tag(
        @image_src,
        class: "gem-c-image-card__image",
        alt: @image_alt,
        loading: @image_loading,
        sizes: @sizes,
        srcset: @srcset,
        height: 200,
        width: 300,
      )
    end
  end
end

#is_tracking?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 28

def is_tracking?
  return true if @href_data_attributes

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