Sha256: 9bb4dad03a8f694a76354c3175df7eadc3ba854cd1934f8aaf49bbd65191c17a
Contents?: true
Size: 1.82 KB
Versions: 223
Compression:
Stored size: 1.82 KB
Contents
module GovukPublishingComponents module Presenters class Breadcrumbs def initialize(breadcrumbs) @breadcrumbs = breadcrumbs end def structured_data { "@context" => "http://schema.org", "@type" => "BreadcrumbList", "itemListElement" => item_list_element, } end private attr_reader :breadcrumbs def item_list_element breadcrumbs.each_with_index.map { |crumb, index| Breadcrumb.new(crumb, index) } .select(&:is_link?) .map(&:item_list_element) end end class Breadcrumb extend Forwardable def_delegators :@crumb, :[] def initialize(crumb, index) @crumb = crumb @index = index + 1 end def item_list_element { "@type" => "ListItem", "position" => index, "item" => list_item_item, } end def is_link? crumb[:url].present? end def path crumb[:url] end def tracking_data(breadcrumbs_length) data = { track_category: "breadcrumbClicked", track_action: index, track_label: path, track_options: { dimension28: breadcrumbs_length.to_s, dimension29: crumb[:title], }, } is_homepage = crumb[:url] == "/" if is_homepage data[:track_category] = "homeLinkClicked" data[:track_action] = "homeBreadcrumb" data[:track_label] = "" data[:track_options] = "{}" end data end private attr_reader :crumb, :index def list_item_item path = crumb[:url] item = { "name" => crumb[:title] } item["@id"] = Plek.new.website_root + path if path item end end end end
Version data entries
223 entries across 223 versions & 1 rubygems