Commit 717faee79a87868cca4add5dc889fe9edd542d86
1 parent
f6c22e88
Exists in
master
and in
1 other branch
Add gravatars to comments
Showing
5 changed files
with
59 additions
and
0 deletions
Show diff stats
app/assets/stylesheets/errbit.css
@@ -841,6 +841,9 @@ table.comment tbody th { | @@ -841,6 +841,9 @@ table.comment tbody th { | ||
841 | height: 20px; | 841 | height: 20px; |
842 | line-height: 0.5em; | 842 | line-height: 0.5em; |
843 | } | 843 | } |
844 | +table.comment tbody th img { | ||
845 | + float: right; | ||
846 | +} | ||
844 | table.comment tbody td { | 847 | table.comment tbody td { |
845 | background-color: #F9F9F9; | 848 | background-color: #F9F9F9; |
846 | } | 849 | } |
app/helpers/errs_helper.rb
@@ -13,5 +13,17 @@ module ErrsHelper | @@ -13,5 +13,17 @@ module ErrsHelper | ||
13 | truncate(msg, :length => 300).scan(/.{1,5}/).map { |s| h(s) }.join("​").html_safe | 13 | truncate(msg, :length => 300).scan(/.{1,5}/).map { |s| h(s) }.join("​").html_safe |
14 | end | 14 | end |
15 | end | 15 | end |
16 | + | ||
17 | + def gravatar_tag(email, options = {}) | ||
18 | + default_options = { | ||
19 | + :s => Errbit::Config.gravatar_size, | ||
20 | + :d => Errbit::Config.gravatar_default, | ||
21 | + :alt => email | ||
22 | + } | ||
23 | + options.reverse_merge! default_options | ||
24 | + params = options.extract!(:s, :d).delete_if { |k, v| v.blank? } | ||
25 | + email_hash = Digest::MD5.hexdigest(email) | ||
26 | + image_tag "http://www.gravatar.com/avatar/#{email_hash}?#{params.to_query}", options | ||
27 | + end | ||
16 | end | 28 | end |
17 | 29 |
app/views/errs/show.html.haml
@@ -31,6 +31,8 @@ | @@ -31,6 +31,8 @@ | ||
31 | %span= link_to '✘'.html_safe, app_err_comment_path(@app, @problem, comment), :method => :delete, :data => { :confirm => "Are sure you don't need this comment?" }, :class => "destroy-comment" | 31 | %span= link_to '✘'.html_safe, app_err_comment_path(@app, @problem, comment), :method => :delete, :data => { :confirm => "Are sure you don't need this comment?" }, :class => "destroy-comment" |
32 | = time_ago_in_words(comment.created_at, true) << " ago by " | 32 | = time_ago_in_words(comment.created_at, true) << " ago by " |
33 | = link_to comment.user.email, user_path(comment.user) | 33 | = link_to comment.user.email, user_path(comment.user) |
34 | + - if Errbit::Config.use_gravatar | ||
35 | + = gravatar_tag comment.user.email | ||
34 | %tr | 36 | %tr |
35 | %td= comment.body.gsub("\n", "<br>").html_safe | 37 | %td= comment.body.gsub("\n", "<br>").html_safe |
36 | - if Errbit::Config.allow_comments_with_issue_tracker || !@app.issue_tracker_configured? | 38 | - if Errbit::Config.allow_comments_with_issue_tracker || !@app.issue_tracker_configured? |
spec/helpers/errs_helper_spec.rb
@@ -9,4 +9,43 @@ describe ErrsHelper do | @@ -9,4 +9,43 @@ describe ErrsHelper do | ||
9 | truncated.should_not include('<', '>') | 9 | truncated.should_not include('<', '>') |
10 | end | 10 | end |
11 | end | 11 | end |
12 | + | ||
13 | + describe "#gravatar_tag" do | ||
14 | + let(:email) { "gravatar@example.com" } | ||
15 | + let(:email_hash) { Digest::MD5.hexdigest email } | ||
16 | + let(:base_url) { "http://www.gravatar.com/avatar/#{email_hash}" } | ||
17 | + | ||
18 | + context "default config" do | ||
19 | + before do | ||
20 | + Errbit::Config.stub(:use_gravatar).and_return(true) | ||
21 | + Errbit::Config.stub(:gravatar_size).and_return(48) | ||
22 | + Errbit::Config.stub(:gravatar_default).and_return('identicon') | ||
23 | + end | ||
24 | + | ||
25 | + it "should render image_tag with correct alt and src" do | ||
26 | + expected = "<img alt=\"#{email}\" src=\"#{base_url}?d=identicon&s=48\" />" | ||
27 | + helper.gravatar_tag(email).should eq(expected) | ||
28 | + end | ||
29 | + | ||
30 | + it "should override :s" do | ||
31 | + expected = "<img alt=\"#{email}\" src=\"#{base_url}?d=identicon&s=64\" />" | ||
32 | + helper.gravatar_tag(email, :s => 64).should eq(expected) | ||
33 | + end | ||
34 | + | ||
35 | + it "should override :d" do | ||
36 | + expected = "<img alt=\"#{email}\" src=\"#{base_url}?d=retro&s=48\" />" | ||
37 | + helper.gravatar_tag(email, :d => 'retro').should eq(expected) | ||
38 | + end | ||
39 | + | ||
40 | + it "should override alt" do | ||
41 | + expected = "<img alt=\"gravatar\" src=\"#{base_url}?d=identicon&s=48\" />" | ||
42 | + helper.gravatar_tag(email, :alt => 'gravatar').should eq(expected) | ||
43 | + end | ||
44 | + | ||
45 | + it "should pass other options to image_tag" do | ||
46 | + expected = "<img align=\"left\" alt=\"#{email}\" src=\"#{base_url}?d=identicon&s=48\" />" | ||
47 | + helper.gravatar_tag(email, :align => :left).should eq(expected) | ||
48 | + end | ||
49 | + end | ||
50 | + end | ||
12 | end | 51 | end |
spec/views/errs/show.html.haml_spec.rb
@@ -90,6 +90,7 @@ describe "errs/show.html.haml" do | @@ -90,6 +90,7 @@ describe "errs/show.html.haml" do | ||
90 | describe "content_for :comments with comments disabled for configured issue tracker" do | 90 | describe "content_for :comments with comments disabled for configured issue tracker" do |
91 | before do | 91 | before do |
92 | Errbit::Config.stub(:allow_comments_with_issue_tracker).and_return(false) | 92 | Errbit::Config.stub(:allow_comments_with_issue_tracker).and_return(false) |
93 | + Errbit::Config.stub(:use_gravatar).and_return(true) | ||
93 | end | 94 | end |
94 | 95 | ||
95 | it 'should display comments and new comment form when no issue tracker' do | 96 | it 'should display comments and new comment form when no issue tracker' do |
@@ -99,6 +100,7 @@ describe "errs/show.html.haml" do | @@ -99,6 +100,7 @@ describe "errs/show.html.haml" do | ||
99 | render | 100 | render |
100 | 101 | ||
101 | view.content_for(:comments).should include('Test comment') | 102 | view.content_for(:comments).should include('Test comment') |
103 | + view.content_for(:comments).should have_selector('img[src^="http://www.gravatar.com/avatar"]') | ||
102 | view.content_for(:comments).should include('Add a comment') | 104 | view.content_for(:comments).should include('Add a comment') |
103 | end | 105 | end |
104 | 106 | ||
@@ -117,6 +119,7 @@ describe "errs/show.html.haml" do | @@ -117,6 +119,7 @@ describe "errs/show.html.haml" do | ||
117 | render | 119 | render |
118 | 120 | ||
119 | view.content_for(:comments).should include('Test comment') | 121 | view.content_for(:comments).should include('Test comment') |
122 | + view.content_for(:comments).should have_selector('img[src^="http://www.gravatar.com/avatar"]') | ||
120 | view.content_for(:comments).should_not include('Add a comment') | 123 | view.content_for(:comments).should_not include('Add a comment') |
121 | end | 124 | end |
122 | end | 125 | end |