<path d="M16 19h6"/>
<path d="M19 16v6"/>
</symbol>
+ <symbol viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" id="icon--key">
+ <path d="M16.555 3.843l3.602 3.602a2.877 2.877 0 0 1 0 4.069l-2.643 2.643a2.877 2.877 0 0 1 -4.069 0l-.301 -.301l-6.558 6.558a2 2 0 0 1 -1.239 .578l-.175 .008h-1.172a1 1 0 0 1 -.993 -.883l-.007 -.117v-1.172a2 2 0 0 1 .467 -1.284l.119 -.13l.414 -.414h2v-2h2v-2l2.144 -2.144l-.301 -.301a2.877 2.877 0 0 1 0 -4.069l2.643 -2.643a2.877 2.877 0 0 1 4.069 0z"/>
+ <path d="M15 9h.01"/>
+ </symbol>
<symbol viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" id="icon--link">
<path d="M9 15l6 -6"/>
<path d="M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464"/>
only_path = options[:only_path].nil? ? true : options[:only_path]
case principal
when User
- name = h(principal.name(options[:format]))
- name = "@".html_safe + name if options[:mention]
+ name = principal.name(options[:format])
+ name = "@#{name}" if options[:mention]
css_classes = ''
if principal.active? || (User.current.admin? && principal.logged?)
url = user_url(principal, :only_path => only_path)
css_classes += principal.css_classes
end
when Group
- name = h(principal.to_s)
+ name = principal.to_s
url = group_url(principal, :only_path => only_path)
css_classes = principal.css_classes
else
- name = h(principal.to_s)
+ name = principal.to_s
end
css_classes += " #{options[:class]}" if css_classes && options[:class].present?
- url ? link_to(principal_icon(principal.class.name.downcase).to_s + name, url, :class => css_classes) : name
+ url ? link_to(principal_icon(principal).to_s + name, url, :class => css_classes) : h(name)
end
# Displays a link to edit group page if current user is admin
check_box_tag(name, principal.id, false, :id => nil) +
(avatar(principal, :size => 16).presence ||
content_tag(
- 'span', principal_icon(principal.class.name.downcase),
+ 'span', principal_icon(principal),
:class => "name icon icon-#{principal.class.name.downcase}"
)
) + principal.to_s
end
end
- def file_icon(entry, name, size: DEFAULT_ICON_SIZE, css_class: nil)
+ def file_icon(entry, name, **options)
if entry.is_dir?
- sprite_icon("folder", name, size: size, css_class: css_class)
+ sprite_icon("folder", name, **options)
else
icon_name = icon_for_mime_type(Redmine::MimeType.css_class_of(name))
- sprite_icon(icon_name, name, size: size, css_class: css_class)
+ sprite_icon(icon_name, name, **options)
end
end
- def principal_icon(principal_class, size: DEFAULT_ICON_SIZE, css_class: nil)
- sprite_icon('group', size: size, css_class: css_class) if ['groupanonymous', 'groupnonmember', 'group'].include?(principal_class)
+ def principal_icon(principal, **options)
+ raise ArgumentError, "First argument has to be a Principal, was #{principal.inspect}" unless principal.is_a?(Principal)
+
+ principal_class = principal.class.name.downcase
+ sprite_icon('group', **options) if ['groupanonymous', 'groupnonmember', 'group'].include?(principal_class)
end
- def activity_event_type_icon(event_type, size: DEFAULT_ICON_SIZE, css_class: nil)
+ def activity_event_type_icon(event_type, **options)
icon_name = case event_type
when 'reply'
'comments'
event_type
end
- sprite_icon(icon_name, size: size, css_class: css_class)
+ sprite_icon(icon_name, **options)
end
private
<% next if member.new_record? %>
<tr id="member-<%= member.id %>" class="member">
<td class="name icon icon-<%= member.principal.class.name.downcase %>">
- <%= principal_icon(member.principal.class.name.downcase) %>
+ <%= principal_icon(member.principal) %>
<%= link_to_user member.principal %>
</td>
<td class="roles">
svg: chevrons-right
- name: chevrons-left
svg: chevrons-left
+- name: key
+ svg: key
def test_link_to_principal_should_link_to_group
group = Group.find(10)
- result = link_to('A Team', '/groups/10', :class => 'group')
- assert_equal result, link_to_principal(group)
+ result = %r{<a class="group" href="/groups/10"><svg class="s18 icon-svg" aria-hidden="true"><use href="/assets/icons-\w+.svg#icon--group"></use></svg>A Team</a>}
+ assert_match result, link_to_principal(group)
end
def test_link_to_principal_should_return_string_representation_for_unknown_type_principal
tags = principals_check_box_tags(name, principals)
principals.each_with_index do |principal, i|
assert_not_include avatar_tags[i], tags
- assert_include content_tag('span', principal_icon(principal.class.name.downcase), :class => "name icon icon-#{principal.class.name.downcase}"), tags
+ assert_include content_tag('span', principal_icon(principal), :class => "name icon icon-#{principal.class.name.downcase}"), tags
end
end
end
class IconsHelperTest < Redmine::HelperTest
include IconsHelper
+ fixtures :users
+
def test_sprite_icon_should_return_svg_with_defaults
expected = %r{<svg class="s18 icon-svg" aria-hidden="true"><use href="/assets/icons-\w+.svg#icon--edit"></use></svg>$}
icon = sprite_icon('edit')
def test_principal_icon_should_return_group_icon_for_group_classes
expected = %r{<svg class="s18 icon-svg" aria-hidden="true"><use href="/assets/icons-\w+.svg#icon--group"></use></svg>}
- %w(groupanonymous groupnonmember group).each do |principal_class|
- assert_match expected, principal_icon(principal_class)
+ [Principal.find(12), Principal.find(13), Principal.find(10)].each do |principal|
+ assert_match expected, principal_icon(principal)
end
end