factor out avatar <img> code to show 2x version everywhere

This commit is contained in:
Carl Chenet 2017-05-19 14:06:09 +02:00
parent fb421febce
commit 9ae80b1e9e
4 changed files with 16 additions and 13 deletions

View File

@ -1,6 +1,15 @@
module ApplicationHelper
MAX_PAGES = 15
def avatar_img(user, size)
image_tag(user.avatar_url(size), {
:srcset => "#{user.avatar_url(size)} 1x, " <<
"#{user.avatar_url(size * 2)} 2x",
:class => "avatar",
:size => "#{size}x#{size}",
:alt => "#{user.username} avatar" })
end
def break_long_words(str, len = 30)
safe_join(str.split(" ").map{|w|
if w.length > len

View File

@ -38,8 +38,8 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ?
<% end %>
<% if (@user && @user.show_avatars?) || !@user %>
<a href="/u/<%= comment.user.username %>"><img
src="<%= comment.user.avatar_url(16) %>" class="avatar"></a>
<a href="/u/<%= comment.user.username %>"><%=
avatar_img(comment.user, 16) %></a>
<% end %>
<a href="/u/<%= comment.user.username %>"

View File

@ -62,10 +62,8 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>
<% end %>
<span class="byline">
<% if (@user && @user.show_avatars?) || !@user %>
<a href="/u/<%= ms.user.username %>"><img
src="<%= ms.user.avatar_url(16) %>"
srcset="<%= ms.user.avatar_url(16) %> 1x,
<%= ms.user.avatar_url(32) %> 2x" class="avatar"></a>
<a href="/u/<%= ms.user.username %>"><%=
avatar_img(ms.user, 16) %></a>
<% end %>
<% if story.user_is_author? %>
<%= t('.authoredby') %>
@ -92,10 +90,8 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>
<div class="byline">
<% if (@user && @user.show_avatars?) || !@user %>
<a href="/u/<%= story.user.username %>"><img
src="<%= story.user.avatar_url(16) %>"
srcset="<%= story.user.avatar_url(16) %> 1x,
<%= story.user.avatar_url(32) %> 2x" class="avatar"></a>
<a href="/u/<%= story.user.username %>"><%=
avatar_img(story.user, 16) %></a>
<% end %>
<% if story.previewing %>
<% if story.user_is_author? %>

View File

@ -17,9 +17,7 @@
<% if @showing_user.is_active? %>
<div id="gravatar">
<img src="<%= @showing_user.avatar_url(100) %>"
srcset="<%= @showing_user.avatar_url(100) %> 1x,
<%= @showing_user.avatar_url(200) %> 2x">
<%= avatar_img(@showing_user, 100) %>
</div>
<% end %>