OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/app/helpers/avatar_helper.rb

39 lines
1.1 KiB

#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
#
# Copyright (C) 2012-2013 the OpenProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
module AvatarHelper
include GravatarHelper::PublicMethods
# 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 = { })
avatar = if Setting.gravatar_enabled? && (email = extract_email_address(user)).present?
options.merge!({ :ssl => (defined?(request) && request.ssl?),
:default => Setting.gravatar_default })
gravatar(email.to_s.downcase, options)
end
ensure
# return is actually needed here
return (avatar || ''.html_safe)
end
private
def extract_email_address(object)
if object.respond_to?(:mail)
object.mail
elsif object.to_s =~ %r{<(.+?)>}
$1
end
end
end