Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write browse element icons as <img> #5385

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow to specify browse icon priorities
AntonKhorev committed Dec 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 5b5ffaf90f54b19379223ee912fe6a4f59234fcd
4 changes: 2 additions & 2 deletions app/helpers/browse_helper.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module BrowseHelper
def element_icon(type, object)
selected_icon_data = { :filename => "#{type}.svg" }
selected_icon_data = { :filename => "#{type}.svg", :priority => 1 }

unless object.redacted?
target_tags = object.tags.find_all { |k, _v| BROWSE_ICONS.key? k }.sort
title = target_tags.map { |k, v| "#{k}=#{v}" }.to_sentence unless target_tags.empty?

target_tags.each do |k, v|
icon_data = BROWSE_ICONS[k][v] || BROWSE_ICONS[k][:*]
selected_icon_data = icon_data if icon_data
selected_icon_data = icon_data if icon_data && icon_data[:priority] > selected_icon_data[:priority]
end
end

2 changes: 1 addition & 1 deletion config/browse_icons.yml
Original file line number Diff line number Diff line change
@@ -144,7 +144,7 @@ railway:
tram: { filename: "tram.20.png" }

shop:
:*: { filename: "shop_convenience.p.16.png" }
:*: { filename: "shop_convenience.p.16.png", priority: 20 }
alcohol: { filename: "shop_alcohol.16.png" }
bakery: { filename: "shop_bakery.16.png" }
bicycle: { filename: "shop_bicycle.16.png" }
4 changes: 3 additions & 1 deletion config/initializers/browse_icons.rb
Original file line number Diff line number Diff line change
@@ -2,7 +2,9 @@
BROWSE_ICONS = YAML.load_file(Rails.root.join("config/browse_icons.yml")).transform_values do |tag_key_data|
transformed_tag_key_data = {}
tag_key_data.each do |tag_value, tag_value_data|
transformed_tag_key_data[tag_value] = tag_value_data.deep_symbolize_keys
tag_value_data = tag_value_data.deep_symbolize_keys
tag_value_data[:priority] ||= tag_value == :* ? 10 : 100
transformed_tag_key_data[tag_value] = tag_value_data
end
transformed_tag_key_data
end