avatar 0.0.5 → 0.2.0

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 (92) hide show
  1. data/History.txt +7 -0
  2. data/{README.txt → README.rdoc} +12 -4
  3. data/init.rb +5 -0
  4. data/lib/avatar.rb +3 -2
  5. data/lib/avatar/source/pavatar_source.rb +109 -0
  6. data/lib/avatar/source/wrapper/rails_asset_source_wrapper.rb +3 -1
  7. data/lib/avatar/version.rb +2 -2
  8. data/rails/init.rb +1 -0
  9. metadata +28 -125
  10. data/.gitignore +0 -8
  11. data/Manifest.txt +0 -104
  12. data/Rakefile +0 -10
  13. data/config/hoe.rb +0 -70
  14. data/config/requirements.rb +0 -17
  15. data/script/destroy +0 -14
  16. data/script/generate +0 -14
  17. data/script/txt2html +0 -74
  18. data/setup.rb +0 -1585
  19. data/tasks/deployment.rake +0 -34
  20. data/tasks/environment.rake +0 -7
  21. data/tasks/testing.rake +0 -37
  22. data/tasks/website.rake +0 -17
  23. data/test/.gitignore +0 -3
  24. data/test/lib/database.rb +0 -2
  25. data/test/lib/database.yml +0 -10
  26. data/test/lib/file_column/CHANGELOG +0 -69
  27. data/test/lib/file_column/README +0 -54
  28. data/test/lib/file_column/Rakefile +0 -36
  29. data/test/lib/file_column/TODO +0 -6
  30. data/test/lib/file_column/init.rb +0 -13
  31. data/test/lib/file_column/lib/file_column.rb +0 -720
  32. data/test/lib/file_column/lib/file_column_helper.rb +0 -150
  33. data/test/lib/file_column/lib/file_compat.rb +0 -28
  34. data/test/lib/file_column/lib/magick_file_column.rb +0 -260
  35. data/test/lib/file_column/lib/rails_file_column.rb +0 -19
  36. data/test/lib/file_column/lib/test_case.rb +0 -124
  37. data/test/lib/file_column/lib/validations.rb +0 -112
  38. data/test/lib/file_column/test/abstract_unit.rb +0 -63
  39. data/test/lib/file_column/test/connection.rb +0 -17
  40. data/test/lib/file_column/test/file_column_helper_test.rb +0 -97
  41. data/test/lib/file_column/test/file_column_test.rb +0 -650
  42. data/test/lib/file_column/test/fixtures/entry.rb +0 -32
  43. data/test/lib/file_column/test/fixtures/invalid-image.jpg +0 -1
  44. data/test/lib/file_column/test/fixtures/kerb.jpg +0 -0
  45. data/test/lib/file_column/test/fixtures/mysql.sql +0 -25
  46. data/test/lib/file_column/test/fixtures/schema.rb +0 -10
  47. data/test/lib/file_column/test/fixtures/skanthak.png +0 -0
  48. data/test/lib/file_column/test/magick_test.rb +0 -380
  49. data/test/lib/file_column/test/magick_view_only_test.rb +0 -21
  50. data/test/lib/paperclip/README +0 -32
  51. data/test/lib/paperclip/Rakefile +0 -41
  52. data/test/lib/paperclip/generators/paperclip/USAGE +0 -5
  53. data/test/lib/paperclip/generators/paperclip/paperclip_generator.rb +0 -27
  54. data/test/lib/paperclip/generators/paperclip/templates/paperclip_migration.rb +0 -17
  55. data/test/lib/paperclip/init.rb +0 -3
  56. data/test/lib/paperclip/lib/paperclip.rb +0 -197
  57. data/test/lib/paperclip/lib/paperclip/attachment.rb +0 -230
  58. data/test/lib/paperclip/lib/paperclip/geometry.rb +0 -109
  59. data/test/lib/paperclip/lib/paperclip/iostream.rb +0 -43
  60. data/test/lib/paperclip/lib/paperclip/thumbnail.rb +0 -80
  61. data/test/lib/paperclip/lib/paperclip/upfile.rb +0 -32
  62. data/test/lib/paperclip/tasks/paperclip_tasks.rake +0 -38
  63. data/test/lib/paperclip/test/database.yml +0 -5
  64. data/test/lib/paperclip/test/fixtures/12k.png +0 -0
  65. data/test/lib/paperclip/test/fixtures/5k.png +0 -0
  66. data/test/lib/paperclip/test/fixtures/bad.png +0 -1
  67. data/test/lib/paperclip/test/helper.rb +0 -38
  68. data/test/lib/paperclip/test/test_attachment.rb +0 -99
  69. data/test/lib/paperclip/test/test_geometry.rb +0 -142
  70. data/test/lib/paperclip/test/test_integration.rb +0 -76
  71. data/test/lib/paperclip/test/test_iostream.rb +0 -60
  72. data/test/lib/paperclip/test/test_paperclip.rb +0 -83
  73. data/test/lib/paperclip/test/test_thumbnail.rb +0 -76
  74. data/test/lib/schema.rb +0 -20
  75. data/test/lib/user_suit.png +0 -0
  76. data/test/test_abstract_view_support.rb +0 -22
  77. data/test/test_action_view_support.rb +0 -30
  78. data/test/test_avatar.rb +0 -12
  79. data/test/test_file_column_source.rb +0 -38
  80. data/test/test_gravatar_source.rb +0 -79
  81. data/test/test_helper.rb +0 -27
  82. data/test/test_nil_source.rb +0 -18
  83. data/test/test_paperclip_source.rb +0 -52
  84. data/test/test_rails_asset_source_wrapper.rb +0 -37
  85. data/test/test_source_chain.rb +0 -44
  86. data/test/test_static_url_source.rb +0 -18
  87. data/test/test_string_substitution_source_wrapper.rb +0 -25
  88. data/website/index.html +0 -105
  89. data/website/index.txt +0 -48
  90. data/website/javascripts/rounded_corners_lite.inc.js +0 -285
  91. data/website/stylesheets/screen.css +0 -138
  92. data/website/template.rhtml +0 -48
@@ -1,109 +0,0 @@
1
- module Paperclip
2
-
3
- # Defines the geometry of an image.
4
- class Geometry
5
- attr_accessor :height, :width, :modifier
6
-
7
- # Gives a Geometry representing the given height and width
8
- def initialize width = nil, height = nil, modifier = nil
9
- height = nil if height == ""
10
- width = nil if width == ""
11
- @height = (height || width).to_f
12
- @width = (width || height).to_f
13
- @modifier = modifier
14
- end
15
-
16
- # Uses ImageMagick to determing the dimensions of a file, passed in as either a
17
- # File or path.
18
- def self.from_file file
19
- file = file.path if file.respond_to? "path"
20
- parse(`#{Paperclip.path_for_command('identify')} "#{file}"`) ||
21
- raise(Errno::ENOENT, file)
22
- end
23
-
24
- # Parses a "WxH" formatted string, where W is the width and H is the height.
25
- def self.parse string
26
- if match = (string && string.match(/\b(\d*)x(\d*)\b([\>\<\#\@\%^!])?/))
27
- Geometry.new(*match[1,3])
28
- end
29
- end
30
-
31
- # True if the dimensions represent a square
32
- def square?
33
- height == width
34
- end
35
-
36
- # True if the dimensions represent a horizontal rectangle
37
- def horizontal?
38
- height < width
39
- end
40
-
41
- # True if the dimensions represent a vertical rectangle
42
- def vertical?
43
- height > width
44
- end
45
-
46
- # The aspect ratio of the dimensions.
47
- def aspect
48
- width / height
49
- end
50
-
51
- # Returns the larger of the two dimensions
52
- def larger
53
- [height, width].max
54
- end
55
-
56
- # Returns the smaller of the two dimensions
57
- def smaller
58
- [height, width].min
59
- end
60
-
61
- # Returns the width and height in a format suitable to be passed to Geometry.parse
62
- def to_s
63
- "%dx%d%s" % [width, height, modifier]
64
- end
65
-
66
- # Same as to_s
67
- def inspect
68
- to_s
69
- end
70
-
71
- # Returns the scaling and cropping geometries (in string-based ImageMagick format)
72
- # neccessary to transform this Geometry into the Geometry given. If crop is true,
73
- # then it is assumed the destination Geometry will be the exact final resolution.
74
- # In this case, the source Geometry is scaled so that an image containing the
75
- # destination Geometry would be completely filled by the source image, and any
76
- # overhanging image would be cropped. Useful for square thumbnail images. The cropping
77
- # is weighted at the center of the Geometry.
78
- def transformation_to dst, crop = false
79
- ratio = Geometry.new( dst.width / self.width, dst.height / self.height )
80
-
81
- if crop
82
- scale_geometry, scale = scaling(dst, ratio)
83
- crop_geometry = cropping(dst, ratio, scale)
84
- else
85
- scale_geometry = dst.to_s
86
- end
87
-
88
- [ scale_geometry, crop_geometry ]
89
- end
90
-
91
- private
92
-
93
- def scaling dst, ratio
94
- if ratio.horizontal? || ratio.square?
95
- [ "%dx" % dst.width, ratio.width ]
96
- else
97
- [ "x%d" % dst.height, ratio.height ]
98
- end
99
- end
100
-
101
- def cropping dst, ratio, scale
102
- if ratio.horizontal? || ratio.square?
103
- "%dx%d+%d+%d" % [ dst.width, dst.height, 0, (self.height * scale - dst.height) / 2 ]
104
- else
105
- "%dx%d+%d+%d" % [ dst.width, dst.height, (self.width * scale - dst.width) / 2, 0 ]
106
- end
107
- end
108
- end
109
- end
@@ -1,43 +0,0 @@
1
- # Provides method that can be included on File-type objects (IO, StringIO, Tempfile, etc) to allow stream copying
2
- # and Tempfile conversion.
3
- module IOStream
4
-
5
- # Returns a Tempfile containing the contents of the readable object.
6
- def to_tempfile
7
- tempfile = Tempfile.new("stream")
8
- tempfile.binmode
9
- self.stream_to(tempfile)
10
- end
11
-
12
- # Copies one read-able object from one place to another in blocks, obviating the need to load
13
- # the whole thing into memory. Defaults to 8k blocks. If this module is included in both
14
- # both StringIO and Tempfile, then either can have its data copied anywhere else without typing
15
- # worries or memory overhead worries. Returns a File if a String is passed in as the destination
16
- # and returns the IO or Tempfile as passed in if one is sent as the destination.
17
- def stream_to path_or_file, in_blocks_of = 8192
18
- dstio = case path_or_file
19
- when String then File.new(path_or_file, "wb+")
20
- when IO then path_or_file
21
- when Tempfile then path_or_file
22
- end
23
- buffer = ""
24
- self.rewind
25
- while self.read(in_blocks_of, buffer) do
26
- dstio.write(buffer)
27
- end
28
- dstio.rewind
29
- dstio
30
- end
31
- end
32
-
33
- class IO
34
- include IOStream
35
- end
36
-
37
- %w( Tempfile StringIO ).each do |klass|
38
- if Object.const_defined? klass
39
- Object.const_get(klass).class_eval do
40
- include IOStream
41
- end
42
- end
43
- end
@@ -1,80 +0,0 @@
1
- module Paperclip
2
- # Handles thumbnailing images that are uploaded.
3
- class Thumbnail
4
-
5
- attr_accessor :file, :current_geometry, :target_geometry, :format, :whiny_thumbnails
6
-
7
- # Creates a Thumbnail object set to work on the +file+ given. It
8
- # will attempt to transform the image into one defined by +target_geometry+
9
- # which is a "WxH"-style string. +format+ will be inferred from the +file+
10
- # unless specified. Thumbnail creation will raise no errors unless
11
- # +whiny_thumbnails+ is true (which it is, by default.
12
- def initialize file, target_geometry, format = nil, whiny_thumbnails = true
13
- @file = file
14
- @crop = target_geometry[-1,1] == '#'
15
- @target_geometry = Geometry.parse target_geometry
16
- @current_geometry = Geometry.from_file file
17
- @whiny_thumbnails = whiny_thumbnails
18
-
19
- @current_format = File.extname(@file.path)
20
- @basename = File.basename(@file.path, @current_format)
21
-
22
- @format = format
23
- end
24
-
25
- # Creates a thumbnail, as specified in +initialize+, +make+s it, and returns the
26
- # resulting Tempfile.
27
- def self.make file, dimensions, format = nil, whiny_thumbnails = true
28
- new(file, dimensions, format, whiny_thumbnails).make
29
- end
30
-
31
- # Returns true if the +target_geometry+ is meant to crop.
32
- def crop?
33
- @crop
34
- end
35
-
36
- # Performs the conversion of the +file+ into a thumbnail. Returns the Tempfile
37
- # that contains the new image.
38
- def make
39
- src = @file
40
- dst = Tempfile.new([@basename, @format].compact.join("."))
41
- dst.binmode
42
-
43
- command = <<-end_command
44
- #{ Paperclip.path_for_command('convert') }
45
- "#{ File.expand_path(src.path) }"
46
- #{ transformation_command }
47
- "#{ File.expand_path(dst.path) }"
48
- end_command
49
- success = system(command.gsub(/\s+/, " "))
50
-
51
- if success && $?.exitstatus != 0 && @whiny_thumbnails
52
- raise PaperclipError, "There was an error processing this thumbnail"
53
- end
54
-
55
- dst
56
- end
57
-
58
- # Returns the command ImageMagick's +convert+ needs to transform the image
59
- # into the thumbnail.
60
- def transformation_command
61
- scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
62
- trans = "-scale \"#{scale}\""
63
- trans << " -crop \"#{crop}\" +repage" if crop
64
- trans
65
- end
66
- end
67
-
68
- # Due to how ImageMagick handles its image format conversion and how Tempfile
69
- # handles its naming scheme, it is necessary to override how Tempfile makes
70
- # its names so as to allow for file extensions. Idea taken from the comments
71
- # on this blog post:
72
- # http://marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions
73
- class Tempfile < ::Tempfile
74
- # Replaces Tempfile's +make_tmpname+ with one that honors file extensions.
75
- def make_tmpname(basename, n)
76
- extension = File.extname(basename)
77
- sprintf("%s,%d,%d%s", File.basename(basename, extension), $$, n, extension)
78
- end
79
- end
80
- end
@@ -1,32 +0,0 @@
1
- module Paperclip
2
- # The Upfile module is a convenience module for adding uploaded-file-type methods
3
- # to the +File+ class. Useful for testing.
4
- # user.avatar = File.new("test/test_avatar.jpg")
5
- module Upfile
6
-
7
- # Infer the MIME-type of the file from the extension.
8
- def content_type
9
- type = self.path.match(/\.(\w+)$/)[1] rescue "octet-stream"
10
- case type
11
- when "jpg", "png", "gif" then "image/#{type}"
12
- when "txt", "csv", "xml", "html", "htm", "css", "js" then "text/#{type}"
13
- else "x-application/#{type}"
14
- end
15
- end
16
-
17
- # Returns the file's normal name.
18
- def original_filename
19
- File.basename(self.path)
20
- end
21
-
22
- # Returns the size of the file.
23
- def size
24
- File.size(self)
25
- end
26
- end
27
-
28
- end
29
-
30
- class File #:nodoc:
31
- include Paperclip::Upfile
32
- end
@@ -1,38 +0,0 @@
1
- require 'environment'
2
-
3
- def obtain_class
4
- class_name = ENV['CLASS'] || ENV['class']
5
- @klass = Object.const_get(class_name)
6
- end
7
-
8
- def obtain_attachments
9
- name = ENV['ATTACHMENT'] || ENV['attachment']
10
- if !name.blank? && @klass.attachment_names.include?(name)
11
- [ name ]
12
- else
13
- @klass.attachment_definitions.keys
14
- end
15
- end
16
-
17
- namespace :paperclip do
18
- desc "Regenerates thumbnails for a given CLASS (and optional ATTACHMENT)"
19
- task :refresh do
20
- klass = obtain_class
21
- instances = klass.find(:all)
22
- names = obtain_attachments
23
-
24
- puts "Regenerating thumbnails for #{instances.length} instances of #{klass.name}:"
25
- instances.each do |instance|
26
- names.each do |name|
27
- result = if instance.send("#{ name }?")
28
- instance.send(name).send("post_process")
29
- instance.send(name).save
30
- else
31
- true
32
- end
33
- print result ? "." : "x"; $stdout.flush
34
- end
35
- end
36
- puts " Done."
37
- end
38
- end
@@ -1,5 +0,0 @@
1
- test:
2
- adapter: sqlite3
3
- #dbfile: paperclip.db
4
- database: ":memory:"
5
-
@@ -1 +0,0 @@
1
- This is not an image.
@@ -1,38 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
- require 'mocha'
5
- require 'tempfile'
6
-
7
- require 'active_record'
8
- require 'ruby-debug'
9
-
10
- ROOT = File.join(File.dirname(__FILE__), '..')
11
- RAILS_ROOT = ROOT
12
-
13
- $LOAD_PATH << File.join(ROOT, 'lib')
14
- $LOAD_PATH << File.join(ROOT, 'lib', 'paperclip')
15
-
16
- require File.join(ROOT, 'lib', 'paperclip.rb')
17
-
18
- FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
19
- config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
20
- ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
21
- ActiveRecord::Base.establish_connection(config[ENV['RAILS_ENV'] || 'test'])
22
-
23
- def rebuild_model options = {}
24
- ActiveRecord::Base.connection.create_table :dummies, :force => true do |table|
25
- table.column :other, :string
26
- table.column :avatar_file_name, :string
27
- table.column :avatar_content_type, :string
28
- table.column :avatar_file_size, :integer
29
- end
30
-
31
- ActiveRecord::Base.send(:include, Paperclip)
32
- Object.send(:remove_const, "Dummy") rescue nil
33
- Object.const_set("Dummy", Class.new(ActiveRecord::Base))
34
- Dummy.class_eval do
35
- include Paperclip
36
- has_attached_file :avatar, options
37
- end
38
- end
@@ -1,99 +0,0 @@
1
- require 'test/helper'
2
-
3
- class Dummy
4
- # This is a dummy class
5
- end
6
-
7
- class AttachmentTest < Test::Unit::TestCase
8
- context "An attachment" do
9
- setup do
10
- @default_options = {
11
- :path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
12
- }
13
- @instance = stub
14
- @instance.stubs(:id).returns(41)
15
- @instance.stubs(:class).returns(Dummy)
16
- @instance.stubs(:[]).with(:test_file_name).returns("5k.png")
17
- @instance.stubs(:[]).with(:test_content_type).returns("image/png")
18
- @instance.stubs(:[]).with(:test_file_size).returns(12345)
19
- @attachment = Paperclip::Attachment.new(:test, @instance, @default_options)
20
- @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"))
21
- end
22
-
23
- should "return its default_url when no file assigned" do
24
- assert @attachment.file.nil?
25
- assert_equal "/tests/original/missing.png", @attachment.url
26
- assert_equal "/tests/blah/missing.png", @attachment.url(:blah)
27
- end
28
-
29
- context "when expecting three styles" do
30
- setup do
31
- @attachment = Paperclip::Attachment.new(:test, @instance, @default_options.merge({
32
- :styles => { :large => ["400x400", :png],
33
- :medium => ["100x100", :gif],
34
- :small => ["32x32#", :jpg]}
35
- }))
36
- end
37
-
38
- context "and assigned a file" do
39
- setup do
40
- @instance.expects(:[]=).with(:test_file_name, File.basename(@file.path))
41
- @instance.expects(:[]=).with(:test_content_type, "image/png")
42
- @instance.expects(:[]=).with(:test_file_size, @file.size)
43
- @instance.expects(:[]=).with(:test_file_name, nil)
44
- @instance.expects(:[]=).with(:test_content_type, nil)
45
- @instance.expects(:[]=).with(:test_file_size, nil)
46
- @attachment.assign(@file)
47
- end
48
-
49
- should "return the real url" do
50
- assert @attachment.file
51
- assert_equal "/tests/41/original/5k.png", @attachment.url
52
- assert_equal "/tests/41/blah/5k.png", @attachment.url(:blah)
53
- end
54
-
55
- should "be dirty" do
56
- assert @attachment.dirty?
57
- end
58
-
59
- should "have its image and attachments as tempfiles" do
60
- [nil, :large, :medium, :small].each do |style|
61
- assert File.exists?(@attachment.to_io(style))
62
- end
63
- end
64
-
65
- context "and saved" do
66
- setup do
67
- @attachment.save
68
- end
69
-
70
- should "commit the files to disk" do
71
- [nil, :large, :medium, :small].each do |style|
72
- io = @attachment.to_io(style)
73
- assert File.exists?(io)
74
- assert ! io.is_a?(::Tempfile)
75
- end
76
- end
77
-
78
- should "save the files as the right formats and sizes" do
79
- [[:large, 400, 61, "PNG"], [:medium, 100, 15, "GIF"], [:small, 32, 32, "JPEG"]].each do |style|
80
- out = `identify -format "%w %h %b %m" #{@attachment.to_io(style.first).path}`
81
- width, height, size, format = out.split(" ")
82
- assert_equal style[1].to_s, width.to_s
83
- assert_equal style[2].to_s, height.to_s
84
- assert_equal style[3].to_s, format.to_s
85
- end
86
- end
87
-
88
- should "have #file be equal #to_io(:original)" do
89
- assert @attachment.file == @attachment.to_io(:original)
90
- end
91
-
92
- should "still have its #file attribute not be nil" do
93
- assert ! @attachment.file.nil?
94
- end
95
- end
96
- end
97
- end
98
- end
99
- end