<% add_gem_component_stylesheet("contents-list") underline_links ||= false format_numbers ||= false alternative_line_style ||= false title ||= nil brand ||= false local_assigns[:aria] ||= {} local_assigns[:margin_bottom] ||= 4 cl_helper = GovukPublishingComponents::Presenters::ContentsListHelper.new(local_assigns) brand_helper = GovukPublishingComponents::AppHelpers::BrandHelper.new(brand) link_classes = %w[gem-c-contents-list__link govuk-link gem-c-force-print-link-styles] link_classes << brand_helper.color_class link_classes << "govuk-link--no-underline" unless underline_links disable_ga4 ||= false ga4_data = { event_name: "navigation", section: t("components.contents_list.contents", locale: :en) || "", type: "contents list", index_total: cl_helper.get_index_total, } unless disable_ga4 component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns) component_helper.add_class("gem-c-contents-list #{brand_helper.brand_class}") component_helper.add_class("gem-c-contents-list--alternative-line-style") if alternative_line_style component_helper.add_class("gem-c-contents-list--custom-title") if title component_helper.add_data_attribute({ module: "ga4-link-tracker" }) unless disable_ga4 component_helper.add_aria_attribute({ label: t("components.contents_list.contents") }) unless local_assigns[:aria][:label] title_fallback = t("components.contents_list.contents", locale: I18n.locale, fallback: false, default: "en") %> <% if cl_helper.contents.any? %> <%= tag.nav(**component_helper.all_attributes) do %> <%= content_tag( :h2, {class: "gem-c-contents-list__title"}.merge( title_fallback == "en" ? {:lang => "en",} : {} ) ) do %> <%= title || t("components.contents_list.contents") %> <% end %>
    <% index_link = 1 unless disable_ga4 %> <% contents.each do |contents_item| %>
  1. > <% link_text = format_numbers ? cl_helper.wrap_numbers_with_spans(contents_item[:text]) : cl_helper.clean_string(contents_item[:text]) unless disable_ga4 ga4_data[:event_name] = cl_helper.get_ga4_event_name(contents_item[:href]) if contents_item[:href] ga4_data[:index_link] = index_link end %> <%= link_to_if !contents_item[:active], link_text, contents_item[:href], class: link_classes, data: { ga4_link: (!disable_ga4 ? ga4_data.to_json : nil) } %> <% index_link += 1 unless disable_ga4 %> <% if contents_item[:items] && contents_item[:items].any? %>
      <% contents_item[:items].each do |nested_contents_item| %>
    1. > <% unless disable_ga4 ga4_data[:event_name] = cl_helper.get_ga4_event_name(nested_contents_item[:href]) if nested_contents_item[:href] ga4_data[:index_link] = index_link end %> <%= link_to_if !nested_contents_item[:active], nested_contents_item[:text], nested_contents_item[:href], class: link_classes, data: { ga4_link: (!disable_ga4 ? ga4_data.to_json : nil) } %>
    2. <% index_link += 1 unless disable_ga4 %> <% end %>
    <% end %>
  2. <% end %>
<% end %> <% end %>