Class: DsfrComponent::HighlightComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/dsfr_component/highlight_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(text: nil, size: :md, html_attributes: {}) ⇒ HighlightComponent

Returns a new instance of HighlightComponent.

Parameters:

  • text (String) (defaults to: nil)

    Le contenu textuel du composant

  • size (Symbol) (defaults to: :md)

    La taille de la mise en exergue



5
6
7
8
9
10
# File 'app/components/dsfr_component/highlight_component.rb', line 5

def initialize(text: nil, size: :md, html_attributes: {})
  @text = text
  @size = size

  super(html_attributes: html_attributes)
end

Instance Method Details

#callObject

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
# File 'app/components/dsfr_component/highlight_component.rb', line 12

def call
  raise(ArgumentError, "You must provide either a text param or some block content") if no_content?
  raise(ArgumentError, "Size '#{size}' is not allowed; possible values are #{SIZES}") if SIZES.exclude?(size)

  tag.div(**html_attributes) do
    tag.p(class: "fr-text--#{@size}") do
      @text || content
    end
  end
end