From 9ae80b1e9eaf5302a0098ac3cbd7be468af6668a Mon Sep 17 00:00:00 2001 From: Carl Chenet Date: Fri, 19 May 2017 14:06:09 +0200 Subject: [PATCH] factor out avatar code to show 2x version everywhere --- app/helpers/application_helper.rb | 9 +++++++++ app/views/comments/_comment.html.erb | 4 ++-- app/views/stories/_listdetail.html.erb | 12 ++++-------- app/views/users/show.html.erb | 4 +--- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 69869f7..f294671 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index c4be4ce..51d3337 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -38,8 +38,8 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ? <% end %> <% if (@user && @user.show_avatars?) || !@user %> - + <%= + avatar_img(comment.user, 16) %> <% end %> <% end %> + <%= + avatar_img(ms.user, 16) %> <% end %> <% if story.user_is_author? %> <%= t('.authoredby') %> @@ -92,10 +90,8 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>
<% if (@user && @user.show_avatars?) || !@user %> - + <%= + avatar_img(story.user, 16) %> <% end %> <% if story.previewing %> <% if story.user_is_author? %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 10ca8ee..f9ee06a 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -17,9 +17,7 @@ <% if @showing_user.is_active? %>
- + <%= avatar_img(@showing_user, 100) %>
<% end %>