gravatarify 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +15 -5
 - data/Rakefile +4 -3
 - data/VERSION.yml +1 -1
 - data/lib/gravatarify/base.rb +14 -24
 - data/lib/gravatarify/helper.rb +25 -6
 - data/lib/gravatarify/object_support.rb +2 -1
 - data/test/test_helper.rb +7 -1
 - data/test/unit/gravatarify_base_test.rb +6 -3
 - data/test/unit/gravatarify_helper_test.rb +51 -20
 - metadata +6 -5
 
    
        data/README.md
    CHANGED
    
    | 
         @@ -60,7 +60,7 @@ When using Rails or HAML these should be automatically available, if not do some 
     | 
|
| 
       60 
60 
     | 
    
         | 
| 
       61 
61 
     | 
    
         
             
            This then provides three helper methods: `gravatar_url`, `gravatar_attrs` and `gravatar_tag`.
         
     | 
| 
       62 
62 
     | 
    
         
             
            To just build a simple `<img/>` tag, pass in an object (if it responds to `email` or `mail`)
         
     | 
| 
       63 
     | 
    
         
            -
            or a string  
     | 
| 
      
 63 
     | 
    
         
            +
            or a string containing the e-mail address:
         
     | 
| 
       64 
64 
     | 
    
         | 
| 
       65 
65 
     | 
    
         
             
                <%= gravatar_tag @user %> # => assumes @user has email or mail field!
         
     | 
| 
       66 
66 
     | 
    
         | 
| 
         @@ -188,7 +188,7 @@ Need more control? 
     | 
|
| 
       188 
188 
     | 
    
         
             
              </tr>
         
     | 
| 
       189 
189 
     | 
    
         
             
            </table>
         
     | 
| 
       190 
190 
     | 
    
         | 
| 
       191 
     | 
    
         
            -
            To options globally, access the `Gravatarify.options` hash and set any options which should apply to all
         
     | 
| 
      
 191 
     | 
    
         
            +
            To set the options globally, access the `Gravatarify.options` hash and set any options which should apply to all
         
     | 
| 
       192 
192 
     | 
    
         
             
            gravatar urls there. Of course all settings can be overridden locally:
         
     | 
| 
       193 
193 
     | 
    
         | 
| 
       194 
194 
     | 
    
         
             
                # disable suffix and set default size to 16x16px
         
     | 
| 
         @@ -197,7 +197,13 @@ gravatar urls there. Of course all settings can be overridden locally: 
     | 
|
| 
       197 
197 
     | 
    
         | 
| 
       198 
198 
     | 
    
         
             
                gravatar_url(@user.email) # => http://0.gravatar.com/avatar/..f93ff1e?s=16
         
     | 
| 
       199 
199 
     | 
    
         
             
                gravatar_url(@user.email, :filetype => :png) # => http://0.gravatar.com/avatar/..f93ff1e.png?s=16
         
     | 
| 
      
 200 
     | 
    
         
            +
                
         
     | 
| 
      
 201 
     | 
    
         
            +
            A pretty nifty option also exists to set options globally for `gravatar_tag` and `gravatar_attrs`, e.g.
         
     | 
| 
      
 202 
     | 
    
         
            +
            to always add a title attribute:
         
     | 
| 
       200 
203 
     | 
    
         | 
| 
      
 204 
     | 
    
         
            +
                # add title attribute
         
     | 
| 
      
 205 
     | 
    
         
            +
                Gravatarify::Helper.html_options[:title] = "Gravatar"
         
     | 
| 
      
 206 
     | 
    
         
            +
                
         
     | 
| 
       201 
207 
     | 
    
         
             
            ### Not yet enough?
         
     | 
| 
       202 
208 
     | 
    
         | 
| 
       203 
209 
     | 
    
         
             
            The `:default` option can be passed in a `Proc`, so this is certainly useful to for example
         
     | 
| 
         @@ -228,7 +234,7 @@ it should evaluate against `request.ssl?` for example. 
     | 
|
| 
       228 
234 
     | 
    
         
             
            About the code
         
     | 
| 
       229 
235 
     | 
    
         
             
            ==============
         
     | 
| 
       230 
236 
     | 
    
         | 
| 
       231 
     | 
    
         
            -
            Eventhough this library has  
     | 
| 
      
 237 
     | 
    
         
            +
            Eventhough this library has about 100 LOC, it's split into four files, maybe a bit
         
     | 
| 
       232 
238 
     | 
    
         
             
            of an overkill, though I like neat and tidy classes :)
         
     | 
| 
       233 
239 
     | 
    
         | 
| 
       234 
240 
     | 
    
         
             
                lib/gravatarify.rb                      # loads the other files from lib/gravatarify
         
     | 
| 
         @@ -245,13 +251,17 @@ of an overkill, though I like neat and tidy classes :) 
     | 
|
| 
       245 
251 
     | 
    
         
             
                                                        # gravatarify class method to add a gravatar_url
         
     | 
| 
       246 
252 
     | 
    
         
             
                                                        # to any object.
         
     | 
| 
       247 
253 
     | 
    
         | 
| 
       248 
     | 
    
         
            -
                lib/gravatarify/helper.rb               # Defines those view helpers, mainly  
     | 
| 
       249 
     | 
    
         
            -
             
     | 
| 
      
 254 
     | 
    
         
            +
                lib/gravatarify/helper.rb               # Defines those view helpers, mainly gravatar_attrs
         
     | 
| 
      
 255 
     | 
    
         
            +
                                                        # and gravatar_tag
         
     | 
| 
       250 
256 
     | 
    
         
             
            ### Contribute
         
     | 
| 
       251 
257 
     | 
    
         | 
| 
       252 
258 
     | 
    
         
             
             1. Fork the project and hack away
         
     | 
| 
       253 
259 
     | 
    
         
             
             2. Ensure that the changes are well tested
         
     | 
| 
       254 
260 
     | 
    
         
             
             3. Send me a pull request
         
     | 
| 
      
 261 
     | 
    
         
            +
             
         
     | 
| 
      
 262 
     | 
    
         
            +
            ### Thanks
         
     | 
| 
      
 263 
     | 
    
         
            +
             
     | 
| 
      
 264 
     | 
    
         
            +
             - [gudleik](http://github.com/gudleik) for his work on allowing an empty `:filetype`
         
     | 
| 
       255 
265 
     | 
    
         | 
| 
       256 
266 
     | 
    
         
             
            Licence
         
     | 
| 
       257 
267 
     | 
    
         
             
            =======
         
     | 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -30,10 +30,11 @@ begin 
     | 
|
| 
       30 
30 
     | 
    
         
             
              require 'jeweler'
         
     | 
| 
       31 
31 
     | 
    
         
             
              Jeweler::Tasks.new do |gemspec|
         
     | 
| 
       32 
32 
     | 
    
         
             
                gemspec.name = "gravatarify"
         
     | 
| 
       33 
     | 
    
         
            -
                gemspec.summary = "Awesome gravatar support for  
     | 
| 
      
 33 
     | 
    
         
            +
                gemspec.summary = "Awesome gravatar support for Ruby (and Rails, DataMapper, Haml)."
         
     | 
| 
       34 
34 
     | 
    
         
             
                description = <<-DESC
         
     | 
| 
       35 
     | 
    
         
            -
                 
     | 
| 
       36 
     | 
    
         
            -
                 
     | 
| 
      
 35 
     | 
    
         
            +
                Awesome gravatar support for Ruby (and Rails, DataMapper, Haml) -
         
     | 
| 
      
 36 
     | 
    
         
            +
                with unique options like Proc's for default images, or
         
     | 
| 
      
 37 
     | 
    
         
            +
                support for gravatar.com's multiple host names.
         
     | 
| 
       37 
38 
     | 
    
         
             
                DESC
         
     | 
| 
       38 
39 
     | 
    
         
             
                gemspec.description = description.strip
         
     | 
| 
       39 
40 
     | 
    
         
             
                gemspec.email = "lukas.westermann@gmail.com"
         
     | 
    
        data/VERSION.yml
    CHANGED
    
    
    
        data/lib/gravatarify/base.rb
    CHANGED
    
    | 
         @@ -1,19 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'digest/md5'
         
     | 
| 
       2 
2 
     | 
    
         
             
            begin; require 'rack/utils'; rescue LoadError; require 'cgi' end
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            module Gravatarify
         
     | 
| 
       5 
     | 
    
         
            -
              # Subdomains used for balancing
         
     | 
| 
       6 
     | 
    
         
            -
              GRAVATAR_SUBDOMAINS = %w{ 0 1 2 www } 
         
     | 
| 
       7 
     | 
    
         
            -
              
         
     | 
| 
       8 
     | 
    
         
            -
              # Fallback if no subdomain is found
         
     | 
| 
       9 
     | 
    
         
            -
              GRAVATAR_DEFAULT_SUBDOMAIN = 'www'
         
     | 
| 
       10 
     | 
    
         
            -
              
         
     | 
| 
       11 
     | 
    
         
            -
              # If no size is specified, gravatar.com returns 80x80px images
         
     | 
| 
       12 
     | 
    
         
            -
              GRAVATAR_DEFAULT_SIZE = 80
         
     | 
| 
       13 
     | 
    
         
            -
              
         
     | 
| 
       14 
     | 
    
         
            -
              # Default filetype is JPG
         
     | 
| 
       15 
     | 
    
         
            -
              GRAVATAR_DEFAULT_FILETYPE = :jpg
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
            module Gravatarify  
         
     | 
| 
       17 
5 
     | 
    
         
             
              # List of known and valid gravatar options (includes shortened options).
         
     | 
| 
       18 
6 
     | 
    
         
             
              GRAVATAR_OPTIONS = [ :default, :d, :rating, :r, :size, :s, :secure, :filetype ]
         
     | 
| 
       19 
7 
     | 
    
         | 
| 
         @@ -35,7 +23,7 @@ module Gravatarify 
     | 
|
| 
       35 
23 
     | 
    
         
             
                #     # or disable adding an extension
         
     | 
| 
       36 
24 
     | 
    
         
             
                #     Gravatarify.options[:filetype] = false
         
     | 
| 
       37 
25 
     | 
    
         
             
                #
         
     | 
| 
       38 
     | 
    
         
            -
                def options; @options ||= {} end
         
     | 
| 
      
 26 
     | 
    
         
            +
                def options; @options ||= { :filetype => :jpg } end
         
     | 
| 
       39 
27 
     | 
    
         | 
| 
       40 
28 
     | 
    
         
             
                # Globally overide subdomains used to build gravatar urls, normally
         
     | 
| 
       41 
29 
     | 
    
         
             
                # +gravatarify+ picks from either +0.gravatar.com+, +1.gravatar.com+,
         
     | 
| 
         @@ -53,16 +41,16 @@ module Gravatarify 
     | 
|
| 
       53 
41 
     | 
    
         
             
                # i.e. disable host balancing!
         
     | 
| 
       54 
42 
     | 
    
         
             
                def use_www_only!; self.subdomains = %w{ www } end
         
     | 
| 
       55 
43 
     | 
    
         | 
| 
       56 
     | 
    
         
            -
                # Access currently defined subdomains, defaults are  
     | 
| 
       57 
     | 
    
         
            -
                def subdomains; @subdomains ||=  
     | 
| 
      
 44 
     | 
    
         
            +
                # Access currently defined subdomains, defaults are +%w{ 0 1 2 www }+.
         
     | 
| 
      
 45 
     | 
    
         
            +
                def subdomains; @subdomains ||= %w{ 0 1 2 www } end
         
     | 
| 
       58 
46 
     | 
    
         | 
| 
       59 
     | 
    
         
            -
                # Get subdomain for supplied string or returns + 
     | 
| 
      
 47 
     | 
    
         
            +
                # Get subdomain for supplied string or returns +www+ if none is
         
     | 
| 
       60 
48 
     | 
    
         
             
                # defined.
         
     | 
| 
       61 
     | 
    
         
            -
                def subdomain(str); subdomains[str.hash % subdomains.size] ||  
     | 
| 
      
 49 
     | 
    
         
            +
                def subdomain(str); subdomains[str.hash % subdomains.size] || 'www' end
         
     | 
| 
       62 
50 
     | 
    
         | 
| 
       63 
     | 
    
         
            -
                # Helper method to escape string using either <tt>Rack::Utils</tt> if available or else
         
     | 
| 
      
 51 
     | 
    
         
            +
                # Helper method to URI escape a string using either <tt>Rack::Utils#escape</tt> if available or else
         
     | 
| 
       64 
52 
     | 
    
         
             
                # fallback to <tt>CGI#escape</tt>.
         
     | 
| 
       65 
     | 
    
         
            -
                def escape(str)
         
     | 
| 
      
 53 
     | 
    
         
            +
                def escape(str) #:nodoc:
         
     | 
| 
       66 
54 
     | 
    
         
             
                  str = str.to_s unless str.is_a?(String) # convert to string!
         
     | 
| 
       67 
55 
     | 
    
         
             
                  defined?(Rack::Utils) ? Rack::Utils.escape(str) : CGI.escape(str)
         
     | 
| 
       68 
56 
     | 
    
         
             
                end
         
     | 
| 
         @@ -104,14 +92,14 @@ module Gravatarify 
     | 
|
| 
       104 
92 
     | 
    
         
             
                # @option url_options [Integer] :size (80) The size of the (square) image.
         
     | 
| 
       105 
93 
     | 
    
         
             
                # @option url_options [Boolean, Proc] :secure (false) If set to +true+, then uses the secure gravatar.com URL. If a Proc is
         
     | 
| 
       106 
94 
     | 
    
         
             
                #                                     supplied it's evaluated, the Proc should evaluate to +true+ or +false+.
         
     | 
| 
       107 
     | 
    
         
            -
                # @option url_options [String, Symbol] :filetype (:jpg) Gravatar.com supports only <tt>:gif</tt>, <tt>:jpg</tt> and <tt>:png</tt 
     | 
| 
      
 95 
     | 
    
         
            +
                # @option url_options [String, Symbol] :filetype (:jpg) Gravatar.com supports only <tt>:gif</tt>, <tt>:jpg</tt> and <tt>:png</tt>.
         
     | 
| 
      
 96 
     | 
    
         
            +
                #                                      if an set to +false+, +nil+ or an empty string no extension is added.
         
     | 
| 
       108 
97 
     | 
    
         
             
                # @return [String] In any case (even if supplied +email+ is +nil+) returns a fully qualified gravatar.com URL.
         
     | 
| 
       109 
98 
     | 
    
         
             
                #                  The returned string is not yet HTML escaped, *but* all +url_options+ have been URI escaped.
         
     | 
| 
       110 
99 
     | 
    
         
             
                def build_gravatar_url(email, url_options = {})
         
     | 
| 
       111 
     | 
    
         
            -
                  # FIXME: add symbolize_keys again, maybe just write custom method, so we do not depend on ActiveSupport magic...
         
     | 
| 
       112 
100 
     | 
    
         
             
                  url_options = Gravatarify.options.merge(url_options)
         
     | 
| 
       113 
101 
     | 
    
         
             
                  email_hash = Digest::MD5.hexdigest(Base.get_smart_email_from(email).strip.downcase)
         
     | 
| 
       114 
     | 
    
         
            -
                  extension = url_options 
     | 
| 
      
 102 
     | 
    
         
            +
                  extension = (ext = url_options.delete(:filetype) and ext != '') ? ".#{ext || 'jpg'}" : '' # slightly adapted from gudleik's implementation
         
     | 
| 
       115 
103 
     | 
    
         
             
                  build_gravatar_host(email_hash, url_options.delete(:secure)) << "/avatar/#{email_hash}#{extension}#{build_gravatar_options(email, url_options)}"
         
     | 
| 
       116 
104 
     | 
    
         
             
                end
         
     | 
| 
       117 
105 
     | 
    
         | 
| 
         @@ -140,7 +128,9 @@ module Gravatarify 
     | 
|
| 
       140 
128 
     | 
    
         
             
                    "?#{params.sort * '&'}" unless params.empty?
         
     | 
| 
       141 
129 
     | 
    
         
             
                  end
         
     | 
| 
       142 
130 
     | 
    
         | 
| 
       143 
     | 
    
         
            -
                   
     | 
| 
      
 131 
     | 
    
         
            +
                  # Tries first to call +email+, then +mail+ then +to_s+ on supplied
         
     | 
| 
      
 132 
     | 
    
         
            +
                  # object.
         
     | 
| 
      
 133 
     | 
    
         
            +
                  def self.get_smart_email_from(obj) #:nodoc:
         
     | 
| 
       144 
134 
     | 
    
         
             
                    (obj.respond_to?(:email) ? obj.email : (obj.respond_to?(:mail) ? obj.mail : obj)).to_s
         
     | 
| 
       145 
135 
     | 
    
         
             
                  end
         
     | 
| 
       146 
136 
     | 
    
         
             
              end
         
     | 
    
        data/lib/gravatarify/helper.rb
    CHANGED
    
    | 
         @@ -2,7 +2,15 @@ module Gravatarify::Helper 
     | 
|
| 
       2 
2 
     | 
    
         
             
              # so that it's possible to access that build_gravatar_url method
         
     | 
| 
       3 
3 
     | 
    
         
             
              include Gravatarify::Base
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
              #  
     | 
| 
      
 5 
     | 
    
         
            +
              # Allow HTML options to be overriden globally as well, useful
         
     | 
| 
      
 6 
     | 
    
         
            +
              # to e.g. define a common alt attribute, or class.
         
     | 
| 
      
 7 
     | 
    
         
            +
              #
         
     | 
| 
      
 8 
     | 
    
         
            +
              #    Gravatarify::Helper.html_options[:title] = "Gravatar"
         
     | 
| 
      
 9 
     | 
    
         
            +
              #
         
     | 
| 
      
 10 
     | 
    
         
            +
              # @return [Hash] globally defined html attributes  
         
     | 
| 
      
 11 
     | 
    
         
            +
              def self.html_options; @html_options ||= { :alt => '' } end
         
     | 
| 
      
 12 
     | 
    
         
            +
              
         
     | 
| 
      
 13 
     | 
    
         
            +
              # To simplify things a bit and have a neat-o naming
         
     | 
| 
       6 
14 
     | 
    
         
             
              alias_method :gravatar_url, :build_gravatar_url
         
     | 
| 
       7 
15 
     | 
    
         | 
| 
       8 
16 
     | 
    
         
             
              # Helper method for HAML to return a neat hash to be used as attributes in an image tag.
         
     | 
| 
         @@ -11,17 +19,28 @@ module Gravatarify::Helper 
     | 
|
| 
       11 
19 
     | 
    
         
             
              #
         
     | 
| 
       12 
20 
     | 
    
         
             
              #    %img{ gravatar_attrs(@user.mail, :size => 20) }/
         
     | 
| 
       13 
21 
     | 
    
         
             
              #
         
     | 
| 
      
 22 
     | 
    
         
            +
              # This is also the base method for +gravatar_tag+.
         
     | 
| 
      
 23 
     | 
    
         
            +
              #
         
     | 
| 
      
 24 
     | 
    
         
            +
              # @param [String, #email, #mail, #gravatar_url] email a string or an object used
         
     | 
| 
      
 25 
     | 
    
         
            +
              #        to generate to gravatar url for.
         
     | 
| 
      
 26 
     | 
    
         
            +
              # @param [Hash] options other gravatar or html options for building the resulting
         
     | 
| 
      
 27 
     | 
    
         
            +
              #        hash.
         
     | 
| 
      
 28 
     | 
    
         
            +
              # @return [Hash] all html attributes required to build an +img+ tag.
         
     | 
| 
       14 
29 
     | 
    
         
             
              def gravatar_attrs(email, options = {})
         
     | 
| 
       15 
     | 
    
         
            -
                url_options = options. 
     | 
| 
       16 
     | 
    
         
            -
                options = options 
     | 
| 
       17 
     | 
    
         
            -
                options[:alt] ||= Gravatarify::Base.get_smart_email_from(email) # use email as :alt attribute
         
     | 
| 
       18 
     | 
    
         
            -
                options[:width] = options[:height] = (url_options[:size] || Gravatarify::GRAVATAR_DEFAULT_SIZE) # customize size
         
     | 
| 
      
 30 
     | 
    
         
            +
                url_options = options.inject({}) { |hsh, (key, value)| hsh[key] = options.delete(key) if Gravatarify::GRAVATAR_OPTIONS.include?(key.to_sym); hsh }
         
     | 
| 
      
 31 
     | 
    
         
            +
                options[:width] = options[:height] = (url_options[:size] || 80) # customize size
         
     | 
| 
       19 
32 
     | 
    
         
             
                options[:src] = email.respond_to?(:gravatar_url) ? email.gravatar_url(url_options) : build_gravatar_url(email, url_options)
         
     | 
| 
       20 
     | 
    
         
            -
                options
         
     | 
| 
      
 33 
     | 
    
         
            +
                Gravatarify::Helper.html_options.merge(options)
         
     | 
| 
       21 
34 
     | 
    
         
             
              end
         
     | 
| 
       22 
35 
     | 
    
         | 
| 
       23 
36 
     | 
    
         
             
              # Takes care of creating an <tt><img/></tt>-tag based on a gravatar url, it no longer
         
     | 
| 
       24 
37 
     | 
    
         
             
              # makes use of any Rails helper, so is totally useable in any other library.
         
     | 
| 
      
 38 
     | 
    
         
            +
              #
         
     | 
| 
      
 39 
     | 
    
         
            +
              # @param [String, #email, #mail, #gravatar_url] email a string or an object used
         
     | 
| 
      
 40 
     | 
    
         
            +
              #        to generate the gravatar url from
         
     | 
| 
      
 41 
     | 
    
         
            +
              # @param [Hash] options other gravatar or html options for building the resulting
         
     | 
| 
      
 42 
     | 
    
         
            +
              #        image tag.
         
     | 
| 
      
 43 
     | 
    
         
            +
              # @return [String] a complete and hopefully valid +img+ tag.
         
     | 
| 
       25 
44 
     | 
    
         
             
              def gravatar_tag(email, options = {})
         
     | 
| 
       26 
45 
     | 
    
         
             
                html_attrs = gravatar_attrs(email, options).map do |key,value|
         
     | 
| 
       27 
46 
     | 
    
         
             
                  escaped = defined?(Rack::Utils) ? Rack::Utils.escape_html(value) : CGI.escapeHTML(value)
         
     | 
| 
         @@ -16,8 +16,9 @@ 
     | 
|
| 
       16 
16 
     | 
    
         
             
            #      include DataMapper::Resource
         
     | 
| 
       17 
17 
     | 
    
         
             
            #      property ...
         
     | 
| 
       18 
18 
     | 
    
         
             
            #      property :author_email, String
         
     | 
| 
      
 19 
     | 
    
         
            +
            #      gravatarify :author_email
         
     | 
| 
       19 
20 
     | 
    
         
             
            #    end
         
     | 
| 
       20 
     | 
    
         
            -
            #    @user.gravatar_url  
     | 
| 
      
 21 
     | 
    
         
            +
            #    @user.gravatar_url # that's it, using the specified field!
         
     | 
| 
       21 
22 
     | 
    
         
             
            #
         
     | 
| 
       22 
23 
     | 
    
         
             
            # And finally, using a plain old ruby object:
         
     | 
| 
       23 
24 
     | 
    
         
             
            #
         
     | 
    
        data/test/test_helper.rb
    CHANGED
    
    | 
         @@ -13,7 +13,13 @@ Test::Unit::TestCase.send :include, RR::Adapters::TestUnit 
     | 
|
| 
       13 
13 
     | 
    
         
             
            # Reset +Gravatarify+ to default hosts and cleared options
         
     | 
| 
       14 
14 
     | 
    
         
             
            def reset_gravatarify!
         
     | 
| 
       15 
15 
     | 
    
         
             
              Gravatarify.options.clear
         
     | 
| 
       16 
     | 
    
         
            -
              Gravatarify. 
     | 
| 
      
 16 
     | 
    
         
            +
              Gravatarify.options[:filetype] = :jpg
         
     | 
| 
      
 17 
     | 
    
         
            +
              Gravatarify.subdomains = %w{ 0 1 2 www }
         
     | 
| 
      
 18 
     | 
    
         
            +
              
         
     | 
| 
      
 19 
     | 
    
         
            +
              if defined?(Gravatarify::Helper)
         
     | 
| 
      
 20 
     | 
    
         
            +
                Gravatarify::Helper.html_options.clear
         
     | 
| 
      
 21 
     | 
    
         
            +
                Gravatarify::Helper.html_options[:alt] = ''
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
       17 
23 
     | 
    
         
             
            end
         
     | 
| 
       18 
24 
     | 
    
         | 
| 
       19 
25 
     | 
    
         
             
            # some often used values...
         
     | 
| 
         @@ -46,9 +46,12 @@ class GravatarifyBaseTest < Test::Unit::TestCase 
     | 
|
| 
       46 
46 
     | 
    
         
             
                  assert_equal "#{BELLA_AT_GMAIL}.png", build_gravatar_url('bella@gmail.com', :filetype => :png)
         
     | 
| 
       47 
47 
     | 
    
         
             
                end
         
     | 
| 
       48 
48 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
                should "skip :filetype if set to false" do
         
     | 
| 
       50 
     | 
    
         
            -
                  assert_equal "#{BELLA_AT_GMAIL}", build_gravatar_url('bella@gmail.com', :filetype => false) 
     | 
| 
       51 
     | 
    
         
            -
                  assert_equal "#{ 
     | 
| 
      
 49 
     | 
    
         
            +
                should "skip :filetype if set to false, nil or ''" do
         
     | 
| 
      
 50 
     | 
    
         
            +
                  assert_equal "#{BELLA_AT_GMAIL}", build_gravatar_url('bella@gmail.com', :filetype => false)
         
     | 
| 
      
 51 
     | 
    
         
            +
                  assert_equal "#{BELLA_AT_GMAIL}", build_gravatar_url('bella@gmail.com', :filetype => nil)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  assert_equal "#{BELLA_AT_GMAIL}", build_gravatar_url('bella@gmail.com', :filetype => '')
         
     | 
| 
      
 53 
     | 
    
         
            +
                  assert_equal "#{BELLA_AT_GMAIL}.foobar", build_gravatar_url('bella@gmail.com', :filetype => 'foobar')
         
     | 
| 
      
 54 
     | 
    
         
            +
                  assert_equal "#{BELLA_AT_GMAIL}.gif", build_gravatar_url('bella@gmail.com', :filetype => :gif)
         
     | 
| 
       52 
55 
     | 
    
         
             
                end
         
     | 
| 
       53 
56 
     | 
    
         | 
| 
       54 
57 
     | 
    
         
             
                should "handle Procs as :default, to easily generate default urls based on supplied :size" do
         
     | 
| 
         @@ -19,22 +19,18 @@ class GravatarifyHelpersTest < Test::Unit::TestCase 
     | 
|
| 
       19 
19 
     | 
    
         
             
              context "#gravatar_attrs" do
         
     | 
| 
       20 
20 
     | 
    
         
             
                should "return hash with :height, :width, :alt and :src defined" do
         
     | 
| 
       21 
21 
     | 
    
         
             
                  hash = gravatar_attrs('bella@gmail.com', :size => 16)
         
     | 
| 
       22 
     | 
    
         
            -
                   
     | 
| 
       23 
     | 
    
         
            -
                  assert_equal  
     | 
| 
       24 
     | 
    
         
            -
                  assert_equal 16, hash[:height]
         
     | 
| 
       25 
     | 
    
         
            -
                  assert_equal 'bella@gmail.com', hash[:alt]
         
     | 
| 
      
 22 
     | 
    
         
            +
                  expected = { :alt => "", :src => "#{BELLA_AT_GMAIL_JPG}?s=16", :width => 16, :height => 16 }
         
     | 
| 
      
 23 
     | 
    
         
            +
                  assert_equal expected, hash
         
     | 
| 
       26 
24 
     | 
    
         
             
                  assert_nil hash[:size]
         
     | 
| 
       27 
25 
     | 
    
         
             
                end
         
     | 
| 
       28 
26 
     | 
    
         | 
| 
       29 
27 
     | 
    
         
             
                should "allow any param to be defined/overridden, except src, width and heigth" do
         
     | 
| 
       30 
28 
     | 
    
         
             
                  hash = gravatar_attrs('bella@gmail.com', :size => 20, :r => :x, :height => 40, :alt => 'bella', :id => 'test', :title => 'something', :class => 'gravatar')
         
     | 
| 
       31 
     | 
    
         
            -
                   
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                   
     | 
| 
       35 
     | 
    
         
            -
                  assert_equal  
     | 
| 
       36 
     | 
    
         
            -
                  assert_equal 'something', hash[:title]
         
     | 
| 
       37 
     | 
    
         
            -
                  assert_equal 'gravatar', hash[:class]
         
     | 
| 
      
 29 
     | 
    
         
            +
                  expected = {
         
     | 
| 
      
 30 
     | 
    
         
            +
                    :alt => 'bella', :src => "#{BELLA_AT_GMAIL_JPG}?r=x&s=20", :width => 20, :height => 20,
         
     | 
| 
      
 31 
     | 
    
         
            +
                    :id => 'test', :title => 'something', :class => 'gravatar'
         
     | 
| 
      
 32 
     | 
    
         
            +
                  }
         
     | 
| 
      
 33 
     | 
    
         
            +
                  assert_equal expected, hash
         
     | 
| 
       38 
34 
     | 
    
         
             
                  assert_nil hash[:size]
         
     | 
| 
       39 
35 
     | 
    
         
             
                  assert_nil hash[:r]
         
     | 
| 
       40 
36 
     | 
    
         
             
                end
         
     | 
| 
         @@ -42,18 +38,18 @@ class GravatarifyHelpersTest < Test::Unit::TestCase 
     | 
|
| 
       42 
38 
     | 
    
         | 
| 
       43 
39 
     | 
    
         
             
              context "#gravatar_tag helper" do
         
     | 
| 
       44 
40 
     | 
    
         
             
                should "create <img/> tag with correct gravatar urls" do
         
     | 
| 
       45 
     | 
    
         
            -
                  assert_equal '<img alt=" 
     | 
| 
      
 41 
     | 
    
         
            +
                  assert_equal '<img alt="" height="80" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg" width="80" />', gravatar_tag('bella@gmail.com')
         
     | 
| 
       46 
42 
     | 
    
         
             
                end
         
     | 
| 
       47 
43 
     | 
    
         | 
| 
       48 
44 
     | 
    
         
             
                should "create <img/> tags and handle all options correctly, other options should be passed to Rails' image_tag" do
         
     | 
| 
       49 
     | 
    
         
            -
                  assert_equal '<img alt=" 
     | 
| 
      
 45 
     | 
    
         
            +
                  assert_equal '<img alt="" height="16" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg?s=16" width="16" />',
         
     | 
| 
       50 
46 
     | 
    
         
             
                          gravatar_tag('bella@gmail.com', :size => 16)
         
     | 
| 
       51 
     | 
    
         
            -
                  assert_equal '<img alt=" 
     | 
| 
      
 47 
     | 
    
         
            +
                  assert_equal '<img alt="" class="gravatar" height="16" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg?d=x&s=16" width="16" />',
         
     | 
| 
       52 
48 
     | 
    
         
             
                          gravatar_tag('bella@gmail.com', :class => "gravatar", :size => 16, :d => "x")
         
     | 
| 
       53 
49 
     | 
    
         
             
                end
         
     | 
| 
       54 
50 
     | 
    
         | 
| 
       55 
51 
     | 
    
         
             
                should "ensure that all values are correctly html-esacped!" do
         
     | 
| 
       56 
     | 
    
         
            -
                  assert_equal '<img alt=" 
     | 
| 
      
 52 
     | 
    
         
            +
                  assert_equal '<img alt="" height="80" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg" title="<>" width="80" />',
         
     | 
| 
       57 
53 
     | 
    
         
             
                          gravatar_tag('bella@gmail.com', :title => '<>')
         
     | 
| 
       58 
54 
     | 
    
         
             
                end
         
     | 
| 
       59 
55 
     | 
    
         
             
              end
         
     | 
| 
         @@ -61,18 +57,53 @@ class GravatarifyHelpersTest < Test::Unit::TestCase 
     | 
|
| 
       61 
57 
     | 
    
         
             
              context "#gravatar_tag when passed in an object" do
         
     | 
| 
       62 
58 
     | 
    
         
             
                should "create <img/>-tag based on :email field" do
         
     | 
| 
       63 
59 
     | 
    
         
             
                  obj = Object.new
         
     | 
| 
       64 
     | 
    
         
            -
                  mock(obj).email 
     | 
| 
      
 60 
     | 
    
         
            +
                  mock(obj).email { "bella@gmail.com" }
         
     | 
| 
       65 
61 
     | 
    
         | 
| 
       66 
     | 
    
         
            -
                  assert_equal '<img alt=" 
     | 
| 
      
 62 
     | 
    
         
            +
                  assert_equal '<img alt="" height="80" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg" width="80" />',
         
     | 
| 
       67 
63 
     | 
    
         
             
                                  gravatar_tag(obj)      
         
     | 
| 
       68 
64 
     | 
    
         
             
                end
         
     | 
| 
       69 
65 
     | 
    
         | 
| 
       70 
66 
     | 
    
         
             
                should "create <img/>-tag based on gravatar_url from object if object responds to gravatar_url" do
         
     | 
| 
       71 
67 
     | 
    
         
             
                  obj = Object.new
         
     | 
| 
      
 68 
     | 
    
         
            +
                  mock(obj).name { "Mr. X" }
         
     | 
| 
       72 
69 
     | 
    
         
             
                  mock(obj).gravatar_url({ :size => 16 }) { "http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg?s=16" }
         
     | 
| 
       73 
70 
     | 
    
         | 
| 
       74 
     | 
    
         
            -
                  assert_equal '<img alt="Gravatar" height="16" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg?s=16" width="16" />',
         
     | 
| 
       75 
     | 
    
         
            -
                                  gravatar_tag(obj, :size => 16, :alt => "Gravatar")
         
     | 
| 
      
 71 
     | 
    
         
            +
                  assert_equal '<img alt="Gravatar for Mr. X" height="16" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg?s=16" width="16" />',
         
     | 
| 
      
 72 
     | 
    
         
            +
                                  gravatar_tag(obj, :size => 16, :alt => "Gravatar for #{obj.name}")
         
     | 
| 
       76 
73 
     | 
    
         
             
                end
         
     | 
| 
       77 
     | 
    
         
            -
              end 
     | 
| 
      
 74 
     | 
    
         
            +
              end
         
     | 
| 
      
 75 
     | 
    
         
            +
              
         
     | 
| 
      
 76 
     | 
    
         
            +
              context "Gravatarify::Helper#html_options" do
         
     | 
| 
      
 77 
     | 
    
         
            +
                should "add be added to all tags/hashes created by gravatar_tag or gravatar_attrs" do
         
     | 
| 
      
 78 
     | 
    
         
            +
                  Gravatarify::Helper.html_options[:title] = "Gravatar" # add a title attribute, yeah neat-o!
         
     | 
| 
      
 79 
     | 
    
         
            +
                  Gravatarify::Helper.html_options[:class] = "gravatar"
         
     | 
| 
      
 80 
     | 
    
         
            +
                  
         
     | 
| 
      
 81 
     | 
    
         
            +
                  assert_equal '<img alt="" class="gravatar" height="80" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg" title="Gravatar" width="80" />',
         
     | 
| 
      
 82 
     | 
    
         
            +
                                  gravatar_tag('bella@gmail.com')
         
     | 
| 
      
 83 
     | 
    
         
            +
                  hash = gravatar_attrs('bella@gmail.com', :size => 20, :title => "Gravatar for Bella", :id => "test")
         
     | 
| 
      
 84 
     | 
    
         
            +
                  expected = {
         
     | 
| 
      
 85 
     | 
    
         
            +
                    :alt => "", :width => 20, :height => 20, :src => "http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg?s=20",
         
     | 
| 
      
 86 
     | 
    
         
            +
                    :title => "Gravatar for Bella", :id => "test", :class => "gravatar"
         
     | 
| 
      
 87 
     | 
    
         
            +
                  }
         
     | 
| 
      
 88 
     | 
    
         
            +
                  assert_equal expected, hash
         
     | 
| 
      
 89 
     | 
    
         
            +
                end
         
     | 
| 
      
 90 
     | 
    
         
            +
                
         
     | 
| 
      
 91 
     | 
    
         
            +
                should "not allow :src, :height or :width to be set via global options and all local options should override!" do
         
     | 
| 
      
 92 
     | 
    
         
            +
                  Gravatarify::Helper.html_options[:src] = "avatar-30.jpg"
         
     | 
| 
      
 93 
     | 
    
         
            +
                  Gravatarify::Helper.html_options[:width] = 30
         
     | 
| 
      
 94 
     | 
    
         
            +
                  Gravatarify::Helper.html_options[:title] = "Avatar"
         
     | 
| 
      
 95 
     | 
    
         
            +
                  
         
     | 
| 
      
 96 
     | 
    
         
            +
                  assert_equal '<img alt="" height="25" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg?s=25" title="Gravatar" width="25" />',
         
     | 
| 
      
 97 
     | 
    
         
            +
                               gravatar_tag('bella@gmail.com', :size => 25, :title => 'Gravatar')
         
     | 
| 
      
 98 
     | 
    
         
            +
                end
         
     | 
| 
      
 99 
     | 
    
         
            +
                
         
     | 
| 
      
 100 
     | 
    
         
            +
                should "allow :alt to be set globally" do
         
     | 
| 
      
 101 
     | 
    
         
            +
                  Gravatarify::Helper.html_options[:alt] = "Gravatar"
         
     | 
| 
      
 102 
     | 
    
         
            +
                  
         
     | 
| 
      
 103 
     | 
    
         
            +
                  assert_equal '<img alt="Gravatar" height="80" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg" width="80" />',
         
     | 
| 
      
 104 
     | 
    
         
            +
                               gravatar_tag('bella@gmail.com')
         
     | 
| 
      
 105 
     | 
    
         
            +
                  assert_equal '<img alt="Avatar" height="80" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d" width="80" />',
         
     | 
| 
      
 106 
     | 
    
         
            +
                               gravatar_tag('bella@gmail.com', :filetype => false, :alt => 'Avatar')
         
     | 
| 
      
 107 
     | 
    
         
            +
                end
         
     | 
| 
      
 108 
     | 
    
         
            +
              end
         
     | 
| 
       78 
109 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: gravatarify
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.2.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors: 
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Lukas Westermann
         
     | 
| 
         @@ -9,13 +9,14 @@ autorequire: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
            date: 2009-10- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2009-10-27 00:00:00 +01:00
         
     | 
| 
       13 
13 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       14 
14 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
            description: |-
         
     | 
| 
       17 
     | 
    
         
            -
               
     | 
| 
       18 
     | 
    
         
            -
                   
     | 
| 
      
 17 
     | 
    
         
            +
              Awesome gravatar support for Ruby (and Rails, DataMapper, Haml) -
         
     | 
| 
      
 18 
     | 
    
         
            +
                  with unique options like Proc's for default images, or
         
     | 
| 
      
 19 
     | 
    
         
            +
                  support for gravatar.com's multiple host names.
         
     | 
| 
       19 
20 
     | 
    
         
             
            email: lukas.westermann@gmail.com
         
     | 
| 
       20 
21 
     | 
    
         
             
            executables: []
         
     | 
| 
       21 
22 
     | 
    
         | 
| 
         @@ -69,7 +70,7 @@ rubyforge_project: 
     | 
|
| 
       69 
70 
     | 
    
         
             
            rubygems_version: 1.3.5
         
     | 
| 
       70 
71 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       71 
72 
     | 
    
         
             
            specification_version: 3
         
     | 
| 
       72 
     | 
    
         
            -
            summary: Awesome gravatar support for  
     | 
| 
      
 73 
     | 
    
         
            +
            summary: Awesome gravatar support for Ruby (and Rails, DataMapper, Haml).
         
     | 
| 
       73 
74 
     | 
    
         
             
            test_files: 
         
     | 
| 
       74 
75 
     | 
    
         
             
            - test/test_helper.rb
         
     | 
| 
       75 
76 
     | 
    
         
             
            - test/unit/gravatarify_ar_dm_test.rb
         
     |