dragonfly 0.5.7 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of dragonfly might be problematic. Click here for more details.

Files changed (77) hide show
  1. data/.gitignore +1 -0
  2. data/.yardopts +1 -0
  3. data/History.md +109 -0
  4. data/VERSION +1 -1
  5. data/config.rb +1 -1
  6. data/dragonfly.gemspec +19 -16
  7. data/extra_docs/ActiveRecord.md +8 -7
  8. data/extra_docs/Analysers.md +1 -1
  9. data/extra_docs/Encoding.md +1 -1
  10. data/extra_docs/ExampleUseCases.md +66 -73
  11. data/extra_docs/GettingStarted.md +1 -1
  12. data/extra_docs/Processing.md +1 -1
  13. data/extra_docs/Shortcuts.md +2 -2
  14. data/extra_docs/UsingWithRails.md +25 -37
  15. data/features/rails_2.3.5.feature +1 -8
  16. data/features/rails_3.0.0.beta3.feature +7 -0
  17. data/features/steps/rails_steps.rb +1 -11
  18. data/features/support/env.rb +1 -1
  19. data/fixtures/files/app/views/albums/show.html.erb +1 -0
  20. data/fixtures/files/config/initializers/{aaa_dragonfly_load_path.rb → dragonfly.rb} +1 -0
  21. data/fixtures/rails_2.3.5/template.rb +4 -6
  22. data/fixtures/rails_3.0.0.beta3/template.rb +16 -0
  23. data/lib/dragonfly.rb +23 -1
  24. data/lib/dragonfly/active_record_extensions/attachment.rb +1 -1
  25. data/lib/dragonfly/analyser_list.rb +4 -0
  26. data/lib/dragonfly/analysis/base.rb +1 -0
  27. data/lib/dragonfly/analysis/r_magick_analyser.rb +7 -0
  28. data/lib/dragonfly/app.rb +3 -11
  29. data/lib/dragonfly/belongs_to_app.rb +24 -0
  30. data/lib/dragonfly/config/heroku_rails_images.rb +23 -0
  31. data/lib/dragonfly/config/r_magick_images.rb +69 -0
  32. data/lib/dragonfly/config/r_magick_text.rb +25 -0
  33. data/lib/dragonfly/config/rails_defaults.rb +18 -0
  34. data/lib/dragonfly/config/rails_images.rb +13 -0
  35. data/lib/dragonfly/configurable.rb +4 -3
  36. data/lib/dragonfly/data_storage/base.rb +2 -0
  37. data/lib/dragonfly/data_storage/s3data_store.rb +11 -4
  38. data/lib/dragonfly/delegator.rb +22 -10
  39. data/lib/dragonfly/encoder_list.rb +4 -0
  40. data/lib/dragonfly/encoding/base.rb +1 -0
  41. data/lib/dragonfly/encoding/r_magick_encoder.rb +52 -8
  42. data/lib/dragonfly/extended_temp_object.rb +26 -27
  43. data/lib/dragonfly/processing/base.rb +1 -0
  44. data/lib/dragonfly/processing/r_magick_processor.rb +12 -127
  45. data/lib/dragonfly/processing/r_magick_text_processor.rb +155 -0
  46. data/lib/dragonfly/processor_list.rb +4 -0
  47. data/lib/dragonfly/rails/images.rb +2 -14
  48. data/lib/dragonfly/temp_object.rb +41 -34
  49. data/spec/dragonfly/active_record_extensions/migration.rb +7 -0
  50. data/spec/dragonfly/active_record_extensions/model_spec.rb +10 -11
  51. data/spec/dragonfly/active_record_extensions/spec_helper.rb +1 -1
  52. data/spec/dragonfly/analysis/r_magick_analyser_spec.rb +14 -1
  53. data/spec/dragonfly/belongs_to_app_spec.rb +55 -0
  54. data/spec/dragonfly/configurable_spec.rb +21 -6
  55. data/spec/dragonfly/data_storage/s3_data_store_spec.rb +1 -0
  56. data/spec/dragonfly/delegator_spec.rb +23 -12
  57. data/spec/dragonfly/extended_temp_object_spec.rb +13 -29
  58. data/spec/dragonfly/processing/{rmagick_processor_spec.rb → r_magick_processor_spec.rb} +8 -75
  59. data/spec/dragonfly/processing/r_magick_text_processor_spec.rb +84 -0
  60. data/spec/dragonfly/temp_object_spec.rb +126 -151
  61. data/spec/dragonfly_spec.rb +12 -0
  62. data/spec/ginger_scenarios.rb +2 -2
  63. data/spec/image_matchers.rb +2 -2
  64. data/yard/setup.rb +12 -2
  65. data/yard/templates/default/fulldoc/html/css/common.css +1 -2
  66. data/yard/templates/default/layout/html/layout.erb +3 -2
  67. metadata +21 -18
  68. data/History.txt +0 -75
  69. data/features/rails_3.0.0.beta.feature +0 -15
  70. data/fixtures/dragonfly_setup.rb +0 -1
  71. data/fixtures/rails +0 -22
  72. data/fixtures/rails_3.0.0.beta/template.rb +0 -13
  73. data/generators/dragonfly_app/USAGE +0 -16
  74. data/generators/dragonfly_app/dragonfly_app_generator.rb +0 -24
  75. data/generators/dragonfly_app/templates/initializer.erb +0 -35
  76. data/lib/dragonfly/r_magick_configuration.rb +0 -67
  77. data/spec/dragonfly/active_record_extensions/initializer.rb +0 -1
data/.gitignore CHANGED
@@ -7,3 +7,4 @@ pkg
7
7
  doc
8
8
  tmp
9
9
  fixtures/*/tmp_app
10
+ .ginger
data/.yardopts CHANGED
@@ -13,3 +13,4 @@ extra_docs/Encoding.md
13
13
  extra_docs/MimeTypes.md
14
14
  extra_docs/ExampleUseCases.md
15
15
  LICENSE
16
+ History.md
data/History.md ADDED
@@ -0,0 +1,109 @@
1
+ 0.6.0 (2010-05-11)
2
+ ==================
3
+
4
+ Features
5
+ --------
6
+ - Added 'scale factor' for text generation, which gives better quality font rendering for smaller fonts
7
+ - Configurable objects allow for passing args, and passing a block for extra config
8
+ - Added more 'saved configurations', for easier setting up on e.g. Heroku
9
+ - Added RMagickAnalyser#format
10
+ - Added greyscale to RMagickProcessor
11
+ - S3DataStore is configurable as to whether it uses the filesystem or not (to save a tempfile)
12
+
13
+ Fixes
14
+ -----
15
+ - Some specs refactoring, including making text processing specs less brittle
16
+ - RMagickEncoder::SUPPORTED_FORMATS was proving problematic - now we use a configurable list instead
17
+ - Got Rails 3 beta3 cucumber features working
18
+ - Added check to see if bucket already exists in S3DataStore - apparently this was problematic in EU
19
+
20
+ Changes
21
+ -------
22
+ - temp_object.tempfile now returns a closed tempfile, which temp_object.file returns an open file.
23
+ Can also pass a block to temp_object.file which closes the file automatically
24
+ - Processors/Analysers/Encoders know about app now so can log to app's log
25
+ - Imagemagick errors in RMagick processor/analyser/encoder now throw unable_to_handle and log a warning
26
+ - Removed Rails generators - better being more explicit with saved configurations which are more concise now
27
+
28
+ 0.5.7 (2010-04-18)
29
+ ==================
30
+
31
+ Fixes
32
+ --------
33
+ - Strip file command mime_type value because some versions of file command were appending a line-break
34
+
35
+ 0.5.6 (2010-04-13)
36
+ ==================
37
+
38
+ Fixes
39
+ --------
40
+ - Wasn't working properly with Single-Table Inheritance
41
+
42
+ 0.5.5 (2010-04-13)
43
+ ==================
44
+
45
+ Fixes
46
+ --------
47
+ - Rails 3 has changed 'metaclass' -> 'singleton_class' so adapt accordingly
48
+
49
+ 0.5.4 (2010-04-12)
50
+ ==================
51
+
52
+ Features
53
+ --------
54
+ - Allow setting the uid manually
55
+
56
+ Fixes
57
+ -----
58
+ - Assigning an accessor to nil wasn't working properly
59
+
60
+
61
+ 0.5.3 (2010-03-27)
62
+ ==================
63
+
64
+ Fixes
65
+ -----
66
+ - Assigning an accessor to nil wasn't working properly
67
+
68
+
69
+ 0.5.2 (2010-03-04)
70
+ ==================
71
+
72
+ Features
73
+ --------
74
+ - Added 'registered mime-types'
75
+ - Enhanced docs
76
+
77
+ Fixes
78
+ -----
79
+ - RMagickEncoder only encodes if not already in that format
80
+
81
+
82
+ 0.5.1 (2010-02-20)
83
+ ==================
84
+
85
+ Fixes
86
+ -----
87
+ - Fixed 'broken pipe' errors in FileCommandAnalyser due to outputting loads of stuff to the command line stdin
88
+
89
+ 0.5.0 (2010-02-20)
90
+ ==================
91
+
92
+ Added support
93
+ -------------
94
+ - support for Rails 3
95
+
96
+
97
+ 0.4.4 (2010-02-16)
98
+ ==================
99
+
100
+ Better late than never to start logging change history...
101
+
102
+ New features
103
+ ------------
104
+ - added aspect_ratio to rmagick_analyser
105
+
106
+ Added support
107
+ -------------
108
+ - support for ruby 1.9
109
+ - added development dependencies to gemspec for easier setting up
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.7
1
+ 0.6.0
data/config.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/lib/dragonfly'
2
2
 
3
3
  APP = Dragonfly::App[:images]
4
- APP.configure_with(Dragonfly::RMagickConfiguration)
4
+ APP.configure_with(Dragonfly::Config::RMagickImages)
5
5
  APP.url_handler.protect_from_dos_attacks = false
data/dragonfly.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dragonfly}
8
- s.version = "0.5.7"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mark Evans"]
12
- s.date = %q{2010-04-18}
12
+ s.date = %q{2010-05-11}
13
13
  s.email = %q{mark@new-bamboo.co.uk}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.files = [
19
19
  ".gitignore",
20
20
  ".yardopts",
21
- "History.txt",
21
+ "History.md",
22
22
  "LICENSE",
23
23
  "README.md",
24
24
  "Rakefile",
@@ -41,25 +41,20 @@ Gem::Specification.new do |s|
41
41
  "features/images.feature",
42
42
  "features/no_processing.feature",
43
43
  "features/rails_2.3.5.feature",
44
- "features/rails_3.0.0.beta.feature",
44
+ "features/rails_3.0.0.beta3.feature",
45
45
  "features/steps/common_steps.rb",
46
46
  "features/steps/dragonfly_steps.rb",
47
47
  "features/steps/rails_steps.rb",
48
48
  "features/support/env.rb",
49
- "fixtures/dragonfly_setup.rb",
50
49
  "fixtures/files/app/models/album.rb",
51
50
  "fixtures/files/app/views/albums/new.html.erb",
52
51
  "fixtures/files/app/views/albums/show.html.erb",
53
- "fixtures/files/config/initializers/aaa_dragonfly_load_path.rb",
52
+ "fixtures/files/config/initializers/dragonfly.rb",
54
53
  "fixtures/files/features/manage_album_images.feature",
55
54
  "fixtures/files/features/step_definitions/album_steps.rb",
56
55
  "fixtures/files/features/support/paths.rb",
57
- "fixtures/rails",
58
56
  "fixtures/rails_2.3.5/template.rb",
59
- "fixtures/rails_3.0.0.beta/template.rb",
60
- "generators/dragonfly_app/USAGE",
61
- "generators/dragonfly_app/dragonfly_app_generator.rb",
62
- "generators/dragonfly_app/templates/initializer.erb",
57
+ "fixtures/rails_3.0.0.beta3/template.rb",
63
58
  "irbrc.rb",
64
59
  "lib/dragonfly.rb",
65
60
  "lib/dragonfly/active_record_extensions.rb",
@@ -72,6 +67,12 @@ Gem::Specification.new do |s|
72
67
  "lib/dragonfly/analysis/file_command_analyser.rb",
73
68
  "lib/dragonfly/analysis/r_magick_analyser.rb",
74
69
  "lib/dragonfly/app.rb",
70
+ "lib/dragonfly/belongs_to_app.rb",
71
+ "lib/dragonfly/config/heroku_rails_images.rb",
72
+ "lib/dragonfly/config/r_magick_images.rb",
73
+ "lib/dragonfly/config/r_magick_text.rb",
74
+ "lib/dragonfly/config/rails_defaults.rb",
75
+ "lib/dragonfly/config/rails_images.rb",
75
76
  "lib/dragonfly/configurable.rb",
76
77
  "lib/dragonfly/core_ext/object.rb",
77
78
  "lib/dragonfly/core_ext/string.rb",
@@ -93,8 +94,8 @@ Gem::Specification.new do |s|
93
94
  "lib/dragonfly/parameters.rb",
94
95
  "lib/dragonfly/processing/base.rb",
95
96
  "lib/dragonfly/processing/r_magick_processor.rb",
97
+ "lib/dragonfly/processing/r_magick_text_processor.rb",
96
98
  "lib/dragonfly/processor_list.rb",
97
- "lib/dragonfly/r_magick_configuration.rb",
98
99
  "lib/dragonfly/rails/images.rb",
99
100
  "lib/dragonfly/temp_object.rb",
100
101
  "lib/dragonfly/url_handler.rb",
@@ -105,7 +106,6 @@ Gem::Specification.new do |s|
105
106
  "samples/taj.jpg",
106
107
  "spec/argument_matchers.rb",
107
108
  "spec/dragonfly/active_record_extensions/attachment_spec.rb",
108
- "spec/dragonfly/active_record_extensions/initializer.rb",
109
109
  "spec/dragonfly/active_record_extensions/migration.rb",
110
110
  "spec/dragonfly/active_record_extensions/model_spec.rb",
111
111
  "spec/dragonfly/active_record_extensions/models.rb",
@@ -113,6 +113,7 @@ Gem::Specification.new do |s|
113
113
  "spec/dragonfly/analysis/file_command_analyser_spec.rb",
114
114
  "spec/dragonfly/analysis/r_magick_analyser_spec.rb",
115
115
  "spec/dragonfly/app_spec.rb",
116
+ "spec/dragonfly/belongs_to_app_spec.rb",
116
117
  "spec/dragonfly/configurable_spec.rb",
117
118
  "spec/dragonfly/core_ext/string_spec.rb",
118
119
  "spec/dragonfly/core_ext/symbol_spec.rb",
@@ -125,7 +126,8 @@ Gem::Specification.new do |s|
125
126
  "spec/dragonfly/extended_temp_object_spec.rb",
126
127
  "spec/dragonfly/middleware_spec.rb",
127
128
  "spec/dragonfly/parameters_spec.rb",
128
- "spec/dragonfly/processing/rmagick_processor_spec.rb",
129
+ "spec/dragonfly/processing/r_magick_processor_spec.rb",
130
+ "spec/dragonfly/processing/r_magick_text_processor_spec.rb",
129
131
  "spec/dragonfly/temp_object_spec.rb",
130
132
  "spec/dragonfly/url_handler_spec.rb",
131
133
  "spec/dragonfly_spec.rb",
@@ -148,7 +150,6 @@ Gem::Specification.new do |s|
148
150
  s.test_files = [
149
151
  "spec/argument_matchers.rb",
150
152
  "spec/dragonfly/active_record_extensions/attachment_spec.rb",
151
- "spec/dragonfly/active_record_extensions/initializer.rb",
152
153
  "spec/dragonfly/active_record_extensions/migration.rb",
153
154
  "spec/dragonfly/active_record_extensions/model_spec.rb",
154
155
  "spec/dragonfly/active_record_extensions/models.rb",
@@ -156,6 +157,7 @@ Gem::Specification.new do |s|
156
157
  "spec/dragonfly/analysis/file_command_analyser_spec.rb",
157
158
  "spec/dragonfly/analysis/r_magick_analyser_spec.rb",
158
159
  "spec/dragonfly/app_spec.rb",
160
+ "spec/dragonfly/belongs_to_app_spec.rb",
159
161
  "spec/dragonfly/configurable_spec.rb",
160
162
  "spec/dragonfly/core_ext/string_spec.rb",
161
163
  "spec/dragonfly/core_ext/symbol_spec.rb",
@@ -168,7 +170,8 @@ Gem::Specification.new do |s|
168
170
  "spec/dragonfly/extended_temp_object_spec.rb",
169
171
  "spec/dragonfly/middleware_spec.rb",
170
172
  "spec/dragonfly/parameters_spec.rb",
171
- "spec/dragonfly/processing/rmagick_processor_spec.rb",
173
+ "spec/dragonfly/processing/r_magick_processor_spec.rb",
174
+ "spec/dragonfly/processing/r_magick_text_processor_spec.rb",
172
175
  "spec/dragonfly/temp_object_spec.rb",
173
176
  "spec/dragonfly/url_handler_spec.rb",
174
177
  "spec/dragonfly_spec.rb",
@@ -11,13 +11,11 @@ Suppose we have a dragonfly app
11
11
 
12
12
  app = Dragonfly::App[:my_app_name]
13
13
 
14
- First extend activerecord
14
+ We can define an accessor on ActiveRecord models using
15
15
 
16
- ActiveRecord::Base.extend Dragonfly::ActiveRecordExtensions
16
+ Dragonfly.active_record_macro(:image, app)
17
17
 
18
- Now register the app, giving the prefix for defining accessor methods (in this case 'image')
19
-
20
- ActiveRecord::Base.register_dragonfly_app(:image, app)
18
+ The first argument is the prefix for the accessor macro (in this case 'image').
21
19
 
22
20
  Adding accessors
23
21
  ----------------
@@ -73,8 +71,11 @@ We can play around with the data
73
71
 
74
72
  album.cover_image.data # => "\377???JFIF\000\..."
75
73
  album.cover_image.to_file('out.png') # writes to file 'out.png' and returns a readable file object
76
- album.cover_image.tempfile # => #<File:/var/folders/st/strHv74sH044JPabSiODz... i.e. a tempfile holding the data
77
- album.cover_image.file # alias for tempfile, above
74
+ album.cover_image.tempfile # => #<File:/var/folders/st/strHv74sH044JPabSiODz... a closed Tempfile object
75
+ album.cover_image.file # => #<File:/var/folders/st/strHv74sH044JPabSiODz... a readable (open) File object
76
+ album.cover_image.file do |f| # Yields an open file object, returns the return value of
77
+ data = f.read(256) # the block, and closes the file object
78
+ end
78
79
  album.cover_image.path # => '/var/folders/st/strHv74sH044JPabSiODz...' i.e. the path of the tempfile
79
80
  album.cover_image.size # => 134507 (size in bytes)
80
81
 
@@ -35,7 +35,7 @@ As the file command analyser is {Dragonfly::Configurable configurable}, we can c
35
35
  a.file_command = '/usr/bin/file'
36
36
  end
37
37
 
38
- The saved configuration {Dragonfly::RMagickConfiguration RMagickConfiguration} registers the above two analysers automatically.
38
+ The saved configuration {Dragonfly::Config::RMagickImages RMagickImages} registers the above two analysers automatically.
39
39
 
40
40
  Custom Analysers
41
41
  ----------------
@@ -27,7 +27,7 @@ Then we can encode {Dragonfly::ExtendedTempObject temp_objects} to formats recog
27
27
 
28
28
  temp_object.encode(:doc) # => throws :unable_to_handle
29
29
 
30
- The saved configuration {Dragonfly::RMagickConfiguration RMagickConfiguration} registers the above encoder automatically.
30
+ The saved configuration {Dragonfly::Config::RMagickImages RMagickImages} registers the above encoder automatically.
31
31
 
32
32
  Custom Encoders
33
33
  ---------------
@@ -17,10 +17,6 @@ Image thumbnails in Rails, hosted on Heroku with S3 storage
17
17
  {http://heroku.com Heroku} is a commonly used platform for hosting Rack-based websites.
18
18
  The following assumes your site is set up for deployment onto Heroku.
19
19
 
20
- As explained in {file:UsingWithRails}, we can use a generator to create an initializer for setting up Dragonfly.
21
-
22
- ./script/generate dragonfly_app images
23
-
24
20
  The default configuration won't work out of the box for Heroku, because
25
21
 
26
22
  - Heroku doesn't allow saving files to the filesystem (although it does use tempfiles)
@@ -31,46 +27,47 @@ Amazon's {http://aws.amazon.com/s3 S3} is a commonly used platform for storing d
31
27
 
32
28
  The following assumes you have an S3 account set up, and know your provided 'access key' and 'secret'.
33
29
 
34
- Assuming we don't bother with any caching for development/testing environments, our environment.rb then has:
30
+ ### Rails 2.3
35
31
 
36
- config.gem 'rmagick', :lib => 'RMagick'
37
- config.gem 'dragonfly', :source => "http://www.gemcutter.org"
32
+ environment.rb:
38
33
 
39
- (these are ignored by Heroku but you might want them locally)
34
+ config.gem 'rmagick', :lib => 'RMagick'
35
+ gem 'aws-s3', :lib => 'aws/s3'
36
+ config.gem 'dragonfly'
40
37
 
41
- The gems file for Heroku, `.gems`, has
38
+ and
39
+ .gems:
42
40
 
43
41
  dragonfly
42
+ aws-s3
44
43
 
45
- (rmagick not needed because it is already installed)
44
+ ### Rails 3
46
45
 
47
- Then in our configuration initializer, we replace
46
+ Gemfile:
48
47
 
49
- c.datastore.configure do |d|
50
- d.root_path = "#{Rails.root}/public/system/dragonfly/#{Rails.env}"
51
- end
48
+ gem 'rmagick', '2.12.2', :require => 'RMagick'
49
+ gem 'aws-s3', :require => 'aws/s3'
50
+ gem 'dragonfly'
52
51
 
53
- with
52
+ Apparently to use Bundler you need to switch to the 'Bamboo' stack - see {http://docs.heroku.com/bamboo}
54
53
 
55
- # Use S3 for production
56
- if Rails.env == 'production'
57
- c.datastore = Dragonfly::DataStorage::S3DataStore.new
58
- c.datastore.configure do |d|
59
- d.bucket_name = 'my_s3_bucket_name'
60
- d.access_key_id = ENV['S3_KEY'] || raise("ENV variable 'S3_KEY' needs to be set")
61
- d.secret_access_key = ENV['S3_SECRET'] || raise("ENV variable 'S3_SECRET' needs to be set")
62
- end
63
- # and filesystem for other environments
64
- else
65
- c.datastore.configure do |d|
66
- d.root_path = "#{Rails.root}/public/system/dragonfly/#{Rails.env}"
67
- end
68
- end
54
+ ### All versions
55
+
56
+ Initializer (e.g. config/initializers/dragonfly.rb):
57
+
58
+ require 'dragonfly'
59
+ app = Dragonfly::App[:images]
60
+ app.configure_with(Dragonfly::Config::HerokuRailsImages, 'my_bucket_name')
61
+ Dragonfly.active_record_macro(:image, app)
69
62
 
70
- We've left the datastore as {Dragonfly::DataStorage::FileDataStore FileDataStore} for non-production environments.
63
+ The datastore remains as the {Dragonfly::DataStorage::FileDataStore FileDataStore} for non-production environments.
71
64
 
72
- As you can see we've used `ENV` to store the S3 access key and secret to avoid having them in the repository.
73
- Heroku has a {http://docs.heroku.com/config-vars way of setting these} using the command line (we only have to do this once).
65
+ environment.rb (application.rb in Rails 3):
66
+
67
+ config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :images
68
+
69
+ We don't store the S3 access key and secret in the repository, rather we use Heroku's
70
+ {http://docs.heroku.com/config-vars config variables} using the command line (we only have to do this once).
74
71
 
75
72
  From your app's directory:
76
73
 
@@ -80,8 +77,8 @@ Obviously you replace 'XXXXXXXXX' with your access key and secret.
80
77
 
81
78
  Now you can benefit use Dragonfly in the normal way, benefitting from super-fast images served straight from Heroku's cache!
82
79
 
83
- The only downside is that Heroku's cache is cleared every time you deploy, so if this is an issue you may want to look into using something like
84
- a Memcached add-on, or maybe an after-deploy hook for hitting specific Dragonfly urls you want to cache, etc.
80
+ NOTE: HEROKU'S CACHE IS CLEARED EVERY TIME YOU DEPLOY.
81
+ If this is an issue you may want to look into using something like a Memcached add-on, or maybe an after-deploy hook for hitting specific Dragonfly urls you want to cache, etc.
85
82
  It won't be a problem for most sites though.
86
83
 
87
84
 
@@ -91,33 +88,25 @@ Although Dragonfly is normally concerned with processing and encoding, you may w
91
88
  (e.g. .doc, .xls, .pdf files, etc.) without processing or encoding them, so as to still benefit from the {file:ActiveRecord ActiveRecord Extensions} API.
92
89
 
93
90
  The below shows how to do it in Rails, but the principles are the same in any context.
94
- Let's generate a configuration for a Dragonfly App called 'attachments'
95
-
96
- ./script/generate dragonfly_app attachments
97
91
 
98
- This generates an initializer for configuring the Dragonfly App 'attachments'.
92
+ Initializer, e.g. config/initializers/dragonfly.rb:
99
93
 
100
- We won't be using RMagick or Rack::Cache (as there is no processing), so our environment.rb only has:
94
+ require 'dragonfly'
101
95
 
102
- config.gem 'dragonfly', :source => 'http://gemcutter.org'
103
-
104
- and in the generated configuration, we DELETE the line
105
-
106
- app.configure_with(Dragonfly::RMagickConfiguration)
107
-
108
- Then in the configure block, we add the lines
109
-
110
- c.url_handler.configure do |u|
111
- # ...
112
- u.protect_from_dos_attacks = false
96
+ app = Dragonfly::App[:attachments]
97
+ app.configure_with(Dragonfly::Config::RailsDefaults) do |c|
98
+ c.register_analyser(Dragonfly::Analysis::FileCommandAnalyser)
99
+ c.register_encoder(Dragonfly::Encoding::TransparentEncoder)
113
100
  end
114
- c.register_analyser(Dragonfly::Analysis::FileCommandAnalyser)
115
- c.register_encoder(Dragonfly::Encoding::TransparentEncoder)
101
+ Dragonfly.active_record_macro(:attachment, app)
116
102
 
117
- We don't need to protect the urls from Denial-of-service attacks as we aren't doing any expensive processing.
118
103
  The {Dragonfly::Analysis::FileCommandAnalyser FileCommandAnalyser} is needed to know the mime-type of the content,
119
104
  and the {Dragonfly::Encoding::TransparentEncoder TransparentEncoder} is like a 'dummy' encoder which does nothing
120
- (the way to switch off encoding may change in the future).
105
+ (the way to switch off encoding will be simplified in future versions of Dragonfly).
106
+
107
+ environment.rb (application.rb in Rails 3):
108
+
109
+ config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :attachments
121
110
 
122
111
  If a user uploads a file called 'report.pdf', then normally the original file extension will be lost.
123
112
  Thankfully, to record it is as easy as adding an 'ext' column as well as the usual uid column to our migration
@@ -150,7 +139,7 @@ Each {Dragonfly::App Dragonfly App} has a 'generate' method, which returns an {D
150
139
  The actual generation is delegated to the registered processors (along with any args passed in).
151
140
 
152
141
  For example, if our app is registered with the {Dragonfly::Processing::RMagickProcessor RMagickProcessor} (which is already done if using with one of
153
- the Rails helper files/generators)
142
+ the RMagick/RailsImage configurations)
154
143
 
155
144
  Dragonfly::App[:my_app].register_processor(Dragonfly::Processing::RMagickProcessor)
156
145
 
@@ -167,30 +156,34 @@ A common technique for making sure a specific font is displayed on a website is
167
156
 
168
157
  We can easily use Dragonfly to do this on-the-fly.
169
158
 
170
- The {Dragonfly::Processing::RMagickProcessor RMagickProcessor} has a 'text' method, which takes content in the form of text,
171
- and creates an image of the text, given the options passed in.
159
+ Configuration (e.g. initializer in Rails):
172
160
 
173
- We can also make use of the simple {Dragonfly::DataStorage::TransparentDataStore TransparentDataStore}, where rather than fetch
174
- data for a given uid, the uid IS the data.
175
-
176
- The configuration will look something like:
177
-
178
- Dragonfly::App[:text].configure do |c|
179
- c.datastore = Dragonfly::DataStorage::TransparentDataStore.new
180
- c.register_analyser(Dragonfly::Analysis::FileCommandAnalyser)
181
- c.register_processor(Dragonfly::Processing::RMagickProcessor)
182
- c.register_encoder(Dragonfly::Encoding::RMagickEncoder)
183
- c.parameters.configure do |p|
184
- p.default_format = :png
185
- p.default_processing_method = :text
186
- end
161
+ require 'dragonfly'
162
+ Dragonfly::App[:text].configure_with(Dragonfly::Config::RMagickText) do |c|
163
+ c.url_handler.path_prefix = '/text'
187
164
  end
188
165
 
189
- We need the {Dragonfly::Analysis::FileCommandAnalyser FileCommandAnalyser} for mime-type analysis.
166
+ If using Rails, then in environment.rb (application.rb in Rails 3):
167
+
168
+ config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :text
169
+
170
+ You probably will want to insert Rack::Cache too or use some other caching proxy - see {file:UsingWithRails}.
190
171
 
191
172
  Then when we visit a url like
192
173
 
193
- url = Dragonfly::App[:text].url_for('some text', :processing_options => {:font_size => 30, :font_family => 'Monaco'})
174
+ url = Dragonfly::App[:text].url_for('some text', :text, :font_size => 30, :font_family => 'Monaco')
194
175
 
195
176
  we get a png image of the text. We could easily wrap this in some kind of helper if we use it often.
196
177
 
178
+ This configuration uses the {Dragonfly::Processing::RMagickTextProcessor RMagickTextProcessor} processor.
179
+ Options can be specified either css-like (e.g. `'font-family' => 'Helvetica'`), or with underscore-style symbols
180
+ (e.g. `:font_family => 'Helvetica'`).
181
+
182
+ Available options are `font` (see {http://www.imagemagick.org/RMagick/doc/draw.html#font}),
183
+ `'font-family'`,
184
+ `'stroke_color'`,
185
+ `'color'`,
186
+ `'font_style'`,
187
+ `'font_stretch'`,
188
+ `'font_weight'` and
189
+ `'padding'` (or `'padding-left'`, `'padding-top'`, etc.)