Commit b598154cc1462d78905fa2afd2584d764ff3c599

Authored by Nathan Broadbent
2 parents f6c22e88 b4cea2f9
Exists in master and in 1 other branch production

Merge pull request #232 from BlackFoks/add_gravatars

Gravatars
app/assets/stylesheets/errbit.css
... ... @@ -841,6 +841,9 @@ table.comment tbody th {
841 841 height: 20px;
842 842 line-height: 0.5em;
843 843 }
  844 +table.comment tbody th img {
  845 + float: right;
  846 +}
844 847 table.comment tbody td {
845 848 background-color: #F9F9F9;
846 849 }
... ...
app/helpers/errs_helper.rb
... ... @@ -13,5 +13,17 @@ module ErrsHelper
13 13 truncate(msg, :length => 300).scan(/.{1,5}/).map { |s| h(s) }.join("​").html_safe
14 14 end
15 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 28 end
17 29  
... ...
app/views/errs/show.html.haml
... ... @@ -31,6 +31,8 @@
31 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 32 = time_ago_in_words(comment.created_at, true) << " ago by "
33 33 = link_to comment.user.email, user_path(comment.user)
  34 + - if Errbit::Config.use_gravatar
  35 + = gravatar_tag comment.user.email
34 36 %tr
35 37 %td= comment.body.gsub("\n", "<br>").html_safe
36 38 - if Errbit::Config.allow_comments_with_issue_tracker || !@app.issue_tracker_configured?
... ...
config/config.example.yml
... ... @@ -39,6 +39,13 @@ user_has_username: false
39 39 # but you want to leave a short comment.
40 40 allow_comments_with_issue_tracker: true
41 41  
  42 +# Enable Gravatar.
  43 +use_gravatar: false
  44 +# Default Gravatar size.
  45 +gravatar_size: 40
  46 +# Default Gravatar image, can be: mm, identicon, monsterid, wavatar, retro.
  47 +gravatar_default: identicon
  48 +
42 49 # Setup your deploy options for capistrano.
43 50 deployment:
44 51 hosts:
... ...
config/initializers/_load_config.rb
... ... @@ -14,6 +14,10 @@ unless defined?(Errbit::Config)
14 14 Errbit::Config.user_has_username = ENV['ERRBIT_USER_HAS_USERNAME']
15 15 Errbit::Config.allow_comments_with_issue_tracker = ENV['ERRBIT_ALLOW_COMMENTS_WITH_ISSUE_TRACKER']
16 16  
  17 + Errbit::Config.use_gravatar = ENV['ERRBIT_USE_GRAVATAR']
  18 + Errbit::Config.gravatar_size = ENV['ERRBIT_GRAVATAR_SIZE']
  19 + Errbit::Config.gravatar_default = ENV['ERRBIT_GRAVATAR_DEFAULT']
  20 +
17 21 Errbit::Config.github_authentication = ENV['GITHUB_AUTHENTICATION']
18 22 Errbit::Config.github_client_id = ENV['GITHUB_CLIENT_ID']
19 23 Errbit::Config.github_secret = ENV['GITHUB_SECRET']
... ...
spec/helpers/errs_helper_spec.rb
... ... @@ -9,4 +9,43 @@ describe ErrsHelper do
9 9 truncated.should_not include('<', '>')
10 10 end
11 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&amp;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&amp;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&amp;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&amp;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&amp;s=48\" />"
  47 + helper.gravatar_tag(email, :align => :left).should eq(expected)
  48 + end
  49 + end
  50 + end
12 51 end
... ...
spec/views/errs/show.html.haml_spec.rb
... ... @@ -90,6 +90,7 @@ describe &quot;errs/show.html.haml&quot; do
90 90 describe "content_for :comments with comments disabled for configured issue tracker" do
91 91 before do
92 92 Errbit::Config.stub(:allow_comments_with_issue_tracker).and_return(false)
  93 + Errbit::Config.stub(:use_gravatar).and_return(true)
93 94 end
94 95  
95 96 it 'should display comments and new comment form when no issue tracker' do
... ... @@ -99,6 +100,7 @@ describe &quot;errs/show.html.haml&quot; do
99 100 render
100 101  
101 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 104 view.content_for(:comments).should include('Add a comment')
103 105 end
104 106  
... ... @@ -117,6 +119,7 @@ describe &quot;errs/show.html.haml&quot; do
117 119 render
118 120  
119 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 123 view.content_for(:comments).should_not include('Add a comment')
121 124 end
122 125 end
... ...