dragonfly 0.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.

Files changed (75) hide show
  1. data/.gitignore +7 -0
  2. data/LICENSE +20 -0
  3. data/README.markdown +95 -0
  4. data/Rakefile +60 -0
  5. data/VERSION +1 -0
  6. data/config.rb +7 -0
  7. data/config.ru +10 -0
  8. data/dragonfly-rails.gemspec +41 -0
  9. data/dragonfly.gemspec +137 -0
  10. data/features/dragonfly.feature +38 -0
  11. data/features/steps/common_steps.rb +8 -0
  12. data/features/steps/dragonfly_steps.rb +39 -0
  13. data/features/support/env.rb +25 -0
  14. data/features/support/image_helpers.rb +9 -0
  15. data/generators/dragonfly_app/USAGE +16 -0
  16. data/generators/dragonfly_app/dragonfly_app_generator.rb +54 -0
  17. data/generators/dragonfly_app/templates/custom_processing.erb +13 -0
  18. data/generators/dragonfly_app/templates/initializer.erb +7 -0
  19. data/generators/dragonfly_app/templates/metal_file.erb +32 -0
  20. data/irbrc.rb +20 -0
  21. data/lib/dragonfly/active_record_extensions/attachment.rb +117 -0
  22. data/lib/dragonfly/active_record_extensions/class_methods.rb +41 -0
  23. data/lib/dragonfly/active_record_extensions/instance_methods.rb +28 -0
  24. data/lib/dragonfly/active_record_extensions/validations.rb +19 -0
  25. data/lib/dragonfly/active_record_extensions.rb +12 -0
  26. data/lib/dragonfly/analysis/analyser.rb +45 -0
  27. data/lib/dragonfly/analysis/base.rb +10 -0
  28. data/lib/dragonfly/analysis/r_magick_analyser.rb +40 -0
  29. data/lib/dragonfly/app.rb +85 -0
  30. data/lib/dragonfly/app_configuration.rb +9 -0
  31. data/lib/dragonfly/configurable.rb +113 -0
  32. data/lib/dragonfly/core_ext/object.rb +8 -0
  33. data/lib/dragonfly/data_storage/base.rb +19 -0
  34. data/lib/dragonfly/data_storage/file_data_store.rb +72 -0
  35. data/lib/dragonfly/data_storage.rb +9 -0
  36. data/lib/dragonfly/encoding/base.rb +13 -0
  37. data/lib/dragonfly/encoding/r_magick_encoder.rb +17 -0
  38. data/lib/dragonfly/extended_temp_object.rb +94 -0
  39. data/lib/dragonfly/middleware.rb +27 -0
  40. data/lib/dragonfly/parameters.rb +152 -0
  41. data/lib/dragonfly/processing/processor.rb +14 -0
  42. data/lib/dragonfly/processing/r_magick_processor.rb +71 -0
  43. data/lib/dragonfly/r_magick_configuration.rb +47 -0
  44. data/lib/dragonfly/rails/images.rb +20 -0
  45. data/lib/dragonfly/temp_object.rb +118 -0
  46. data/lib/dragonfly/url_handler.rb +148 -0
  47. data/lib/dragonfly.rb +33 -0
  48. data/samples/beach.png +0 -0
  49. data/samples/egg.png +0 -0
  50. data/samples/round.gif +0 -0
  51. data/samples/taj.jpg +0 -0
  52. data/spec/argument_matchers.rb +29 -0
  53. data/spec/dragonfly/active_record_extensions/attachment_spec.rb +8 -0
  54. data/spec/dragonfly/active_record_extensions/initializer.rb +1 -0
  55. data/spec/dragonfly/active_record_extensions/migration.rb +21 -0
  56. data/spec/dragonfly/active_record_extensions/model_spec.rb +400 -0
  57. data/spec/dragonfly/active_record_extensions/models.rb +2 -0
  58. data/spec/dragonfly/active_record_extensions/spec_helper.rb +23 -0
  59. data/spec/dragonfly/analysis/analyser_spec.rb +85 -0
  60. data/spec/dragonfly/analysis/r_magick_analyser_spec.rb +35 -0
  61. data/spec/dragonfly/app_spec.rb +69 -0
  62. data/spec/dragonfly/configurable_spec.rb +193 -0
  63. data/spec/dragonfly/data_storage/data_store_spec.rb +47 -0
  64. data/spec/dragonfly/data_storage/file_data_store_spec.rb +93 -0
  65. data/spec/dragonfly/extended_temp_object_spec.rb +67 -0
  66. data/spec/dragonfly/middleware_spec.rb +44 -0
  67. data/spec/dragonfly/parameters_spec.rb +293 -0
  68. data/spec/dragonfly/processing/rmagick_processor_spec.rb +148 -0
  69. data/spec/dragonfly/temp_object_spec.rb +233 -0
  70. data/spec/dragonfly/url_handler_spec.rb +246 -0
  71. data/spec/dragonfly_spec.rb +4 -0
  72. data/spec/image_matchers.rb +31 -0
  73. data/spec/simple_matchers.rb +14 -0
  74. data/spec/spec_helper.rb +19 -0
  75. metadata +160 -0
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ **.sqlite3
5
+ pkg
6
+ .yardoc
7
+ doc
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Mark Evans
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,95 @@
1
+ Dragonfly
2
+ ===========
3
+
4
+ Dragonfly is an on-the-fly processing/encoding framework written as a Rack application.
5
+ It includes an extension for Ruby on Rails to enable easy image handling.
6
+
7
+ For the lazy rails user
8
+ -----------------------
9
+
10
+ In environment.rb:
11
+
12
+ config.gem 'dragonfly-rails', :lib => 'dragonfly/rails/images'
13
+ config.middleware.use 'Dragonfly::Middleware', :images
14
+
15
+ IMPORTANT: see 'Caching' below to add caching (recommended!)
16
+
17
+ Migration:
18
+
19
+ class AddCoverImageToAlbums < ActiveRecord::Migration
20
+
21
+ def self.up
22
+ add_column :albums, :cover_image_uid, :string
23
+ end
24
+
25
+ def self.down
26
+ remove_column :albums, :cover_image_uid
27
+ end
28
+
29
+ end
30
+
31
+ Model:
32
+
33
+ class Album < ActiveRecord::Base
34
+
35
+
36
+ validates_presence_of :cover_image
37
+ validates_size_of :cover_image, :maximum => 500.kilobytes
38
+ validates_mime_type_of :cover_image, :in => %w(image/jpeg image/png image/gif)
39
+
40
+ image_accessor :cover_image # This provides the reader/writer for cover_image
41
+
42
+ end
43
+
44
+ View (for uploading via a file field):
45
+
46
+ <% form_for @album, :html => {:multipart => true} do |f| %>
47
+ ...
48
+ <%= f.file_field :cover_image %>
49
+ ...
50
+ <% end %>
51
+
52
+
53
+ View (to display):
54
+
55
+ <%= image_tag @album.cover_image.url('400x200') %>
56
+ <%= image_tag @album.cover_image.url('100x100!') %>
57
+ <%= image_tag @album.cover_image.url('100x100#') %>
58
+ <%= image_tag @album.cover_image.url('50x50+30+30sw') %>
59
+ ...etc.
60
+
61
+
62
+ Caching
63
+ -------
64
+
65
+ All this processing and encoding on the fly is pretty expensive to perform on every page request.
66
+ Thankfully, HTTP caching comes to the rescue.
67
+ You could use any HTTP caching component such as Varnish, Squid, etc., but the quickest and easiest way is to use the excellent Rack::Cache, which should be adequate for most websites.
68
+
69
+ In that case, rather than the above, your `environment.rb` should contain something like this:
70
+
71
+ config.gem 'dragonfly-rails', :lib => 'dragonfly/rails/images'
72
+ config.gem 'rack-cache', :lib => 'rack/cache'
73
+ config.middleware.use 'Rack::Cache',
74
+ :verbose => true,
75
+ :metastore => 'file:/var/cache/rack/meta',
76
+ :entitystore => 'file:/var/cache/rack/body'
77
+ config.middleware.use 'Dragonfly::Middleware', :images
78
+
79
+
80
+ Using outside of rails, custom storage/processing/encoding/analysis, and more...
81
+ ------------------------------------------------------------------------
82
+ Dragonfly is primarily a Rack app, the Rails part of it being nothing more than a separate layer on top of the main code, which means you can use it as a standalone app, or with Sinatra, Merb, etc.
83
+
84
+ It is intended to be highly customizable, and is not limited to images, but any data type that could suit on-the-fly processing/encoding.
85
+
86
+ The docs are in the process of being added, and will appear soon!...
87
+
88
+ Credits
89
+ =======
90
+ - <a href="http://github.com/markevans">Mark Evans</a> (author)
91
+
92
+ Copyright
93
+ ========
94
+
95
+ Copyright (c) 2009 Mark Evans. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ require 'rake'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |s|
6
+ s.name = "dragonfly"
7
+ s.summary = %Q{dragonfly is an on-the-fly processing/encoding framework written as a Rack application.
8
+ It includes an extension for Ruby on Rails to enable easy image handling}
9
+ s.email = "mark@new-bamboo.co.uk"
10
+ s.homepage = "http://github.com/markevans/dragonfly"
11
+ s.authors = ["Mark Evans"]
12
+ s.add_dependency('rack')
13
+ end
14
+ Jeweler::Tasks.new do |s|
15
+ s.name = "dragonfly-rails"
16
+ s.summary = %Q{dragonfly-rails has no code of its own - it simply gathers dependencies for using dragonfly in rails}
17
+ s.email = "mark@new-bamboo.co.uk"
18
+ s.homepage = "http://github.com/markevans/dragonfly"
19
+ s.authors = ["Mark Evans"]
20
+ s.files = []
21
+ s.test_files = []
22
+ s.extra_rdoc_files = []
23
+ s.add_dependency('dragonfly')
24
+ s.add_dependency('rack')
25
+ s.add_dependency('mime-types')
26
+ s.add_dependency('rmagick')
27
+ end
28
+ rescue LoadError
29
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
30
+ end
31
+
32
+ require 'rake/rdoctask'
33
+ Rake::RDocTask.new do |rdoc|
34
+ rdoc.rdoc_dir = 'rdoc'
35
+ rdoc.title = 'dragonfly'
36
+ rdoc.options << '--line-numbers' << '--inline-source'
37
+ rdoc.rdoc_files.include('README*')
38
+ rdoc.rdoc_files.include('lib/**/*.rb')
39
+ end
40
+
41
+ require 'spec/rake/spectask'
42
+ Spec::Rake::SpecTask.new(:spec) do |t|
43
+ t.libs << 'lib' << 'spec'
44
+ t.spec_files = FileList['spec/**/*_spec.rb']
45
+ end
46
+
47
+ Spec::Rake::SpecTask.new(:rcov) do |t|
48
+ t.libs << 'lib' << 'spec'
49
+ t.spec_files = FileList['spec/**/*_spec.rb']
50
+ t.rcov = true
51
+ end
52
+
53
+ begin
54
+ require 'cucumber/rake/task'
55
+ Cucumber::Rake::Task.new(:features)
56
+ rescue LoadError
57
+ puts "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
58
+ end
59
+
60
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/config.rb ADDED
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/lib/dragonfly'
2
+
3
+ include Dragonfly
4
+
5
+ APP = Dragonfly::App[:images]
6
+ APP.configure_with(RMagickConfiguration)
7
+ APP.url_handler.protect_from_dos_attacks = false
data/config.ru ADDED
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + '/config'
2
+ require 'rubygems'
3
+ require 'rack/cache'
4
+
5
+ use Rack::Cache,
6
+ :verbose => true,
7
+ :metastore => 'file:/var/cache/rack/meta',
8
+ :entitystore => 'file:/var/cache/rack/body'
9
+
10
+ run APP
@@ -0,0 +1,41 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{dragonfly-rails}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Mark Evans"]
12
+ s.date = %q{2009-11-09}
13
+ s.email = %q{mark@new-bamboo.co.uk}
14
+ s.homepage = %q{http://github.com/markevans/dragonfly}
15
+ s.rdoc_options = ["--charset=UTF-8"]
16
+ s.require_paths = ["lib"]
17
+ s.rubygems_version = %q{1.3.5}
18
+ s.summary = %q{dragonfly-rails has no code of its own - it simply gathers dependencies for using dragonfly in rails}
19
+
20
+ if s.respond_to? :specification_version then
21
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
25
+ s.add_runtime_dependency(%q<dragonfly>, [">= 0"])
26
+ s.add_runtime_dependency(%q<rack>, [">= 0"])
27
+ s.add_runtime_dependency(%q<mime-types>, [">= 0"])
28
+ s.add_runtime_dependency(%q<rmagick>, [">= 0"])
29
+ else
30
+ s.add_dependency(%q<dragonfly>, [">= 0"])
31
+ s.add_dependency(%q<rack>, [">= 0"])
32
+ s.add_dependency(%q<mime-types>, [">= 0"])
33
+ s.add_dependency(%q<rmagick>, [">= 0"])
34
+ end
35
+ else
36
+ s.add_dependency(%q<dragonfly>, [">= 0"])
37
+ s.add_dependency(%q<rack>, [">= 0"])
38
+ s.add_dependency(%q<mime-types>, [">= 0"])
39
+ s.add_dependency(%q<rmagick>, [">= 0"])
40
+ end
41
+ end
data/dragonfly.gemspec ADDED
@@ -0,0 +1,137 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{dragonfly}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Mark Evans"]
12
+ s.date = %q{2009-11-09}
13
+ s.email = %q{mark@new-bamboo.co.uk}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.markdown"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "LICENSE",
21
+ "README.markdown",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "config.rb",
25
+ "config.ru",
26
+ "dragonfly-rails.gemspec",
27
+ "dragonfly.gemspec",
28
+ "features/dragonfly.feature",
29
+ "features/steps/common_steps.rb",
30
+ "features/steps/dragonfly_steps.rb",
31
+ "features/support/env.rb",
32
+ "features/support/image_helpers.rb",
33
+ "generators/dragonfly_app/USAGE",
34
+ "generators/dragonfly_app/dragonfly_app_generator.rb",
35
+ "generators/dragonfly_app/templates/custom_processing.erb",
36
+ "generators/dragonfly_app/templates/initializer.erb",
37
+ "generators/dragonfly_app/templates/metal_file.erb",
38
+ "irbrc.rb",
39
+ "lib/dragonfly.rb",
40
+ "lib/dragonfly/active_record_extensions.rb",
41
+ "lib/dragonfly/active_record_extensions/attachment.rb",
42
+ "lib/dragonfly/active_record_extensions/class_methods.rb",
43
+ "lib/dragonfly/active_record_extensions/instance_methods.rb",
44
+ "lib/dragonfly/active_record_extensions/validations.rb",
45
+ "lib/dragonfly/analysis/analyser.rb",
46
+ "lib/dragonfly/analysis/base.rb",
47
+ "lib/dragonfly/analysis/r_magick_analyser.rb",
48
+ "lib/dragonfly/app.rb",
49
+ "lib/dragonfly/app_configuration.rb",
50
+ "lib/dragonfly/configurable.rb",
51
+ "lib/dragonfly/core_ext/object.rb",
52
+ "lib/dragonfly/data_storage.rb",
53
+ "lib/dragonfly/data_storage/base.rb",
54
+ "lib/dragonfly/data_storage/file_data_store.rb",
55
+ "lib/dragonfly/encoding/base.rb",
56
+ "lib/dragonfly/encoding/r_magick_encoder.rb",
57
+ "lib/dragonfly/extended_temp_object.rb",
58
+ "lib/dragonfly/middleware.rb",
59
+ "lib/dragonfly/parameters.rb",
60
+ "lib/dragonfly/processing/processor.rb",
61
+ "lib/dragonfly/processing/r_magick_processor.rb",
62
+ "lib/dragonfly/r_magick_configuration.rb",
63
+ "lib/dragonfly/rails/images.rb",
64
+ "lib/dragonfly/temp_object.rb",
65
+ "lib/dragonfly/url_handler.rb",
66
+ "samples/beach.png",
67
+ "samples/egg.png",
68
+ "samples/round.gif",
69
+ "samples/taj.jpg",
70
+ "spec/argument_matchers.rb",
71
+ "spec/dragonfly/active_record_extensions/attachment_spec.rb",
72
+ "spec/dragonfly/active_record_extensions/initializer.rb",
73
+ "spec/dragonfly/active_record_extensions/migration.rb",
74
+ "spec/dragonfly/active_record_extensions/model_spec.rb",
75
+ "spec/dragonfly/active_record_extensions/models.rb",
76
+ "spec/dragonfly/active_record_extensions/spec_helper.rb",
77
+ "spec/dragonfly/analysis/analyser_spec.rb",
78
+ "spec/dragonfly/analysis/r_magick_analyser_spec.rb",
79
+ "spec/dragonfly/app_spec.rb",
80
+ "spec/dragonfly/configurable_spec.rb",
81
+ "spec/dragonfly/data_storage/data_store_spec.rb",
82
+ "spec/dragonfly/data_storage/file_data_store_spec.rb",
83
+ "spec/dragonfly/extended_temp_object_spec.rb",
84
+ "spec/dragonfly/middleware_spec.rb",
85
+ "spec/dragonfly/parameters_spec.rb",
86
+ "spec/dragonfly/processing/rmagick_processor_spec.rb",
87
+ "spec/dragonfly/temp_object_spec.rb",
88
+ "spec/dragonfly/url_handler_spec.rb",
89
+ "spec/dragonfly_spec.rb",
90
+ "spec/image_matchers.rb",
91
+ "spec/simple_matchers.rb",
92
+ "spec/spec_helper.rb"
93
+ ]
94
+ s.homepage = %q{http://github.com/markevans/dragonfly}
95
+ s.rdoc_options = ["--charset=UTF-8"]
96
+ s.require_paths = ["lib"]
97
+ s.rubygems_version = %q{1.3.5}
98
+ s.summary = %q{dragonfly is an on-the-fly processing/encoding framework written as a Rack application. It includes an extension for Ruby on Rails to enable easy image handling}
99
+ s.test_files = [
100
+ "spec/argument_matchers.rb",
101
+ "spec/dragonfly/active_record_extensions/attachment_spec.rb",
102
+ "spec/dragonfly/active_record_extensions/initializer.rb",
103
+ "spec/dragonfly/active_record_extensions/migration.rb",
104
+ "spec/dragonfly/active_record_extensions/model_spec.rb",
105
+ "spec/dragonfly/active_record_extensions/models.rb",
106
+ "spec/dragonfly/active_record_extensions/spec_helper.rb",
107
+ "spec/dragonfly/analysis/analyser_spec.rb",
108
+ "spec/dragonfly/analysis/r_magick_analyser_spec.rb",
109
+ "spec/dragonfly/app_spec.rb",
110
+ "spec/dragonfly/configurable_spec.rb",
111
+ "spec/dragonfly/data_storage/data_store_spec.rb",
112
+ "spec/dragonfly/data_storage/file_data_store_spec.rb",
113
+ "spec/dragonfly/extended_temp_object_spec.rb",
114
+ "spec/dragonfly/middleware_spec.rb",
115
+ "spec/dragonfly/parameters_spec.rb",
116
+ "spec/dragonfly/processing/rmagick_processor_spec.rb",
117
+ "spec/dragonfly/temp_object_spec.rb",
118
+ "spec/dragonfly/url_handler_spec.rb",
119
+ "spec/dragonfly_spec.rb",
120
+ "spec/image_matchers.rb",
121
+ "spec/simple_matchers.rb",
122
+ "spec/spec_helper.rb"
123
+ ]
124
+
125
+ if s.respond_to? :specification_version then
126
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
127
+ s.specification_version = 3
128
+
129
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
130
+ s.add_runtime_dependency(%q<rack>, [">= 0"])
131
+ else
132
+ s.add_dependency(%q<rack>, [">= 0"])
133
+ end
134
+ else
135
+ s.add_dependency(%q<rack>, [">= 0"])
136
+ end
137
+ end
@@ -0,0 +1,38 @@
1
+ Feature: champion uses dragonfly to process images
2
+ In order to be a champion
3
+ A user uses dragonfly
4
+
5
+ Background:
6
+ Given a stored image "beach.png" with dimensions 200x100
7
+
8
+ Scenario: Go to url for original
9
+ When I go to the url for image "beach.png", with format 'png'
10
+ Then the response should be OK
11
+ And the response should have mime-type 'image/png'
12
+ And the image should have width '200'
13
+ And the image should have height '100'
14
+ And the image should have format 'png'
15
+
16
+ Scenario: Go to url for changed format version
17
+ When I go to the url for image "beach.png", with format 'gif'
18
+ Then the response should be OK
19
+ And the response should have mime-type 'image/gif'
20
+ And the image should have width '200'
21
+ And the image should have height '100'
22
+ And the image should have format 'gif'
23
+
24
+ Scenario: Go to url for soft resized version
25
+ When I go to the url for image "beach.png", with format 'png' and resize geometry '100x150'
26
+ Then the response should be OK
27
+ And the response should have mime-type 'image/png'
28
+ And the image should have width '100'
29
+ And the image should have height '50'
30
+ And the image should have format 'png'
31
+
32
+ Scenario: Go to url for hard resized version
33
+ When I go to the url for image "beach.png", with format 'png' and resize geometry '100x150!'
34
+ Then the response should be OK
35
+ And the response should have mime-type 'image/png'
36
+ And the image should have width '100'
37
+ And the image should have height '150'
38
+ And the image should have format 'png'
@@ -0,0 +1,8 @@
1
+ Then "debug" do
2
+ debugger
3
+ true
4
+ end
5
+
6
+ Then 'show "(.*)"' do |code|
7
+ eval "puts #{code}"
8
+ end
@@ -0,0 +1,39 @@
1
+ Given /^a stored image "(.+?)" with dimensions (\d+)x(\d+)$/ do |name, width, height|
2
+ tempfile = Tempfile.new(name)
3
+ `convert -resize #{width}x#{height}! #{SAMPLE_IMAGE_PATH} #{tempfile.path}`
4
+ temp_object = APP.temp_object_class.new(tempfile)
5
+ uid = APP.datastore.store(temp_object)
6
+ TEMP_IMAGES[name] = uid
7
+ end
8
+
9
+ When /^I go to the url for image "(.+?)", with format '([^']+?)'$/ do |name, ext|
10
+ make_image_request name, :format => ext
11
+ end
12
+
13
+ When /^I go to the url for image "(.+?)", with format '(.+?)' and resize geometry '(.+?)'$/ do |name, ext, geometry|
14
+ make_image_request(name,
15
+ :format => ext,
16
+ :processing_method => :resize,
17
+ :processing_options => {:geometry => geometry}
18
+ )
19
+ end
20
+
21
+ Then "the response should be OK" do
22
+ @response.status.should == 200
23
+ end
24
+
25
+ Then "the response should have mime-type '(.+?)'" do |mime_type|
26
+ @response.headers['Content-Type'].should == mime_type
27
+ end
28
+
29
+ Then "the image should have width '(.+?)'" do |width|
30
+ @response.body.should have_width(width.to_i)
31
+ end
32
+
33
+ Then "the image should have height '(.+?)'" do |height|
34
+ @response.body.should have_height(height.to_i)
35
+ end
36
+
37
+ Then "the image should have format '(.+?)'" do |format|
38
+ @response.body.should have_format(format)
39
+ end
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'dragonfly'
3
+ require 'spec/expectations'
4
+ require 'test/unit/assertions'
5
+ require 'ruby-debug'
6
+ require File.dirname(__FILE__) + '/image_helpers.rb'
7
+ require File.dirname(__FILE__) + '/../../spec/image_matchers.rb'
8
+
9
+ # A hash of <name for reference> => <dragonfly uid> pairs
10
+ TEMP_IMAGES = {}
11
+
12
+ APP = Dragonfly::App[:images]
13
+ APP.configure_with(Dragonfly::RMagickConfiguration)
14
+
15
+ SAMPLE_IMAGE_PATH = File.dirname(__FILE__)+'/../../samples/beach.png'
16
+
17
+ Before do
18
+ # Remove temporary images
19
+ TEMP_IMAGES.each do |name, uid|
20
+ APP.datastore.destroy(uid)
21
+ TEMP_IMAGES.delete(name)
22
+ end
23
+ end
24
+
25
+ World(ImageHelpers)
@@ -0,0 +1,9 @@
1
+ module ImageHelpers
2
+
3
+ def make_image_request(name, parameters = {})
4
+ request = Rack::MockRequest.new(APP)
5
+ url = APP.url_handler.url_for(TEMP_IMAGES[name], parameters)
6
+ @response = request.get(url)
7
+ end
8
+
9
+ end
@@ -0,0 +1,16 @@
1
+ ------------------------------------------------------------------------
2
+
3
+ Example:
4
+
5
+ ./script/generate dragonfly_app images
6
+
7
+ This will:
8
+ - create a metal file with a dragonfly app routed to '/images'
9
+ - add an initializer to extend activerecord, so you can do things like
10
+
11
+ image_accessor :preview_image
12
+
13
+ in your models.
14
+ - create an empty placeholder for putting your own custom processing methods
15
+
16
+ ------------------------------------------------------------------------
@@ -0,0 +1,54 @@
1
+ require 'digest/sha1'
2
+
3
+ class DragonflyAppGenerator < Rails::Generator::NamedBase
4
+
5
+ def manifest
6
+ app_name = plural_name
7
+ metal_name = plural_name.camelize
8
+ path_prefix = plural_name
9
+ single_name = singular_name.singularize
10
+ custom_processor_name = "Custom#{single_name.camelize}Processing"
11
+
12
+ record do |m|
13
+ # The initializer
14
+ initializer_path = File.join(Rails.root, 'config', 'initializers', 'dragonfly.rb')
15
+ already_initialized_code = File.read(initializer_path) if File.exists?(initializer_path)
16
+ m.template(
17
+ 'initializer.erb',
18
+ 'config/initializers/dragonfly.rb',
19
+ :assigns => {
20
+ :app_name => app_name,
21
+ :accessor_prefix => single_name,
22
+ :already_initialized_code => already_initialized_code
23
+ },
24
+ :collision => :force
25
+ )
26
+
27
+ # The metal file
28
+ m.directory('app/metal')
29
+ m.template(
30
+ 'metal_file.erb',
31
+ "app/metal/#{plural_name}.rb",
32
+ :assigns => {
33
+ :app_name => app_name,
34
+ :metal_name => metal_name,
35
+ :path_prefix => path_prefix,
36
+ :random_secret => Digest::SHA1.hexdigest(Time.now.to_s),
37
+ :custom_processor_name => custom_processor_name
38
+ }
39
+ )
40
+
41
+ # The custom processor
42
+ m.template(
43
+ 'custom_processing.erb',
44
+ "lib/#{custom_processor_name.underscore}.rb",
45
+ :assigns => {
46
+ :module_name => custom_processor_name,
47
+ :temp_object_name => single_name
48
+ }
49
+ )
50
+
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,13 @@
1
+ module <%= module_name %>
2
+
3
+ # Define any of your own custom processing methods here
4
+ # e.g.
5
+ # def my_processing_method(<%= temp_object_name %>, opts={})
6
+ # # ...do processing here - you can use methods like
7
+ # # <%= temp_object_name %>.data, <%= temp_object_name %>.path, etc.
8
+ # # (see Dragonfly::ExtendedTempObject for more details)
9
+ # #
10
+ # # the method must return a String, Tempfile, File, or Dragonfly::TempObject
11
+ # end
12
+
13
+ end
@@ -0,0 +1,7 @@
1
+ <%- if already_initialized_code -%>
2
+ <%= already_initialized_code %>
3
+ <%- else -%>
4
+ require 'dragonfly'
5
+ ActiveRecord::Base.extend Dragonfly::ActiveRecordExtensions
6
+ <%- end -%>
7
+ ActiveRecord::Base.register_dragonfly_app(:<%= accessor_prefix %>, Dragonfly::App[:<%= app_name %>])
@@ -0,0 +1,32 @@
1
+ # Allow the metal piece to run in isolation
2
+ require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
3
+ require 'dragonfly'
4
+
5
+ # Configuration of the Dragonfly App
6
+ Dragonfly::App[:<%= app_name %>].configure_with(Dragonfly::RMagickConfiguration)
7
+ Dragonfly::App[:<%= app_name %>].configure do |c|
8
+ c.log = RAILS_DEFAULT_LOGGER
9
+ c.datastore.configure do |d|
10
+ d.root_path = "#{Rails.root}/public/system/dragonfly/#{Rails.env}"
11
+ end
12
+ c.url_handler do |u|
13
+ u.secret = '<%= random_secret %>'
14
+ u.path_prefix = '/<%= path_prefix %>'
15
+ end
16
+ end
17
+
18
+ # The metal, for running the app
19
+ app = Dragonfly::App[:<%= app_name %>]
20
+ <%= metal_name %> = Rack::Builder.new do
21
+
22
+ # UNCOMMENT ME!!!
23
+ # ... if you want to use super-dooper middleware 'rack-cache'
24
+ # require 'rack/cache'
25
+ # use Rack::Cache,
26
+ # :verbose => true,
27
+ # :metastore => 'file:/var/cache/rack/meta',
28
+ # :entitystore => 'file:/var/cache/rack/body'
29
+
30
+ run app
31
+
32
+ end
data/irbrc.rb ADDED
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/config'
2
+
3
+ available_uids = `find #{APP.datastore.root_path} ! -type d`.split("\n").map do |file|
4
+ file.sub("#{APP.datastore.root_path}/", '')
5
+ end
6
+
7
+ def new_image
8
+ APP.create_object(File.new(Dir['samples/*'].first))
9
+ end
10
+
11
+ puts "Loaded stuff from dragonfly irbrc"
12
+ puts "\nAvailable uids:\n"
13
+ puts available_uids
14
+ puts "\nAvailable sample images:\n"
15
+ puts Dir['samples/*']
16
+ puts "\nAvailable methods:\n"
17
+ puts "new_image"
18
+ puts "\nAvailable constants:\n"
19
+ puts "APP"
20
+ puts