Class: DsfrComponent::HeaderComponent::OperatorImageComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/dsfr_component/header_component/operator_image_component.rb

Constant Summary

Constants inherited from Base

Base::HEADING_LEVELS, Base::SIZES

Instance Attribute Summary

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Constructor Details

#initialize(src:, alt:, href: "/", title: nil, html_attributes: {}) ⇒ OperatorImageComponent

Returns a new instance of OperatorImageComponent.

Parameters:

  • src (String)

    L’attribut src qui sera passé au tag img

  • alt (String)

    Le texte alternatif qui sera passé au tag img. Il doit impérativement contenir le texte présent dans l’image.

  • href (String, nil) (defaults to: "/")

    L’URL du lien vers la page d’accueil du site. Passer nil pour ne pas rendre de lien.

  • title (String) (defaults to: nil)

    Le title du lien vers la page d’accueil du site. Ignoré si href est nil.



6
7
8
9
10
11
12
13
# File 'app/components/dsfr_component/header_component/operator_image_component.rb', line 6

def initialize(src:, alt:, href: "/", title: nil, html_attributes: {})
  @src = src
  @alt = alt
  @href = href
  @title = title

  super(html_attributes: html_attributes)
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
# File 'app/components/dsfr_component/header_component/operator_image_component.rb', line 15

def call
  tag.div(class: "fr-header__operator") do
    if href
      tag.a(href: href, title: title) do
        image_tag
      end
    else
      image_tag
    end
  end
end

#default_attributesObject



27
28
29
# File 'app/components/dsfr_component/header_component/operator_image_component.rb', line 27

def default_attributes
  {}
end