avatar 0.0.1 → 0.0.2
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/.gitignore +2 -5
- data/History.txt +10 -0
- data/lib/avatar/source/gravatar_source.rb +39 -10
- data/lib/avatar/source/source_chain.rb +3 -2
- data/lib/avatar/version.rb +1 -1
- data/test/test_gravatar_source.rb +2 -2
- data/website/index.html +4 -4
- data/website/index.txt +2 -2
- metadata +2 -2
data/.gitignore
CHANGED
data/History.txt
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
== 0.0.2 2008-03-24
|
2
|
+
* 1 major fix:
|
3
|
+
* SourceChain duplicates options before passing to elements
|
4
|
+
|
5
|
+
* 1 minor fix:
|
6
|
+
* forced GravatarSource to coerce rating and size to proper values
|
7
|
+
|
8
|
+
* 1 minor enhancement:
|
9
|
+
* broke out URL generation in GravatarSource to allow overriding
|
10
|
+
|
1
11
|
== 0.0.1 2008-03-24
|
2
12
|
|
3
13
|
* 1 major enhancement:
|
@@ -3,6 +3,15 @@ require 'avatar/source/static_url_source'
|
|
3
3
|
require 'avatar/source/nil_source'
|
4
4
|
require 'digest/md5'
|
5
5
|
|
6
|
+
unless Object.method_defined?(:returning)
|
7
|
+
Object.class_eval do
|
8
|
+
def returning(value)
|
9
|
+
yield(value)
|
10
|
+
value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
6
15
|
module Avatar # :nodoc:
|
7
16
|
module Source # :nodoc:
|
8
17
|
# NOTE: since Gravatar always returns a URL (never a 404), instances of this
|
@@ -23,7 +32,14 @@ module Avatar # :nodoc:
|
|
23
32
|
'http://www.gravatar.com/avatar/'
|
24
33
|
end
|
25
34
|
|
26
|
-
#
|
35
|
+
# ['G', 'PG', 'R', 'X']
|
36
|
+
def self.allowed_ratings
|
37
|
+
['G', 'PG', 'R', 'X']
|
38
|
+
end
|
39
|
+
|
40
|
+
# Arguments:
|
41
|
+
# * +default_source+: a Source to generate defaults to be passed to Gravatar; optional; default: nil (a NilSource).
|
42
|
+
# * +default_field+: the field within each +person+ passed to <code>avatar_url_for</code> in which to look for an email address
|
27
43
|
def initialize(default_source = nil, default_field = :email)
|
28
44
|
self.default_source = default_source #not @default_source = ... b/c want to use the setter function below
|
29
45
|
@default_field = default_field
|
@@ -38,17 +54,30 @@ module Avatar # :nodoc:
|
|
38
54
|
# * <code>:rating or :r</code> - the maximum rating; one of ['G', 'PG', 'R', 'X']
|
39
55
|
def avatar_url_for(person, options = {})
|
40
56
|
return nil if person.nil?
|
41
|
-
options
|
42
|
-
field = options[:field] || default_field
|
57
|
+
field = options.delete(:field) || default_field
|
43
58
|
raise ArgumentError.new('No field specified; either specify a default field or pass in a value for :field (probably :email)') unless field
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
59
|
+
|
60
|
+
options = parse_options(person, options)
|
61
|
+
returning(self.class.base_url) do |url|
|
62
|
+
url << Digest::MD5::hexdigest(person.send(field)).strip
|
63
|
+
options.each do |k, v|
|
64
|
+
next if v.nil?
|
65
|
+
url << (url.include?('?') ? '&' : '?')
|
66
|
+
url << "#{k}=#{v}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def parse_options(person, options)
|
72
|
+
returning({}) do |result|
|
73
|
+
result[:default] = options[:default] || default_avatar_url_for(person, options)
|
74
|
+
|
75
|
+
size = options[:size] || options[:s]
|
76
|
+
result[:size] = size if size.to_s =~ /^\d*/
|
77
|
+
|
78
|
+
rating = options[:rating] || options[:r]
|
79
|
+
result[:rating] = rating.upcase if rating and self.class.allowed_ratings.include?(rating.to_s)
|
50
80
|
end
|
51
|
-
url
|
52
81
|
end
|
53
82
|
|
54
83
|
# Set the default source for all people.
|
@@ -37,10 +37,11 @@ module Avatar # :nodoc:
|
|
37
37
|
end
|
38
38
|
|
39
39
|
# Iterate through the chain and return the first URL returned.
|
40
|
-
# Any error raised will propagate.
|
40
|
+
# Any error raised will propagate. Duplicates +options+ before
|
41
|
+
# passing so each Source receives the same arguments.
|
41
42
|
def avatar_url_for(person, options = {})
|
42
43
|
@chain.each do |source|
|
43
|
-
result = source.avatar_url_for(person, options)
|
44
|
+
result = source.avatar_url_for(person, options.dup)
|
44
45
|
return result unless result.nil?
|
45
46
|
end
|
46
47
|
return nil
|
data/lib/avatar/version.rb
CHANGED
@@ -47,12 +47,12 @@ class TestGravatarSource < Test::Unit::TestCase
|
|
47
47
|
|
48
48
|
def test_size
|
49
49
|
assert_equal "http://www.gravatar.com/avatar/#{@email_hash}?size=70", @source.avatar_url_for(@gary, :size => 70)
|
50
|
-
assert_equal "http://www.gravatar.com/avatar/#{@email_hash}?
|
50
|
+
assert_equal "http://www.gravatar.com/avatar/#{@email_hash}?size=62", @source.avatar_url_for(@gary, :s => 62)
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_rating
|
54
54
|
assert_equal "http://www.gravatar.com/avatar/#{@email_hash}?rating=R", @source.avatar_url_for(@gary, :rating => 'R')
|
55
|
-
assert_equal "http://www.gravatar.com/avatar/#{@email_hash}?
|
55
|
+
assert_equal "http://www.gravatar.com/avatar/#{@email_hash}?rating=PG", @source.avatar_url_for(@gary, :r => 'PG')
|
56
56
|
end
|
57
57
|
|
58
58
|
end
|
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>Avatar</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/avatar"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/avatar" class="numbers">0.0.
|
36
|
+
<a href="http://rubyforge.org/projects/avatar" class="numbers">0.0.2</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ ‘Avatar’</h1>
|
39
39
|
|
@@ -76,7 +76,7 @@ end</p>
|
|
76
76
|
<p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people’s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
|
77
77
|
|
78
78
|
|
79
|
-
<p>The
|
79
|
+
<p>The project is hosted on <a href="http://github.com/gcnovus/avatar/tree/master">GitHub</a></p>
|
80
80
|
|
81
81
|
|
82
82
|
<h2>License</h2>
|
@@ -88,9 +88,9 @@ end</p>
|
|
88
88
|
<h2>Contact</h2>
|
89
89
|
|
90
90
|
|
91
|
-
<p>Comments are welcome.
|
91
|
+
<p>Comments are welcome. Put them on the <a href="http://groups.google.com/group/ruby-avatar">forum</a></p>
|
92
92
|
<p class="coda">
|
93
|
-
<a href="FIXME email">FIXME full name</a>,
|
93
|
+
<a href="FIXME email">FIXME full name</a>, 26th March 2008<br>
|
94
94
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
95
95
|
</p>
|
96
96
|
</div>
|
data/website/index.txt
CHANGED
@@ -32,7 +32,7 @@ h2. How to submit patches
|
|
32
32
|
|
33
33
|
Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
|
34
34
|
|
35
|
-
The
|
35
|
+
The project is hosted on "GitHub":http://github.com/gcnovus/avatar/tree/master
|
36
36
|
|
37
37
|
h2. License
|
38
38
|
|
@@ -40,5 +40,5 @@ This code is free to use under the terms of the MIT license.
|
|
40
40
|
|
41
41
|
h2. Contact
|
42
42
|
|
43
|
-
Comments are welcome.
|
43
|
+
Comments are welcome. Put them on the "forum":http://groups.google.com/group/ruby-avatar
|
44
44
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avatar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Rosen
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-03-
|
12
|
+
date: 2008-03-26 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|