2 def element_icon(type, object)
3 selected_icon_data = { :filename => "#{type}.svg", :priority => 1 }
5 unless object.redacted?
6 target_tags = object.tags.find_all { |k, _v| BROWSE_ICONS.key? k }.sort
7 title = target_tags.map { |k, v| "#{k}=#{v}" }.to_sentence unless target_tags.empty?
9 target_tags.each do |k, v|
10 icon_data = BROWSE_ICONS[k][v] || BROWSE_ICONS[k][:*]
11 selected_icon_data = icon_data if icon_data && icon_data[:priority] > selected_icon_data[:priority]
15 image_tag "browse/#{selected_icon_data[:filename]}",
17 :class => ["align-bottom object-fit-none browse-icon", { "browse-icon-invertible" => selected_icon_data[:invert] }],
21 def element_single_current_link(type, object)
22 link_to object, { :rel => (link_follow(object) if type == "node") } do
23 element_strikethrough object do
24 printable_element_name object
29 def element_list_item(type, object, &)
30 tag.li(tag.div(element_icon(type, object) + tag.div(:class => "align-self-center", &), :class => "d-flex gap-1"))
33 def element_list_item_with_strikethrough(type, object, &)
34 element_list_item type, object do
35 element_strikethrough object, &
39 def printable_element_name(object)
40 id = if object.id.is_a?(Array)
47 # don't look at object tags if redacted, so as to avoid giving
48 # away redacted version tag information.
49 unless object.redacted?
50 available_locales = Locale.list(name_locales(object))
52 locale = available_locales.preferred(preferred_languages, :default => nil)
54 if object.tags.include? "name:#{locale}"
55 name = t "printable_name.with_name_html", :name => tag.bdi(object.tags["name:#{locale}"].to_s), :id => tag.bdi(name)
56 elsif object.tags.include? "name"
57 name = t "printable_name.with_name_html", :name => tag.bdi(object.tags["name"].to_s), :id => tag.bdi(name)
58 elsif object.tags.include? "ref"
59 name = t "printable_name.with_name_html", :name => tag.bdi(object.tags["ref"].to_s), :id => tag.bdi(name)
66 def printable_element_version(object)
67 t "printable_name.version", :version => object.version
70 def element_strikethrough(object, &)
71 if object.redacted? || !object.visible?
78 def link_follow(object)
79 "nofollow" if object.tags.empty?
82 def type_and_paginated_count(type, pages, selected_page = pages.current_page)
83 if pages.page_count == 1
84 t ".#{type.pluralize}",
85 :count => pages.item_count
87 t ".#{type.pluralize}_paginated",
88 :x => selected_page.first_item,
89 :y => selected_page.last_item,
90 :count => pages.item_count
94 def sidebar_classic_pagination(pages, page_param)
95 max_width_for_default_padding = 35
98 pagination_items(pages, {}).each do |(body)|
99 width += 2 # padding width
102 link_classes = ["page-link", { "px-1" => width > max_width_for_default_padding }]
104 tag.ul :class => "pagination pagination-sm mb-2" do
105 pagination_items(pages, {}).each do |body, page_or_class|
106 linked = !(page_or_class.is_a? String)
108 link_to body, url_for(page_param => page_or_class.number), :class => link_classes, **yield(page_or_class)
110 tag.span body, :class => link_classes
112 concat tag.li link, :class => ["page-item", { page_or_class => !linked }]
119 def name_locales(object)
120 object.tags.keys.map { |k| Regexp.last_match(1) if k =~ /^name:(.*)$/ }.flatten