From 7619c286cc27ed048f216f60972c50cea1564914 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 9 Nov 2008 14:52:16 +0000 Subject: [PATCH] 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 --- app/helpers/application_helper.rb | 13 +++++++++++-- app/views/account/show.rhtml | 2 +- app/views/issues/_history.rhtml | 2 +- app/views/issues/show.rhtml | 4 ++-- app/views/projects/activity.rhtml | 4 +--- app/views/users/list.rhtml | 2 +- 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 ') + 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? %> -

<%= gravatar_for_mail @user.mail unless @user.mail.empty? %> <%=h @user.name %>

+

<%= avatar @user %> <%=h @user.name %>

<%= 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 @@

<%= link_to "##{journal.indice}", :anchor => "note-#{journal.indice}" %>
<%= content_tag('a', '', :name => "note-#{journal.indice}")%> <%= format_time(journal.created_on) %> - <%= journal.user.name %>

- <%= gravatar_for_mail(journal.user.mail.blank? ? "" : journal.user.mail, :size => "32") %> + <%= avatar(journal.user, :size => "32") %>