Sha256: 206c101e51a766b3769b8e11faba3314e4079dfb139bade4b029c37d2ae45709

Contents?: true

Size: 688 Bytes

Versions: 6

Compression:

Stored size: 688 Bytes

Contents

module Trestle
  module AvatarHelper
    def avatar(options={})
      fallback = options.delete(:fallback) if options[:fallback]

      content_tag(:div, default_avatar_options.merge(options)) do
        concat content_tag(:span, fallback, class: "avatar-fallback") if fallback
        concat yield if block_given?
      end
    end

    def gravatar(email, options={})
      options = { d: "mp" }.merge(options)

      url = "https://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email.to_s.downcase)}.png"
      url << "?#{options.to_query}" if options.any?

      image_tag(url)
    end

    def default_avatar_options
      Trestle::Options.new(class: ["avatar"])
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
trestle-0.10.0 app/helpers/trestle/avatar_helper.rb
trestle-0.10.0.pre2 app/helpers/trestle/avatar_helper.rb
trestle-0.10.0.pre app/helpers/trestle/avatar_helper.rb
trestle-0.9.8 app/helpers/trestle/avatar_helper.rb
trestle-0.9.7 app/helpers/trestle/avatar_helper.rb
trestle-0.9.6 app/helpers/trestle/avatar_helper.rb