app/helpers/formol/posts_helper.rb in formol-0.0.4 vs app/helpers/formol/posts_helper.rb in formol-0.0.5
- old
+ new
@@ -21,7 +21,30 @@
def display_signatures?(user, post)
s = post.display_signature? && !post.user.preference.signature.blank?
(s && user ? user.preference.display_signatures? : s)
end
+
+ def avatar_for(user)
+ img = if user.respond_to?(:avatar_url) && user.avatar_url.present?
+ user.avatar_url
+ elsif user.respond_to?(:email) && user.email.present?
+ require 'digest/md5' unless defined?(Digest::MD5)
+
+ email_h = Digest::MD5.hexdigest(user.email.to_s.strip.downcase)
+ options = { :s => 100, :d => default_avatar }
+
+ "http://www.gravatar.com/avatar/#{email_h}?#{options.to_param}"
+ else
+ default_avatar
+ end
+
+ image_tag(img, :alt => user.display_name)
+ end
+
+ def default_avatar
+ img = Formol.config.default_avatar
+
+ img && URI(img).absolute? ? img : request.protocol + request.host_with_port + path_to_image(img)
+ end
end
end