Class: CCS::Components::GovUK::StepByStepNavigation::Section

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/step_by_step_navigation/section.rb,
lib/ccs/components/govuk/step_by_step_navigation/section/content.rb,
lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb,
lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb,
lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb,
lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb

Overview

GOV.UK Step by step navigation section

The individual section for the step by step navigation

Defined Under Namespace

Classes: Content, Heading

Constant Summary

Constants inherited from Base

Base::DEFAULT_ATTRIBUTES

Instance Method Summary collapse

Constructor Details

#initialize(heading:, content:, index:, context:) ⇒ Section

Returns a new instance of Section.

Parameters:

  • heading (Hash)

    options for the section heading. See Heading#initialize for details of the options.

  • content (Hash)

    options for the section content. See Content#initialize for details of the options.

  • index (String)

    the index of the section

  • context (ActionView::Base)

    the view context



32
33
34
35
36
37
38
39
40
# File 'lib/ccs/components/govuk/step_by_step_navigation/section.rb', line 32

def initialize(heading:, content:, index:, context:)
  super(context: context)

  @options[:attributes][:class] = 'gem-c-step-nav__step js-step'
  @options[:attributes][:id] = heading[:text].downcase.gsub(' ', '-').gsub('(', '').gsub(')', '')

  @heading = Heading.new(index: index, **heading)
  @content = Content.new(content_items: content, index: index, id: @options[:attributes][:id])
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Step by step navigation section

Returns:

  • (ActiveSupport::SafeBuffer)


46
47
48
49
50
51
# File 'lib/ccs/components/govuk/step_by_step_navigation/section.rb', line 46

def render
  tag.li(class: @options[:attributes][:class], id: @options[:attributes][:id]) do
    concat(heading.render)
    concat(content.render)
  end
end