gravatar_for 0.0.2.pre → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -0
- data/Rakefile +8 -0
- data/gravatar_for.gemspec +15 -10
- data/lib/gravatar_for/gravatar_for.rb +53 -2
- data/lib/gravatar_for/version.rb +8 -0
- data/test/test_gravatar_for.rb +22 -0
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffdc8512a1ff13176db89b4d32ec52abf3df3906
|
4
|
+
data.tar.gz: 53e58c70ce9bc9005750b2afa49ab487faf131d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd74cc355f5e6005589ef3261414fcb807354d701fd6813b53918fecc16fe79094317aaae36427485d6ecbed31405ae1de8d99490285a7d6177b086d4ce54d6a
|
7
|
+
data.tar.gz: b01532d550544c0fe915aab02a3104304e3dd4d3446cbc1e1edf1105015fbd1551370ef130fdf3fb2a132fb14ed8eaef4949621628813a9e4ffea3b2cabdeaae
|
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
## gravatar_for
|
2
|
+
|
3
|
+
Simple Rails view helper for getting Gravatar images.
|
4
|
+
|
5
|
+
Install
|
6
|
+
|
7
|
+
```zsh
|
8
|
+
gem install gravatar_for
|
9
|
+
```
|
10
|
+
|
11
|
+
Basic usage
|
12
|
+
```erb
|
13
|
+
<%= gravatar_for('user@example.com', class: 'gravatar') =>
|
14
|
+
```
|
15
|
+
|
16
|
+
Please check the documentation or read the source to what all can be applied
|
17
|
+
with this call.
|
data/Rakefile
ADDED
data/gravatar_for.gemspec
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
+
lib_directory = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib_directory) unless $LOAD_PATH.include?(lib_directory)
|
3
|
+
require 'gravatar_for/version'
|
4
|
+
|
1
5
|
Gem::Specification.new do |s|
|
2
|
-
s.name
|
3
|
-
s.version
|
4
|
-
s.
|
5
|
-
s.
|
6
|
-
s.
|
7
|
-
s.
|
8
|
-
s.
|
9
|
-
s.
|
10
|
-
s.
|
11
|
-
s.license
|
6
|
+
s.name = 'gravatar_for'
|
7
|
+
s.version = GravatarFor::VERSION
|
8
|
+
s.summary = 'A simple Gravatar view helper.'
|
9
|
+
s.description = 'gravatar_for is a simple, but capable Gravatar view helper.'
|
10
|
+
s.authors = 'Daniel Seitz'
|
11
|
+
s.email = 'daniel.e.seitz@gmail.com'
|
12
|
+
s.homepage = 'http://github.com/s3itz/gravatar_for'
|
13
|
+
s.files = `git ls-files`.split($/)
|
14
|
+
s.test_files = `git ls-files ./test`.split
|
15
|
+
s.license = 'MIT'
|
16
|
+
s.require_paths = ['lib']
|
12
17
|
end
|
@@ -1,7 +1,58 @@
|
|
1
1
|
module GravatarFor
|
2
|
+
GRAVATAR_BASE_URL = 'http://www.gravatar.com/avatar/'
|
3
|
+
GRAVATAR_SECURE_BASE_URL = GRAVATAR_BASE_URL.gsub('://www', 's://secure')
|
4
|
+
|
2
5
|
module ViewHelpers
|
3
|
-
|
4
|
-
|
6
|
+
# Returns an HTML5 image tag to the Gravatar image for +email+.
|
7
|
+
#
|
8
|
+
# #### Options
|
9
|
+
#
|
10
|
+
# You can add HTML attributes and modify Gravatar results using the
|
11
|
+
# +options+
|
12
|
+
#
|
13
|
+
# * <tt>:size</tt> - If no size is given; Gravatar's default
|
14
|
+
# of 80px by 80px is used.
|
15
|
+
# * <tt>:default</tt> - The default URL for an image to display if the
|
16
|
+
# email has no Gravatar image. By default, Gravatar returns its logo if
|
17
|
+
# there is no image to reference. To cover all basis, you can use the
|
18
|
+
# following symbols to use some of Gravtar's other options:
|
19
|
+
# * :mm - Mystery Man
|
20
|
+
# * :identicon - A geometric pattern based on an email has
|
21
|
+
# * :monsterid - A generated monster
|
22
|
+
# * :wavatar - Computer generated faces
|
23
|
+
# * :retro - 8-bit generated arcade-styled face
|
24
|
+
# * :blank - A transparent PNG image
|
25
|
+
# * 404 - HTTP 404 response (File Not Found)
|
26
|
+
# * <tt>:rating</tt> - Rating to request, either :g or 'g' (default);
|
27
|
+
# :pg or 'pg'; :r or 'r'; :x or 'x'
|
28
|
+
# * <tt>:forcedefault</tt> - Force default image, default: false
|
29
|
+
# * <tt>:alt</tt> - Override the HTML alternate text attribute. By default
|
30
|
+
# the email provided will be placed into this attribute.
|
31
|
+
# * <tt>:ssl</tt> - Use regular or secure URL, default +false+
|
32
|
+
# * Any additional +options+ will be passed to
|
33
|
+
# ActionView::Helpers::TagHelper::tag
|
34
|
+
def gravatar_for(email, options = {})
|
35
|
+
raise ArgumentError, 'Email must be provided' unless email && !email.strip.empty?
|
36
|
+
|
37
|
+
base_url = options[:ssl]? GRAVATAR_SECURE_BASE_URL : GRAVATAR_BASE_URL
|
38
|
+
options.delete(:ssl) if options.has_key?(:ssh)
|
39
|
+
|
40
|
+
options[:alt] ||= email
|
41
|
+
|
42
|
+
query = ''
|
43
|
+
[:size, :default, :rating, :forcedefault].each do |key|
|
44
|
+
if options.has_key?(key)
|
45
|
+
query << query.empty? ? '?' : '&'
|
46
|
+
query << "#{key}=#{options.delete(key)}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
src = base_url + Digest::MD5.hexdigest(email)
|
51
|
+
src << query unless query.empty?
|
52
|
+
|
53
|
+
options[:src] = src
|
54
|
+
|
55
|
+
tag('img', options, true)
|
5
56
|
end
|
6
57
|
end
|
7
58
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'digest/md5'
|
3
|
+
require 'gravatar_for'
|
4
|
+
require 'action_view'
|
5
|
+
|
6
|
+
include ActionView::Helpers::TagHelper
|
7
|
+
include GravatarFor
|
8
|
+
include ViewHelpers
|
9
|
+
|
10
|
+
class GravatarForTest < MiniTest::Test
|
11
|
+
BASE_URL = GravatarFor::GRAVATAR_BASE_URL
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@email = 'user@aol.com'
|
15
|
+
@email_hash = Digest::MD5.hexdigest(@email)
|
16
|
+
@response = "<img alt=\"#{@email}\" src=\"#{BASE_URL}#{@email_hash}\">"
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_generate_image_tag
|
20
|
+
assert_equal gravatar_for(@email), @response
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gravatar_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Seitz
|
@@ -17,10 +17,14 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- ".gitignore"
|
20
|
+
- README.md
|
21
|
+
- Rakefile
|
20
22
|
- gravatar_for.gemspec
|
21
23
|
- lib/gravatar_for.rb
|
22
24
|
- lib/gravatar_for/gravatar_for.rb
|
23
25
|
- lib/gravatar_for/railtie.rb
|
26
|
+
- lib/gravatar_for/version.rb
|
27
|
+
- test/test_gravatar_for.rb
|
24
28
|
homepage: http://github.com/s3itz/gravatar_for
|
25
29
|
licenses:
|
26
30
|
- MIT
|
@@ -36,13 +40,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
40
|
version: '0'
|
37
41
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
42
|
requirements:
|
39
|
-
- - "
|
43
|
+
- - ">="
|
40
44
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
45
|
+
version: '0'
|
42
46
|
requirements: []
|
43
47
|
rubyforge_project:
|
44
48
|
rubygems_version: 2.2.2
|
45
49
|
signing_key:
|
46
50
|
specification_version: 4
|
47
51
|
summary: A simple Gravatar view helper.
|
48
|
-
test_files:
|
52
|
+
test_files:
|
53
|
+
- test/test_gravatar_for.rb
|