Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions app/helpers/browse_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

module BrowseHelper
include BrowseTagsHelper

def element_icon(type, object)
selected_icon_data = { :filename => "#{type}.svg", :priority => 1 }

Expand Down Expand Up @@ -72,6 +74,18 @@ def link_follow(object)
"nofollow" if object.tags.empty?
end

def browse_tag_value_cell(tag)
content_tag :td,
format_value(tag[0], tag[1]),
:class => "py-1 border-secondary-subtle border-start",
:dir => "auto",
:lang => tag_language(tag[0])
end

def tag_language(key)
key[/\Aname:([a-z]{2,3}(?:-[A-Za-z0-9]+)*)\z/, 1]
end

Comment thread
hlfan marked this conversation as resolved.
private

def feature_name(tags)
Expand Down
7 changes: 5 additions & 2 deletions app/views/browse/_tag.html.erb
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not remove this partial entirely? Then some classes (py-1 border-secondary-subtle) can be reused.

Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<tr>
<th class="py-1 border-secondary-subtle table-secondary fw-normal" dir="auto"><%= format_key(tag[0]) %></th>
<td class="py-1 border-secondary-subtle border-start" dir="auto"><%= format_value(tag[0], tag[1]) %></td>
<th class="py-1 border-secondary-subtle table-secondary fw-normal" dir="auto">
<%= format_key(tag[0]) %>
</th>

<%= browse_tag_value_cell(tag) %>
</tr>
7 changes: 6 additions & 1 deletion test/controllers/api/changesets/uploads_controller_test.rb
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in this file are unrelated to the PR. Please remove them.

Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,14 @@ def test_upload_race_condition

threads = Array.new(concurrency_level) do
Thread.new do
post path, :params => diff, :headers => auth_header
ActiveRecord::Base.connection_pool.with_connection do
open_session do |sess|
sess.post path, :params => diff, :headers => auth_header
end
end
end
end

threads.each(&:join)

changeset.reload
Expand Down
16 changes: 16 additions & 0 deletions test/helpers/browse_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ def test_element_icon
end
end

def test_lang_attribute_for_localized_name_tags
tag = ["name:pt", "Nó teste"]

html = browse_tag_value_cell(tag)

assert_match(/lang="pt"/, html)
end

def test_non_language_name_tags_do_not_get_lang_attribute
tag = ["name:etymology", "Origin"]

html = browse_tag_value_cell(tag)

assert_no_match(/lang="/, html)
end

private

def add_old_tags_selection(old_node)
Expand Down