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 ⇒ Object
readonly
Returns the value of attribute href.
-
#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 ⇒ Object
readonly
Returns the value of attribute large.
-
#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.
Instance Method Summary collapse
- #context ⇒ Object
- #description ⇒ Object
-
#initialize(local_assigns) ⇒ ImageCardHelper
constructor
A new instance of ImageCardHelper.
- #large_mobile_font_size? ⇒ Boolean
- #media ⇒ Object
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] @extra_details = local_assigns[:extra_details] || [] @image_src = local_assigns[:image_src] @image_alt = local_assigns[:image_alt] || "" @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] = local_assigns[:metadata] @lang = local_assigns[:lang] 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 ⇒ Object (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 |
#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 ⇒ Object (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 |
#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 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 |
Instance Method Details
#context ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 57 def context return unless @context content_tag(:p, class: "gem-c-image-card__context") do if @context[:date] @context[:date] = Date.parse(@context[:date]) if @context[:date].is_a? String 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
77 78 79 80 81 82 83 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 77 def description return unless @description classes = %w[gem-c-image-card__description] classes << "gem-c-image-card__description--large-font-size-mobile" if large_mobile_font_size? content_tag(:div, @description, class: classes) end |
#large_mobile_font_size? ⇒ Boolean
28 29 30 31 32 33 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 28 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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/govuk_publishing_components/presenters/image_card_helper.rb', line 35 def media height = 200 width = 300 height = 90 if @two_thirds width = 90 if @two_thirds 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, loading: @image_loading, sizes: @sizes, srcset: @srcset, height:, width:, ) end end end |