avatar 0.0.1

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.
Files changed (74) hide show
  1. data/.gitignore +11 -0
  2. data/History.txt +14 -0
  3. data/License.txt +20 -0
  4. data/Manifest.txt +73 -0
  5. data/README.txt +65 -0
  6. data/Rakefile +10 -0
  7. data/config/hoe.rb +70 -0
  8. data/config/requirements.rb +17 -0
  9. data/lib/avatar.rb +44 -0
  10. data/lib/avatar/source.rb +4 -0
  11. data/lib/avatar/source/abstract_source.rb +15 -0
  12. data/lib/avatar/source/file_column_source.rb +35 -0
  13. data/lib/avatar/source/gravatar_source.rb +78 -0
  14. data/lib/avatar/source/nil_source.rb +17 -0
  15. data/lib/avatar/source/source_chain.rb +51 -0
  16. data/lib/avatar/source/static_url_source.rb +25 -0
  17. data/lib/avatar/source/string_substitution_source.rb +48 -0
  18. data/lib/avatar/version.rb +9 -0
  19. data/lib/avatar/view.rb +4 -0
  20. data/lib/avatar/view/abstract_view_support.rb +15 -0
  21. data/lib/avatar/view/action_view_support.rb +23 -0
  22. data/script/destroy +14 -0
  23. data/script/generate +14 -0
  24. data/script/txt2html +74 -0
  25. data/setup.rb +1585 -0
  26. data/tasks/deployment.rake +34 -0
  27. data/tasks/environment.rake +7 -0
  28. data/tasks/testing.rake +37 -0
  29. data/tasks/website.rake +17 -0
  30. data/test/.gitignore +3 -0
  31. data/test/lib/database.rb +2 -0
  32. data/test/lib/database.yml +10 -0
  33. data/test/lib/file_column/CHANGELOG +69 -0
  34. data/test/lib/file_column/README +54 -0
  35. data/test/lib/file_column/Rakefile +36 -0
  36. data/test/lib/file_column/TODO +6 -0
  37. data/test/lib/file_column/init.rb +13 -0
  38. data/test/lib/file_column/lib/file_column.rb +720 -0
  39. data/test/lib/file_column/lib/file_column_helper.rb +150 -0
  40. data/test/lib/file_column/lib/file_compat.rb +28 -0
  41. data/test/lib/file_column/lib/magick_file_column.rb +260 -0
  42. data/test/lib/file_column/lib/rails_file_column.rb +19 -0
  43. data/test/lib/file_column/lib/test_case.rb +124 -0
  44. data/test/lib/file_column/lib/validations.rb +112 -0
  45. data/test/lib/file_column/test/abstract_unit.rb +63 -0
  46. data/test/lib/file_column/test/connection.rb +17 -0
  47. data/test/lib/file_column/test/file_column_helper_test.rb +97 -0
  48. data/test/lib/file_column/test/file_column_test.rb +650 -0
  49. data/test/lib/file_column/test/fixtures/entry.rb +32 -0
  50. data/test/lib/file_column/test/fixtures/invalid-image.jpg +1 -0
  51. data/test/lib/file_column/test/fixtures/kerb.jpg +0 -0
  52. data/test/lib/file_column/test/fixtures/mysql.sql +25 -0
  53. data/test/lib/file_column/test/fixtures/schema.rb +10 -0
  54. data/test/lib/file_column/test/fixtures/skanthak.png +0 -0
  55. data/test/lib/file_column/test/magick_test.rb +380 -0
  56. data/test/lib/file_column/test/magick_view_only_test.rb +21 -0
  57. data/test/lib/schema.rb +7 -0
  58. data/test/lib/user_suit.png +0 -0
  59. data/test/test_abstract_view_support.rb +22 -0
  60. data/test/test_action_view_support.rb +30 -0
  61. data/test/test_avatar.rb +12 -0
  62. data/test/test_file_column_source.rb +30 -0
  63. data/test/test_gravatar_source.rb +58 -0
  64. data/test/test_helper.rb +22 -0
  65. data/test/test_nil_source.rb +18 -0
  66. data/test/test_source_chain.rb +44 -0
  67. data/test/test_static_url_source.rb +18 -0
  68. data/test/test_string_substitution_source.rb +22 -0
  69. data/website/index.html +101 -0
  70. data/website/index.txt +44 -0
  71. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  72. data/website/stylesheets/screen.css +138 -0
  73. data/website/template.rhtml +48 -0
  74. metadata +141 -0
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/abstract_unit'
2
+ require File.dirname(__FILE__) + '/fixtures/entry'
3
+
4
+ class RMagickViewOnlyTest < Test::Unit::TestCase
5
+ include FileColumnHelper
6
+
7
+ def setup
8
+ Entry.file_column :image
9
+ @request = RequestMock.new
10
+ end
11
+
12
+ def teardown
13
+ FileUtils.rm_rf File.dirname(__FILE__)+"/public/entry/"
14
+ end
15
+
16
+ def test_url_for_image_column_without_model_versions
17
+ e = Entry.new(:image => upload(f("skanthak.png")))
18
+
19
+ assert_nothing_raised { url_for_image_column e, "image", "50x50" }
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ ActiveRecord::Schema.define :version => 0 do
2
+ create_table :users, :force => true do |t|
3
+ t.column :name, :text, :nil => false
4
+ t.column :email, :text, :nil => false
5
+ t.column :avatar, :string
6
+ end
7
+ end
Binary file
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'avatar/view/abstract_view_support'
3
+ require 'avatar/source/static_url_source'
4
+
5
+ class TestAbstractViewSupport < Test::Unit::TestCase
6
+
7
+ def setup
8
+ Avatar::source = Avatar::Source::StaticUrlSource.new('golfing.png')
9
+ @view_class = Class.new
10
+ @view_class.send :include, Avatar::View::AbstractViewSupport
11
+ @view = @view_class.new
12
+ end
13
+
14
+ def test_includes_basic_view_support
15
+ assert @view.kind_of?(Avatar::View::AbstractViewSupport)
16
+ end
17
+
18
+ def test_avatar_url_for_with_no_arguments
19
+ assert_equal 'golfing.png', @view.avatar_url_for(:a_person)
20
+ end
21
+
22
+ end
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'avatar/view/action_view_support'
3
+ require 'avatar/source/static_url_source'
4
+
5
+ class TestActionViewSupport < Test::Unit::TestCase
6
+
7
+ def setup
8
+ Avatar::source = Avatar::Source::StaticUrlSource.new('i-am-oscar-wilde.png')
9
+ @view_class = Class.new(ActionView::Base)
10
+ @view_class.send :include, Avatar::View::ActionViewSupport
11
+ @view = @view_class.new
12
+ end
13
+
14
+ def test_includes_basic_view_support
15
+ assert @view.kind_of?(Avatar::View::AbstractViewSupport)
16
+ end
17
+
18
+ def test_avatar_tag_empty_if_person_is_nil
19
+ assert_equal "", @view.avatar_tag(nil)
20
+ end
21
+
22
+ def test_avatar_tag_with_no_options
23
+ assert_equal "<img alt=\"I-am-oscar-wilde\" src=\"/images/i-am-oscar-wilde.png\" />", @view.avatar_tag(:a_person)
24
+ end
25
+
26
+ def test_avatar_tag_with_html_options
27
+ assert_equal "<img alt=\"I-am-oscar-wilde\" class=\"avatar\" src=\"/images/i-am-oscar-wilde.png\" />", @view.avatar_tag(:a_person, {}, {:class => :avatar})
28
+ end
29
+
30
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestAvatar < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_load_path_includes_avatar_lib
9
+ lib_path = File.expand_path(File.join(File.dirname(__FILE__), ['..', 'lib']))
10
+ assert $:.include?(lib_path)
11
+ end
12
+ end
@@ -0,0 +1,30 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
+ require 'file_column'
3
+ require 'avatar/source/file_column_source'
4
+
5
+ class User < ActiveRecord::Base
6
+ file_column :avatar
7
+ end
8
+
9
+ class TestFileColumnSource < Test::Unit::TestCase
10
+
11
+ def setup
12
+ @source = Avatar::Source::FileColumnSource.new
13
+ png = File.new(File.join(File.dirname(__FILE__), ['lib', 'user_suit.png']))
14
+ @user_with_avatar = User.create!(:email => 'joe@example.com', :avatar => png)
15
+ @user_without_avatar = User.create!(:email => 'sue@example.com')
16
+ end
17
+
18
+ def test_avatar_url_is_nil_if_person_is_nil
19
+ assert_nil @source.avatar_url_for(nil)
20
+ end
21
+
22
+ def test_avatar_url_is_nil_if_person_has_no_avatar
23
+ assert_nil @source.avatar_url_for(@user_without_avatar)
24
+ end
25
+
26
+ def test_avatar_url_for_person_with_avatar
27
+ assert_equal "/user/avatar/#{@user_with_avatar.id}/0/user_suit.png", @source.avatar_url_for(@user_with_avatar)
28
+ end
29
+
30
+ end
@@ -0,0 +1,58 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'avatar/source/gravatar_source'
3
+ require 'avatar/source/static_url_source'
4
+ require 'digest/md5'
5
+
6
+ class TestGravatarSource < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @source = Avatar::Source::GravatarSource.new
10
+ @gary = Person.new('gary@example.com', 'Gary Glumph')
11
+ @email_hash = Digest::MD5::hexdigest(@gary.email)
12
+ end
13
+
14
+ def test_nil_when_person_is_nil
15
+ assert_nil @source.avatar_url_for(nil)
16
+ end
17
+
18
+ def test_not_nil_when_person_is_not_nil
19
+ assert_equal "http://www.gravatar.com/avatar/#{@email_hash}", @source.avatar_url_for(@gary)
20
+ end
21
+
22
+ def test_field
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)
25
+ end
26
+
27
+ def test_site_wide_default_string
28
+ @source.default_source = 'fazbot'
29
+ assert_equal "http://www.gravatar.com/avatar/#{@email_hash}?default=fazbot", @source.avatar_url_for(@gary)
30
+ end
31
+
32
+ def test_site_wide_default_source
33
+ @source.default_source = Avatar::Source::StaticUrlSource.new('funky')
34
+ assert_equal "http://www.gravatar.com/avatar/#{@email_hash}?default=funky", @source.avatar_url_for(@gary)
35
+ end
36
+
37
+ def test_site_wide_default_nil
38
+ @source.default_source = Avatar::Source::StaticUrlSource.new('plumb')
39
+ @source.default_source = nil
40
+ assert_equal "http://www.gravatar.com/avatar/#{@email_hash}", @source.avatar_url_for(@gary)
41
+ end
42
+
43
+ def test_default_override
44
+ @source.default_source = Avatar::Source::StaticUrlSource.new('does it really matter?')
45
+ assert_equal "http://www.gravatar.com/avatar/#{@email_hash}?default=gonzo", @source.avatar_url_for(@gary, :default => 'gonzo')
46
+ end
47
+
48
+ def test_size
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}?s=62", @source.avatar_url_for(@gary, :s => 62)
51
+ end
52
+
53
+ def test_rating
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}?r=PG", @source.avatar_url_for(@gary, :r => 'PG')
56
+ end
57
+
58
+ end
@@ -0,0 +1,22 @@
1
+ # for Rails-specific tests:
2
+ RAILS_ROOT = "#{File.dirname(__FILE__)}" unless defined?(RAILS_ROOT)
3
+ RAILS_ENV = 'test' unless defined?(RAILS_ENV)
4
+ require 'test/unit'
5
+ require 'rubygems'
6
+ require 'active_record'
7
+ require 'active_support'
8
+ require 'action_controller'
9
+ require 'action_view'
10
+ $: << File.expand_path(File.join(File.dirname(__FILE__), ['lib', 'file_column', 'lib']))
11
+ require File.join(File.dirname(__FILE__), ['lib', 'file_column', 'init'])
12
+ require File.join(File.dirname(__FILE__), ['lib', 'database'])
13
+ require File.join(File.dirname(__FILE__), ['lib', 'schema'])
14
+ require File.join(File.dirname(__FILE__), ['..', 'lib', 'avatar'])
15
+
16
+ class Person
17
+ attr_accessor :email, :name
18
+ def initialize(email, name = nil)
19
+ @email = email
20
+ @name = name || email
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'avatar/source/nil_source'
3
+
4
+ class TestNilSource < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @source = Avatar::Source::NilSource.new
8
+ end
9
+
10
+ def test_nil_when_person_is_nil
11
+ assert_nil @source.avatar_url_for(nil)
12
+ end
13
+
14
+ def test_nil_when_person_is_not_nil
15
+ assert_nil @source.avatar_url_for(49329)
16
+ end
17
+
18
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'avatar/source/abstract_source'
3
+ require 'avatar/source/static_url_source'
4
+ require 'avatar/source/source_chain'
5
+
6
+ class FooSource
7
+ include Avatar::Source::AbstractSource
8
+ def avatar_url_for(person, options = {})
9
+ 'foobar' if person.to_s == 'foobar'
10
+ end
11
+ end
12
+
13
+ class TestSourceChain < Test::Unit::TestCase
14
+
15
+ def setup
16
+ @source = Avatar::Source::SourceChain.new
17
+ end
18
+
19
+ def test_nil_when_person_is_nil
20
+ assert_nil @source.avatar_url_for(nil)
21
+ end
22
+
23
+ def test_nil_when_person_is_not_nil
24
+ assert_nil @source.avatar_url_for(:scottish_terrier)
25
+ end
26
+
27
+ def test_avatar_url_for
28
+ @source << FooSource.new
29
+ assert_equal 'foobar', @source.avatar_url_for(:foobar)
30
+ assert_nil @source.avatar_url_for(:fazbot)
31
+
32
+ @source << Avatar::Source::StaticUrlSource.new('default_avatar.png')
33
+ assert_equal 'foobar', @source.avatar_url_for(:foobar)
34
+ assert_equal 'default_avatar.png', @source.avatar_url_for(:fazbot)
35
+ end
36
+
37
+ def test_clear!
38
+ @source << FooSource.new
39
+ @source << Avatar::Source::StaticUrlSource.new('eeek_a_mouse!')
40
+ @source.clear!
41
+ assert @source.empty?
42
+ end
43
+
44
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'avatar/source/static_url_source'
3
+
4
+ class TestStaticUrlSource < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @source = Avatar::Source::StaticUrlSource.new('foobar')
8
+ end
9
+
10
+ def test_nil_when_person_is_nil
11
+ assert_nil @source.avatar_url_for(nil)
12
+ end
13
+
14
+ def test_not_nil_when_person_is_not_nil
15
+ assert_equal 'foobar', @source.avatar_url_for(7)
16
+ end
17
+
18
+ end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'avatar/source/string_substitution_source'
3
+
4
+ class TestStringSubstitutionSource < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @source = Avatar::Source::StringSubstitutionSource.new('#{a} and #{b} but not {b}')
8
+ end
9
+
10
+ def test_avatar_url_nil_for_nil_person
11
+ assert_nil @source.avatar_url_for(nil)
12
+ end
13
+
14
+ def test_avatar_url_nil_when_not_all_variables_replaced
15
+ assert_nil @source.avatar_url_for(:bar, :b => 'ham')
16
+ end
17
+
18
+ def test_avatar_url_when_all_variables_replaced
19
+ assert_equal 'green eggs and ham but not {b}', @source.avatar_url_for(:bar, :a => 'green eggs', :b => 'ham')
20
+ end
21
+
22
+ end
@@ -0,0 +1,101 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+ <title>
8
+ Avatar
9
+ </title>
10
+ <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
+ <style>
12
+
13
+ </style>
14
+ <script type="text/javascript">
15
+ window.onload = function() {
16
+ settings = {
17
+ tl: { radius: 10 },
18
+ tr: { radius: 10 },
19
+ bl: { radius: 10 },
20
+ br: { radius: 10 },
21
+ antiAlias: true,
22
+ autoPad: true,
23
+ validTags: ["div"]
24
+ }
25
+ var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
+ versionBox.applyCornersToAll();
27
+ }
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <div id="main">
32
+
33
+ <h1>Avatar</h1>
34
+ <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/avatar"; return false'>
35
+ <p>Get Version</p>
36
+ <a href="http://rubyforge.org/projects/avatar" class="numbers">0.0.1</a>
37
+ </div>
38
+ <h1>&#x2192; &#8216;Avatar&#8217;</h1>
39
+
40
+
41
+ <h2>What
42
+ support for avatars</h2>
43
+
44
+
45
+ <h2>Installing</h2>
46
+
47
+
48
+ <p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">avatar</span></pre></p>
49
+
50
+
51
+ <h2>The basics
52
+ Set up Avatar::source (by default, a Gravatar with a StaticUrl as the default)</h2>
53
+
54
+
55
+ <h2>Demonstration of usage</h2>
56
+
57
+
58
+ <p>class PeopleHelper
59
+ 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>
65
+
66
+
67
+ <h2>Forum</h2>
68
+
69
+
70
+ <p><a href="http://groups.google.com/group/ruby-avatar">http://groups.google.com/group/ruby-avatar</a></p>
71
+
72
+
73
+ <h2>How to submit patches</h2>
74
+
75
+
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&#8217;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
+
78
+
79
+ <p>The trunk repository is <code>svn://rubyforge.org/var/svn/avatar/trunk</code> for anonymous access.</p>
80
+
81
+
82
+ <h2>License</h2>
83
+
84
+
85
+ <p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
86
+
87
+
88
+ <h2>Contact</h2>
89
+
90
+
91
+ <p>Comments are welcome. Send an email to <a href="mailto:FIXME"><span class="caps">FIXME</span> full name</a> email via the <a href="http://groups.google.com/group/avatar">forum</a></p>
92
+ <p class="coda">
93
+ <a href="FIXME email">FIXME full name</a>, 25th March 2008<br>
94
+ Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
95
+ </p>
96
+ </div>
97
+
98
+ <!-- insert site tracking codes here, like Google Urchin -->
99
+
100
+ </body>
101
+ </html>
@@ -0,0 +1,44 @@
1
+ h1. Avatar
2
+
3
+ h1. &#x2192; 'Avatar'
4
+
5
+
6
+ h2. What
7
+ support for avatars
8
+
9
+ h2. Installing
10
+
11
+ <pre syntax="ruby">sudo gem install avatar</pre>
12
+
13
+ h2. The basics
14
+ Set up Avatar::source (by default, a Gravatar with a StaticUrl as the default)
15
+
16
+
17
+ h2. Demonstration of usage
18
+
19
+ class PeopleHelper
20
+ include Avatar::View::ActionViewSupport
21
+ end
22
+
23
+ app/views/people/show.html.erb:
24
+ <%= avatar_tag(@current_user, :size => 40) %>
25
+
26
+
27
+ h2. Forum
28
+
29
+ "http://groups.google.com/group/ruby-avatar":http://groups.google.com/group/ruby-avatar
30
+
31
+ h2. How to submit patches
32
+
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
+
35
+ The trunk repository is <code>svn://rubyforge.org/var/svn/avatar/trunk</code> for anonymous access.
36
+
37
+ h2. License
38
+
39
+ This code is free to use under the terms of the MIT license.
40
+
41
+ h2. Contact
42
+
43
+ Comments are welcome. Send an email to "FIXME full name":mailto:FIXME email via the "forum":http://groups.google.com/group/avatar
44
+