class GovukPublishingComponents::Presenters::StepByStepNavHelper

@private Only used by the step by step component

Public Instance Methods

generate_step_nav_id(step_title) click to toggle source
# File lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb, line 21
def generate_step_nav_id(step_title)
  step_title.parameterize
end
render_step_nav_element(element, options) click to toggle source
# File lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb, line 9
def render_step_nav_element(element, options)
  @options = options
  @link_index = options[:link_index]

  case element[:type]
  when "paragraph"
    paragraph(element[:text])
  when "list"
    list(element)
  end
end

Private Instance Methods

create_context(context) click to toggle source
# File lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb, line 82
def create_context(context)
  content_tag(:span, context, class: "gem-c-step-nav__context") if context
end
create_list_item_content(link) click to toggle source
# File lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb, line 56
def create_list_item_content(link)
  if link[:href]
    @link_index += 1
    href = link_href(link[:active], link[:href])

    text = capture do
      concat link_text(link[:active], link[:text])
      concat " "
      concat create_context(link[:context])
    end

    link_to(
      href,
      rel: ("external" if href.start_with?("http")),
      data: {
        position: "#{@options[:step_index] + 1}.#{@link_index}",
      },
      class: "gem-c-step-nav__link js-link",
    ) do
      text
    end
  else
    link[:text]
  end
end
external_url?(href) click to toggle source
# File lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb, line 101
def external_url?(href)
  href.start_with?("http")
end
get_list_element(style) click to toggle source
# File lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb, line 90
def get_list_element(style)
  style == "choice" ? "ul" : "ol"
end
get_list_style(style) click to toggle source
# File lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb, line 86
def get_list_style(style)
  "gem-c-step-nav__list--choice" if style == "choice"
end
list(element) click to toggle source
# File lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb, line 35
def list(element)
  content_tag(
    get_list_element(element[:style]),
    class: "gem-c-step-nav__list #{get_list_style(element[:style])}",
    data: {
      length: element[:contents].length,
    },
  ) do
    element[:contents].collect do |contents|
      concat(
        content_tag(
          :li,
          class: "gem-c-step-nav__list-item js-list-item #{link_active(contents[:active])}",
        ) do
          create_list_item_content(contents)
        end,
      )
    end
  end
end
paragraph(text) click to toggle source
# File lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb, line 27
def paragraph(text)
  content_tag(
    :p,
    text,
    class: "gem-c-step-nav__paragraph",
  )
end