avatar 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,12 @@
1
+ == 0.0.3 2008-03-27
2
+ * 2 minor fixes:
3
+ * GravatarSource now takes parameter :gravatar_field instead of :field for compatibility with other sources
4
+ * FileColumnSource now takes parameter :file_column_field instead of :field for compatibility with other sources
5
+
6
+ * 2 minor enhancements:
7
+ * broke out options parsing in FileColumnSource to allow overriding
8
+ * added :gravatar_xxx versions to allowed options for GravatarSource
9
+
1
10
  == 0.0.2 2008-03-24
2
11
  * 1 major fix:
3
12
  * SourceChain duplicates options before passing to elements
@@ -1,3 +1,12 @@
1
+ unless Object.method_defined?(:returning)
2
+ Object.class_eval do
3
+ def returning(value)
4
+ yield(value)
5
+ value
6
+ end
7
+ end
8
+ end
9
+
1
10
  module Avatar # :nodoc:
2
11
  module Source # :nodoc:
3
12
  # To be included by classes that generate avatar URLs from profiles.
@@ -16,20 +16,24 @@ module Avatar # :nodoc:
16
16
  end
17
17
 
18
18
  # Returns nil if person is nil; otherwise, returns the (possibly nil) result of
19
- # <code>url_for_image_column</code>, passing in all of +options+ except :field.
19
+ # <code>url_for_image_column</code>, passing in all of +options+ except :file_column_field.
20
20
  # Options:
21
- # * <code>:field</code> - the image file column within +person+; by default, :avatar
21
+ # * <code>:file_column_field</code> - the image file column within +person+; by default, :avatar
22
22
  # * <code>:file_column_version</code> - one of the versions of the file_column; no default
23
23
  # If :file_column_version is not specified, all other options are passed to
24
24
  # <code>url_for_image_column</code> as +options+ (see FileColumnHelper)
25
25
  def avatar_url_for(person, options = {})
26
26
  return nil if person.nil?
27
- field = options.delete(:field) || default_field
27
+ options = parse_options(person, options)
28
+ field = options.delete(:file_column_field) || default_field
28
29
  return nil if field.nil? || person.send(field).nil?
29
30
  options = options[:file_column_version] || options
30
31
  url_for_image_column(person, field, options)
31
32
  end
32
33
 
34
+ def parse_options(person, options)
35
+ options
36
+ end
33
37
  end
34
38
  end
35
39
  end
@@ -3,15 +3,6 @@ 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
-
15
6
  module Avatar # :nodoc:
16
7
  module Source # :nodoc:
17
8
  # NOTE: since Gravatar always returns a URL (never a 404), instances of this
@@ -48,16 +39,16 @@ module Avatar # :nodoc:
48
39
 
49
40
  # Generates a Gravatar URL. Returns nil if person is nil.
50
41
  # Options:
51
- # * <code>:field (Symbol)</code> - the field to call from person. By default, <code>:email</code>.
42
+ # * <code>:gravatar_field (Symbol)</code> - the field to call from person. By default, <code>:email</code>.
52
43
  # * <code>:default (String)</code> - override the default generated by <code>default_source</code>.
53
- # * <code>:size or :s</code> - the size in pixels of the avatar to render.
54
- # * <code>:rating or :r</code> - the maximum rating; one of ['G', 'PG', 'R', 'X']
44
+ # * <code>:gravatar_size or size or :s</code> - the size in pixels of the avatar to render.
45
+ # * <code>:gravatar_rating or rating or :r</code> - the maximum rating; one of ['G', 'PG', 'R', 'X']
55
46
  def avatar_url_for(person, options = {})
56
47
  return nil if person.nil?
57
- field = options.delete(:field) || default_field
58
- raise ArgumentError.new('No field specified; either specify a default field or pass in a value for :field (probably :email)') unless field
59
-
60
48
  options = parse_options(person, options)
49
+ field = options.delete(:gravatar_field)
50
+ raise ArgumentError.new('No field specified; either specify a default field or pass in a value for :gravatar_field (probably :email)') unless field
51
+
61
52
  returning(self.class.base_url) do |url|
62
53
  url << Digest::MD5::hexdigest(person.send(field)).strip
63
54
  options.each do |k, v|
@@ -68,14 +59,21 @@ module Avatar # :nodoc:
68
59
  end
69
60
  end
70
61
 
62
+ # Returns a Hash containing
63
+ # * :field - passed through; defaults to <code>self.default_field</code>
64
+ # * :default - passed through; defaults to <code>self.default_avatar_url_for(+person+, +options+)</code>
65
+ # * :size - :gravatar_size or :size or :s passed through <em>only if a number</em>
66
+ # * :rating - :gravatar_rating or :rating or :r passed through <em>only if one of <code>self.class.allowed_ratings</code></em>
71
67
  def parse_options(person, options)
72
68
  returning({}) do |result|
69
+ result[:gravatar_field] = options[:gravatar_field] || default_field
70
+
73
71
  result[:default] = options[:default] || default_avatar_url_for(person, options)
74
72
 
75
- size = options[:size] || options[:s]
73
+ size = options[:gravatar_size] || options[:size] || options[:s]
76
74
  result[:size] = size if size.to_s =~ /^\d*/
77
75
 
78
- rating = options[:rating] || options[:r]
76
+ rating = options[:gravatar_rating] || options[:rating] || options[:r]
79
77
  result[:rating] = rating.upcase if rating and self.class.allowed_ratings.include?(rating.to_s)
80
78
  end
81
79
  end
@@ -15,8 +15,8 @@ module Avatar # :nodoc:
15
15
  # Create a new source with static url +url+, which can contain any number
16
16
  # of variables to be subsituted through +options+. Strings should
17
17
  # be of the form '...#{variable_a}...#{variable_b}...'. <em>note the
18
- # single quotes</em>; double quotes will cause the variables to be
19
- # substituted at Source-creation (when #new is called); this is almost
18
+ # single quotes</em>. Double quotes will cause the variables to be
19
+ # substituted at Source-creation (when #new is called), which is almost
20
20
  # certainly <strong>not</strong> what you want.
21
21
  def initialize(url)
22
22
  raise ArgumentError.new("URL cannot be nil") if url.nil?
@@ -2,7 +2,7 @@ module Avatar #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -4,6 +4,7 @@ require 'avatar/source/file_column_source'
4
4
 
5
5
  class User < ActiveRecord::Base
6
6
  file_column :avatar
7
+ file_column :icon
7
8
  end
8
9
 
9
10
  class TestFileColumnSource < Test::Unit::TestCase
@@ -12,6 +13,7 @@ class TestFileColumnSource < Test::Unit::TestCase
12
13
  @source = Avatar::Source::FileColumnSource.new
13
14
  png = File.new(File.join(File.dirname(__FILE__), ['lib', 'user_suit.png']))
14
15
  @user_with_avatar = User.create!(:email => 'joe@example.com', :avatar => png)
16
+ @user_with_icon = User.create!(:email => 'terry@example.com', :icon => png)
15
17
  @user_without_avatar = User.create!(:email => 'sue@example.com')
16
18
  end
17
19
 
@@ -27,4 +29,8 @@ class TestFileColumnSource < Test::Unit::TestCase
27
29
  assert_equal "/user/avatar/#{@user_with_avatar.id}/0/user_suit.png", @source.avatar_url_for(@user_with_avatar)
28
30
  end
29
31
 
32
+ def test_avatar_url_for_person_with_icon_and_custom_file_column_field
33
+ assert_equal "/user/icon/#{@user_with_icon.id}/0/user_suit.png", @source.avatar_url_for(@user_with_icon, :file_column_field => :icon)
34
+ end
35
+
30
36
  end
@@ -21,7 +21,7 @@ class TestGravatarSource < Test::Unit::TestCase
21
21
 
22
22
  def test_field
23
23
  name_hash = Digest::MD5::hexdigest(@gary.name)
24
- assert_equal "http://www.gravatar.com/avatar/#{name_hash}", @source.avatar_url_for(@gary, :field => :name)
24
+ assert_equal "http://www.gravatar.com/avatar/#{name_hash}", @source.avatar_url_for(@gary, :gravatar_field => :name)
25
25
  end
26
26
 
27
27
  def test_site_wide_default_string
@@ -46,11 +46,13 @@ class TestGravatarSource < Test::Unit::TestCase
46
46
  end
47
47
 
48
48
  def test_size
49
- assert_equal "http://www.gravatar.com/avatar/#{@email_hash}?size=70", @source.avatar_url_for(@gary, :size => 70)
49
+ assert_equal "http://www.gravatar.com/avatar/#{@email_hash}?size=70", @source.avatar_url_for(@gary, :gravatar_size => 70)
50
+ assert_equal "http://www.gravatar.com/avatar/#{@email_hash}?size=109", @source.avatar_url_for(@gary, :size => 109)
50
51
  assert_equal "http://www.gravatar.com/avatar/#{@email_hash}?size=62", @source.avatar_url_for(@gary, :s => 62)
51
52
  end
52
53
 
53
54
  def test_rating
55
+ assert_equal "http://www.gravatar.com/avatar/#{@email_hash}?rating=G", @source.avatar_url_for(@gary, :gravatar_rating => 'G')
54
56
  assert_equal "http://www.gravatar.com/avatar/#{@email_hash}?rating=R", @source.avatar_url_for(@gary, :rating => 'R')
55
57
  assert_equal "http://www.gravatar.com/avatar/#{@email_hash}?rating=PG", @source.avatar_url_for(@gary, :r => 'PG')
56
58
  end
@@ -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.2</a>
36
+ <a href="http://rubyforge.org/projects/avatar" class="numbers">0.0.3</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;Avatar&#8217;</h1>
39
39
 
@@ -55,14 +55,17 @@ Set up Avatar::source (by default, a Gravatar with a StaticUrl as the default)</
55
55
  <h2>Demonstration of usage</h2>
56
56
 
57
57
 
58
- <p>class PeopleHelper
58
+ app/helpers/people_helper.rb:
59
+ <pre><code class='ruby'>
60
+ class PeopleHelper
59
61
  include Avatar::View::ActionViewSupport
60
- end</p>
61
-
62
-
63
- <p>app/views/people/show.html.erb:
64
- &lt;%= avatar_tag(@current_user, :size =&gt; 40) %&gt;</p>
62
+ end
63
+ </code></pre>
65
64
 
65
+ app/views/people/show.html.erb:
66
+ <pre><code class='ruby erb'>
67
+ &lt;%= avatar_tag(@current_user, :size =&gt; 40) %&gt;
68
+ </code></pre>
66
69
 
67
70
  <h2>Forum</h2>
68
71
 
@@ -90,7 +93,7 @@ end</p>
90
93
 
91
94
  <p>Comments are welcome. Put them on the <a href="http://groups.google.com/group/ruby-avatar">forum</a></p>
92
95
  <p class="coda">
93
- <a href="FIXME email">FIXME full name</a>, 26th March 2008<br>
96
+ <a href="FIXME email">FIXME full name</a>, 27th March 2008<br>
94
97
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
95
98
  </p>
96
99
  </div>
@@ -16,12 +16,17 @@ Set up Avatar::source (by default, a Gravatar with a StaticUrl as the default)
16
16
 
17
17
  h2. Demonstration of usage
18
18
 
19
+ app/helpers/people_helper.rb:
20
+ <pre><code class='ruby'>
19
21
  class PeopleHelper
20
22
  include Avatar::View::ActionViewSupport
21
- end
23
+ end
24
+ </code></pre>
22
25
 
23
26
  app/views/people/show.html.erb:
27
+ <pre><code class='ruby erb'>
24
28
  <%= avatar_tag(@current_user, :size => 40) %>
29
+ </code></pre>
25
30
 
26
31
 
27
32
  h2. Forum
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.2
4
+ version: 0.0.3
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-26 00:00:00 -04:00
12
+ date: 2008-03-27 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15