Class: Www::DocumentCardComponent

Inherits:
ApplicationComponent show all
Defined in:
app/components/www/document_card_component.rb

Overview

ViewComponent: renders the document card block.

Instance Method Summary collapse

Methods inherited from ApplicationComponent

#cms_link, #fetch_or_fallback, #image_asset_tag, #image_tag, #number_to_currency, #number_with_delimiter, #post_path, #post_url, #strip_tags

Constructor Details

#initialize(publication_code:, title:, image_url: nil, image_asset_id: nil, alt_text: nil, target: '_blank', _rel: "noopener noreferrer", col_size: 'col-6 col-sm-4 col-md-3 col-xl-2 mt-4', image_asset_tag_options: {}, link: nil) ⇒ DocumentCardComponent

Returns a new instance of DocumentCardComponent.

Parameters:

  • publication_code (String)

    SKU/code of the publication used to resolve
    its URL via PublicationFinder when no explicit link is given

  • title (String)

    document title shown in the card footer link

  • image_url (String, nil) (defaults to: nil)

    fallback image URL rendered when no image
    asset id is provided

  • image_asset_id (Integer, String, nil) (defaults to: nil)

    image asset rendered via
    ApplicationHelper#image_asset_tag; takes precedence over image_url

  • alt_text (String, nil) (defaults to: nil)

    image alt text; defaults to title

  • target (String) (defaults to: '_blank')

    link target attribute for the footer link

  • _rel (String) (defaults to: "noopener noreferrer")

    link rel attribute (currently unused by the template)

  • col_size (String) (defaults to: 'col-6 col-sm-4 col-md-3 col-xl-2 mt-4')

    Bootstrap column classes wrapping the card

  • image_asset_tag_options (Hash) (defaults to: {})

    extra options merged over
    #default_image_asset_tag_options and passed to
    ApplicationHelper#image_asset_tag

  • link (String, nil) (defaults to: nil)

    explicit URL for the footer link; defaults to the
    resolved publication URL



21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/components/www/document_card_component.rb', line 21

def initialize(publication_code:, title:, image_url: nil, image_asset_id: nil, alt_text: nil, target: '_blank', _rel: "noopener noreferrer", col_size: 'col-6 col-sm-4 col-md-3 col-xl-2 mt-4', image_asset_tag_options: {}, link: nil)
  @publication_code = publication_code
  @image_url = image_url
  @image_asset_id = image_asset_id
  @title = title
  @alt_text = alt_text || title
  @target = target
  @col_size = col_size
  @image_asset_tag_options = default_image_asset_tag_options.merge(image_asset_tag_options)
  @link = link
  super()
end