dragonfly 0.9.8 → 0.9.9

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 (58) hide show
  1. data/Gemfile +1 -1
  2. data/History.md +32 -0
  3. data/README.md +54 -32
  4. data/VERSION +1 -1
  5. data/dragonfly.gemspec +23 -21
  6. data/extra_docs/Configuration.md +0 -8
  7. data/extra_docs/DataStorage.md +13 -5
  8. data/extra_docs/ExampleUseCases.md +4 -1
  9. data/extra_docs/Heroku.md +14 -6
  10. data/extra_docs/Models.md +5 -1
  11. data/extra_docs/Rails3.md +1 -1
  12. data/extra_docs/URLs.md +8 -1
  13. data/lib/dragonfly.rb +7 -8
  14. data/lib/dragonfly/active_model_extensions/attachment.rb +37 -17
  15. data/lib/dragonfly/active_model_extensions/attachment_class_methods.rb +1 -1
  16. data/lib/dragonfly/active_model_extensions/validations.rb +53 -26
  17. data/lib/dragonfly/analyser.rb +1 -1
  18. data/lib/dragonfly/app.rb +1 -1
  19. data/lib/dragonfly/config/heroku.rb +7 -0
  20. data/lib/dragonfly/configurable.rb +19 -20
  21. data/lib/dragonfly/data_storage/couch_data_store.rb +2 -3
  22. data/lib/dragonfly/data_storage/file_data_store.rb +2 -9
  23. data/lib/dragonfly/data_storage/mongo_data_store.rb +1 -1
  24. data/lib/dragonfly/data_storage/s3data_store.rb +17 -10
  25. data/lib/dragonfly/function_manager.rb +4 -8
  26. data/lib/dragonfly/has_filename.rb +24 -0
  27. data/lib/dragonfly/image_magick/analyser.rb +1 -1
  28. data/lib/dragonfly/image_magick/generator.rb +1 -1
  29. data/lib/dragonfly/image_magick/processor.rb +5 -0
  30. data/lib/dragonfly/image_magick/utils.rb +1 -2
  31. data/lib/dragonfly/job.rb +52 -71
  32. data/lib/dragonfly/railtie.rb +1 -1
  33. data/lib/dragonfly/temp_object.rb +32 -14
  34. data/lib/dragonfly/url_attributes.rb +30 -0
  35. data/lib/dragonfly/url_mapper.rb +2 -2
  36. data/samples/DSC02119.JPG +0 -0
  37. data/samples/a.jp2 +0 -0
  38. data/samples/beach.jpg +0 -0
  39. data/spec/dragonfly/active_model_extensions/model_spec.rb +63 -40
  40. data/spec/dragonfly/active_model_extensions/spec_helper.rb +4 -0
  41. data/spec/dragonfly/app_spec.rb +11 -3
  42. data/spec/dragonfly/configurable_spec.rb +38 -20
  43. data/spec/dragonfly/data_storage/file_data_store_spec.rb +24 -36
  44. data/spec/dragonfly/data_storage/s3_data_store_spec.rb +21 -5
  45. data/spec/dragonfly/data_storage/shared_data_store_examples.rb +2 -2
  46. data/spec/dragonfly/has_filename_spec.rb +88 -0
  47. data/spec/dragonfly/image_magick/analyser_spec.rb +10 -0
  48. data/spec/dragonfly/image_magick/processor_spec.rb +11 -0
  49. data/spec/dragonfly/job_spec.rb +173 -167
  50. data/spec/dragonfly/temp_object_spec.rb +82 -10
  51. data/spec/dragonfly/url_attributes.rb +47 -0
  52. data/spec/dragonfly/url_mapper_spec.rb +9 -1
  53. data/spec/functional/model_urls_spec.rb +36 -1
  54. metadata +179 -250
  55. data/lib/dragonfly/core_ext/string.rb +0 -9
  56. data/lib/dragonfly/core_ext/symbol.rb +0 -9
  57. data/spec/dragonfly/core_ext/string_spec.rb +0 -17
  58. data/spec/dragonfly/core_ext/symbol_spec.rb +0 -17
data/Gemfile CHANGED
@@ -23,7 +23,7 @@ group :development, :test, :cucumber do
23
23
  gem "jruby-openssl"
24
24
  else
25
25
  gem 'bluecloth'
26
- gem 'bson_ext'
26
+ gem 'bson_ext', '~>1.3.1'
27
27
  gem 'sqlite3-ruby'
28
28
  end
29
29
  end
data/History.md CHANGED
@@ -1,3 +1,35 @@
1
+ 0.9.9 (2011-12-30)
2
+ ==================
3
+ Features
4
+ --------
5
+ - Created tempfiles use the original file extension if known
6
+ - Added `:case_sensitive` option to `validates_property` for dealing with upper-case extensions and mime-types.
7
+ - Github Markup syntax on readme for code highlighting
8
+ - S3DataStore can use https for remote urls (either configurable or per-url)
9
+ - `to_file` can take `:mode` option for setting custom permissions
10
+ - `to_file` creates intermediate subdirs by default, can be turned off with `:mkdirs => false` option
11
+ - Added some more S3 regions
12
+
13
+ Changes
14
+ -------
15
+ - Datastores now use `temp_object.meta`, not the second arg passed in to `store`
16
+ - `meta`, `name`, etc. now lazily load the job on an attachment - previously you'd have to call `apply` to get the meta from the datastore
17
+ - When assigning an image via the activemodel extensions, mark that uid attribute will change
18
+ - `validates_property` uses Rails 3 validators
19
+ - Deprecated saved 'heroku' config, in favour of configuring S3 explicitly
20
+
21
+ Fixes
22
+ -----
23
+ - Model attachment urls are consistent now - the name is appended to the url (with format "/:job/:name") ONLY if it has the "name" magic attribute
24
+ - `identify` wasn't working properly for files with capital letter extensions
25
+ - S3 datastore sets content mime_type by default
26
+ - File extensions with numbers like JP2 weren't being processed/analysed properly
27
+ - Protect against object_ids being recycled and messing with analyser cache
28
+ - All url segments are correctly url-escaped now
29
+ - Fixed TempObject File.open mode
30
+ - S3DataStore was breaking on bucket_exists? when using AWS IAM
31
+ - Put CookieMonster before ActionDispatch::Cookies in rack middleware stack - that way Rack::Cache won't come between them and mess things up
32
+
1
33
  0.9.8 (2011-09-08)
2
34
  ==================
3
35
  Fixes
data/README.md CHANGED
@@ -11,73 +11,95 @@ For the lazy Rails user...
11
11
  --------------------------
12
12
  **Gemfile**:
13
13
 
14
- gem 'rack-cache', :require => 'rack/cache'
15
- gem 'dragonfly', '~>0.9.8'
14
+ ```ruby
15
+ gem 'rack-cache', :require => 'rack/cache'
16
+ gem 'dragonfly', '~>0.9.9'
17
+ ```
16
18
 
17
19
  **Initializer** (e.g. config/initializers/dragonfly.rb):
18
20
 
19
- require 'dragonfly/rails/images'
21
+ ```ruby
22
+ require 'dragonfly/rails/images'
23
+ ```
20
24
 
21
25
  **Migration**:
22
26
 
23
- add_column :albums, :cover_image_uid, :string
24
- add_column :albums, :cover_image_name, :string # Optional - only if you want urls
25
- # to end with the original filename
27
+ ```ruby
28
+ add_column :albums, :cover_image_uid, :string
29
+ add_column :albums, :cover_image_name, :string # Optional - only if you want urls
30
+ # to end with the original filename
31
+ ```
26
32
 
27
33
  **Model**:
28
34
 
29
- class Album < ActiveRecord::Base
30
- image_accessor :cover_image # 'image_accessor' is provided by Dragonfly
31
- # this defines a reader/writer for cover_image
32
- # ...
33
- end
35
+ ```ruby
36
+ class Album < ActiveRecord::Base
37
+ image_accessor :cover_image # 'image_accessor' is provided by Dragonfly
38
+ # this defines a reader/writer for cover_image
39
+ # ...
40
+ end
41
+ ```
34
42
 
35
43
  **View** (for uploading via a file field):
36
44
 
37
- <% form_for @album, :html => {:multipart => true} do |f| %>
38
- ...
39
- <%= f.file_field :cover_image %>
40
- ...
41
- <% end %>
45
+ ```erb
46
+ <% form_for @album, :html => {:multipart => true} do |f| %>
47
+ ...
48
+ <%= f.file_field :cover_image %>
49
+ ...
50
+ <% end %>
51
+ ```
42
52
 
43
53
  NB: REMEMBER THE MULTIPART BIT!!!
44
54
 
45
55
  You can avoid having to re-upload when validations fail with
46
56
 
47
- <%= f.hidden_field :retained_cover_image %>
57
+ ```erb
58
+ <%= f.hidden_field :retained_cover_image %>
59
+ ```
48
60
 
49
61
  remove the attachment with
50
62
 
51
- <%= f.check_box :remove_cover_image %>
63
+ ```erb
64
+ <%= f.check_box :remove_cover_image %>
65
+ ```
52
66
 
53
67
  assign from some other url with
54
68
 
55
- <%= f.text_field :cover_image_url %>
69
+ ```erb
70
+ <%= f.text_field :cover_image_url %>
71
+ ```
56
72
 
57
73
  and display a thumbnail (on the upload form) with
58
74
 
59
- <%= image_tag @album.cover_image.thumb('100x100').url if @album.cover_image_uid %>
75
+ ```erb
76
+ <%= image_tag @album.cover_image.thumb('100x100').url if @album.cover_image_uid %>
77
+ ```
60
78
 
61
79
  **View** (to display):
62
80
 
63
- <%= image_tag @album.cover_image.url %>
64
- <%= image_tag @album.cover_image.thumb('400x200#').url %>
65
- <%= image_tag @album.cover_image.jpg.url %>
66
- <%= image_tag @album.cover_image.process(:greyscale).encode(:tiff).url %>
67
- ...etc.
81
+ ```erb
82
+ <%= image_tag @album.cover_image.url %>
83
+ <%= image_tag @album.cover_image.thumb('400x200#').url %>
84
+ <%= image_tag @album.cover_image.jpg.url %>
85
+ <%= image_tag @album.cover_image.process(:greyscale).encode(:tiff).url %>
86
+ ...etc.
87
+ ```
68
88
 
69
89
  The above relies on imagemagick being installed. Dragonfly doesn't depend on it per se, but the default configuration `'dragonfly/rails/images'`
70
90
  uses it. For alternative configurations, see below.
71
91
 
72
92
  If using Capistrano with the above, you probably will want to keep the cache between deploys, so in deploy.rb:
73
93
 
74
- namespace :dragonfly do
75
- desc "Symlink the Rack::Cache files"
76
- task :symlink, :roles => [:app] do
77
- run "mkdir -p #{shared_path}/tmp/dragonfly && ln -nfs #{shared_path}/tmp/dragonfly #{release_path}/tmp/dragonfly"
78
- end
79
- end
80
- after 'deploy:update_code', 'dragonfly:symlink'
94
+ ```ruby
95
+ namespace :dragonfly do
96
+ desc "Symlink the Rack::Cache files"
97
+ task :symlink, :roles => [:app] do
98
+ run "mkdir -p #{shared_path}/tmp/dragonfly && ln -nfs #{shared_path}/tmp/dragonfly #{release_path}/tmp/dragonfly"
99
+ end
100
+ end
101
+ after 'deploy:update_code', 'dragonfly:symlink'
102
+ ```
81
103
 
82
104
  Sinatra, CouchDB, Mongo, Rack, S3, custom storage, processing, and more...
83
105
  --------------------------------------------------------------------------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.8
1
+ 0.9.9
data/dragonfly.gemspec CHANGED
@@ -4,15 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{dragonfly}
8
- s.version = "0.9.8"
7
+ s.name = "dragonfly"
8
+ s.version = "0.9.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Mark Evans}]
12
- s.date = %q{2011-09-08}
13
- s.description = %q{Dragonfly is a framework that enables on-the-fly processing for any content type.
14
- It is especially suited to image handling. Its uses range from image thumbnails to standard attachments to on-demand text generation.}
15
- s.email = %q{mark@new-bamboo.co.uk}
11
+ s.authors = ["Mark Evans"]
12
+ s.date = "2011-12-30"
13
+ s.description = "Dragonfly is a framework that enables on-the-fly processing for any content type.\n It is especially suited to image handling. Its uses range from image thumbnails to standard attachments to on-demand text generation."
14
+ s.email = "mark@new-bamboo.co.uk"
16
15
  s.extra_rdoc_files = [
17
16
  "LICENSE",
18
17
  "README.md"
@@ -89,8 +88,6 @@ Gem::Specification.new do |s|
89
88
  "lib/dragonfly/core_ext/array.rb",
90
89
  "lib/dragonfly/core_ext/hash.rb",
91
90
  "lib/dragonfly/core_ext/object.rb",
92
- "lib/dragonfly/core_ext/string.rb",
93
- "lib/dragonfly/core_ext/symbol.rb",
94
91
  "lib/dragonfly/data_storage.rb",
95
92
  "lib/dragonfly/data_storage/couch_data_store.rb",
96
93
  "lib/dragonfly/data_storage/file_data_store.rb",
@@ -101,6 +98,7 @@ Gem::Specification.new do |s|
101
98
  "lib/dragonfly/function_manager.rb",
102
99
  "lib/dragonfly/generation/image_magick_generator.rb",
103
100
  "lib/dragonfly/generator.rb",
101
+ "lib/dragonfly/has_filename.rb",
104
102
  "lib/dragonfly/hash_with_css_style_keys.rb",
105
103
  "lib/dragonfly/image_magick/analyser.rb",
106
104
  "lib/dragonfly/image_magick/config.rb",
@@ -126,7 +124,11 @@ Gem::Specification.new do |s|
126
124
  "lib/dragonfly/shell.rb",
127
125
  "lib/dragonfly/simple_cache.rb",
128
126
  "lib/dragonfly/temp_object.rb",
127
+ "lib/dragonfly/url_attributes.rb",
129
128
  "lib/dragonfly/url_mapper.rb",
129
+ "samples/DSC02119.JPG",
130
+ "samples/a.jp2",
131
+ "samples/beach.jpg",
130
132
  "samples/beach.png",
131
133
  "samples/egg.png",
132
134
  "samples/round.gif",
@@ -142,14 +144,13 @@ Gem::Specification.new do |s|
142
144
  "spec/dragonfly/cookie_monster_spec.rb",
143
145
  "spec/dragonfly/core_ext/array_spec.rb",
144
146
  "spec/dragonfly/core_ext/hash_spec.rb",
145
- "spec/dragonfly/core_ext/string_spec.rb",
146
- "spec/dragonfly/core_ext/symbol_spec.rb",
147
147
  "spec/dragonfly/data_storage/couch_data_store_spec.rb",
148
148
  "spec/dragonfly/data_storage/file_data_store_spec.rb",
149
149
  "spec/dragonfly/data_storage/mongo_data_store_spec.rb",
150
150
  "spec/dragonfly/data_storage/s3_data_store_spec.rb",
151
151
  "spec/dragonfly/data_storage/shared_data_store_examples.rb",
152
152
  "spec/dragonfly/function_manager_spec.rb",
153
+ "spec/dragonfly/has_filename_spec.rb",
153
154
  "spec/dragonfly/hash_with_css_style_keys_spec.rb",
154
155
  "spec/dragonfly/image_magick/analyser_spec.rb",
155
156
  "spec/dragonfly/image_magick/encoder_spec.rb",
@@ -167,6 +168,7 @@ Gem::Specification.new do |s|
167
168
  "spec/dragonfly/shell_spec.rb",
168
169
  "spec/dragonfly/simple_cache_spec.rb",
169
170
  "spec/dragonfly/temp_object_spec.rb",
171
+ "spec/dragonfly/url_attributes.rb",
170
172
  "spec/dragonfly/url_mapper_spec.rb",
171
173
  "spec/functional/deprecations_spec.rb",
172
174
  "spec/functional/image_magick_app_spec.rb",
@@ -187,11 +189,11 @@ Gem::Specification.new do |s|
187
189
  "yard/templates/default/module/html/configuration_summary.erb",
188
190
  "yard/templates/default/module/setup.rb"
189
191
  ]
190
- s.homepage = %q{http://github.com/markevans/dragonfly}
191
- s.licenses = [%q{MIT}]
192
- s.require_paths = [%q{lib}]
193
- s.rubygems_version = %q{1.8.6}
194
- s.summary = %q{Ideal gem for handling attachments in Rails, Sinatra and Rack applications.}
192
+ s.homepage = "http://github.com/markevans/dragonfly"
193
+ s.licenses = ["MIT"]
194
+ s.require_paths = ["lib"]
195
+ s.rubygems_version = "1.8.10"
196
+ s.summary = "Ideal gem for handling attachments in Rails, Sinatra and Rack applications."
195
197
  s.test_files = [
196
198
  "spec/dragonfly/active_model_extensions/model_spec.rb",
197
199
  "spec/dragonfly/active_model_extensions/spec_helper.rb",
@@ -202,14 +204,13 @@ Gem::Specification.new do |s|
202
204
  "spec/dragonfly/cookie_monster_spec.rb",
203
205
  "spec/dragonfly/core_ext/array_spec.rb",
204
206
  "spec/dragonfly/core_ext/hash_spec.rb",
205
- "spec/dragonfly/core_ext/string_spec.rb",
206
- "spec/dragonfly/core_ext/symbol_spec.rb",
207
207
  "spec/dragonfly/data_storage/couch_data_store_spec.rb",
208
208
  "spec/dragonfly/data_storage/file_data_store_spec.rb",
209
209
  "spec/dragonfly/data_storage/mongo_data_store_spec.rb",
210
210
  "spec/dragonfly/data_storage/s3_data_store_spec.rb",
211
211
  "spec/dragonfly/data_storage/shared_data_store_examples.rb",
212
212
  "spec/dragonfly/function_manager_spec.rb",
213
+ "spec/dragonfly/has_filename_spec.rb",
213
214
  "spec/dragonfly/hash_with_css_style_keys_spec.rb",
214
215
  "spec/dragonfly/image_magick/analyser_spec.rb",
215
216
  "spec/dragonfly/image_magick/encoder_spec.rb",
@@ -227,6 +228,7 @@ Gem::Specification.new do |s|
227
228
  "spec/dragonfly/shell_spec.rb",
228
229
  "spec/dragonfly/simple_cache_spec.rb",
229
230
  "spec/dragonfly/temp_object_spec.rb",
231
+ "spec/dragonfly/url_attributes.rb",
230
232
  "spec/dragonfly/url_mapper_spec.rb",
231
233
  "spec/functional/deprecations_spec.rb",
232
234
  "spec/functional/image_magick_app_spec.rb",
@@ -259,7 +261,7 @@ Gem::Specification.new do |s|
259
261
  s.add_development_dependency(%q<webmock>, [">= 0"])
260
262
  s.add_development_dependency(%q<yard>, [">= 0"])
261
263
  s.add_development_dependency(%q<bluecloth>, [">= 0"])
262
- s.add_development_dependency(%q<bson_ext>, [">= 0"])
264
+ s.add_development_dependency(%q<bson_ext>, ["~> 1.3.1"])
263
265
  s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
264
266
  else
265
267
  s.add_dependency(%q<rack>, [">= 0"])
@@ -277,7 +279,7 @@ Gem::Specification.new do |s|
277
279
  s.add_dependency(%q<webmock>, [">= 0"])
278
280
  s.add_dependency(%q<yard>, [">= 0"])
279
281
  s.add_dependency(%q<bluecloth>, [">= 0"])
280
- s.add_dependency(%q<bson_ext>, [">= 0"])
282
+ s.add_dependency(%q<bson_ext>, ["~> 1.3.1"])
281
283
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
282
284
  end
283
285
  else
@@ -296,7 +298,7 @@ Gem::Specification.new do |s|
296
298
  s.add_dependency(%q<webmock>, [">= 0"])
297
299
  s.add_dependency(%q<yard>, [">= 0"])
298
300
  s.add_dependency(%q<bluecloth>, [">= 0"])
299
- s.add_dependency(%q<bson_ext>, [">= 0"])
301
+ s.add_dependency(%q<bson_ext>, ["~> 1.3.1"])
300
302
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
301
303
  end
302
304
  end
@@ -112,14 +112,6 @@ registers the {Dragonfly::Analysis::FileCommandAnalyser FileCommandAnalyser} for
112
112
 
113
113
  The file 'dragonfly/rails/images' does this for you.
114
114
 
115
- Heroku
116
- ------
117
-
118
- app.configure_with(:heroku, 's3_bucket_name')
119
-
120
- The {Dragonfly::Config::Heroku Heroku configuration} configures it to use the {Dragonfly::DataStorage::S3DataStore}, using Heroku's config attributes.
121
- See {file:Heroku} for more info.
122
-
123
115
  Custom Saved Configuration
124
116
  --------------------------
125
117
  You can create your own saved configuration with any object that responds to 'apply_configuration':
@@ -44,7 +44,7 @@ or (the same)
44
44
 
45
45
  or
46
46
 
47
- my_model.remote_url(:some => 'option')
47
+ my_model.attachment.remote_url(:some => 'option')
48
48
 
49
49
  You can create your own datastore, or use one of the provided ones as outlined below.
50
50
 
@@ -89,17 +89,22 @@ To configure with the {Dragonfly::DataStorage::S3DataStore S3DataStore}:
89
89
  c.secret_access_key = '8u2u3rhkhfo23...'
90
90
  c.region = 'eu-west-1' # defaults to 'us-east-1'
91
91
  c.storage_headers = {'some' => 'thing'} # defaults to {'x-amz-acl' => 'public-read'}
92
+ c.url_scheme = 'https' # defaults to 'http'
92
93
  end
93
94
 
94
95
  You can also pass these options to `S3DataStore.new` as an options hash.
95
96
 
96
97
  You can serve directly from the S3DataStore using e.g.
97
98
 
98
- my_model.remote_url
99
+ my_model.attachment.remote_url
99
100
 
100
101
  or with an expiring url:
101
102
 
102
- my_model.remote_url(:expires => 3.days.from_now)
103
+ my_model.attachment.remote_url(:expires => 3.days.from_now)
104
+
105
+ or with an https url:
106
+
107
+ my_model.attachment.remote_url(:scheme => 'https') # also configurable for all urls with 'url_scheme'
103
108
 
104
109
  Extra options you can use on store are `:path` and `:headers`
105
110
 
@@ -163,7 +168,9 @@ Data stores are key-value in nature, and need to implement 3 methods: `store`, `
163
168
  class MyDataStore
164
169
 
165
170
  def store(temp_object, opts={})
166
- # ... use temp_object.data, temp_object.file, temp_object.path, etc. ...
171
+ # ... use temp_object.data, temp_object.file, temp_object.path, etc.
172
+ # ... also we can use temp_object.meta and store it ...
173
+
167
174
  # store and return the uid
168
175
  'return_some_unique_uid'
169
176
  end
@@ -187,7 +194,8 @@ You can now configure the app to use your datastore:
187
194
  Dragonfly[:my_app_name].datastore = MyDataStore.new
188
195
 
189
196
  Notice that `store` takes a second `opts` argument.
190
- Any options, including `:meta`, get passed here
197
+ Any options, get passed here.
198
+ `:meta` is treated specially and is accessible inside `MyDataStore#store` as `temp_object.meta`
191
199
 
192
200
  uid = app.store('SOME CONTENT',
193
201
  :meta => {:name => 'great_content.txt'},
@@ -74,13 +74,16 @@ We can set up a Dragonfly endpoint in routes.rb for generating thumbnails:
74
74
  app.fetch(params[:uid]).thumb(params[:geometry])
75
75
  }
76
76
 
77
+ NOTE: if you use `do`...`end` here instead of curly braces, make sure you put brackets around the arguments to `match`,
78
+ otherwise Ruby will parse it incorrectly
79
+
77
80
  If we have access to the image uid in javascript, we can create the url like so:
78
81
 
79
82
  var url = '/thumbs/400x300?uid=' + uid
80
83
 
81
84
  Then we can get the content with ajax, create an img tag, etc.
82
85
 
83
- NB: in the above example we've put the uid in the query string and not the path because the dot in it confuses Rails' pattern recognition.
86
+ NOTE: in the above example we've put the uid in the query string and not the path because the dot in it confuses Rails' pattern recognition.
84
87
  You could always put it in the path and escape/unescape it either side of the request.
85
88
 
86
89
  Also javascript's built-in `encodeURIComponent` function may be useful when Rails has difficulty matching routes due to special characters like '#' and '/'.
data/extra_docs/Heroku.md CHANGED
@@ -4,7 +4,9 @@ Heroku
4
4
  The default configuration won't work out of the box for Heroku, because
5
5
 
6
6
  - Heroku doesn't allow saving files to the filesystem (although it does use tempfiles)
7
- - We won't need {http://tomayko.com/src/rack-cache/ Rack::Cache} on Heroku because it already uses the caching proxy {http://varnish.projects.linpro.no/ Varnish}, which we can make use of
7
+ - If on Heroku {http://devcenter.heroku.com/articles/stack Aspen/Bamboo stacks}, we won't need {http://tomayko.com/src/rack-cache/ Rack::Cache},
8
+ because it already uses the caching proxy {http://varnish.projects.linpro.no/ Varnish}, which we can make use of.
9
+ We will still need it on {http://devcenter.heroku.com/articles/cedar Heroku Cedar}, however, as it doesn't include Varnish.
8
10
 
9
11
  Instead of the normal {file:DataStorage#File\_datastore FileDataStore}, we can use the {file:DataStorage#S3\_datastore S3DataStore}.
10
12
 
@@ -22,7 +24,15 @@ Initializer (e.g. config/initializers/dragonfly.rb in Rails):
22
24
 
23
25
  app.configure_with(:imagemagick)
24
26
  app.configure_with(:rails)
25
- app.configure_with(:heroku, 'my_bucket_name') if Rails.env.production?
27
+ if Rails.env.production?
28
+ app.configure do |c|
29
+ c.datastore = Dragonfly::DataStorage::S3DataStore.new(
30
+ :bucket_name => 'my-bucket-name',
31
+ :access_key_id => ENV['S3_KEY'],
32
+ :secret_access_key => ENV['S3_SECRET']
33
+ )
34
+ end
35
+ end
26
36
 
27
37
  app.define_macro(ActiveRecord::Base, :image_accessor)
28
38
 
@@ -41,9 +51,7 @@ From your app's directory:
41
51
 
42
52
  Replace 'XXXXXXXXX' with your access key and secret.
43
53
 
44
- Now you can benefit from super-fast images served straight from Heroku's cache!
54
+ **NOTE**: HEROKU'S VARNISH CACHE IS CLEARED EVERY TIME YOU DEPLOY!!! (DOESN'T APPLY TO CEDAR STACK)
45
55
 
46
- **NOTE**: HEROKU'S CACHE IS CLEARED EVERY TIME YOU DEPLOY!!!
47
-
48
- If this is an issue, you may want to look into storing thumbnails on S3 (see {file:ServingRemotely}), or maybe an after-deploy hook for hitting specific Dragonfly urls you want to cache, etc.
56
+ If this is an issue, you may want to look into storing thumbnails on S3 (see {file:ServingRemotely}), or maybe generating thumbnails _on upload_ (see {file:Models#Up-front_thumbnailing}), or maybe an after-deploy hook for hitting specific Dragonfly urls you want to cache, etc.
49
57
  It won't be a problem for most sites though.
data/extra_docs/Models.md CHANGED
@@ -89,6 +89,10 @@ We can play around with the data
89
89
 
90
90
  @album.cover_image.data # => "\377???JFIF\000\..."
91
91
  @album.cover_image.to_file('out.png') # writes to file 'out.png' and returns a readable file object
92
+ @album.cover_image.to_file('out.png',
93
+ :mode => 0600,
94
+ :mkdirs => false
95
+ )
92
96
  @album.cover_image.tempfile # => #<File:/var/folders/st/strHv74sH044JPabSiODz... a closed Tempfile object
93
97
  @album.cover_image.file # => #<File:/var/folders/st/strHv74sH044JPabSiODz... a readable (open) File object
94
98
  @album.cover_image.file do |f| # Yields an open file object, returns the return value of
@@ -198,7 +202,7 @@ Validations
198
202
 
199
203
  validates_property :format, :of => :cover_image, :in => [:jpeg, :png, :gif]
200
204
  # ..or..
201
- validates_property :mime_type, :of => :cover_image, :in => %w(image/jpeg image/png image/gif)
205
+ validates_property :mime_type, :of => :cover_image, :as => 'image/jpeg', :case_sensitive => false
202
206
 
203
207
  validates_property :width, :of => :cover_image, :in => (0..400), :message => "é demais cara!"
204
208