leifcr-gravtastic 3.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 29647e6d7a04eed8222c31944a2712a383172190
4
+ data.tar.gz: e3481f3d058ebaee839cb6fbaa17e16b504abd8d
5
+ SHA512:
6
+ metadata.gz: ee9ed6501f0b19ce4bbd1225acd0efcfec9552e92c56778f864a4339e7d90478763f6f4dc644365a2a64198baa3df484f52a97ba10b5c236e494b87b184794d8
7
+ data.tar.gz: 14a4d0f8d97a1cfe8fbbebbf6c2cf6a69282983271904a63f5b2e96a205f40b789fcbce8bc94da2b4a3c151cc4b6b9fc6a2721feb3a8e1cec04222a2f4f7a9df
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,200 @@
1
+ [![Build Status](https://travis-ci.org/leifcr/gravtastic.svg)](https://travis-ci.org/leifcr/gravtastic)
2
+
3
+ _____ _ _ _
4
+ / ____| | | | | (_)
5
+ | | __ _ __ __ ___ _| |_ __ _ ___| |_ _ ___
6
+ | | |_ | '__/ _` \ \ / / __/ _` / __| __| |/ __|
7
+ | |__| | | | (_| |\ V /| || (_| \__ \ |_| | (__
8
+ \_____|_| \__,_| \_/ \__\__,_|___/\__|_|\___|
9
+
10
+
11
+ <center><small>The super fantastic way of getting Gravatars. By [The Poacher](http://thelincolnshirepoacher.com).</small></center>
12
+
13
+ In less than a minute you can add Gravatars to your Ruby project. It works in Rails, Merb & Sinatra.
14
+
15
+ The best way to learn more about Gravtastic is to [look through the annotated source](http://chrislloyd.github.com/gravtastic). It's one file, about 80 LOC and really pretty simple. If that isn't for you, then follow the instructions below!
16
+
17
+
18
+ ## Install
19
+
20
+ sudo gem install gravtastic
21
+
22
+
23
+ ## Usage
24
+
25
+ For this example I'm going to assume you are using Rails. Don't worry if you aren't, the concepts are still the same.
26
+
27
+ First off, add this to your `Gemfile`:
28
+
29
+ gem 'gravtastic'
30
+
31
+ Next, in your model:
32
+
33
+ class User < ActiveRecord::Base
34
+ include Gravtastic
35
+ gravtastic
36
+ end
37
+
38
+ <small>_Note: You can use either `is_gravtastic!`, `is_gravtastic` or `has_gravatar`, they all do the same thing._</small>
39
+
40
+ And you are done! In your views you can now use the `#gravatar_url` method on instances of `User`:
41
+
42
+ <%= image_tag @user.gravatar_url %>
43
+
44
+ Gravatar gives you some options. You can use them like this:
45
+
46
+ <%= image_tag @user.gravatar_url(:rating => 'R', :secure => true) %>
47
+
48
+ That will show R rated Gravatars over a secure connection. If you find yourself using the same options over and over again, you can set the Gravatar defaults. In your model, just change the `gravtastic` line to something like this:
49
+
50
+ gravtastic :secure => true,
51
+ :filetype => :gif,
52
+ :size => 120
53
+
54
+ Now all your Gravatars will come from a secure connection, be a GIF and be 120x120px.
55
+
56
+ If your Gravatar defaults depend on your instance, you can define them with a lambda:
57
+
58
+ class User < ActiveRecord::Base
59
+ include Gravtastic
60
+ # default avatar is the first letter of the user's first name
61
+ gravtastic :default => lambda { |u| "https://assets.example.com/#{u.first_name[0]}.png" }
62
+
63
+ Gravatar needs an email address to find the person's avatar. By default, Gravtastic calls the `#email` method to find this. You can customise this.
64
+
65
+ gravtastic :author_email
66
+
67
+ ### Defaults
68
+
69
+ A common question is "how do I detect wether the user has an avatar or not?" People usually write code to perform a HTTP request to Gravatar to see wether the gravatar exists. This is certainly a solution, but not a very good one. If you have page where you show 50 users, the client will have to wait for 50 HTTP requests before they even get the page. Slooww.
70
+
71
+ The best way to do this is to set the `:default` option when using `#gravatar_url`. If the user doesn't have an avatar, Gravatar essentially redirects to the "default" url you provide.
72
+
73
+ ### Complete List of Options
74
+
75
+ <table width="100%">
76
+ <thead>
77
+ <th>Option</th>
78
+ <th>Description</th>
79
+ <th>Default</th>
80
+ <th>Values<th>
81
+ </tr>
82
+ <tr>
83
+ <td><b>secure</b></td>
84
+ <td>Gravatar transmitted with SSL</td>
85
+ <td>true</td>
86
+ <td>true/false</td>
87
+ </tr>
88
+ <tr>
89
+ <td><b>size</b></td>
90
+ <td>The size of the image</td>
91
+ <td>80</td>
92
+ <td>1..512</td>
93
+ </tr>
94
+ <tr>
95
+ <td><b>default</b></td>
96
+ <td>The default avatar image</td>
97
+ <td><i>none</i></td>
98
+ <td>"identicon", "monsterid", "wavatar" or an absolute URL.</td>
99
+ </tr>
100
+ <tr>
101
+ <td><b>rating</b></td>
102
+ <td>The highest level of ratings you want to allow</td>
103
+ <td>PG</td>
104
+ <td>G, PG, R or X</td>
105
+ </tr>
106
+ <tr>
107
+ <td><b>filetype</b></td>
108
+ <td>The filetype of the image</td>
109
+ <td>png</td>
110
+ <td>gif, jpg or png</td>
111
+ </tr>
112
+ </table>
113
+
114
+
115
+ ### Other ORMs
116
+
117
+ Gravatar is really just simple Ruby. There is no special magic which ties it to one ORM (like ActiveRecord or MongoMapper). You can use the following pattern to include it anywhere:
118
+
119
+ require 'gravtastic'
120
+ class MyClass
121
+ include Gravtastic
122
+ gravtastic
123
+ end
124
+
125
+ For instance, with the excellent [MongoMapper](http://github.com/jnunemaker/mongomapper) you can use do this:
126
+
127
+ class Person
128
+ include MongoMapper::Document
129
+ include Gravtastic
130
+
131
+ gravtastic
132
+
133
+ key :email
134
+ end
135
+
136
+ And wallah! It's exactly the same as with ActiveRecord! Now all instances of the `Person` class will have `#gravatar_url` methods.
137
+
138
+ _Note: the `#gravatar_url` methods don't get included until you call the `gravtastic` method._
139
+
140
+
141
+ ## Javascript
142
+
143
+ _Note: this feature requires Rails 3.1 & CoffeeScript._
144
+
145
+ Web applications are increasingly performing client side rendering in Javascript. It's not always practical or clean to calculate the `gravatar_url` on the server. As of version 3.2, Gravtastic comes bundled with Javascript helpers.
146
+
147
+ If you are using Rails 3.1 you can simple require Gravtastic in your `Gemfile` and add
148
+
149
+ //= require gravtastic
150
+
151
+ in your `application.js` file. This will include a function, `Gravtastic` which performs similarly to `gravtastic_url`.
152
+
153
+ > Gravtastic('christopher.lloyd@gmail.com')
154
+ "https://secure.gravatar.com/avatar/08f077ea061585744ee080824f5a8e65.png?r=PG"
155
+ > Gravtastic('christopher.lloyd@gmail.com', {default: 'identicon', size: 64})
156
+ "https://secure.gravatar.com/avatar/08f077ea061585744ee080824f5a8e65.png?r=PG&d=identicon&s=64"
157
+
158
+
159
+ ## Making Changes Yourself
160
+
161
+ Gravtastic is a mature project. There isn't any active work which needs to be done on it, but I do continue to maintain it. Just don't expect same day fixes. If you find something that needs fixing, the best way to contribute is to fork the repo and submit a pull request.
162
+
163
+ git clone git://github.com/chrislloyd/gravtastic.git
164
+
165
+
166
+ ## Thanks
167
+
168
+ * [Xavier Shay](http://github.com/xaviershay) and others for [Enki](http://enkiblog.com) (the reason this was originally written)
169
+ * [Matthew Moore](http://github.com/moorage)
170
+ * [Galen O'Hanlon](http://github.com/gohanlon)
171
+ * [Jason Cheow](http://jasoncheow.com)
172
+ * [Paul Farnell](http://github.com/salted)
173
+ * [Jeff Kreeftmeijer](http://github.com/jeffkreeftmeijer)
174
+ * [Ryan Lewis](http://github.com/c00lryguy)
175
+ * [Arthur Chiu](http://github.com/achiu)
176
+ * [Paul Johnston](http://pajhome.org.uk/crypt/md5/) for his awesome MD5.js implementation.
177
+ * [Leif Ringstad](http://github.com/leifcr)
178
+
179
+ ## License
180
+
181
+ Copyright (c) 2008 Chris Lloyd.
182
+
183
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
184
+
185
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
186
+
187
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
188
+
189
+ --
190
+
191
+ md5.js Copyright (c) 1998 - 2009, Paul Johnston & Contributors
192
+ All rights reserved.
193
+
194
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
195
+
196
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
197
+
198
+ Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
199
+
200
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/clean'
3
+ require 'rspec/core/rake_task'
4
+
5
+ def name
6
+ @name ||= File.basename(Dir['*.gemspec'].first, '.gemspec')
7
+ end
8
+
9
+ def gemspec_file
10
+ "#{name}.gemspec"
11
+ end
12
+
13
+ load(gemspec_file)
14
+
15
+ RSpec::Core::RakeTask.new do |t|
16
+ t.rspec_opts = ['--color', '--require ./spec/helper']
17
+ end
18
+
19
+ task :default => :spec
20
+
data/lib/gravtastic.rb ADDED
@@ -0,0 +1,128 @@
1
+ # Gravtastic is a small module which quickly generates a Gravatar URL. Just
2
+ # include in your class!
3
+
4
+ # Gravatar uses an MD5 hash of the users email to locate their avatar.
5
+ require 'digest/md5'
6
+ require 'gravtastic/version'
7
+
8
+ begin
9
+ require 'rails'
10
+ require 'gravtastic/engine'
11
+ rescue LoadError
12
+ end
13
+
14
+ module Gravtastic
15
+
16
+ # When you `include Gravtastic`, Ruby automatically calls this method
17
+ # with the class you called it in. It allows us extend the class with the
18
+ # `#gravtastic` method.
19
+ def self.included(model)
20
+ model.extend StageOne
21
+ end
22
+
23
+ # Sets the model's default attributes. It is called when you use
24
+ # `#gravtastic` in your model.
25
+ def self.configure(model, *args, &blk)
26
+ options = args.last.is_a?(Hash) ? args.pop : {}
27
+
28
+ model.gravatar_defaults = {
29
+ :rating => 'PG',
30
+ :secure => true,
31
+ :filetype => :png,
32
+ }.merge(options)
33
+
34
+ # The method where Gravtastic get the users' email from defaults to `#email`.
35
+ model.gravatar_source = args.first || :email
36
+ end
37
+
38
+ # We include Gravtastic in multiple stages. This is mainly so that if you
39
+ # include Gravastic in a superclass (something like `ActiveRecord::Base`)
40
+ # then it only adds the relevant methods to the classes which _actually_ use
41
+ # it.
42
+ module StageOne
43
+ def gravtastic(*args, &blk)
44
+ extend ClassMethods
45
+ include InstanceMethods
46
+ Gravtastic.configure(self, *args, &blk)
47
+ self
48
+ end
49
+
50
+ # All these aliases deal with previous bad design decisions. Let that be a
51
+ # lesson, name things simply, try not to follow fads and try not to break
52
+ # backwards compatibility.
53
+ alias_method :gravtastic!, :gravtastic
54
+ alias_method :has_gravatar, :gravtastic
55
+ alias_method :is_gravtastic, :gravtastic
56
+ alias_method :is_gravtastic!, :gravtastic
57
+ end
58
+
59
+ module ClassMethods
60
+ attr_accessor :gravatar_source, :gravatar_defaults
61
+
62
+ # Gravtastic abbreviates certain params so that it produces the smallest
63
+ # possible URL. Every byte counts.
64
+ def gravatar_abbreviations
65
+ { :size => 's',
66
+ :default => 'd',
67
+ :rating => 'r',
68
+ :forcedefault => 'f'
69
+ }
70
+ end
71
+ end
72
+
73
+ module InstanceMethods
74
+
75
+ # The raw MD5 hash of the users' email. Gravatar is particularly tricky as
76
+ # it downcases all emails. This is really the guts of the module,
77
+ # everything else is just convenience.
78
+ def gravatar_id
79
+ Digest::MD5.hexdigest(send(self.class.gravatar_source).to_s.downcase)
80
+ end
81
+
82
+ # Constructs the full Gravatar url.
83
+ def gravatar_url(options={})
84
+ options = self.class.gravatar_defaults.merge(options)
85
+ gravatar_hostname(options.delete(:secure)) +
86
+ gravatar_filename(options.delete(:filetype)) +
87
+ url_params_from_hash(process_options(options))
88
+ end
89
+
90
+ private
91
+
92
+ # Creates a params hash like "?foo=bar" from a hash like {'foo' => 'bar'}.
93
+ # The values are sorted so it produces deterministic output (and can
94
+ # therefore be tested easily).
95
+ def url_params_from_hash(hash)
96
+ '?' + hash.map do |key, val|
97
+ [self.class.gravatar_abbreviations[key.to_sym] || key.to_s, val.to_s ].join('=')
98
+ end.sort.join('&')
99
+ end
100
+
101
+ # Returns either Gravatar's secure hostname or not.
102
+ def gravatar_hostname(secure)
103
+ 'http' + (secure ? 's://secure.' : '://') + 'gravatar.com/avatar/'
104
+ end
105
+
106
+ # Munges the ID and the filetype into one. Like "abc123.png"
107
+ def gravatar_filename(filetype)
108
+ "#{gravatar_id}.#{filetype}"
109
+ end
110
+
111
+ # Some options need to be processed before becoming URL params
112
+ def process_options(options)
113
+ processed_options = {}
114
+ options.each do |key, val|
115
+ case key
116
+ when :forcedefault
117
+ if val
118
+ processed_options[key] = 'y'
119
+ end
120
+ else
121
+ processed_options[key] = val.is_a?(Proc) ? val.call(self) : val
122
+ end
123
+ end
124
+ processed_options
125
+ end
126
+ end
127
+
128
+ end
@@ -0,0 +1,4 @@
1
+ module Gravtastic
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,10 @@
1
+ module Gravtastic
2
+
3
+ VERSION = '3.2.7'
4
+
5
+ # Returns the version of Gravtastic
6
+ def self.version
7
+ VERSION
8
+ end
9
+
10
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path("../gravtastic", __FILE__)
@@ -0,0 +1,94 @@
1
+ require "helper.rb"
2
+
3
+ describe Gravtastic do
4
+
5
+ before(:each) do
6
+ @g = Class.new do |c|
7
+ c.send(:include, Gravtastic)
8
+ c.is_gravtastic
9
+ end
10
+ end
11
+
12
+ describe ".is_gravtastic" do
13
+
14
+ it "includes the methods" do
15
+ expect(@g.included_modules).to include(Gravtastic::InstanceMethods)
16
+ end
17
+
18
+ end
19
+
20
+ describe 'default' do
21
+
22
+ it "options are {:rating => 'PG', :secure => true, :filetype => :png}" do
23
+ expect(@g.gravatar_defaults).to eq ({
24
+ :rating => 'PG',
25
+ :secure => true,
26
+ :filetype => :png,
27
+ })
28
+ end
29
+
30
+ it "source is :email" do
31
+ expect(@g.gravatar_source).to eq(:email)
32
+ end
33
+
34
+ end
35
+
36
+ describe "#gravatar_id" do
37
+
38
+ it "downcases email" do
39
+ a = @g.new
40
+ stub(a).email do 'USER@EXAMPLE.COM' end
41
+ b = @g.new
42
+ stub(b).email do 'user@example.com' end
43
+ expect(a.gravatar_id).to eq(b.gravatar_id)
44
+ end
45
+
46
+ end
47
+
48
+ describe "#gravatar_url" do
49
+
50
+ before(:each) do
51
+ @user = @g.new
52
+ stub(@user).email{ 'user@example.com' }
53
+ end
54
+
55
+ it "makes a pretty URL" do
56
+ expect(@user.gravatar_url(:secure => false)).to eq('http://gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?r=PG')
57
+ end
58
+
59
+ it "makes a secure URL" do
60
+ expect(@user.gravatar_url).to eq('https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?r=PG')
61
+ end
62
+
63
+ it "makes a jpeggy URL" do
64
+ expect(@user.gravatar_url(:secure => false, :filetype => :jpg)).to eq('http://gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.jpg?r=PG')
65
+ end
66
+
67
+ it "makes a saucy URL" do
68
+ expect(@user.gravatar_url(:secure => false, :rating => 'R')).to eq('http://gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?r=R')
69
+ end
70
+
71
+ it "makes a forcedefault URL" do
72
+ expect(@user.gravatar_url(:secure => false, :forcedefault => true)).to eq('http://gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?f=y&r=PG')
73
+ end
74
+
75
+ it "abides to some new fancy feature" do
76
+ expect(@user.gravatar_url(:secure => false, :extreme => true)).to eq('http://gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?extreme=true&r=PG')
77
+ end
78
+
79
+ it "makes a URL from the defaults" do
80
+ stub(@user.class).gravatar_defaults{ {:size => 20, :rating => 'R18', :secure => true, :filetype => :png} }
81
+ expect(@user.gravatar_url).to eq('https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?r=R18&s=20')
82
+ end
83
+
84
+ it "makes a URL with the default option" do
85
+ expect(@user.gravatar_url(:default => 'default.jpg')).to eq('https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?d=default.jpg&r=PG')
86
+ end
87
+
88
+ it "makes a URL when the default option is a lambda" do
89
+ expect(@user.gravatar_url(:default => lambda {|u| "#{u.email}.jpg"})).to eq('https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?d=user@example.com.jpg&r=PG')
90
+ end
91
+
92
+ end
93
+
94
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,7 @@
1
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
2
+
3
+ require 'gravtastic'
4
+
5
+ RSpec.configure do |config|
6
+ config.mock_with :rr
7
+ end
@@ -0,0 +1,37 @@
1
+ #= require md5
2
+
3
+ # Private abbreviations
4
+ abbreviations =
5
+ size: 's'
6
+ default: 'd'
7
+ rating: 'r'
8
+
9
+ window.Gravtastic = (email, options={}) ->
10
+ id = MD5(email.toString().toLowerCase())
11
+
12
+ # Initialize options
13
+ opts = {}
14
+ opts[key] = val for key, val of Gravtastic.defaults
15
+ opts[key] = val for key, val of options
16
+
17
+ host = if opts.secure
18
+ "https://secure.gravatar.com/avatar"
19
+ else
20
+ "http://gravatar.com/avatar"
21
+
22
+ path = "/#{id}.#{opts.filetype || 'png'}"
23
+
24
+ params = "?" + (
25
+ for key, val of opts when key isnt "secure" and key isnt "filetype"
26
+ "#{abbreviations[key] || key}=#{val}"
27
+ ).join('&')
28
+
29
+ host + path + params
30
+
31
+
32
+ # These are easily overridden in your own application
33
+ window.Gravtastic.defaults =
34
+ rating: 'PG'
35
+ secure: true
36
+ filetype: 'png'
37
+
@@ -0,0 +1,383 @@
1
+ (function(out) {
2
+ /*
3
+ * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
4
+ * Digest Algorithm, as defined in RFC 1321.
5
+ * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
6
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
7
+ * Distributed under the BSD License
8
+ * See http://pajhome.org.uk/crypt/md5 for more info.
9
+ */
10
+
11
+ /*
12
+ * Configurable variables. You may need to tweak these to be compatible with
13
+ * the server-side, but the defaults work in most cases.
14
+ */
15
+ var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
16
+ var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
17
+
18
+ /*
19
+ * These are the functions you'll usually want to call
20
+ * They take string arguments and return either hex or base-64 encoded strings
21
+ */
22
+ function hex_md5(s) { return rstr2hex(rstr_md5(str2rstr_utf8(s))); }
23
+ function b64_md5(s) { return rstr2b64(rstr_md5(str2rstr_utf8(s))); }
24
+ function any_md5(s, e) { return rstr2any(rstr_md5(str2rstr_utf8(s)), e); }
25
+ function hex_hmac_md5(k, d)
26
+ { return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); }
27
+ function b64_hmac_md5(k, d)
28
+ { return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); }
29
+ function any_hmac_md5(k, d, e)
30
+ { return rstr2any(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)), e); }
31
+
32
+ /*
33
+ * Perform a simple self-test to see if the VM is working
34
+ */
35
+ function md5_vm_test()
36
+ {
37
+ return hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72";
38
+ }
39
+
40
+ /*
41
+ * Calculate the MD5 of a raw string
42
+ */
43
+ function rstr_md5(s)
44
+ {
45
+ return binl2rstr(binl_md5(rstr2binl(s), s.length * 8));
46
+ }
47
+
48
+ /*
49
+ * Calculate the HMAC-MD5, of a key and some data (raw strings)
50
+ */
51
+ function rstr_hmac_md5(key, data)
52
+ {
53
+ var bkey = rstr2binl(key);
54
+ if(bkey.length > 16) bkey = binl_md5(bkey, key.length * 8);
55
+
56
+ var ipad = Array(16), opad = Array(16);
57
+ for(var i = 0; i < 16; i++)
58
+ {
59
+ ipad[i] = bkey[i] ^ 0x36363636;
60
+ opad[i] = bkey[i] ^ 0x5C5C5C5C;
61
+ }
62
+
63
+ var hash = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
64
+ return binl2rstr(binl_md5(opad.concat(hash), 512 + 128));
65
+ }
66
+
67
+ /*
68
+ * Convert a raw string to a hex string
69
+ */
70
+ function rstr2hex(input)
71
+ {
72
+ try { hexcase } catch(e) { hexcase=0; }
73
+ var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
74
+ var output = "";
75
+ var x;
76
+ for(var i = 0; i < input.length; i++)
77
+ {
78
+ x = input.charCodeAt(i);
79
+ output += hex_tab.charAt((x >>> 4) & 0x0F)
80
+ + hex_tab.charAt( x & 0x0F);
81
+ }
82
+ return output;
83
+ }
84
+
85
+ /*
86
+ * Convert a raw string to a base-64 string
87
+ */
88
+ function rstr2b64(input)
89
+ {
90
+ try { b64pad } catch(e) { b64pad=''; }
91
+ var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
92
+ var output = "";
93
+ var len = input.length;
94
+ for(var i = 0; i < len; i += 3)
95
+ {
96
+ var triplet = (input.charCodeAt(i) << 16)
97
+ | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
98
+ | (i + 2 < len ? input.charCodeAt(i+2) : 0);
99
+ for(var j = 0; j < 4; j++)
100
+ {
101
+ if(i * 8 + j * 6 > input.length * 8) output += b64pad;
102
+ else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
103
+ }
104
+ }
105
+ return output;
106
+ }
107
+
108
+ /*
109
+ * Convert a raw string to an arbitrary string encoding
110
+ */
111
+ function rstr2any(input, encoding)
112
+ {
113
+ var divisor = encoding.length;
114
+ var i, j, q, x, quotient;
115
+
116
+ /* Convert to an array of 16-bit big-endian values, forming the dividend */
117
+ var dividend = Array(Math.ceil(input.length / 2));
118
+ for(i = 0; i < dividend.length; i++)
119
+ {
120
+ dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
121
+ }
122
+
123
+ /*
124
+ * Repeatedly perform a long division. The binary array forms the dividend,
125
+ * the length of the encoding is the divisor. Once computed, the quotient
126
+ * forms the dividend for the next step. All remainders are stored for later
127
+ * use.
128
+ */
129
+ var full_length = Math.ceil(input.length * 8 /
130
+ (Math.log(encoding.length) / Math.log(2)));
131
+ var remainders = Array(full_length);
132
+ for(j = 0; j < full_length; j++)
133
+ {
134
+ quotient = Array();
135
+ x = 0;
136
+ for(i = 0; i < dividend.length; i++)
137
+ {
138
+ x = (x << 16) + dividend[i];
139
+ q = Math.floor(x / divisor);
140
+ x -= q * divisor;
141
+ if(quotient.length > 0 || q > 0)
142
+ quotient[quotient.length] = q;
143
+ }
144
+ remainders[j] = x;
145
+ dividend = quotient;
146
+ }
147
+
148
+ /* Convert the remainders to the output string */
149
+ var output = "";
150
+ for(i = remainders.length - 1; i >= 0; i--)
151
+ output += encoding.charAt(remainders[i]);
152
+
153
+ return output;
154
+ }
155
+
156
+ /*
157
+ * Encode a string as utf-8.
158
+ * For efficiency, this assumes the input is valid utf-16.
159
+ */
160
+ function str2rstr_utf8(input)
161
+ {
162
+ var output = "";
163
+ var i = -1;
164
+ var x, y;
165
+
166
+ while(++i < input.length)
167
+ {
168
+ /* Decode utf-16 surrogate pairs */
169
+ x = input.charCodeAt(i);
170
+ y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
171
+ if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)
172
+ {
173
+ x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
174
+ i++;
175
+ }
176
+
177
+ /* Encode output as utf-8 */
178
+ if(x <= 0x7F)
179
+ output += String.fromCharCode(x);
180
+ else if(x <= 0x7FF)
181
+ output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
182
+ 0x80 | ( x & 0x3F));
183
+ else if(x <= 0xFFFF)
184
+ output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
185
+ 0x80 | ((x >>> 6 ) & 0x3F),
186
+ 0x80 | ( x & 0x3F));
187
+ else if(x <= 0x1FFFFF)
188
+ output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
189
+ 0x80 | ((x >>> 12) & 0x3F),
190
+ 0x80 | ((x >>> 6 ) & 0x3F),
191
+ 0x80 | ( x & 0x3F));
192
+ }
193
+ return output;
194
+ }
195
+
196
+ /*
197
+ * Encode a string as utf-16
198
+ */
199
+ function str2rstr_utf16le(input)
200
+ {
201
+ var output = "";
202
+ for(var i = 0; i < input.length; i++)
203
+ output += String.fromCharCode( input.charCodeAt(i) & 0xFF,
204
+ (input.charCodeAt(i) >>> 8) & 0xFF);
205
+ return output;
206
+ }
207
+
208
+ function str2rstr_utf16be(input)
209
+ {
210
+ var output = "";
211
+ for(var i = 0; i < input.length; i++)
212
+ output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,
213
+ input.charCodeAt(i) & 0xFF);
214
+ return output;
215
+ }
216
+
217
+ /*
218
+ * Convert a raw string to an array of little-endian words
219
+ * Characters >255 have their high-byte silently ignored.
220
+ */
221
+ function rstr2binl(input)
222
+ {
223
+ var output = Array(input.length >> 2);
224
+ for(var i = 0; i < output.length; i++)
225
+ output[i] = 0;
226
+ for(var i = 0; i < input.length * 8; i += 8)
227
+ output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32);
228
+ return output;
229
+ }
230
+
231
+ /*
232
+ * Convert an array of little-endian words to a string
233
+ */
234
+ function binl2rstr(input)
235
+ {
236
+ var output = "";
237
+ for(var i = 0; i < input.length * 32; i += 8)
238
+ output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);
239
+ return output;
240
+ }
241
+
242
+ /*
243
+ * Calculate the MD5 of an array of little-endian words, and a bit length.
244
+ */
245
+ function binl_md5(x, len)
246
+ {
247
+ /* append padding */
248
+ x[len >> 5] |= 0x80 << ((len) % 32);
249
+ x[(((len + 64) >>> 9) << 4) + 14] = len;
250
+
251
+ var a = 1732584193;
252
+ var b = -271733879;
253
+ var c = -1732584194;
254
+ var d = 271733878;
255
+
256
+ for(var i = 0; i < x.length; i += 16)
257
+ {
258
+ var olda = a;
259
+ var oldb = b;
260
+ var oldc = c;
261
+ var oldd = d;
262
+
263
+ a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
264
+ d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
265
+ c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
266
+ b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
267
+ a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
268
+ d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
269
+ c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
270
+ b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
271
+ a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
272
+ d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
273
+ c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
274
+ b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
275
+ a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
276
+ d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
277
+ c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
278
+ b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
279
+
280
+ a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
281
+ d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
282
+ c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
283
+ b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
284
+ a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
285
+ d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
286
+ c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
287
+ b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
288
+ a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
289
+ d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
290
+ c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
291
+ b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
292
+ a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
293
+ d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
294
+ c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
295
+ b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
296
+
297
+ a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
298
+ d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
299
+ c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
300
+ b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
301
+ a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
302
+ d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
303
+ c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
304
+ b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
305
+ a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
306
+ d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
307
+ c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
308
+ b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
309
+ a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
310
+ d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
311
+ c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
312
+ b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
313
+
314
+ a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
315
+ d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
316
+ c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
317
+ b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
318
+ a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
319
+ d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
320
+ c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
321
+ b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
322
+ a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
323
+ d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
324
+ c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
325
+ b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
326
+ a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
327
+ d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
328
+ c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
329
+ b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
330
+
331
+ a = safe_add(a, olda);
332
+ b = safe_add(b, oldb);
333
+ c = safe_add(c, oldc);
334
+ d = safe_add(d, oldd);
335
+ }
336
+ return Array(a, b, c, d);
337
+ }
338
+
339
+ /*
340
+ * These functions implement the four basic operations the algorithm uses.
341
+ */
342
+ function md5_cmn(q, a, b, x, s, t)
343
+ {
344
+ return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
345
+ }
346
+ function md5_ff(a, b, c, d, x, s, t)
347
+ {
348
+ return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
349
+ }
350
+ function md5_gg(a, b, c, d, x, s, t)
351
+ {
352
+ return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
353
+ }
354
+ function md5_hh(a, b, c, d, x, s, t)
355
+ {
356
+ return md5_cmn(b ^ c ^ d, a, b, x, s, t);
357
+ }
358
+ function md5_ii(a, b, c, d, x, s, t)
359
+ {
360
+ return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
361
+ }
362
+
363
+ /*
364
+ * Add integers, wrapping at 2^32. This uses 16-bit operations internally
365
+ * to work around bugs in some JS interpreters.
366
+ */
367
+ function safe_add(x, y)
368
+ {
369
+ var lsw = (x & 0xFFFF) + (y & 0xFFFF);
370
+ var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
371
+ return (msw << 16) | (lsw & 0xFFFF);
372
+ }
373
+
374
+ /*
375
+ * Bitwise rotate a 32-bit number to the left.
376
+ */
377
+ function bit_rol(num, cnt)
378
+ {
379
+ return (num << cnt) | (num >>> (32 - cnt));
380
+ }
381
+
382
+ out.MD5 = hex_md5;
383
+ })(window);
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: leifcr-gravtastic
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.2.7
5
+ platform: ruby
6
+ authors:
7
+ - Leif Ringstad
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rr
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description: A Ruby wrapper for Gravatar URLs
56
+ email: leifcr@gmail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - Gemfile
62
+ - README.md
63
+ - Rakefile
64
+ - lib/gravtastic.rb
65
+ - lib/gravtastic/engine.rb
66
+ - lib/gravtastic/version.rb
67
+ - lib/leifcr-gravtastic.rb
68
+ - spec/gravtastic_spec.rb
69
+ - spec/helper.rb
70
+ - vendor/assets/javascripts/gravtastic.coffee
71
+ - vendor/assets/javascripts/md5.js
72
+ homepage: http://github.com/leifcr/gravtastic
73
+ licenses: []
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project: gravtastic
91
+ rubygems_version: 2.2.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: A Ruby wrapper for Gravatar URLs
95
+ test_files: []