factor out avatar <img> code to show 2x version everywhere
This commit is contained in:
parent
fb421febce
commit
9ae80b1e9e
|
@ -1,6 +1,15 @@
|
||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
MAX_PAGES = 15
|
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)
|
def break_long_words(str, len = 30)
|
||||||
safe_join(str.split(" ").map{|w|
|
safe_join(str.split(" ").map{|w|
|
||||||
if w.length > len
|
if w.length > len
|
||||||
|
|
|
@ -38,8 +38,8 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ?
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if (@user && @user.show_avatars?) || !@user %>
|
<% if (@user && @user.show_avatars?) || !@user %>
|
||||||
<a href="/u/<%= comment.user.username %>"><img
|
<a href="/u/<%= comment.user.username %>"><%=
|
||||||
src="<%= comment.user.avatar_url(16) %>" class="avatar"></a>
|
avatar_img(comment.user, 16) %></a>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<a href="/u/<%= comment.user.username %>"
|
<a href="/u/<%= comment.user.username %>"
|
||||||
|
|
|
@ -62,10 +62,8 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<span class="byline">
|
<span class="byline">
|
||||||
<% if (@user && @user.show_avatars?) || !@user %>
|
<% if (@user && @user.show_avatars?) || !@user %>
|
||||||
<a href="/u/<%= ms.user.username %>"><img
|
<a href="/u/<%= ms.user.username %>"><%=
|
||||||
src="<%= ms.user.avatar_url(16) %>"
|
avatar_img(ms.user, 16) %></a>
|
||||||
srcset="<%= ms.user.avatar_url(16) %> 1x,
|
|
||||||
<%= ms.user.avatar_url(32) %> 2x" class="avatar"></a>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if story.user_is_author? %>
|
<% if story.user_is_author? %>
|
||||||
<%= t('.authoredby') %>
|
<%= t('.authoredby') %>
|
||||||
|
@ -92,10 +90,8 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>
|
||||||
|
|
||||||
<div class="byline">
|
<div class="byline">
|
||||||
<% if (@user && @user.show_avatars?) || !@user %>
|
<% if (@user && @user.show_avatars?) || !@user %>
|
||||||
<a href="/u/<%= story.user.username %>"><img
|
<a href="/u/<%= story.user.username %>"><%=
|
||||||
src="<%= story.user.avatar_url(16) %>"
|
avatar_img(story.user, 16) %></a>
|
||||||
srcset="<%= story.user.avatar_url(16) %> 1x,
|
|
||||||
<%= story.user.avatar_url(32) %> 2x" class="avatar"></a>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if story.previewing %>
|
<% if story.previewing %>
|
||||||
<% if story.user_is_author? %>
|
<% if story.user_is_author? %>
|
||||||
|
|
|
@ -17,9 +17,7 @@
|
||||||
|
|
||||||
<% if @showing_user.is_active? %>
|
<% if @showing_user.is_active? %>
|
||||||
<div id="gravatar">
|
<div id="gravatar">
|
||||||
<img src="<%= @showing_user.avatar_url(100) %>"
|
<%= avatar_img(@showing_user, 100) %>
|
||||||
srcset="<%= @showing_user.avatar_url(100) %> 1x,
|
|
||||||
<%= @showing_user.avatar_url(200) %> 2x">
|
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue