diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-11-09 14:52:16 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-11-09 14:52:16 +0000 |
commit | 7619c286cc27ed048f216f60972c50cea1564914 (patch) | |
tree | 01634fe4ac6bbc33159dc6d49cb48045e5d2ea25 | |
parent | 6157d20ec012fb34da66f0fe921b32036d582264 (diff) | |
download | redmine-7619c286cc27ed048f216f60972c50cea1564914.tar.gz redmine-7619c286cc27ed048f216f60972c50cea1564914.zip |
Changes ApplicationHelper#gravatar_for_mail to #avatar that takes a User or a String (less code in views).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2000 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/helpers/application_helper.rb | 13 | ||||
-rw-r--r-- | app/views/account/show.rhtml | 2 | ||||
-rw-r--r-- | app/views/issues/_history.rhtml | 2 | ||||
-rw-r--r-- | app/views/issues/show.rhtml | 4 | ||||
-rw-r--r-- | app/views/projects/activity.rhtml | 4 | ||||
-rw-r--r-- | app/views/users/list.rhtml | 2 | ||||
-rw-r--r-- | test/unit/helpers/application_helper_test.rb | 15 |
7 files changed, 31 insertions, 11 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 78fb4a328..81d81a966 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -21,6 +21,7 @@ require 'forwardable' module ApplicationHelper include Redmine::WikiFormatting::Macros::Definitions + include GravatarHelper::PublicMethods extend Forwardable def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter @@ -561,9 +562,17 @@ module ApplicationHelper (@has_content && @has_content[name]) || false end - def gravatar_for_mail(mail, options = { }) + # Returns the avatar image tag for the given +user+ if avatars are enabled + # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>') + def avatar(user, options = { }) if Setting.gravatar_enabled? - return gravatar(mail.to_s.downcase, options) rescue nil + email = nil + if user.respond_to?(:mail) + email = user.mail + elsif user.to_s =~ %r{<(.+?)>} + email = $1 + end + return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil end end diff --git a/app/views/account/show.rhtml b/app/views/account/show.rhtml index 305629a9c..175a11c75 100644 --- a/app/views/account/show.rhtml +++ b/app/views/account/show.rhtml @@ -2,7 +2,7 @@ <%= link_to(l(:button_edit), {:controller => 'users', :action => 'edit', :id => @user}, :class => 'icon icon-edit') if User.current.admin? %> </div> -<h2><%= gravatar_for_mail @user.mail unless @user.mail.empty? %> <%=h @user.name %></h2> +<h2><%= avatar @user %> <%=h @user.name %></h2> <p> <%= mail_to(h(@user.mail)) unless @user.pref.hide_mail %> diff --git a/app/views/issues/_history.rhtml b/app/views/issues/_history.rhtml index e65c4d4d6..2b30dadc5 100644 --- a/app/views/issues/_history.rhtml +++ b/app/views/issues/_history.rhtml @@ -4,7 +4,7 @@ <h4><div style="float:right;"><%= link_to "##{journal.indice}", :anchor => "note-#{journal.indice}" %></div> <%= content_tag('a', '', :name => "note-#{journal.indice}")%> <%= format_time(journal.created_on) %> - <%= journal.user.name %></h4> - <%= gravatar_for_mail(journal.user.mail.blank? ? "" : journal.user.mail, :size => "32") %> + <%= avatar(journal.user, :size => "32") %> <ul> <% for detail in journal.details %> <li><%= show_detail(detail) %></li> diff --git a/app/views/issues/show.rhtml b/app/views/issues/show.rhtml index 15b7b050e..6d6c41a33 100644 --- a/app/views/issues/show.rhtml +++ b/app/views/issues/show.rhtml @@ -10,7 +10,7 @@ <h2><%= @issue.tracker.name %> #<%= @issue.id %></h2> <div class="issue <%= "status-#{@issue.status.position} priority-#{@issue.priority.position}" %>"> - <%= gravatar_for_mail(@issue.author.mail, :size => "64") %> + <%= avatar(@issue.author, :size => "64") %> <h3><%=h @issue.subject %></h3> <p class="author"> <%= authoring @issue.created_on, @issue.author %>. @@ -27,7 +27,7 @@ <td class="due-date"><b><%=l(:field_due_date)%>:</b></td><td class="due-date"><%= format_date(@issue.due_date) %></td> </tr> <tr> - <td class="assigned-to"><b><%=l(:field_assigned_to)%>:</b></td><td><%= gravatar_for_mail(@issue.assigned_to.mail, :size => "14") unless @issue.assigned_to.blank?%><%= @issue.assigned_to ? link_to_user(@issue.assigned_to) : "-" %></td> + <td class="assigned-to"><b><%=l(:field_assigned_to)%>:</b></td><td><%= avatar(@issue.assigned_to, :size => "14") %><%= @issue.assigned_to ? link_to_user(@issue.assigned_to) : "-" %></td> <td class="progress"><b><%=l(:field_done_ratio)%>:</b></td><td class="progress"><%= progress_bar @issue.done_ratio, :width => '80px', :legend => "#{@issue.done_ratio}%" %></td> </tr> <tr> diff --git a/app/views/projects/activity.rhtml b/app/views/projects/activity.rhtml index 1c2591e09..01f7a3e59 100644 --- a/app/views/projects/activity.rhtml +++ b/app/views/projects/activity.rhtml @@ -7,9 +7,7 @@ <dl> <% @events_by_day[day].sort {|x,y| y.event_datetime <=> x.event_datetime }.each do |e| -%> <dt class="<%= e.event_type %> <%= User.current.logged? && e.respond_to?(:event_author) && User.current == e.event_author ? 'me' : nil %>"> - <%= gravatar_for_mail(e.user.mail, :size => "24") if e.respond_to?(:user) %> - <%= gravatar_for_mail(e.author.mail, :size => "24") if e.respond_to?(:author) %> - <%= gravatar_for_mail(e.committer.match('\\<.+?\\>')[0].gsub(/[<>]/, ''), :size => "24") if e.respond_to?(:committer) rescue nil %> + <%= avatar(e.event_author, :size => "24") if e.respond_to?(:event_author) %> <span class="time"><%= format_time(e.event_datetime, false) %></span> <%= content_tag('span', h(e.project), :class => 'project') if @project.nil? || @project != e.project %> <%= link_to format_activity_title(e.event_title), e.event_url %></dt> diff --git a/app/views/users/list.rhtml b/app/views/users/list.rhtml index 2b1cd1449..758f1767a 100644 --- a/app/views/users/list.rhtml +++ b/app/views/users/list.rhtml @@ -29,7 +29,7 @@ <tbody> <% for user in @users -%> <tr class="user <%= cycle("odd", "even") %> <%= %w(anon active registered locked)[user.status] %>"> - <td class="username"><%= gravatar_for_mail(user.mail.blank? ? "" : user.mail, :size => "24") %><%= link_to h(user.login), :action => 'edit', :id => user %></td> + <td class="username"><%= avatar(user, :size => "14") %><%= link_to h(user.login), :action => 'edit', :id => user %></td> <td class="firstname"><%= h(user.firstname) %></td> <td class="lastname"><%= h(user.lastname) %></td> <td class="email"><%= mail_to(h(user.mail)) %></td> diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index b3ff974e9..00e9b0a63 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -20,7 +20,7 @@ require File.dirname(__FILE__) + '/../../test_helper' class ApplicationHelperTest < HelperTestCase include ApplicationHelper include ActionView::Helpers::TextHelper - fixtures :projects, :roles, :enabled_modules, + fixtures :projects, :roles, :enabled_modules, :users, :repositories, :changesets, :trackers, :issue_statuses, :issues, :versions, :documents, :wikis, :wiki_pages, :wiki_contents, @@ -437,4 +437,17 @@ EXPECTED assert_equal expected, due_date_distance_in_words(date) end end + + def test_avatar + # turn on avatars + Setting.gravatar_enabled = '1' + assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) + assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) + assert_nil avatar('jsmith') + assert_nil avatar(nil) + + # turn off avatars + Setting.gravatar_enabled = '0' + assert_nil avatar(User.find_by_mail('jsmith@somenet.foo')) + end end |