Class: GovukPublishingComponents::Presenters::ImageCardHelper
- Inherits:
-
Object
- Object
- GovukPublishingComponents::Presenters::ImageCardHelper
- Includes:
- ActionView::Context, ActionView::Helpers
- Defined in:
- lib/govuk_publishing_components/presenters/image_card_helper.rb
Instance Attribute Summary collapse
-
#extra_details ⇒ Object
readonly
Returns the value of attribute extra_details.
-
#extra_details_no_indent ⇒ Object
readonly
Returns the value of attribute extra_details_no_indent.
-
#heading_text ⇒ Object
readonly
Returns the value of attribute heading_text.
-
#href_data_attributes ⇒ Object
readonly
Returns the value of attribute href_data_attributes.
-
#image_loading ⇒ Object
readonly
Returns the value of attribute image_loading.
-
#image_src ⇒ Object
readonly
Returns the value of attribute image_src.
-
#lang ⇒ Object
readonly
Returns the value of attribute lang.
-
#large_font_size_mobile ⇒ Object
readonly
Returns the value of attribute large_font_size_mobile.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#two_thirds ⇒ Object
readonly
Returns the value of attribute two_thirds.
-
#youtube_video_id ⇒ Object
readonly
Returns the value of attribute youtube_video_id.
Instance Method Summary collapse
- #context ⇒ Object
- #description ⇒ Object
- #href ⇒ Object
- #image ⇒ Object
-
#initialize(local_assigns, brand_helper) ⇒ ImageCardHelper
constructor
A new instance of ImageCardHelper.
- #is_tracking? ⇒ Boolean
- #large ⇒ Object
- #large_mobile_font_size? ⇒ Boolean
- #media ⇒ Object
- #youtube_href ⇒ Object
- #youtube_link ⇒ Object
- #youtube_thumbnail ⇒ Object
- #youtube_thumbnail_url ⇒ Object
Constructor Details
#initialize(local_assigns, brand_helper) ⇒ 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 27 28 29 30 31 32 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 9 def initialize(local_assigns, brand_helper) @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] || "" @youtube_video_alt = local_assigns[:youtube_video_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] @two_thirds = local_assigns[:two_thirds] || false @large_font_size_mobile = local_assigns[:large_font_size_mobile] || false @heading_text = local_assigns[:heading_text] @extra_details_no_indent = local_assigns[:extra_details_no_indent] @metadata = local_assigns[:metadata] @lang = local_assigns[:lang] @youtube_video_id = local_assigns[:youtube_video_id] || nil @brand_helper = brand_helper end |
Instance Attribute Details
#extra_details ⇒ Object (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_indent ⇒ Object (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_text ⇒ Object (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 |
#href_data_attributes ⇒ Object (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_loading ⇒ Object (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 |
#image_src ⇒ Object (readonly)
Returns the value of attribute image_src.
7 8 9 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 7 def image_src @image_src end |
#lang ⇒ Object (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 |
#large_font_size_mobile ⇒ Object (readonly)
Returns the value of attribute large_font_size_mobile.
7 8 9 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 7 def large_font_size_mobile @large_font_size_mobile end |
#metadata ⇒ Object (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 |
#two_thirds ⇒ Object (readonly)
Returns the value of attribute two_thirds.
7 8 9 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 7 def two_thirds @two_thirds end |
#youtube_video_id ⇒ Object (readonly)
Returns the value of attribute youtube_video_id.
7 8 9 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 7 def youtube_video_id @youtube_video_id end |
Instance Method Details
#context ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 95 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, lang: "en") 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 |
#description ⇒ Object
114 115 116 117 118 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 114 def description return content_tag(:div, @description, class: "gem-c-image-card__description gem-c-image-card__description--large-font-size-mobile") if @description && large_mobile_font_size? content_tag(:div, @description, class: "gem-c-image-card__description") if @description end |
#href ⇒ Object
34 35 36 37 38 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 34 def href return youtube_href if @youtube_video_id @href end |
#image ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 71 def image classes = %w[gem-c-image-card__image-wrapper] classes << "gem-c-image-card__image-wrapper--one-third" if @two_thirds height = 200 width = 300 height = 90 if @two_thirds width = 90 if @two_thirds if @image_src content_tag(:figure, class: classes) do image_tag( @image_src, class: "gem-c-image-card__image", alt: @image_alt, loading: @image_loading, sizes: @sizes, srcset: @srcset, height:, width:, ) end end end |
#is_tracking? ⇒ Boolean
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 54 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 |
#large ⇒ Object
40 41 42 43 44 45 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 40 def large # if youtube video, we don't want to use # the small variant, large will be always # true if a youtube_video_id is supplied @youtube_video_id || @large end |
#large_mobile_font_size? ⇒ Boolean
47 48 49 50 51 52 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 47 def large_mobile_font_size? # allow the font-size to be 19px on mobile # for the two-thirds varation of the # image card component @two_thirds && @large_font_size_mobile end |
#media ⇒ Object
65 66 67 68 69 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 65 def media return youtube_link if @youtube_video_id image end |
#youtube_href ⇒ Object
120 121 122 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 120 def youtube_href "https://www.youtube.com/watch?v=#{@youtube_video_id}" end |
#youtube_link ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 140 def youtube_link content_tag( :figure, class: "gem-c-image-card__image-wrapper gem-c-image-card__image-wrapper--youtube-embed", ) do content_tag(:div) do link_to( href, { class: "govuk-body govuk-link gem-c-image-card__youtube-thumbnail-container js-youtube-card-embed", "data-youtube-player-analytics": true, "data-youtube-player-analytics-category": "EmbeddedYoutube", }, ) do youtube_thumbnail end end end end |
#youtube_thumbnail ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 128 def youtube_thumbnail thumbnail = content_tag(:div, class: "gem-c-image-card__youtube-thumbnail-image-container") do image_tag( youtube_thumbnail_url, class: "gem-c-image-card__image gem-c-image-card__youtube-thumbnail-image", alt: "", loading: @image_loading, ) end thumbnail + content_tag(:figcaption, @youtube_video_alt, class: "gem-c-image-card__youtube-thumbnail-container-text govuk-link #{@brand_helper.color_class}") end |
#youtube_thumbnail_url ⇒ Object
124 125 126 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 124 def youtube_thumbnail_url "https://img.youtube.com/vi/#{@youtube_video_id}/maxresdefault.jpg" end |