Sha256: 8c9ae86d623d9d6342f4691daba79ae989d63e50ec92676771d6f3a7062ba413
Contents?: true
Size: 1.35 KB
Versions: 2
Compression:
Stored size: 1.35 KB
Contents
# The view helper, especially for the +gravatar_tag+ helper, requires # rails! module Gravatarify::ViewHelper include Gravatarify::Base # Ensure proper gravatar_url method is available! alias_method :gravatar_url, :build_gravatar_url # Create <img .../> tag by passing +email+ to +gravatar_url+, is based # on rails +image_tag+ helper method. # # <%= gravatar_tag(current_user.email, :size => 20) %> # -> <img alt="... height="20" src="http://grava... width="20" /> # <%= gravatar_tag('foo@bar.com', :class => "gravatar") # -> <img alt="foo@bar.com" class="gravatar" height="80" ... width="80" /> # # Note: this method tries to be very clever about which options need to be passed to # +gravatar_url+ and which to +image_tag+, so using this method it's not possible to # send arbitary attributes to +gravatar_url+ and have them included in the url. def gravatar_tag(email, options = {}) url_options = options.symbolize_keys.reject { |key,value| !Gravatarify::GRAVATAR_OPTIONS.include?(key) } options[:alt] ||= Gravatarify::Base.get_smart_email_from(email) # use email as :alt attribute options[:width] = options[:height] = (url_options[:size] || Gravatarify::GRAVATAR_DEFAULT_SIZE) # customize size image_tag(email.respond_to?(:gravatar_url) ? email.gravatar_url(url_options) : gravatar_url(email, url_options), options) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gravatarify-1.1.0 | lib/gravatarify/view_helper.rb |
gravatarify-1.0.0 | lib/gravatarify/view_helper.rb |