Feature #29824 » 29824-initials_avatars-WIP.patch
| app/helpers/avatars_helper.rb | ||
|---|---|---|
|
elsif user.to_s =~ %r{<(.+?)>}
|
||
|
email = $1
|
||
|
end
|
||
|
if options[:default] == 'blank'
|
||
|
options[:style] ||= +''
|
||
|
options[:style] << "background-image:url(\"data:image/svg+xml,#{url_encode(render(partial: 'common/initials.svg', locals: { initials: user.initials }))}\");"
|
||
|
options[:class] ||= +''
|
||
|
options[:class] << " avatar-color-#{user.id % 8}"
|
||
|
end
|
||
|
if email.present?
|
||
|
gravatar(email.to_s.downcase, options) rescue nil
|
||
|
elsif user.is_a?(AnonymousUser)
|
||
| app/models/anonymous_user.rb | ||
|---|---|---|
|
def logged?; false end
|
||
|
def admin; false end
|
||
|
def name(*args); I18n.t(:label_user_anonymous) end
|
||
|
def initials; 'AN' end
|
||
|
def mail=(*args); nil end
|
||
|
def mail; nil end
|
||
|
def time_zone; nil end
|
||
| app/models/principal.rb | ||
|---|---|---|
|
to_s
|
||
|
end
|
||
|
def initials
|
||
|
if firstname.blank? && lastname.blank?
|
||
|
'NN'
|
||
|
else
|
||
|
"#{firstname.to_s.strip.first}#{lastname.to_s.strip.first}".upcase.strip
|
||
|
end
|
||
|
end
|
||
|
def mail=(*args)
|
||
|
nil
|
||
|
end
|
||
| app/views/common/_initials.svg.erb | ||
|---|---|---|
|
<svg viewBox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
||
|
<link rel="stylesheet" href="/stylesheets/avatars.css" type="text/css"/>
|
||
|
<defs>
|
||
|
<style>
|
||
|
text {
|
||
|
font-family: sans-serif;
|
||
|
}
|
||
|
</style>
|
||
|
</defs>
|
||
|
<%= content_tag :text, initials, x: 50, y: 50,
|
||
|
'font-size': 50, fill: 'white',
|
||
|
'dy': '.36em',
|
||
|
'text-anchor': 'middle' %>
|
||
|
</svg>
|
||
| public/stylesheets/application.css | ||
|---|---|---|
|
display: inline;
|
||
|
opacity: 1;
|
||
|
}
|
||
|
img.avatar-color-0 {
|
||
|
background-color: #880000;
|
||
|
}
|
||
|
img.avatar-color-1 {
|
||
|
background-color: #ff0000;
|
||
|
}
|
||
|
img.avatar-color-2 {
|
||
|
background-color: #00ff00;
|
||
|
}
|
||
|
img.avatar-color-3 {
|
||
|
background-color: #008800;
|
||
|
}
|
||
|
img.avatar-color-4 {
|
||
|
background-color: #0000ff;
|
||
|
}
|
||
|
img.avatar-color-5 {
|
||
|
background-color: #000088;
|
||
|
}
|
||
|
img.avatar-color-6 {
|
||
|
background-color: #ff8800;
|
||
|
}
|
||
|
img.avatar-color-7 {
|
||
|
background-color: #ff0088;
|
||
|
}
|
||