avatar 0.0.4 → 0.0.5

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 (49) hide show
  1. data/History.txt +10 -0
  2. data/Manifest.txt +32 -6
  3. data/lib/avatar.rb +1 -1
  4. data/lib/avatar/source/gravatar_source.rb +7 -5
  5. data/lib/avatar/source/paperclip_source.rb +52 -0
  6. data/lib/avatar/source/wrapper.rb +6 -0
  7. data/lib/avatar/source/wrapper/abstract_source_wrapper.rb +33 -0
  8. data/lib/avatar/source/wrapper/rails_asset_source_wrapper.rb +36 -0
  9. data/lib/avatar/source/wrapper/string_substitution_source_wrapper.rb +55 -0
  10. data/lib/avatar/version.rb +1 -1
  11. data/test/lib/paperclip/README +32 -0
  12. data/test/lib/paperclip/Rakefile +41 -0
  13. data/test/lib/paperclip/generators/paperclip/USAGE +5 -0
  14. data/test/lib/paperclip/generators/paperclip/paperclip_generator.rb +27 -0
  15. data/test/lib/paperclip/generators/paperclip/templates/paperclip_migration.rb +17 -0
  16. data/test/lib/paperclip/init.rb +3 -0
  17. data/test/lib/paperclip/lib/paperclip.rb +197 -0
  18. data/test/lib/paperclip/lib/paperclip/attachment.rb +230 -0
  19. data/test/lib/paperclip/lib/paperclip/geometry.rb +109 -0
  20. data/test/lib/paperclip/lib/paperclip/iostream.rb +43 -0
  21. data/test/lib/paperclip/lib/paperclip/thumbnail.rb +80 -0
  22. data/test/lib/paperclip/lib/paperclip/upfile.rb +32 -0
  23. data/test/lib/paperclip/tasks/paperclip_tasks.rake +38 -0
  24. data/test/lib/paperclip/test/database.yml +5 -0
  25. data/test/lib/paperclip/test/fixtures/12k.png +0 -0
  26. data/test/lib/paperclip/test/fixtures/5k.png +0 -0
  27. data/test/lib/paperclip/test/fixtures/bad.png +1 -0
  28. data/test/lib/paperclip/test/helper.rb +38 -0
  29. data/test/lib/paperclip/test/test_attachment.rb +99 -0
  30. data/test/lib/paperclip/test/test_geometry.rb +142 -0
  31. data/test/lib/paperclip/test/test_integration.rb +76 -0
  32. data/test/lib/paperclip/test/test_iostream.rb +60 -0
  33. data/test/lib/paperclip/test/test_paperclip.rb +83 -0
  34. data/test/lib/paperclip/test/test_thumbnail.rb +76 -0
  35. data/test/lib/schema.rb +14 -1
  36. data/test/test_file_column_source.rb +8 -6
  37. data/test/test_gravatar_source.rb +5 -0
  38. data/test/test_helper.rb +7 -2
  39. data/test/test_paperclip_source.rb +52 -0
  40. data/test/test_rails_asset_source_wrapper.rb +37 -0
  41. data/test/test_string_substitution_source_wrapper.rb +25 -0
  42. data/website/index.html +1 -1
  43. metadata +43 -11
  44. data/lib/avatar/source/rails_asset_source.rb +0 -64
  45. data/lib/avatar/source/string_substitution_source.rb +0 -45
  46. data/lib/avatar/string_substitution.rb +0 -28
  47. data/test/test_rails_asset_source.rb +0 -50
  48. data/test/test_string_substitution.rb +0 -28
  49. data/test/test_string_substitution_source.rb +0 -22
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'avatar/source/static_url_source'
3
+ require 'avatar/source/wrapper/string_substitution_source_wrapper'
4
+
5
+ class TestStringSubstitutionSourceWrapper < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @source = Avatar::Source::StaticUrlSource.new('#{a} and #{b} but not {b}')
9
+ @wrapper = Avatar::Source::Wrapper::StringSubstitutionSourceWrapper.new(@source)
10
+ end
11
+
12
+ def test_returns_nil_if_underlying_source_returns_nil
13
+ @source.instance_eval { def avatar_url_for(*args); nil; end }
14
+ assert_nil @wrapper.avatar_url_for(:a_person)
15
+ end
16
+
17
+ def test_avatar_url_nil_when_not_all_variables_replaced
18
+ assert_nil @wrapper.avatar_url_for(:bar, :b => 'ham')
19
+ end
20
+
21
+ def test_avatar_url_when_all_variables_replaced
22
+ assert_equal 'green eggs and ham but not {b}', @wrapper.avatar_url_for(:bar, :a => 'green eggs', :b => 'ham')
23
+ end
24
+
25
+ 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.4</a>
36
+ <a href="http://rubyforge.org/projects/avatar" class="numbers">0.0.5</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;Avatar&#8217;</h1>
39
39
 
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
4
+ version: 0.0.5
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-28 00:00:00 -04:00
12
+ date: 2008-04-01 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -42,11 +42,13 @@ files:
42
42
  - lib/avatar/source/file_column_source.rb
43
43
  - lib/avatar/source/gravatar_source.rb
44
44
  - lib/avatar/source/nil_source.rb
45
- - lib/avatar/source/rails_asset_source.rb
45
+ - lib/avatar/source/paperclip_source.rb
46
46
  - lib/avatar/source/source_chain.rb
47
47
  - lib/avatar/source/static_url_source.rb
48
- - lib/avatar/source/string_substitution_source.rb
49
- - lib/avatar/string_substitution.rb
48
+ - lib/avatar/source/wrapper.rb
49
+ - lib/avatar/source/wrapper/abstract_source_wrapper.rb
50
+ - lib/avatar/source/wrapper/rails_asset_source_wrapper.rb
51
+ - lib/avatar/source/wrapper/string_substitution_source_wrapper.rb
50
52
  - lib/avatar/version.rb
51
53
  - lib/avatar/view.rb
52
54
  - lib/avatar/view/abstract_view_support.rb
@@ -86,6 +88,30 @@ files:
86
88
  - test/lib/file_column/test/fixtures/skanthak.png
87
89
  - test/lib/file_column/test/magick_test.rb
88
90
  - test/lib/file_column/test/magick_view_only_test.rb
91
+ - test/lib/paperclip/README
92
+ - test/lib/paperclip/Rakefile
93
+ - test/lib/paperclip/generators/paperclip/USAGE
94
+ - test/lib/paperclip/generators/paperclip/paperclip_generator.rb
95
+ - test/lib/paperclip/generators/paperclip/templates/paperclip_migration.rb
96
+ - test/lib/paperclip/init.rb
97
+ - test/lib/paperclip/lib/paperclip.rb
98
+ - test/lib/paperclip/lib/paperclip/attachment.rb
99
+ - test/lib/paperclip/lib/paperclip/geometry.rb
100
+ - test/lib/paperclip/lib/paperclip/iostream.rb
101
+ - test/lib/paperclip/lib/paperclip/thumbnail.rb
102
+ - test/lib/paperclip/lib/paperclip/upfile.rb
103
+ - test/lib/paperclip/tasks/paperclip_tasks.rake
104
+ - test/lib/paperclip/test/database.yml
105
+ - test/lib/paperclip/test/fixtures/12k.png
106
+ - test/lib/paperclip/test/fixtures/5k.png
107
+ - test/lib/paperclip/test/fixtures/bad.png
108
+ - test/lib/paperclip/test/helper.rb
109
+ - test/lib/paperclip/test/test_attachment.rb
110
+ - test/lib/paperclip/test/test_geometry.rb
111
+ - test/lib/paperclip/test/test_integration.rb
112
+ - test/lib/paperclip/test/test_iostream.rb
113
+ - test/lib/paperclip/test/test_paperclip.rb
114
+ - test/lib/paperclip/test/test_thumbnail.rb
89
115
  - test/lib/schema.rb
90
116
  - test/lib/user_suit.png
91
117
  - test/test_abstract_view_support.rb
@@ -95,11 +121,11 @@ files:
95
121
  - test/test_gravatar_source.rb
96
122
  - test/test_helper.rb
97
123
  - test/test_nil_source.rb
98
- - test/test_rails_asset_source.rb
124
+ - test/test_paperclip_source.rb
125
+ - test/test_rails_asset_source_wrapper.rb
99
126
  - test/test_source_chain.rb
100
127
  - test/test_static_url_source.rb
101
- - test/test_string_substitution.rb
102
- - test/test_string_substitution_source.rb
128
+ - test/test_string_substitution_source_wrapper.rb
103
129
  - website/index.html
104
130
  - website/index.txt
105
131
  - website/javascripts/rounded_corners_lite.inc.js
@@ -134,6 +160,12 @@ specification_version: 2
134
160
  summary: helpers for displaying avatars
135
161
  test_files:
136
162
  - test/lib/file_column/lib/test_case.rb
163
+ - test/lib/paperclip/test/test_attachment.rb
164
+ - test/lib/paperclip/test/test_geometry.rb
165
+ - test/lib/paperclip/test/test_integration.rb
166
+ - test/lib/paperclip/test/test_iostream.rb
167
+ - test/lib/paperclip/test/test_paperclip.rb
168
+ - test/lib/paperclip/test/test_thumbnail.rb
137
169
  - test/test_abstract_view_support.rb
138
170
  - test/test_action_view_support.rb
139
171
  - test/test_avatar.rb
@@ -141,8 +173,8 @@ test_files:
141
173
  - test/test_gravatar_source.rb
142
174
  - test/test_helper.rb
143
175
  - test/test_nil_source.rb
144
- - test/test_rails_asset_source.rb
176
+ - test/test_paperclip_source.rb
177
+ - test/test_rails_asset_source_wrapper.rb
145
178
  - test/test_source_chain.rb
146
179
  - test/test_static_url_source.rb
147
- - test/test_string_substitution.rb
148
- - test/test_string_substitution_source.rb
180
+ - test/test_string_substitution_source_wrapper.rb
@@ -1,64 +0,0 @@
1
- require 'avatar/string_substitution'
2
- require 'avatar/source/abstract_source'
3
- require 'action_view/helpers/asset_tag_helper'
4
-
5
- module Avatar # :nodoc:
6
- module Source # :nodoc:
7
- # Source representing a constant path. Allows string variable
8
- # substitution (see link:classes/Avatar/StringSubstitution.html).
9
- # Good as a default or last-resort source in Rails projects.
10
- class RailsAssetSource
11
- include StringSubstitution
12
- include AbstractSource
13
-
14
- attr_accessor :path
15
- attr_accessor :default_options
16
- attr_reader :url_helper
17
-
18
- private :url_helper
19
-
20
- # Create a new source with static path +path+.
21
- # Raises an error unless +path+ exists.
22
- # +default_options+ can include any variables
23
- # to be substituted into +path+ as defaults.
24
- # Additionally, it can contain the key :only_path,
25
- # which determines whether a path or full URI is generated
26
- # by default, :only_path is false.
27
- def initialize(path, default_options = {})
28
- raise ArgumentError.new("path cannot be nil") if path.nil?
29
- self.path = path.to_s
30
- self.default_options = { :only_path => false }.merge(default_options)
31
- @url_helper = Object.new
32
- @url_helper.extend(ActionView::Helpers::AssetTagHelper)
33
- end
34
-
35
- def only_path?
36
- default_options[:default_path]
37
- end
38
-
39
- def default_options=(opts)
40
- @default_options = opts || {}
41
- end
42
-
43
- # Returns nil if person is nil; the static path or URI otherwise.
44
- # Options:
45
- # * :only_path (Boolean) - whether to output only the path or a fully-qualified URI; defaults to object-level value
46
- # Raises an error if both +options[:only_path]+ and the object-level default are both false
47
- # and the url returned would only be a path. Try setting
48
- # <code>ActionController::Base.asset_host</code> to avoid this error.
49
- #
50
- # Note: +only_path+ being true is not a guarantee
51
- # that only a path will be generated; if it is false,
52
- # however, generated URLs will be full URIs.
53
- def avatar_url_for(person, options = {})
54
- return nil if person.nil?
55
- options = default_options.merge(options)
56
- path = apply_substitution(self.path, options)
57
- uri = url_helper.image_path(path)
58
- raise "could not generate protocol and host for #{uri}" unless uri =~ /^http[s]?\:\/\// || options[:only_path]
59
- substitution_needed?(uri) ? nil : uri
60
- end
61
-
62
- end
63
- end
64
- end
@@ -1,45 +0,0 @@
1
- require 'avatar/string_substitution'
2
- require 'avatar/source/abstract_source'
3
-
4
- module Avatar # :nodoc:
5
- module Source # :nodoc:
6
- # Like a StaticUrlSource, but allows variable replacement within the string.
7
- # Usage:
8
- # source = StringSubstitutionSource.new('#{gender}_icon_#{size}.png')
9
- # url = source.avatar_url_for(@person, :gender => :female, :size => :large)
10
- # # => 'female_icon_large.png'
11
- class StringSubstitutionSource
12
- include StringSubstitution
13
- include AbstractSource
14
-
15
- attr_accessor :url
16
- attr_accessor :default_options
17
-
18
- # Create a new source with static url +url+, which can contain any number
19
- # of variables to be subsituted through +options+. See link:classes/Avatar/StringSubstitution.html
20
- #
21
- # Optionally, can pass in +default _options+ to be applied in replacement, overwritable
22
- # by the +options+ passed to :avatar_url_for.
23
- def initialize(url, default_options = {})
24
- raise ArgumentError.new("URL cannot be nil") if url.nil?
25
- self.url = url.to_s
26
- self.default_options = default_options || {}
27
- end
28
-
29
- # Returns nil if +person+ is nil or if variables in <code>url</code>
30
- # remain un-bound after substituting +options+; otherwise, returns
31
- # the result of replacing each variable within <code>url</code>
32
- # with the value of the corresponding key within +options+.
33
- def avatar_url_for(person, options = {})
34
- return nil if person.nil?
35
- result = apply_substitution(self.url, self.default_options.merge(options))
36
- substitution_needed?(result) ? nil : result
37
- end
38
-
39
- def default_options=(opts)
40
- @default_options = opts || {}
41
- end
42
-
43
- end
44
- end
45
- end
@@ -1,28 +0,0 @@
1
- require 'avatar/object_support'
2
-
3
- module Avatar # :nodoc:
4
-
5
- # Allows runtime variable substitution into a String.
6
- module StringSubstitution
7
-
8
- # For each key in +options+ replaces '#{key}' in +string+ with the
9
- # corresponding value in +options+.
10
- # +string+ should
11
- # be of the form '...#{variable_a}...#{variable_b}...'. <em>Note the
12
- # single quotes</em>. Double quotes will cause the variables to be
13
- # substituted before this method is run, which is almost
14
- # certainly <strong>not</strong> what you want.
15
- def apply_substitution(string, options)
16
- returning(string.dup) do |result|
17
- options.each do |k,v|
18
- result.gsub!(Regexp.new('#\{' + "#{k}" + '\}'), "#{v}")
19
- end
20
- end
21
- end
22
-
23
- def substitution_needed?(string)
24
- string =~ /#\{.*\}/
25
- end
26
-
27
- end
28
- end
@@ -1,50 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
- require 'avatar/source/rails_asset_source'
3
- require 'action_controller/base'
4
-
5
- class TestRailsAssetSource < Test::Unit::TestCase
6
-
7
- def setup
8
- ActionController::Base.asset_host = 'http://test.com'
9
- end
10
-
11
- def test_fully_qualified_uri
12
- source = Avatar::Source::RailsAssetSource.new('http://example.com/images/avatar.png')
13
- assert_equal 'http://example.com/images/avatar.png', source.avatar_url_for(3)
14
- end
15
-
16
- def test_string_substitution
17
- source = Avatar::Source::RailsAssetSource.new('http://example.com/images/avatar_#{size}.png')
18
- assert_equal 'http://example.com/images/avatar_huge.png', source.avatar_url_for(4, {:size => 'huge'})
19
- end
20
-
21
- def test_uses_asset_host
22
- source = Avatar::Source::RailsAssetSource.new('/images/avatar.png')
23
- assert_equal 'http://test.com/images/avatar.png', source.avatar_url_for(4)
24
- end
25
-
26
- def test_error_if_cannot_generate_full_uri_and_only_path_false
27
- ActionController::Base.asset_host = ''
28
- source = Avatar::Source::RailsAssetSource.new('/images/avatar.png')
29
- assert_raise(RuntimeError) {
30
- source.avatar_url_for(4)
31
- }
32
- end
33
-
34
- def test_no_error_if_cannot_generate_full_uri_and_only_path_true
35
- ActionController::Base.asset_host = ''
36
- source = Avatar::Source::RailsAssetSource.new('/images/avatar.png')
37
- assert_equal '/images/avatar.png', source.avatar_url_for(12, :only_path => true)
38
- end
39
-
40
- def test_no_url_generated_if_person_is_nil
41
- source = Avatar::Source::RailsAssetSource.new('/images/avatar.png')
42
- assert_nil source.avatar_url_for(nil)
43
- end
44
-
45
- def test_no_url_generated_if_substitution_incomplete
46
- source = Avatar::Source::RailsAssetSource.new('/images/avatar_#{size}.png')
47
- assert_nil source.avatar_url_for(8)
48
- end
49
-
50
- end
@@ -1,28 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
- require 'avatar/string_substitution'
3
-
4
- class TestStringSubstitution < Test::Unit::TestCase
5
-
6
- def setup
7
- @foo = Object.new
8
- @foo.extend Avatar::StringSubstitution
9
- @string = 'I don\'t like #{a}, #{b}, or #{c}'
10
- end
11
-
12
- def test_apply_complete_substitution
13
- assert_equal "I don't like Detroit, jam, or the letter e", @foo.apply_substitution(@string, {:a => 'Detroit', :b => 'jam', :c => 'the letter e'})
14
- end
15
-
16
- def test_apply_incomplete_substitution
17
- assert_equal 'I don\'t like #{a}, jam, or #{c}', @foo.apply_substitution(@string, {:b => 'jam'})
18
- end
19
-
20
- def test_substitution_not_needed
21
- assert !@foo.substitution_needed?('foo # bar { baz }# { yoo}')
22
- end
23
-
24
- def test_substitution_needed
25
- assert @foo.substitution_needed?('foo #{bar} #{baz}')
26
- end
27
-
28
- end
@@ -1,22 +0,0 @@
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