Class: GovukComponent::AccordionComponent::SectionComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/govuk_component/accordion_component/section_component.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#html_attributes

Attributes included from Traits::CustomHtmlAttributes

#html_attributes

Instance Method Summary collapse

Methods included from Traits::CustomClasses

#classes

Methods included from Govuk::Components::Helpers::CssUtilities

#combine_classes

Constructor Details

#initialize(heading_text:, summary_text:, expanded:, heading_level:, classes: [], html_attributes: {}) ⇒ SectionComponent

Returns a new instance of SectionComponent.



9
10
11
12
13
14
15
16
# File 'app/components/govuk_component/accordion_component/section_component.rb', line 9

def initialize(heading_text:, summary_text:, expanded:, heading_level:, classes: [], html_attributes: {})
  super(classes: classes, html_attributes: html_attributes)

  @heading_text  = heading_text
  @summary_text  = summary_text
  @expanded      = expanded
  @heading_level = heading_level
end

Instance Attribute Details

#expandedObject (readonly) Also known as: expanded?

Returns the value of attribute expanded.



2
3
4
# File 'app/components/govuk_component/accordion_component/section_component.rb', line 2

def expanded
  @expanded
end

#heading_levelObject (readonly)

Returns the value of attribute heading_level.



2
3
4
# File 'app/components/govuk_component/accordion_component/section_component.rb', line 2

def heading_level
  @heading_level
end

#heading_textObject (readonly)

Returns the value of attribute heading_text.



2
3
4
# File 'app/components/govuk_component/accordion_component/section_component.rb', line 2

def heading_text
  @heading_text
end

#summary_textObject (readonly)

Returns the value of attribute summary_text.



2
3
4
# File 'app/components/govuk_component/accordion_component/section_component.rb', line 2

def summary_text
  @summary_text
end

Instance Method Details

#heading_contentObject



26
27
28
# File 'app/components/govuk_component/accordion_component/section_component.rb', line 26

def heading_content
  heading_html || heading_text || fail(ArgumentError, "no heading_text or heading_html")
end

#id(suffix: nil) ⇒ Object



18
19
20
21
22
23
24
# File 'app/components/govuk_component/accordion_component/section_component.rb', line 18

def id(suffix: nil)
  # generate a random number if we don't have heading_text to avoid attempting
  # to parameterize a potentially-huge chunk of HTML
  @prefix ||= heading_text&.parameterize || SecureRandom.hex(4)

  [@prefix, suffix].compact.join('-')
end

#summary_contentObject



30
31
32
# File 'app/components/govuk_component/accordion_component/section_component.rb', line 30

def summary_content
  summary_html || summary_text
end