dragonfly 0.9.15 → 1.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.
- checksums.yaml +7 -0
- data/.gitignore +1 -8
- data/.travis.yml +11 -0
- data/Gemfile +1 -0
- data/History.md +52 -2
- data/LICENSE +1 -1
- data/README.md +38 -95
- data/dev/grid.jpg +0 -0
- data/dev/irbrc.rb +27 -0
- data/dev/rails_template.rb +38 -0
- data/dev/test.ru +56 -0
- data/dev/test_rails +19 -0
- data/dragonfly.gemspec +3 -21
- data/lib/dragonfly.rb +45 -44
- data/lib/dragonfly/app.rb +175 -96
- data/lib/dragonfly/configurable.rb +71 -170
- data/lib/dragonfly/content.rb +211 -0
- data/lib/dragonfly/core_ext/object.rb +1 -6
- data/lib/dragonfly/file_data_store.rb +197 -0
- data/lib/dragonfly/image_magick/analysers/image_properties.rb +23 -0
- data/lib/dragonfly/image_magick/generators/convert.rb +19 -0
- data/lib/dragonfly/image_magick/generators/plain.rb +26 -0
- data/lib/dragonfly/image_magick/generators/plasma.rb +25 -0
- data/lib/dragonfly/image_magick/generators/text.rb +127 -0
- data/lib/dragonfly/image_magick/plugin.rb +83 -0
- data/lib/dragonfly/image_magick/processors/convert.rb +29 -0
- data/lib/dragonfly/image_magick/processors/encode.rb +18 -0
- data/lib/dragonfly/image_magick/processors/thumb.rb +76 -0
- data/lib/dragonfly/job.rb +118 -134
- data/lib/dragonfly/job_endpoint.rb +2 -0
- data/lib/dragonfly/memory_data_store.rb +34 -0
- data/lib/dragonfly/middleware.rb +5 -3
- data/lib/dragonfly/{active_model_extensions.rb → model.rb} +5 -3
- data/lib/dragonfly/{active_model_extensions → model}/attachment.rb +40 -35
- data/lib/dragonfly/{active_model_extensions → model}/attachment_class_methods.rb +36 -40
- data/lib/dragonfly/model/class_methods.rb +109 -0
- data/lib/dragonfly/{active_model_extensions → model}/instance_methods.rb +2 -2
- data/lib/dragonfly/{active_model_extensions → model}/validations.rb +17 -12
- data/lib/dragonfly/railtie.rb +8 -6
- data/lib/dragonfly/register.rb +27 -0
- data/lib/dragonfly/response.rb +47 -52
- data/lib/dragonfly/routed_endpoint.rb +4 -0
- data/lib/dragonfly/serializer.rb +15 -5
- data/lib/dragonfly/server.rb +56 -29
- data/lib/dragonfly/shell.rb +12 -23
- data/lib/dragonfly/spec/data_store_examples.rb +64 -0
- data/lib/dragonfly/temp_object.rb +32 -47
- data/lib/dragonfly/url_attributes.rb +19 -22
- data/lib/dragonfly/url_mapper.rb +3 -0
- data/lib/dragonfly/utils.rb +12 -0
- data/lib/dragonfly/version.rb +1 -1
- data/lib/dragonfly/whitelist.rb +19 -0
- data/lib/rails/generators/dragonfly/USAGE +8 -0
- data/lib/rails/generators/dragonfly/dragonfly_generator.rb +24 -0
- data/lib/rails/generators/dragonfly/templates/initializer.rb.erb +27 -0
- data/samples/gif.gif +0 -0
- data/spec/dragonfly/app_spec.rb +270 -64
- data/spec/dragonfly/configurable_spec.rb +142 -418
- data/spec/dragonfly/content_spec.rb +353 -0
- data/spec/dragonfly/cookie_monster_spec.rb +2 -1
- data/spec/dragonfly/file_data_store_spec.rb +301 -0
- data/spec/dragonfly/image_magick/analysers/image_properties_spec.rb +20 -0
- data/spec/dragonfly/image_magick/generators/convert_spec.rb +19 -0
- data/spec/dragonfly/image_magick/generators/plain_spec.rb +50 -0
- data/spec/dragonfly/image_magick/generators/plasma_spec.rb +32 -0
- data/spec/dragonfly/image_magick/generators/text_spec.rb +77 -0
- data/spec/dragonfly/image_magick/plugin_spec.rb +131 -0
- data/spec/dragonfly/image_magick/processors/convert_spec.rb +56 -0
- data/spec/dragonfly/image_magick/processors/thumb_spec.rb +173 -0
- data/spec/dragonfly/job_endpoint_spec.rb +30 -73
- data/spec/dragonfly/job_spec.rb +280 -608
- data/spec/dragonfly/memory_data_store_spec.rb +20 -0
- data/spec/dragonfly/middleware_spec.rb +47 -27
- data/spec/dragonfly/{active_model_extensions → model}/model_spec.rb +331 -555
- data/spec/dragonfly/model/validations_spec.rb +196 -0
- data/spec/dragonfly/register_spec.rb +35 -0
- data/spec/dragonfly/routed_endpoint_spec.rb +6 -6
- data/spec/dragonfly/serializer_spec.rb +13 -15
- data/spec/dragonfly/server_spec.rb +122 -46
- data/spec/dragonfly/shell_spec.rb +43 -24
- data/spec/dragonfly/temp_object_spec.rb +69 -94
- data/spec/dragonfly/url_attributes_spec.rb +49 -0
- data/spec/dragonfly/utils_spec.rb +32 -0
- data/spec/dragonfly/whitelist_spec.rb +30 -0
- data/spec/dragonfly_spec.rb +43 -0
- data/spec/fixtures/deprecated_stored_content/eggs.bonus +1 -0
- data/spec/fixtures/deprecated_stored_content/eggs.bonus.meta +1 -0
- data/spec/functional/configuration_spec.rb +19 -0
- data/spec/functional/model_urls_spec.rb +43 -41
- data/spec/functional/remote_on_the_fly_spec.rb +14 -16
- data/spec/functional/shell_commands_spec.rb +24 -14
- data/spec/functional/to_response_spec.rb +10 -10
- data/spec/functional/urls_spec.rb +5 -3
- data/spec/spec_helper.rb +23 -28
- data/spec/support/argument_matchers.rb +7 -8
- data/spec/support/image_matchers.rb +14 -36
- data/spec/support/model_helpers.rb +97 -0
- data/spec/support/simple_matchers.rb +12 -0
- metadata +92 -393
- data/.yardopts +0 -29
- data/Rakefile +0 -36
- data/config.ru +0 -14
- data/docs.watchr +0 -1
- data/extra_docs/Analysers.md +0 -68
- data/extra_docs/Caching.md +0 -23
- data/extra_docs/Configuration.md +0 -149
- data/extra_docs/Couch.md +0 -49
- data/extra_docs/DataStorage.md +0 -226
- data/extra_docs/Encoding.md +0 -67
- data/extra_docs/ExampleUseCases.md +0 -116
- data/extra_docs/GeneralUsage.md +0 -105
- data/extra_docs/Generators.md +0 -68
- data/extra_docs/Heroku.md +0 -50
- data/extra_docs/ImageMagick.md +0 -136
- data/extra_docs/Index.md +0 -33
- data/extra_docs/MimeTypes.md +0 -40
- data/extra_docs/Models.md +0 -441
- data/extra_docs/Mongo.md +0 -42
- data/extra_docs/Processing.md +0 -77
- data/extra_docs/Rack.md +0 -52
- data/extra_docs/Rails2.md +0 -57
- data/extra_docs/Rails3.md +0 -56
- data/extra_docs/ServingRemotely.md +0 -104
- data/extra_docs/Sinatra.md +0 -25
- data/extra_docs/URLs.md +0 -203
- data/features/images.feature +0 -47
- data/features/no_processing.feature +0 -14
- data/features/rails.feature +0 -8
- data/features/steps/common_steps.rb +0 -8
- data/features/steps/dragonfly_steps.rb +0 -66
- data/features/steps/rails_steps.rb +0 -40
- data/features/support/env.rb +0 -13
- data/features/support/setup.rb +0 -41
- data/fixtures/rails/files/app/models/album.rb +0 -6
- data/fixtures/rails/files/app/views/albums/new.html.erb +0 -7
- data/fixtures/rails/files/app/views/albums/show.html.erb +0 -6
- data/fixtures/rails/files/config/initializers/dragonfly.rb +0 -4
- data/fixtures/rails/files/features/manage_album_images.feature +0 -38
- data/fixtures/rails/files/features/step_definitions/helper_steps.rb +0 -7
- data/fixtures/rails/files/features/step_definitions/image_steps.rb +0 -25
- data/fixtures/rails/files/features/step_definitions/web_steps.rb +0 -189
- data/fixtures/rails/files/features/support/paths.rb +0 -17
- data/fixtures/rails/files/features/text_images.feature +0 -7
- data/fixtures/rails/template.rb +0 -20
- data/irbrc.rb +0 -19
- data/lib/dragonfly/active_model_extensions/class_methods.rb +0 -98
- data/lib/dragonfly/analyser.rb +0 -58
- data/lib/dragonfly/analysis/file_command_analyser.rb +0 -33
- data/lib/dragonfly/analysis/image_magick_analyser.rb +0 -6
- data/lib/dragonfly/config/heroku.rb +0 -26
- data/lib/dragonfly/config/image_magick.rb +0 -6
- data/lib/dragonfly/config/rails.rb +0 -20
- data/lib/dragonfly/data_storage.rb +0 -11
- data/lib/dragonfly/data_storage/couch_data_store.rb +0 -83
- data/lib/dragonfly/data_storage/file_data_store.rb +0 -144
- data/lib/dragonfly/data_storage/mongo_data_store.rb +0 -96
- data/lib/dragonfly/data_storage/s3data_store.rb +0 -168
- data/lib/dragonfly/encoder.rb +0 -13
- data/lib/dragonfly/encoding/image_magick_encoder.rb +0 -6
- data/lib/dragonfly/function_manager.rb +0 -67
- data/lib/dragonfly/generation/image_magick_generator.rb +0 -6
- data/lib/dragonfly/generator.rb +0 -9
- data/lib/dragonfly/image_magick/analyser.rb +0 -53
- data/lib/dragonfly/image_magick/config.rb +0 -44
- data/lib/dragonfly/image_magick/encoder.rb +0 -57
- data/lib/dragonfly/image_magick/generator.rb +0 -147
- data/lib/dragonfly/image_magick/processor.rb +0 -114
- data/lib/dragonfly/image_magick/utils.rb +0 -46
- data/lib/dragonfly/image_magick_utils.rb +0 -4
- data/lib/dragonfly/job_builder.rb +0 -39
- data/lib/dragonfly/job_definitions.rb +0 -30
- data/lib/dragonfly/loggable.rb +0 -28
- data/lib/dragonfly/processing/image_magick_processor.rb +0 -6
- data/lib/dragonfly/processor.rb +0 -9
- data/lib/dragonfly/rails/images.rb +0 -32
- data/lib/dragonfly/simple_cache.rb +0 -23
- data/spec/dragonfly/active_model_extensions/spec_helper.rb +0 -95
- data/spec/dragonfly/analyser_spec.rb +0 -123
- data/spec/dragonfly/analysis/file_command_analyser_spec.rb +0 -49
- data/spec/dragonfly/data_storage/couch_data_store_spec.rb +0 -84
- data/spec/dragonfly/data_storage/file_data_store_spec.rb +0 -308
- data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +0 -81
- data/spec/dragonfly/data_storage/s3_data_store_spec.rb +0 -277
- data/spec/dragonfly/data_storage/shared_data_store_examples.rb +0 -77
- data/spec/dragonfly/function_manager_spec.rb +0 -154
- data/spec/dragonfly/image_magick/analyser_spec.rb +0 -73
- data/spec/dragonfly/image_magick/encoder_spec.rb +0 -46
- data/spec/dragonfly/image_magick/generator_spec.rb +0 -178
- data/spec/dragonfly/image_magick/processor_spec.rb +0 -293
- data/spec/dragonfly/job_builder_spec.rb +0 -37
- data/spec/dragonfly/job_definitions_spec.rb +0 -57
- data/spec/dragonfly/loggable_spec.rb +0 -80
- data/spec/dragonfly/simple_cache_spec.rb +0 -27
- data/spec/dragonfly/url_attributes.rb +0 -47
- data/spec/functional/deprecations_spec.rb +0 -51
- data/spec/functional/image_magick_app_spec.rb +0 -27
- data/spec/test_imagemagick.ru +0 -49
- data/yard/handlers/configurable_attr_handler.rb +0 -38
- data/yard/setup.rb +0 -15
- data/yard/templates/default/fulldoc/html/css/common.css +0 -109
- data/yard/templates/default/layout/html/layout.erb +0 -93
- data/yard/templates/default/module/html/configuration_summary.erb +0 -31
- data/yard/templates/default/module/setup.rb +0 -17
data/.yardopts
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
--main extra_docs/Index.md
|
2
|
-
-e ./yard/setup.rb
|
3
|
-
--markup-provider=redcarpet
|
4
|
-
--markup=markdown
|
5
|
-
-
|
6
|
-
README.md
|
7
|
-
extra_docs/GeneralUsage.md
|
8
|
-
extra_docs/Rails2.md
|
9
|
-
extra_docs/Rails3.md
|
10
|
-
extra_docs/ImageMagick.md
|
11
|
-
extra_docs/Rack.md
|
12
|
-
extra_docs/Sinatra.md
|
13
|
-
extra_docs/Heroku.md
|
14
|
-
extra_docs/Mongo.md
|
15
|
-
extra_docs/Couch.md
|
16
|
-
extra_docs/Models.md
|
17
|
-
extra_docs/DataStorage.md
|
18
|
-
extra_docs/Analysers.md
|
19
|
-
extra_docs/Processing.md
|
20
|
-
extra_docs/Encoding.md
|
21
|
-
extra_docs/Generators.md
|
22
|
-
extra_docs/Configuration.md
|
23
|
-
extra_docs/URLs.md
|
24
|
-
extra_docs/MimeTypes.md
|
25
|
-
extra_docs/Caching.md
|
26
|
-
extra_docs/ServingRemotely.md
|
27
|
-
extra_docs/ExampleUseCases.md
|
28
|
-
LICENSE
|
29
|
-
History.md
|
data/Rakefile
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'rake'
|
11
|
-
|
12
|
-
require 'rspec/core'
|
13
|
-
require 'rspec/core/rake_task'
|
14
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
15
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
16
|
-
end
|
17
|
-
|
18
|
-
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
19
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
20
|
-
spec.rcov = true
|
21
|
-
end
|
22
|
-
|
23
|
-
require 'cucumber/rake/task'
|
24
|
-
Cucumber::Rake::Task.new(:features)
|
25
|
-
|
26
|
-
task :default => [:spec, :features]
|
27
|
-
|
28
|
-
require 'yard'
|
29
|
-
YARD::Rake::YardocTask.new do |t|
|
30
|
-
t.files = ['lib/**/*.rb']
|
31
|
-
t.options = []
|
32
|
-
end
|
33
|
-
YARD::Rake::YardocTask.new 'yard:changed' do |t|
|
34
|
-
t.files = `git status | grep '.rb' | grep modified | grep -v yard | cut -d' ' -f4`.split
|
35
|
-
t.options = []
|
36
|
-
end
|
data/config.ru
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "bundler/setup"
|
3
|
-
$:.unshift(File.expand_path('../lib', __FILE__))
|
4
|
-
require 'dragonfly'
|
5
|
-
require 'rack/cache'
|
6
|
-
|
7
|
-
APP = Dragonfly[:images].configure_with(:imagemagick)
|
8
|
-
|
9
|
-
use Rack::Cache,
|
10
|
-
:verbose => true,
|
11
|
-
:metastore => 'file:/var/cache/rack/meta',
|
12
|
-
:entitystore => 'file:/var/cache/rack/body'
|
13
|
-
|
14
|
-
run APP
|
data/docs.watchr
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
watch('lib/.*\.rb|yard/.*|extra_docs/.*') {|md| system("rake yard:changed") }
|
data/extra_docs/Analysers.md
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
Analysers
|
2
|
-
=========
|
3
|
-
Analysers are registered with Dragonfly apps for adding methods to {file:GeneralUsage Job} objects and {file:Models model attachments} such as `width`, `height`, etc.
|
4
|
-
|
5
|
-
ImageMagick Analyser
|
6
|
-
--------------------
|
7
|
-
See {file:ImageMagick}.
|
8
|
-
|
9
|
-
FileCommandAnalyser
|
10
|
-
-------------------
|
11
|
-
The {Dragonfly::Analysis::FileCommandAnalyser FileCommandAnalyser} is registered by default by the
|
12
|
-
{Dragonfly::Config::Rails Rails configuration} used by 'dragonfly/rails/images'.
|
13
|
-
|
14
|
-
As the name suggests, it uses the UNIX 'file' command.
|
15
|
-
|
16
|
-
If not already registered:
|
17
|
-
|
18
|
-
app.analyser.register(Dragonfly::Analysis::FileCommandAnalyser)
|
19
|
-
|
20
|
-
gives us:
|
21
|
-
|
22
|
-
image.mime_type # => 'image/png'
|
23
|
-
|
24
|
-
You shouldn't need to configure it but if you need to:
|
25
|
-
|
26
|
-
app.analyser.register(Dragonfly::Analysis::FileCommandAnalyser) do |a|
|
27
|
-
a.use_filesystem = false # defaults to true
|
28
|
-
a.file_command = '/opt/local/bin/file' # defaults to 'file'
|
29
|
-
a.num_bytes_to_check = 1024 # defaults to 255 - only applies if not using the filesystem
|
30
|
-
end
|
31
|
-
|
32
|
-
Custom Analysers
|
33
|
-
----------------
|
34
|
-
|
35
|
-
To register a single custom analyser:
|
36
|
-
|
37
|
-
app.analyser.add :wobbliness do |temp_object|
|
38
|
-
# can use temp_object.data, temp_object.path, temp_object.file, etc.
|
39
|
-
SomeLibrary.assess_wobbliness(temp_object.data)
|
40
|
-
end
|
41
|
-
|
42
|
-
image.wobbliness # => 71
|
43
|
-
|
44
|
-
You can create a class like the ImageMagick one above, in which case all public methods will be counted as analysis methods.
|
45
|
-
Each method takes the temp_object as its argument.
|
46
|
-
|
47
|
-
class MyAnalyser
|
48
|
-
|
49
|
-
def coolness(temp_object)
|
50
|
-
temp_object.size / 30
|
51
|
-
end
|
52
|
-
|
53
|
-
def uglyness(temp_object)
|
54
|
-
`ugly -i #{temp_object.path}`
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
def my_helper_method
|
60
|
-
# do stuff
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
app.analyser.register(MyAnalyser)
|
66
|
-
|
67
|
-
image.coolness # => -4.1
|
68
|
-
image.uglyness # => "VERY"
|
data/extra_docs/Caching.md
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
Caching
|
2
|
-
=======
|
3
|
-
|
4
|
-
Processing and encoding can be an expensive operation. The first time we visit the url,
|
5
|
-
the image is processed, and there might be a short delay and getting the response.
|
6
|
-
|
7
|
-
However, dragonfly apps send `Cache-Control` and `ETag` headers in the response, so we can easily put a caching
|
8
|
-
proxy like {http://varnish.projects.linpro.no Varnish}, {http://www.squid-cache.org Squid},
|
9
|
-
{http://rtomayko.github.com/rack-cache/ Rack::Cache}, etc. in front of the app, so that subsequent requests are served
|
10
|
-
super-quickly straight out of the cache.
|
11
|
-
|
12
|
-
The file 'dragonfly/rails/images' puts Rack::Cache in front of Dragonfly by default, but for better performance
|
13
|
-
you may wish to look into something like Varnish.
|
14
|
-
|
15
|
-
Given a dragonfly app
|
16
|
-
|
17
|
-
app = Dragonfly[:images]
|
18
|
-
|
19
|
-
You can configure the 'Cache-Control' header with
|
20
|
-
|
21
|
-
app.cache_duration = 3600*24*365*3 # time in seconds
|
22
|
-
|
23
|
-
For a well-written discussion of Cache-Control and ETag headers, see {http://tomayko.com/writings/things-caches-do}.
|
data/extra_docs/Configuration.md
DELETED
@@ -1,149 +0,0 @@
|
|
1
|
-
Configuration
|
2
|
-
=============
|
3
|
-
|
4
|
-
Given a Dragonfly app
|
5
|
-
|
6
|
-
app = Dragonfly[:app_name]
|
7
|
-
|
8
|
-
Configuration can either be done using a block...
|
9
|
-
|
10
|
-
app.configure do |c|
|
11
|
-
c.url_format = '/media/:job'
|
12
|
-
# ...
|
13
|
-
end
|
14
|
-
|
15
|
-
...or directly...
|
16
|
-
|
17
|
-
app.url_format = '/media/:job'
|
18
|
-
|
19
|
-
The defaults should be fairly sensible, but you can tweak a number of things if you wish.
|
20
|
-
Here is an example of an app with all attributes configured:
|
21
|
-
|
22
|
-
app.configure do |c|
|
23
|
-
c.datastore = SomeCustomDataStore.new :egg => 'head' # defaults to FileDataStore
|
24
|
-
|
25
|
-
c.cache_duration = 3600*24*365*2 # defaults to 1 year # (1 year)
|
26
|
-
c.fallback_mime_type = 'something/mental' # defaults to application/octet-stream
|
27
|
-
c.log = Logger.new($stdout) # defaults to Logger.new('/var/tmp/dragonfly.log')
|
28
|
-
c.trust_file_extensions = false # defaults to true
|
29
|
-
|
30
|
-
c.url_format = '/images/:job/:basename.:format' # defaults to '/:job/:basename.:format'
|
31
|
-
c.url_host = 'http://some.domain.com:4000' # defaults to nil
|
32
|
-
|
33
|
-
c.content_filename = proc{|job, request| # defaults to the original name, with modified ext if encoded
|
34
|
-
"file.#{job.ext}"
|
35
|
-
}
|
36
|
-
c.content_disposition = :attachment # defaults to nil (use the browser default)
|
37
|
-
|
38
|
-
c.protect_from_dos_attacks = true # defaults to false - adds a SHA parameter on the end of urls
|
39
|
-
c.secret = 'This is my secret yeh!!' # should set this if concerned about DOS attacks
|
40
|
-
|
41
|
-
c.analyser.register(MyAnalyser) # See 'Analysers' for more details
|
42
|
-
c.processor.register(MyProcessor, :type => :fig) # See 'Processing' for more details
|
43
|
-
c.encoder.register(MyEncoder) do |e| # See 'Encoding' for more details
|
44
|
-
e.some_value = 'geg'
|
45
|
-
end
|
46
|
-
c.generator.register(MyGenerator) # See 'Generators' for more details
|
47
|
-
|
48
|
-
c.register_mime_type(:egg, 'fried/egg') # See 'MimeTypes' for more details
|
49
|
-
|
50
|
-
c.job :black_and_white do |size| # Job shortcut - lets you do image.black_and_white('30x30')
|
51
|
-
process :greyscale
|
52
|
-
process :thumb, size
|
53
|
-
encode :gif
|
54
|
-
end
|
55
|
-
|
56
|
-
c.define_url do |app, job, opts| # allows overriding urls - defaults to
|
57
|
-
if job.step_types == [:fetch] # app.server.url_for(job, opts)
|
58
|
-
app.datastore.url_for(job.uid)
|
59
|
-
else
|
60
|
-
app.server.url_for(job, opts)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
c.server.before_serve do |job, env| # allows you to do something before content is served
|
65
|
-
# do something
|
66
|
-
end
|
67
|
-
|
68
|
-
c.response_headers['X-Something'] = 'Custom header' # You can set custom response headers
|
69
|
-
c.response_headers['summink'] = proc{|job, request| # either directly or via a callback
|
70
|
-
job.image? ? 'image yo' : 'not an image'
|
71
|
-
}
|
72
|
-
|
73
|
-
# When using ImageMagick only...
|
74
|
-
c.convert_command = "/opt/local/bin/convert" # defaults to "convert"
|
75
|
-
c.identify_command = "/opt/local/bin/identify" # defaults to "identify"
|
76
|
-
c.log_commands = true # defaults to false
|
77
|
-
end
|
78
|
-
|
79
|
-
Where is configuration done?
|
80
|
-
----------------------------
|
81
|
-
In Rails, it should be done in an initializer, e.g. 'config/initializers/dragonfly.rb'.
|
82
|
-
Otherwise it should be done anywhere where general setup is done, early on.
|
83
|
-
|
84
|
-
Reflecting on configuration
|
85
|
-
---------------------------
|
86
|
-
There are a few methods you can call on the `app` to see what processors etc. are registered: `processor_methods`, `generator_methods`, `analyser_methods` and `job_methods`.
|
87
|
-
|
88
|
-
Saved configurations
|
89
|
-
====================
|
90
|
-
Saved configurations are useful if you often configure the app the same way.
|
91
|
-
There are a number that are provided with Dragonfly:
|
92
|
-
|
93
|
-
ImageMagick
|
94
|
-
-----------
|
95
|
-
|
96
|
-
app.configure_with(:imagemagick)
|
97
|
-
|
98
|
-
The {Dragonfly::ImageMagick::Config ImageMagick configuration} registers the app with the {Dragonfly::ImageMagick::Analyser ImageMagick Analyser}, {Dragonfly::ImageMagick::Processor ImageMagick Processor},
|
99
|
-
{Dragonfly::ImageMagick::Encoder ImageMagick Encoder} and {Dragonfly::ImageMagick::Generator ImageMagick Generator}, and a number of job shortcuts.
|
100
|
-
|
101
|
-
The file 'dragonfly/rails/images' does this for you.
|
102
|
-
|
103
|
-
The processor, analyser, encoder and generator pass data around using tempfiles.
|
104
|
-
|
105
|
-
Rails
|
106
|
-
-----
|
107
|
-
|
108
|
-
app.configure_with(:rails)
|
109
|
-
|
110
|
-
The {Dragonfly::Config::Rails Rails configuration} points the log to the Rails logger, configures the file data store root path, sets the url path prefix to '/media', and
|
111
|
-
registers the {Dragonfly::Analysis::FileCommandAnalyser FileCommandAnalyser} for helping with mime_type validations.
|
112
|
-
|
113
|
-
The file 'dragonfly/rails/images' does this for you.
|
114
|
-
|
115
|
-
Custom Saved Configuration
|
116
|
-
--------------------------
|
117
|
-
You can create your own saved configuration with any object that responds to 'apply_configuration':
|
118
|
-
|
119
|
-
module MyConfiguration
|
120
|
-
|
121
|
-
def self.apply_configuration(app, *args)
|
122
|
-
app.configure do |c|
|
123
|
-
c.url_path_prefix = '/hello/beans'
|
124
|
-
c.processor.register(MyProcessor)
|
125
|
-
# ...
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
Then to configure:
|
132
|
-
|
133
|
-
app.configure_with(MyConfiguration, :any_other => :args) # other args get passed through to apply_configuration
|
134
|
-
|
135
|
-
You can also carry on configuring by passing a block
|
136
|
-
|
137
|
-
app.configure_with(MyConfiguration) do |c|
|
138
|
-
c.any_extra = :config_here
|
139
|
-
# ...
|
140
|
-
end
|
141
|
-
|
142
|
-
If you wish to be able to use a symbol to represent your configuration (e.g. for a plugin, etc.) you can register it
|
143
|
-
globally as a one-off:
|
144
|
-
|
145
|
-
Dragonfly::App.register_configuration(:myconfig){ My::Saved::Configuration }
|
146
|
-
|
147
|
-
Then from then on you can configure Dragonfly apps using
|
148
|
-
|
149
|
-
app.configure_with(:myconfig, :any_other => :args)
|
data/extra_docs/Couch.md
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
CouchDB
|
2
|
-
=====
|
3
|
-
Dragonfly can be used with any ActiveModel-compatible model, and so you can use it with CouchDB using [CouchRest::Model](https://github.com/couchrest/couchrest_model).
|
4
|
-
|
5
|
-
Since CouchDB allows you to store files directly on documents as attachments, you can also use the supplied {Dragonfly::DataStorage::CouchDataStore CouchDataStore}.
|
6
|
-
which allows storing files as attachments directly on documents.
|
7
|
-
|
8
|
-
For more info about ActiveModel, see {file:Models}.
|
9
|
-
|
10
|
-
For more info about using the Couch data store, see {file:DataStorage}.
|
11
|
-
|
12
|
-
Example setup in Rails, using CouchRest::Model
|
13
|
-
-------------------------------------
|
14
|
-
In config/initializers/dragonfly.rb:
|
15
|
-
|
16
|
-
require 'dragonfly'
|
17
|
-
|
18
|
-
app = Dragonfly[:images]
|
19
|
-
|
20
|
-
# Get database config from config/couchdb.yml
|
21
|
-
couch_settings = YAML.load_file(Rails.root.join('config/couchdb.yml'))[Rails.env]
|
22
|
-
|
23
|
-
# Configure to use ImageMagick, Rails defaults, and the Couch data store
|
24
|
-
app.configure_with(:imagemagick)
|
25
|
-
app.configure_with(:rails) do |c|
|
26
|
-
c.datastore = Dragonfly::DataStorage::CouchDataStore.new(
|
27
|
-
:host => couch_settings['host'],
|
28
|
-
:port => couch_settings['port'],
|
29
|
-
:username => couch_settings['username'],
|
30
|
-
:password => couch_settings['password'],
|
31
|
-
:database => couch_settings['database']
|
32
|
-
)
|
33
|
-
end
|
34
|
-
|
35
|
-
# Allow all CouchRest::Model models to use the macro 'image_accessor'
|
36
|
-
app.define_macro(CouchRest::Model::Base, :image_accessor)
|
37
|
-
|
38
|
-
# ... any other setup, see Rails docs
|
39
|
-
|
40
|
-
Then in models:
|
41
|
-
|
42
|
-
class Album < CouchRest::Model::Base
|
43
|
-
property :cover_image_uid
|
44
|
-
image_accessor :cover_image
|
45
|
-
|
46
|
-
# ...
|
47
|
-
end
|
48
|
-
|
49
|
-
See {file:Models} for more info.
|
data/extra_docs/DataStorage.md
DELETED
@@ -1,226 +0,0 @@
|
|
1
|
-
Data Storage
|
2
|
-
============
|
3
|
-
Each dragonfly app has a key-value datastore to store the content (originals only).
|
4
|
-
|
5
|
-
Lets say we have an app
|
6
|
-
|
7
|
-
app = Dragonfly[:my_app_name]
|
8
|
-
|
9
|
-
Then we can store data like so:
|
10
|
-
|
11
|
-
# Can pass in a String, Pathname, File or Tempfile
|
12
|
-
uid = app.store('SOME CONTENT')
|
13
|
-
|
14
|
-
We can also save metadata at the same time, and any other options the configured datastore accepts
|
15
|
-
|
16
|
-
uid = app.store('SOME CONTENT',
|
17
|
-
:meta => {:time => Time.now, :name => 'content.txt'},
|
18
|
-
:some => 'option'
|
19
|
-
)
|
20
|
-
|
21
|
-
We can get content with
|
22
|
-
|
23
|
-
content = app.fetch(uid)
|
24
|
-
content.data # "SOME CONTENT"
|
25
|
-
|
26
|
-
We can also get the extra saved attributes
|
27
|
-
|
28
|
-
content.meta # {:time => Sat Aug 14 12:04:13 +0100 2010, :name => 'content.txt'}
|
29
|
-
content.name # 'content.txt'
|
30
|
-
|
31
|
-
We can destroy it with
|
32
|
-
|
33
|
-
app.destroy(uid)
|
34
|
-
|
35
|
-
Serving directly from the datastore
|
36
|
-
-----------------------------------
|
37
|
-
Datastores can optionally serve data directly too, by implementing `url_for`
|
38
|
-
|
39
|
-
app.datastore.url_for(uid, :some => 'option') # ---> "http://some.url/thing.txt"
|
40
|
-
|
41
|
-
or (the same)
|
42
|
-
|
43
|
-
app.remote_url_for(uid, :some => 'option')
|
44
|
-
|
45
|
-
or
|
46
|
-
|
47
|
-
my_model.attachment.remote_url(:some => 'option')
|
48
|
-
|
49
|
-
You can create your own datastore, or use one of the provided ones as outlined below.
|
50
|
-
|
51
|
-
File datastore
|
52
|
-
--------------
|
53
|
-
The {Dragonfly::DataStorage::FileDataStore FileDataStore} stores data on the local filesystem.
|
54
|
-
|
55
|
-
It is used by default.
|
56
|
-
|
57
|
-
If for whatever reason you need to configure it again:
|
58
|
-
|
59
|
-
# shouldn't need this - it is the default
|
60
|
-
app.datastore = Dragonfly::DataStorage::FileDataStore.new
|
61
|
-
|
62
|
-
app.datastore.configure do |d|
|
63
|
-
d.root_path = '/filesystem/path/public/place' # defaults to /var/tmp/dragonfly
|
64
|
-
d.server_root = '/filesystem/path/public' # filesystem root for serving from - default to nil
|
65
|
-
d.store_meta = false # default to true - can be switched off to avoid
|
66
|
-
# saving an extra .meta file if meta not needed
|
67
|
-
end
|
68
|
-
|
69
|
-
You can serve directly from the FileDataStore if the `server_root` is set.
|
70
|
-
|
71
|
-
To customize the storage path (and therefore the uid), use the `:path` option on store
|
72
|
-
|
73
|
-
app.store("SOME CONTENT", :path => 'some/path.txt')
|
74
|
-
|
75
|
-
To do this on a per-model basis see {file:Models#Storage_options}.
|
76
|
-
|
77
|
-
**BEWARE!!!!** you must make sure the path (which will become the uid for the content) is unique and changes each time the content
|
78
|
-
is changed, otherwise you could have caching problems, as the generated urls will be the same for the same uid.
|
79
|
-
|
80
|
-
S3 datastore
|
81
|
-
------------
|
82
|
-
To configure with the {Dragonfly::DataStorage::S3DataStore S3DataStore}:
|
83
|
-
|
84
|
-
app.datastore = Dragonfly::DataStorage::S3DataStore.new
|
85
|
-
|
86
|
-
app.datastore.configure do |c|
|
87
|
-
c.bucket_name = 'my_bucket'
|
88
|
-
c.access_key_id = 'salfjasd34u23'
|
89
|
-
c.secret_access_key = '8u2u3rhkhfo23...'
|
90
|
-
c.region = 'eu-west-1' # defaults to 'us-east-1'
|
91
|
-
c.storage_headers = {'some' => 'thing'} # defaults to {'x-amz-acl' => 'public-read'}
|
92
|
-
c.url_scheme = 'https' # defaults to 'http'
|
93
|
-
c.url_host = 'some.custom.host' # defaults to "<bucket_name>.s3.amazonaws.com"
|
94
|
-
end
|
95
|
-
|
96
|
-
You can also pass these options to `S3DataStore.new` as an options hash.
|
97
|
-
|
98
|
-
You can serve directly from the S3DataStore using e.g.
|
99
|
-
|
100
|
-
my_model.attachment.remote_url
|
101
|
-
|
102
|
-
or with an expiring url:
|
103
|
-
|
104
|
-
my_model.attachment.remote_url(:expires => 3.days.from_now)
|
105
|
-
|
106
|
-
or with an https url:
|
107
|
-
|
108
|
-
my_model.attachment.remote_url(:scheme => 'https') # also configurable for all urls with 'url_scheme'
|
109
|
-
|
110
|
-
or with a custom host:
|
111
|
-
|
112
|
-
my_model.attachment.remote_url(:host => 'custom.domain') # also configurable for all urls with 'url_host'
|
113
|
-
|
114
|
-
Extra options you can use on store are `:path` and `:headers`
|
115
|
-
|
116
|
-
app.store("SOME CONTENT", :path => 'some/path.txt', :headers => {'x-amz-acl' => 'public-read-write'})
|
117
|
-
|
118
|
-
To do this on a per-model basis see {file:Models#Storage_options}.
|
119
|
-
|
120
|
-
**BEWARE!!!!** you must make sure the path (which will become the uid for the content) is unique and changes each time the content
|
121
|
-
is changed, otherwise you could have caching problems, as the generated urls will be the same for the same uid.
|
122
|
-
|
123
|
-
Mongo datastore
|
124
|
-
---------------
|
125
|
-
To configure with the {Dragonfly::DataStorage::MongoDataStore MongoDataStore}:
|
126
|
-
|
127
|
-
app.datastore = Dragonfly::DataStorage::MongoDataStore.new
|
128
|
-
|
129
|
-
It won't normally need configuring, but if you wish to:
|
130
|
-
|
131
|
-
app.datastore.configure do |d|
|
132
|
-
c.host = 'http://egg.heads:5000' # defaults to localhost
|
133
|
-
c.port = '27018' # defaults to mongo default (27017)
|
134
|
-
c.database = 'my_database' # defaults to 'dragonfly'
|
135
|
-
c.username = 'some_user' # only needed if mongo is running in auth mode
|
136
|
-
c.password = 'some_password' # only needed if mongo is running in auth mode
|
137
|
-
c.connection_opts = {:name => 'prod'} # arg gets passed to Mongo::Connection
|
138
|
-
# or Mongo::ReplSetConnection initializer - see http://api.mongodb.org/ruby/current
|
139
|
-
|
140
|
-
c.hosts = ['localhost:30000', 'localhost:30001'] # will use Mongo::ReplSetConnection instead of Mongo::Connection
|
141
|
-
end
|
142
|
-
|
143
|
-
If you already have a mongo database or connection available, you can skip setting these and set `db` or `connection` instead.
|
144
|
-
|
145
|
-
You can also pass any options to `MongoDataStore.new` as an options hash.
|
146
|
-
|
147
|
-
You can't serve directly from the mongo datastore.
|
148
|
-
|
149
|
-
You can optionally pass in a `:content_type` option to `store` to tell it the content's MIME type.
|
150
|
-
|
151
|
-
Couch datastore
|
152
|
-
---------------
|
153
|
-
To configure with the {Dragonfly::DataStorage::CouchDataStore CouchDataStore}:
|
154
|
-
|
155
|
-
app.datastore = Dragonfly::DataStorage::CouchDataStore.new
|
156
|
-
|
157
|
-
To configure:
|
158
|
-
|
159
|
-
app.datastore.configure do |d|
|
160
|
-
c.host = 'localhost' # defaults to localhost
|
161
|
-
c.port = '5984' # defaults to couchdb default (5984)
|
162
|
-
c.database = 'dragonfly' # defaults to 'dragonfly'
|
163
|
-
c.username = '' # not needed if couchdb is in 'admin party' mode
|
164
|
-
c.password = '' # not needed if couchdb is in 'admin party' mode
|
165
|
-
end
|
166
|
-
|
167
|
-
You can also pass these options to `CouchDataStore.new` as an options hash.
|
168
|
-
|
169
|
-
You can serve directly from the couch datastore.
|
170
|
-
|
171
|
-
You can optionally pass in a `:content_type` option to `store` to tell it what to use for its 'Content-Type' header.
|
172
|
-
|
173
|
-
Custom datastore
|
174
|
-
----------------
|
175
|
-
Data stores are key-value in nature, and need to implement 3 methods: `store`, `retrieve` and `destroy`.
|
176
|
-
|
177
|
-
class MyDataStore
|
178
|
-
|
179
|
-
def store(temp_object, opts={})
|
180
|
-
# ... use temp_object.data, temp_object.file, temp_object.path, etc.
|
181
|
-
# ... also we can use temp_object.meta and store it ...
|
182
|
-
|
183
|
-
# store and return the uid
|
184
|
-
'return_some_unique_uid'
|
185
|
-
end
|
186
|
-
|
187
|
-
def retrieve(uid)
|
188
|
-
# return an array containing
|
189
|
-
[
|
190
|
-
content, # either a File, String or Tempfile
|
191
|
-
meta_data # Hash - :name and :format are treated specially,
|
192
|
-
] # e.g. job.name is taken from job.meta[:name]
|
193
|
-
end
|
194
|
-
|
195
|
-
def destroy(uid)
|
196
|
-
# find the content and destroy
|
197
|
-
end
|
198
|
-
|
199
|
-
end
|
200
|
-
|
201
|
-
You can now configure the app to use your datastore:
|
202
|
-
|
203
|
-
Dragonfly[:my_app_name].datastore = MyDataStore.new
|
204
|
-
|
205
|
-
Notice that `store` takes a second `opts` argument.
|
206
|
-
Any options, get passed here.
|
207
|
-
`:meta` is treated specially and is accessible inside `MyDataStore#store` as `temp_object.meta`
|
208
|
-
|
209
|
-
uid = app.store('SOME CONTENT',
|
210
|
-
:meta => {:name => 'great_content.txt'},
|
211
|
-
:some_other => :option
|
212
|
-
)
|
213
|
-
|
214
|
-
# ...
|
215
|
-
|
216
|
-
You can also optionally serve data directly from the datastore if it implements `url_for`:
|
217
|
-
|
218
|
-
class MyDataStore
|
219
|
-
|
220
|
-
# ...
|
221
|
-
|
222
|
-
def url_for(uid, opts={})
|
223
|
-
"http://some.domain/#{uid}"
|
224
|
-
end
|
225
|
-
|
226
|
-
end
|