debian-mirror-gitlab/app/helpers/breadcrumbs_helper.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

85 lines
2 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
module BreadcrumbsHelper
def add_to_breadcrumbs(text, link)
@breadcrumbs_extra_links ||= []
@breadcrumbs_extra_links.push({
text: text,
link: link
})
end
def breadcrumb_title_link
return @breadcrumb_link if @breadcrumb_link
2018-03-17 18:26:18 +05:30
request.path
2017-09-10 17:25:29 +05:30
end
def breadcrumb_title(title)
return if defined?(@breadcrumb_title)
@breadcrumb_title = title
end
2018-03-17 18:26:18 +05:30
def breadcrumb_list_item(link)
content_tag "li" do
2022-07-23 23:45:48 +05:30
link + sprite_icon("chevron-lg-right", size: 8, css_class: "breadcrumbs-list-angle")
2018-03-17 18:26:18 +05:30
end
end
2021-12-11 22:18:48 +05:30
def add_to_breadcrumb_collapsed_links(link, location: :before)
@breadcrumb_collapsed_links ||= {}
@breadcrumb_collapsed_links[location] ||= []
@breadcrumb_collapsed_links[location] << link
2018-03-17 18:26:18 +05:30
end
2021-01-29 00:20:46 +05:30
def push_to_schema_breadcrumb(text, link)
list_item = schema_list_item(text, link, schema_breadcrumb_list.size + 1)
schema_breadcrumb_list.push(list_item)
end
def schema_breadcrumb_json
{
'@context': 'https://schema.org',
'@type': 'BreadcrumbList',
'itemListElement': build_item_list_elements
}.to_json
end
private
def schema_breadcrumb_list
@schema_breadcrumb_list ||= []
end
def build_item_list_elements
return @schema_breadcrumb_list unless @breadcrumbs_extra_links&.any?
last_element = schema_breadcrumb_list.pop
@breadcrumbs_extra_links.each do |el|
push_to_schema_breadcrumb(el[:text], el[:link])
end
last_element['position'] = schema_breadcrumb_list.last['position'] + 1
schema_breadcrumb_list.push(last_element)
end
def schema_list_item(text, link, position)
{
'@type' => 'ListItem',
'position' => position,
'name' => text,
'item' => ensure_absolute_link(link)
}
end
def ensure_absolute_link(link)
url = URI.parse(link)
url.absolute? ? link : URI.join(request.base_url, link).to_s
rescue URI::InvalidURIError
"#{request.base_url}#{request.path}"
end
2017-09-10 17:25:29 +05:30
end