Class: GOVUKDesignSystemFormBuilder::Elements::Legend

Inherits:
Base
  • Object
show all
Includes:
Traits::Caption, Traits::HTMLAttributes, Traits::HTMLClasses, Traits::Localisation
Defined in:
lib/govuk_design_system_formbuilder/elements/legend.rb

Constant Summary

Constants included from Traits::Localisation

Traits::Localisation::BASE_NAME_REGEXP

Instance Method Summary collapse

Methods included from Traits::HTMLClasses

#build_classes

Methods included from Traits::HTMLAttributes

#attributes

Methods inherited from Base

#field_id, #to_s

Constructor Details

#initialize(builder, object_name, attribute_name, text: nil, size: config.default_legend_size, hidden: false, tag: config.default_legend_tag, caption: nil, content: nil, **kwargs) ⇒ Legend

Returns a new instance of Legend.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/govuk_design_system_formbuilder/elements/legend.rb', line 11

def initialize(builder, object_name, attribute_name, text: nil, size: config.default_legend_size, hidden: false, tag: config.default_legend_tag, caption: nil, content: nil, **kwargs)
  super(builder, object_name, attribute_name)

  if content
    @content = capture { content.call }
  else
    @text            = retrieve_text(text)
    @tag             = tag
    @size_class      = size_class(size)
    @tag             = tag
    @caption         = caption
    @hidden          = hidden
    @html_attributes = kwargs
  end
end

Instance Method Details

#htmlObject



27
28
29
# File 'lib/govuk_design_system_formbuilder/elements/legend.rb', line 27

def html
  @content || legend
end