Sha256: 2e06eb06bf4ec527a42979aa26d06614af251f9170f15b1f1991b7105ce118c5

Contents?: true

Size: 1.05 KB

Versions: 5

Compression:

Stored size: 1.05 KB

Contents

module UsersHelper
  def who(name)
    name = name.name if name.is_a? User
    return current_user.name == name ? "You" : name
  end

  def gravatar_img(user, options = {})
    image_tag gravatar_url(user.email), {:class => 'avatar'}.merge(options)
  end

  def gravatar_url(email = nil, size = 80)
    default = '/assets/adva_cms/avatar.gif'
    return default if Rails.env.test?
    return default if email.blank?
    require 'digest/md5'
    digest = Digest::MD5.hexdigest(email)
    # TODO #{ActionController::AbstractRequest.relative_url_root} missing in Rails 2.2
    "http://www.gravatar.com/avatar.php?size=#{size}&gravatar_id=#{digest}&default=http://#{request.host_with_port}/assets/adva_cms/avatar.gif"
  end

  def link_to_author resource, options = {}
    include_email = options[:include_email] && resource.respond_to?(:author_email)
    name = resource.author_name
    text = resource.author_homepage.blank? ? name : link_to(h(name), h(resource.author_homepage))
    text = "#{text} (#{resource.author_email})" if include_email
    text.html_safe
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
adva-0.2.4 app/helpers/users_helper.rb
adva-0.2.3 app/helpers/users_helper.rb
adva-0.2.2 app/helpers/users_helper.rb
adva-0.2.1 app/helpers/users_helper.rb
adva-0.2.0 app/helpers/users_helper.rb