Project

General

Profile

Feature #29824 » 0001-Generates-a-color-from-the-user-s-ID-without-using-C.patch

Marius BĂLTEANU, 2025-08-07 21:54

View differences:

app/assets/stylesheets/application.css
user-select: none;
font-weight: 700;
}
.avatar.s13 {
block-size: 13px;
inline-size: 13px;
}
span[role="img"].avatar.s13 {
font-size: calc(16px * .3);
}
.avatar.s16 {
block-size: 16px;
inline-size: 16px;
}
span[role="img"].avatar.s16 {
font-size: calc(16px * .4);
}
.avatar.s22 {
block-size: 22px;
inline-size: 22px;
}
span[role="img"].avatar.s22 {
font-size: calc(22px * .4);
}
.avatar.s24 {
block-size: 24px;
inline-size: 24px;
}
span[role="img"].avatar.s24 {
font-size: calc(24px * .4);
}
.avatar.s40 {
block-size: 40px;
inline-size: 40px;
}
span[role="img"].avatar.s40 {
font-size: calc(40px * .4);
}
.avatar.s50 {
block-size: 50px;
inline-size: 50px;
}
span[role="img"].avatar.s50 {
font-size: calc(50px * .4);
}
.avatar-color-0 {
background-color: #880000;
color: #FFFFFF;
}
.avatar-color-1 {
background-color: #ff0000;
color: #000000;
}
.avatar-color-2 {
background-color: #00ff00;
color: #000000;
}
.avatar-color-3 {
background-color: #008800;
color: #FFFFFF;
}
.avatar-color-4 {
background-color: #0000ff;
color: #FFFFFF;
}
.avatar-color-5 {
background-color: #000088;
color: #FFFFFF;
}
.avatar-color-6 {
background-color: #ff8800;
color: #000000;
}
.avatar-color-7 {
background-color: #ff0088;
color: #000000;
}
/* Reaction styles */
.reaction-button:hover, .reaction-button:active {
app/helpers/avatars_helper.rb
nil
end
elsif user.respond_to?(:initials)
size = options.delete(:size) || GravatarHelper::DEFAULT_OPTIONS[:size]
css_class = "avatar-color-#{user.id % 8} avatar s#{size}"
size = (options.delete(:size) || GravatarHelper::DEFAULT_OPTIONS[:size]).to_i
# Generate a color from the user's ID
hue = (user.id * 137.508).modulo(360) # Using the golden angle for a good color distribution
background_color = "hsl(#{hue}, 50%, 45%)"
text_color = "#FFFFFF"
style = "width: #{size}px; height: #{size}px; font-size: #{size * 0.45}px; background-color: #{background_color}; color: #{text_color};"
css_class = "avatar"
css_class += " #{options[:class]}" if options[:class]
content_tag('span', user.initials, role: 'img', class: css_class)
content_tag('span', user.initials, role: 'img', class: css_class, style: style)
else
''
end
(6-6/7)