public
Rubygem
Description: A lightweight and opinionated but hackable library for attaching images to ActiveRecord models.
Homepage:
Clone URL: git://github.com/norman/has_image.git
Improved documentation.
norman (author)
Wed Oct 22 08:13:34 -0700 2008
commit  9942b5c008aaa2b388935668e194a560552f3c99
tree    3cd34fdb8cf0f28f6156fc1485f8ec03ca77534d
parent  7245d7024a48e08e641e8b6c2253d561e6cbd25f
...
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
0
@@ -1,3 +1,15 @@
0
+2008-10-22 Gerrit Keiser and Tricycle Developments
0
+  * Added option to not delete images on destroy
0
+  * Made thumbnail name separator configurable
0
+  * Added height/width methods to storage
0
+  * Allowed regenerating only one thumbnail size
0
+  * Made has_image column configurable
0
+  * Added some compatibility with attachment_fu
0
+  * General refactorings and overall code improvement
0
+
0
+2008-10-22 Norman Clarke <norman@randomba.org>
0
+  * Documentation improvements and minor code cleanups.
0
+
0
 2008-10-09 Dima Sabanin <sdmitry@gmail.com>
0
   * Fixed display of images with special symbols in the name,
0
     like '2777-nipple-+-apple-napple.jpg'. + is reserved by HTTP.
...
42
43
44
45
 
46
47
48
...
42
43
44
 
45
46
47
48
0
@@ -42,7 +42,7 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
0
   rdoc.rdoc_dir = 'rdoc'
0
   rdoc.title    = 'HasImage'
0
   rdoc.options << '--line-numbers' << '--inline-source' << '-c UTF-8'
0
-  rdoc.rdoc_files.include('README')
0
+  rdoc.rdoc_files.include('README.textile')
0
   rdoc.rdoc_files.include('FAQ')
0
   rdoc.rdoc_files.include('CHANGELOG')
0
   rdoc.rdoc_files.include('lib/**/*.rb')
...
14
15
16
17
 
18
19
20
...
34
35
36
37
38
 
 
39
40
...
14
15
16
 
17
18
19
20
...
34
35
36
 
 
37
38
39
40
0
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
0
     "CHANGELOG",
0
     "FAQ",
0
     "MIT-LICENSE",
0
-    "README",
0
+    "README.textile",
0
     "init.rb",
0
     "lib/has_image.rb",
0
     "lib/has_image/processor.rb",
0
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
0
     "test/processor_test.rb",
0
     "test/storage_test.rb",
0
   ]
0
-  s.rdoc_options = ["--main", "README", "--inline-source", "--line-numbers"]
0
-  s.extra_rdoc_files = ["README", "CHANGELOG", "FAQ"]
0
+  s.rdoc_options = ["--main", "--inline-source", "--line-numbers"]
0
+  # s.extra_rdoc_files = ["CHANGELOG", "FAQ"]
0
 
0
 end
...
2
3
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
6
7
...
72
73
74
75
76
77
78
79
80
81
82
 
83
84
85
...
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
...
141
142
143
 
 
 
 
 
 
 
 
144
145
146
147
...
157
158
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
161
162
0
@@ -2,6 +2,75 @@ require 'has_image/processor'
0
 require 'has_image/storage'
0
 require 'has_image/view_helpers'
0
 
0
+# = HasImage
0
+#
0
+# HasImage allows you to very easily attach images to a Rails model. For some
0
+# more basic info on what it does, please see its {project
0
+# page}[http://github.com/norman/has_image] on GitHub.
0
+#
0
+# Install HasImage by using Ruby Gems:
0
+#
0
+#  sudo gem install has_image
0
+#
0
+# To use HasImage in your project, you must add a varchar column to your
0
+# model. By default, this column should be named "has_image_file," though you
0
+# may easily change this. For option defaults, see
0
+# HasImage#default_options_for and ClassMethods#has_image.
0
+#
0
+# == Basic Examples
0
+##
0
+# Uses all default options. This works, but is likely not what you need.
0
+#
0
+#  class Photo < ActiveRecord::Base
0
+#    has_image
0
+#  end
0
+#
0
+# Resize the uploaded image to 800x800 and create a 150x150 thumbnail.
0
+#
0
+#   has_image :resize_to "800x800", :thumbnails => {:square => "150x150"}
0
+#
0
+# Resize the image and set a max file size to 4 megabytes.
0
+#
0
+#   has_image :resize_to "100x150", :max_size => 4.megabytes
0
+#
0
+# == Some slightly more advanced examples
0
+#
0
+# === Localizing HasImage
0
+#
0
+#  has_image :invalid_image_message => "No se puede procesar la imagen."
0
+#
0
+# === Using has_image with Capistrano
0
+#
0
+# When deploying using Capistrano, you will likely want to keep images
0
+# under a "system" directory so that newly deployed versions have access
0
+# to them:
0
+#
0
+#   has_image :resize_to => "150x150",
0
+#     :thumbnails => {
0
+#       :square => "75x75",
0
+#     },
0
+#     :base_path => File.join(Rails.root, 'public', 'system')
0
+#
0
+# === Testing with HasImage:
0
+#
0
+# If you want your tests to actually run the image processing, you should
0
+# make sure your tests write the image files somewhere outside your public
0
+# directory. Add something like this to your config/environments/test.rb:
0
+#
0
+#   config.after_initialize do
0
+#     MyClass.has_image_options[:base_path] = File.join(RAILS_ROOT, "tmp") 
0
+#   end
0
+#
0
+# If you want to stub out calls to has_image so that your tests don't do
0
+# the (slow) image processing, here's an example using Test::Unit and
0
+# Mocha:
0
+#
0
+#   def setup
0
+#     Photo.any_instance.stubs(:image_data=).returns(true)
0
+#     Photo.any_instance.stubs(:install_images).returns(true)
0
+#     Photo.any_instance.stubs(:image_data_valid?).returns(true)
0
+#   end
0
+#
0
 module HasImage
0
 
0
   class ProcessorError < StandardError ; end
0
@@ -72,14 +141,7 @@ module HasImage
0
   end
0
 
0
   module ClassMethods
0
-    # == Using HasImage
0
-    #
0
-    # To use HasImage with a Rails model, all you have to do is add a column
0
-    # named "has_image_file." For configuration defaults, you might want to
0
-    # take a look at the default options specified in
0
-    # HasImage#default_options_for. The different setting options are
0
-    # described below.
0
-    #    
0
+
0
     # === Options
0
     #
0
     # *  <tt>:resize_to</tt> - Dimensions to resize to. This should be an ImageMagick {geometry string}[http://www.imagemagick.org/script/command-line-options.php#resize]. Fixed sizes are recommended.
0
@@ -95,51 +157,6 @@ module HasImage
0
     # *  <tt>:invalid_image_message</tt> - The message that will be shown when the image data can't be processed.
0
     # *  <tt>:image_too_small_message</tt> - The message that will be shown when the image file is too small. You should ideally set this to something that tells the user what the minimum is.
0
     # *  <tt>:image_too_big_message</tt> - The message that will be shown when the image file is too big. You should ideally set this to something that tells the user what the maximum is.
0
-    #
0
-    # === Basic Examples
0
-    #
0
-    #   has_image # uses all default options
0
-    #   has_image :resize_to "800x800", :thumbnails => {:square => "150x150"}
0
-    #   has_image :resize_to "100x150", :max_size => 500.kilobytes
0
-    #
0
-    # === Some slightly more advanced examples
0
-    #
0
-    # ==== Localizing HasImage
0
-    #
0
-    #  has_image :invalid_image_message => "No se puede procesar la imagen."
0
-    #
0
-    # ==== Using has_image with Capistrano
0
-    #
0
-    # When deploying using Capistrano, you will likely want to keep images
0
-    # under a "system" directory so that newly deployed versions have access
0
-    # to them:
0
-    #
0
-    #   has_image :resize_to => "150x150",
0
-    #     :thumbnails => {
0
-    #       :square => "75x75",
0
-    #     },
0
-    #     :base_path => File.join(Rails.root, 'public', 'system')
0
-    #
0
-    # ==== Testing with HasImage:
0
-    #
0
-    # If you want your tests to actually run the image processing, you should
0
-    # make sure your tests write the image files somewhere outside your public
0
-    # directory. Add something like this to your config/environments/test.rb:
0
-    #
0
-    #   config.after_initialize do
0
-    #     MyClass.has_image_options[:base_path] = File.join(RAILS_ROOT, "tmp") 
0
-    #   end
0
-    #
0
-    # If you want to stub out calls to has_image so that your tests don't do
0
-    # the (slow) image processing, here's an example using Test::Unit and
0
-    # Mocha:
0
-    #
0
-    #   def setup
0
-    #     Photo.any_instance.stubs(:image_data=).returns(true)
0
-    #     Photo.any_instance.stubs(:install_images).returns(true)
0
-    #     Photo.any_instance.stubs(:image_data_valid?).returns(true)
0
-    #   end
0
-    #
0
     def has_image(options = {})
0
       options.assert_valid_keys(HasImage.default_options_for(self).keys)
0
       options = HasImage.default_options_for(self).merge(options)

Comments