simple_gravatar 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE +7 -0
- data/README.md +31 -0
- data/Rakefile +10 -0
- data/lib/simple_gravatar/version.rb +3 -0
- data/lib/simple_gravatar.rb +35 -0
- data/simple_gravatar.gemspec +26 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/unit/simple_gravatar_spec.rb +56 -0
- metadata +80 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2012 Patricio Mac Adden <patriciomacadden@gmail.com>
|
2
|
+
|
3
|
+
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:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
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.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# SimpleGravatar [![Build Status](https://travis-ci.org/patriciomacadden/simple_gravatar.png)](https://travis-ci.org/patriciomacadden/simple_gravatar) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/patriciomacadden/simple_gravatar)
|
2
|
+
|
3
|
+
### Add gravatars to your ruby project as simple as possible.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add it to your Gemfile and run the `bundle` command:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'simple_gravatar'
|
11
|
+
```
|
12
|
+
|
13
|
+
## Getting started
|
14
|
+
|
15
|
+
In rails, you can add gravatars just using the `gravatar_url` helper method:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
<%= image_tag gravatar_url('patriciomacadden@gmail.com') %>
|
19
|
+
```
|
20
|
+
|
21
|
+
## Available options
|
22
|
+
|
23
|
+
All available options are the specified by [Gravatar API documentation](http://en.gravatar.com/site/implement/images/).
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create a branch (`git checkout -b my_awesome_branch`)
|
29
|
+
3. Commit your changes (`git commit -am "Added some magic"`)
|
30
|
+
4. Push to the branch (`git push origin my_awesome_branch`)
|
31
|
+
5. Send pull request
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'simple_gravatar/version'
|
2
|
+
|
3
|
+
module SimpleGravatar
|
4
|
+
DEFAULT_OPTIONS = {
|
5
|
+
default: nil,
|
6
|
+
forcedefault: false,
|
7
|
+
rating: :g,
|
8
|
+
secure: false,
|
9
|
+
size: 48
|
10
|
+
}
|
11
|
+
|
12
|
+
def gravatar_url(email, options = {})
|
13
|
+
options = options.reverse_merge(DEFAULT_OPTIONS)
|
14
|
+
secure = options[:secure]
|
15
|
+
options.delete(:secure)
|
16
|
+
|
17
|
+
unless options[:forcedefault]
|
18
|
+
options.delete(:forcedefault)
|
19
|
+
end
|
20
|
+
|
21
|
+
gravatar_id = Digest::MD5.hexdigest(email.downcase)
|
22
|
+
|
23
|
+
params = options.collect { |k, v| "#{k}=#{v}" }.join('&')
|
24
|
+
|
25
|
+
url = if secure
|
26
|
+
"https://secure.gravatar.com/avatar"
|
27
|
+
else
|
28
|
+
"http://gravatar.com/avatar"
|
29
|
+
end
|
30
|
+
|
31
|
+
"#{url}/#{gravatar_id}.png?#{params}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
ActionView::Base.send(:include, SimpleGravatar) if defined? ActionView::Base
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'simple_gravatar/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'simple_gravatar'
|
7
|
+
s.version = SimpleGravatar::VERSION
|
8
|
+
s.authors = ['Patricio Mac Adden']
|
9
|
+
s.email = ['patriciomacadden@gmail.com']
|
10
|
+
s.homepage = 'https://github.com/patriciomacadden/simple_gravatar'
|
11
|
+
s.summary = %q{Add gravatars to your ruby project as simple as possible.}
|
12
|
+
s.description = %q{Add gravatars to your ruby project as simple as possible.}
|
13
|
+
|
14
|
+
s.rubyforge_project = 'simple_gravatar'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ['lib']
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
s.add_dependency 'railties'
|
25
|
+
s.add_dependency 'activesupport'
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include SimpleGravatar
|
4
|
+
|
5
|
+
describe SimpleGravatar do
|
6
|
+
describe SimpleGravatar::VERSION do
|
7
|
+
it 'should be defined' do
|
8
|
+
SimpleGravatar::VERSION.wont_be_nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe :gravatar_url do
|
13
|
+
|
14
|
+
let(:email) { 'some_email@gmail.com' }
|
15
|
+
|
16
|
+
it 'should digest the email' do
|
17
|
+
url = gravatar_url email
|
18
|
+
url.must_match Digest::MD5.hexdigest(email)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'when overriding the default parameter' do
|
22
|
+
it 'should be replaced' do
|
23
|
+
url = gravatar_url email, default: :mm
|
24
|
+
url.must_match 'default=mm'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'when overriding the forcedefault parameter' do
|
29
|
+
it 'should be replaced' do
|
30
|
+
url = gravatar_url email, forcedefault: true
|
31
|
+
url.must_match 'forcedefault=true'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'when overriding the rating parameter' do
|
36
|
+
it 'should be replaced' do
|
37
|
+
url = gravatar_url email, rating: :pg
|
38
|
+
url.must_match 'rating=pg'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'when overriding the secure parameter' do
|
43
|
+
it 'should be replaced' do
|
44
|
+
url = gravatar_url email, secure: true
|
45
|
+
url.must_match 'https://secure.gravatar.com/avatar/'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'when overriding the size parameter' do
|
50
|
+
it 'should be replaced' do
|
51
|
+
url = gravatar_url email, size: 64
|
52
|
+
url.must_match 'size=64'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_gravatar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Patricio Mac Adden
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: &70362587214280 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70362587214280
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activesupport
|
27
|
+
requirement: &70362587212580 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70362587212580
|
36
|
+
description: Add gravatars to your ruby project as simple as possible.
|
37
|
+
email:
|
38
|
+
- patriciomacadden@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- .travis.yml
|
45
|
+
- Gemfile
|
46
|
+
- LICENSE
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- lib/simple_gravatar.rb
|
50
|
+
- lib/simple_gravatar/version.rb
|
51
|
+
- simple_gravatar.gemspec
|
52
|
+
- spec/spec_helper.rb
|
53
|
+
- spec/unit/simple_gravatar_spec.rb
|
54
|
+
homepage: https://github.com/patriciomacadden/simple_gravatar
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project: simple_gravatar
|
74
|
+
rubygems_version: 1.8.17
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Add gravatars to your ruby project as simple as possible.
|
78
|
+
test_files:
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
- spec/unit/simple_gravatar_spec.rb
|