add option to show user avatars on stories and comments

just because
This commit is contained in:
joshua stein 2015-03-12 23:17:30 -05:00
parent 6734436e8c
commit d286eab325
8 changed files with 49 additions and 7 deletions

View file

@ -527,9 +527,18 @@ li .domain {
}
li .byline {
margin-bottom: -5px;
color: #888;
font-size: 8.5pt;
}
li .byline img.avatar {
border-radius: 8px;
height: 16px;
margin-bottom: 2px;
margin-right: 2px;
vertical-align: middle;
width: 16px;
}
li.story .byline {
margin-top: 1px;
}

View file

@ -81,7 +81,7 @@ private
:username, :email, :password, :password_confirmation, :about,
:email_replies, :email_messages, :email_mentions,
:pushover_replies, :pushover_messages, :pushover_mentions,
:mailing_list_mode
:mailing_list_mode, :show_avatars
)
end
end

View file

@ -83,9 +83,9 @@ class User < ActiveRecord::Base
h
end
def avatar_url
def avatar_url(size = 100)
"https://secure.gravatar.com/avatar/" +
Digest::MD5.hexdigest(self.email.strip.downcase) + "?r=pg&d=mm&s=100"
Digest::MD5.hexdigest(self.email.strip.downcase) + "?r=pg&d=mm&s=#{size}"
end
def average_karma

View file

@ -30,6 +30,10 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ?
<span class="merge"></span>
<% end %>
<% if @user && @user.show_avatars? %>
<img src="<%= comment.user.avatar_url(16) %>" class="avatar">
<% end %>
<a href="/u/<%= comment.user.username %>"
<% if !comment.user.is_active? %>
class="inactive_user"

View file

@ -170,6 +170,17 @@
</span>
</div>
<br>
<div class="legend">
Miscellaneous Settings
</div>
<div class="boxline">
<%= f.label :show_avatars, "Show User Avatars:", :class => "required" %>
<%= f.check_box :show_avatars %>
</div>
<br>
<%= f.submit "Save All Settings" %>

View file

@ -54,7 +54,11 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>
ms.domain %></a>
<% end %>
<span class="byline">
by <a href="/u/<%= ms.user.username %>"
by
<% if @user && @user.show_avatars? %>
<img src="<%= ms.user.avatar_url(16) %>" class="avatar">
<% end %>
<a href="/u/<%= ms.user.username %>"
<% if ms.user.is_new? %>
class="new_user"
<% end %>><%= ms.user.username %></a>
@ -67,10 +71,18 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>
<% end %>
<div class="byline">
<% if story.previewing %>
by <a><%= story.user.username %></a>
by
<% if @user && @user.show_avatars? %>
<img src="<%= story.user.avatar_url(16) %>" class="avatar">
<% end %>
<a><%= story.user.username %></a>
just now
<% else %>
by <a href="/u/<%= story.user.username %>"
<% if @user && @user.show_avatars? %>
<img src="<%= story.user.avatar_url(16) %>" class="avatar">
<% end %>
by
<a href="/u/<%= story.user.username %>"
<% if story.user.is_new? %>
class="new_user"
<% end %>><%= story.user.username %></a>

View file

@ -0,0 +1,5 @@
class AddUserAvatarPref < ActiveRecord::Migration
def change
add_column :users, :show_avatars, :boolean, :default => false
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150211170052) do
ActiveRecord::Schema.define(version: 20150313040930) do
create_table "comments", force: true do |t|
t.datetime "created_at", null: false
@ -186,6 +186,7 @@ ActiveRecord::Schema.define(version: 20150211170052) do
t.integer "banned_by_user_id"
t.string "banned_reason", limit: 200
t.datetime "deleted_at"
t.boolean "show_avatars", default: false
end
add_index "users", ["mailing_list_mode"], name: "mailing_list_enabled", using: :btree