fog-dragonfly 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. data/.specopts +2 -0
  2. data/.yardopts +23 -0
  3. data/Gemfile +23 -0
  4. data/Gemfile.rails.2.3.5 +14 -0
  5. data/History.md +266 -0
  6. data/LICENSE +20 -0
  7. data/README.md +88 -0
  8. data/Rakefile +92 -0
  9. data/VERSION +1 -0
  10. data/config.ru +13 -0
  11. data/docs.watchr +1 -0
  12. data/dragonfly.gemspec +293 -0
  13. data/extra_docs/Analysers.md +108 -0
  14. data/extra_docs/Caching.md +23 -0
  15. data/extra_docs/Configuration.md +138 -0
  16. data/extra_docs/DataStorage.md +136 -0
  17. data/extra_docs/Encoding.md +96 -0
  18. data/extra_docs/GeneralUsage.md +121 -0
  19. data/extra_docs/Generators.md +102 -0
  20. data/extra_docs/Heroku.md +50 -0
  21. data/extra_docs/Index.md +36 -0
  22. data/extra_docs/MimeTypes.md +40 -0
  23. data/extra_docs/Models.md +266 -0
  24. data/extra_docs/Mongo.md +45 -0
  25. data/extra_docs/Processing.md +130 -0
  26. data/extra_docs/Rack.md +52 -0
  27. data/extra_docs/Rails2.md +55 -0
  28. data/extra_docs/Rails3.md +62 -0
  29. data/extra_docs/Sinatra.md +25 -0
  30. data/extra_docs/URLs.md +169 -0
  31. data/features/3.0.3.feature +8 -0
  32. data/features/images.feature +47 -0
  33. data/features/no_processing.feature +14 -0
  34. data/features/rails_2.3.5.feature +7 -0
  35. data/features/steps/common_steps.rb +8 -0
  36. data/features/steps/dragonfly_steps.rb +66 -0
  37. data/features/steps/rails_steps.rb +39 -0
  38. data/features/support/env.rb +40 -0
  39. data/fixtures/files/app/models/album.rb +3 -0
  40. data/fixtures/files/app/views/albums/new.html.erb +4 -0
  41. data/fixtures/files/app/views/albums/show.html.erb +4 -0
  42. data/fixtures/files/config/initializers/dragonfly.rb +4 -0
  43. data/fixtures/files/features/manage_album_images.feature +12 -0
  44. data/fixtures/files/features/step_definitions/image_steps.rb +15 -0
  45. data/fixtures/files/features/support/paths.rb +15 -0
  46. data/fixtures/files/features/text_images.feature +7 -0
  47. data/fixtures/rails_2.3.5/template.rb +10 -0
  48. data/fixtures/rails_3.0.3/template.rb +20 -0
  49. data/irbrc.rb +17 -0
  50. data/lib/dragonfly.rb +45 -0
  51. data/lib/dragonfly/active_model_extensions.rb +13 -0
  52. data/lib/dragonfly/active_model_extensions/attachment.rb +169 -0
  53. data/lib/dragonfly/active_model_extensions/class_methods.rb +45 -0
  54. data/lib/dragonfly/active_model_extensions/instance_methods.rb +28 -0
  55. data/lib/dragonfly/active_model_extensions/validations.rb +37 -0
  56. data/lib/dragonfly/analyser.rb +59 -0
  57. data/lib/dragonfly/analysis/file_command_analyser.rb +32 -0
  58. data/lib/dragonfly/analysis/image_magick_analyser.rb +47 -0
  59. data/lib/dragonfly/analysis/r_magick_analyser.rb +63 -0
  60. data/lib/dragonfly/app.rb +182 -0
  61. data/lib/dragonfly/config/heroku.rb +19 -0
  62. data/lib/dragonfly/config/image_magick.rb +41 -0
  63. data/lib/dragonfly/config/r_magick.rb +46 -0
  64. data/lib/dragonfly/config/rails.rb +17 -0
  65. data/lib/dragonfly/configurable.rb +119 -0
  66. data/lib/dragonfly/core_ext/object.rb +8 -0
  67. data/lib/dragonfly/core_ext/string.rb +9 -0
  68. data/lib/dragonfly/core_ext/symbol.rb +9 -0
  69. data/lib/dragonfly/data_storage.rb +9 -0
  70. data/lib/dragonfly/data_storage/file_data_store.rb +114 -0
  71. data/lib/dragonfly/data_storage/mongo_data_store.rb +82 -0
  72. data/lib/dragonfly/data_storage/s3data_store.rb +115 -0
  73. data/lib/dragonfly/encoder.rb +13 -0
  74. data/lib/dragonfly/encoding/image_magick_encoder.rb +57 -0
  75. data/lib/dragonfly/encoding/r_magick_encoder.rb +61 -0
  76. data/lib/dragonfly/function_manager.rb +69 -0
  77. data/lib/dragonfly/generation/hash_with_css_style_keys.rb +23 -0
  78. data/lib/dragonfly/generation/image_magick_generator.rb +140 -0
  79. data/lib/dragonfly/generation/r_magick_generator.rb +155 -0
  80. data/lib/dragonfly/generator.rb +9 -0
  81. data/lib/dragonfly/image_magick_utils.rb +81 -0
  82. data/lib/dragonfly/job.rb +371 -0
  83. data/lib/dragonfly/job_builder.rb +39 -0
  84. data/lib/dragonfly/job_definitions.rb +26 -0
  85. data/lib/dragonfly/job_endpoint.rb +15 -0
  86. data/lib/dragonfly/loggable.rb +28 -0
  87. data/lib/dragonfly/middleware.rb +34 -0
  88. data/lib/dragonfly/processing/image_magick_processor.rb +99 -0
  89. data/lib/dragonfly/processing/r_magick_processor.rb +126 -0
  90. data/lib/dragonfly/processor.rb +9 -0
  91. data/lib/dragonfly/r_magick_utils.rb +48 -0
  92. data/lib/dragonfly/rails/images.rb +22 -0
  93. data/lib/dragonfly/response.rb +82 -0
  94. data/lib/dragonfly/routed_endpoint.rb +40 -0
  95. data/lib/dragonfly/serializer.rb +32 -0
  96. data/lib/dragonfly/simple_cache.rb +23 -0
  97. data/lib/dragonfly/simple_endpoint.rb +63 -0
  98. data/lib/dragonfly/temp_object.rb +220 -0
  99. data/samples/beach.png +0 -0
  100. data/samples/egg.png +0 -0
  101. data/samples/round.gif +0 -0
  102. data/samples/sample.docx +0 -0
  103. data/samples/taj.jpg +0 -0
  104. data/spec/argument_matchers.rb +19 -0
  105. data/spec/dragonfly/active_model_extensions/active_model_setup.rb +97 -0
  106. data/spec/dragonfly/active_model_extensions/active_record_setup.rb +85 -0
  107. data/spec/dragonfly/active_model_extensions/model_spec.rb +723 -0
  108. data/spec/dragonfly/active_model_extensions/spec_helper.rb +11 -0
  109. data/spec/dragonfly/analyser_spec.rb +123 -0
  110. data/spec/dragonfly/analysis/file_command_analyser_spec.rb +57 -0
  111. data/spec/dragonfly/analysis/image_magick_analyser_spec.rb +15 -0
  112. data/spec/dragonfly/analysis/r_magick_analyser_spec.rb +27 -0
  113. data/spec/dragonfly/analysis/shared_analyser_spec.rb +51 -0
  114. data/spec/dragonfly/app_spec.rb +280 -0
  115. data/spec/dragonfly/config/r_magick_spec.rb +25 -0
  116. data/spec/dragonfly/configurable_spec.rb +220 -0
  117. data/spec/dragonfly/core_ext/string_spec.rb +17 -0
  118. data/spec/dragonfly/core_ext/symbol_spec.rb +17 -0
  119. data/spec/dragonfly/data_storage/data_store_spec.rb +76 -0
  120. data/spec/dragonfly/data_storage/file_data_store_spec.rb +169 -0
  121. data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +38 -0
  122. data/spec/dragonfly/data_storage/s3_data_store_spec.rb +94 -0
  123. data/spec/dragonfly/deprecation_spec.rb +20 -0
  124. data/spec/dragonfly/encoding/image_magick_encoder_spec.rb +41 -0
  125. data/spec/dragonfly/encoding/r_magick_encoder_spec.rb +37 -0
  126. data/spec/dragonfly/function_manager_spec.rb +154 -0
  127. data/spec/dragonfly/generation/hash_with_css_style_keys_spec.rb +24 -0
  128. data/spec/dragonfly/generation/image_magick_generator_spec.rb +12 -0
  129. data/spec/dragonfly/generation/r_magick_generator_spec.rb +24 -0
  130. data/spec/dragonfly/generation/shared_generator_spec.rb +91 -0
  131. data/spec/dragonfly/image_magick_utils_spec.rb +16 -0
  132. data/spec/dragonfly/job_builder_spec.rb +37 -0
  133. data/spec/dragonfly/job_definitions_spec.rb +35 -0
  134. data/spec/dragonfly/job_endpoint_spec.rb +120 -0
  135. data/spec/dragonfly/job_spec.rb +773 -0
  136. data/spec/dragonfly/loggable_spec.rb +80 -0
  137. data/spec/dragonfly/middleware_spec.rb +68 -0
  138. data/spec/dragonfly/processing/image_magick_processor_spec.rb +29 -0
  139. data/spec/dragonfly/processing/r_magick_processor_spec.rb +26 -0
  140. data/spec/dragonfly/processing/shared_processing_spec.rb +215 -0
  141. data/spec/dragonfly/routed_endpoint_spec.rb +48 -0
  142. data/spec/dragonfly/serializer_spec.rb +61 -0
  143. data/spec/dragonfly/simple_cache_spec.rb +27 -0
  144. data/spec/dragonfly/simple_endpoint_spec.rb +89 -0
  145. data/spec/dragonfly/temp_object_spec.rb +352 -0
  146. data/spec/image_matchers.rb +47 -0
  147. data/spec/simple_matchers.rb +44 -0
  148. data/spec/spec_helper.rb +58 -0
  149. data/yard/handlers/configurable_attr_handler.rb +38 -0
  150. data/yard/setup.rb +15 -0
  151. data/yard/templates/default/fulldoc/html/css/common.css +107 -0
  152. data/yard/templates/default/layout/html/layout.erb +87 -0
  153. data/yard/templates/default/module/html/configuration_summary.erb +31 -0
  154. data/yard/templates/default/module/setup.rb +17 -0
  155. metadata +550 -0
@@ -0,0 +1,39 @@
1
+ module Dragonfly
2
+ class JobBuilder
3
+
4
+ def initialize(&block)
5
+ @block = block
6
+ end
7
+
8
+ def build(job, *args)
9
+ evaluate_block(job, false, *args)
10
+ end
11
+
12
+ def build!(job, *args)
13
+ evaluate_block(job, true, *args)
14
+ end
15
+
16
+ Job.step_names.each do |step|
17
+
18
+ # fetch, process, etc.
19
+ define_method step do |*args|
20
+ if @perform_with_bangs
21
+ @job.send("#{step}!", *args)
22
+ else
23
+ @job = @job.send(step, *args)
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ private
30
+
31
+ def evaluate_block(job, perform_with_bangs, *args)
32
+ @job = job
33
+ @perform_with_bangs = perform_with_bangs
34
+ instance_exec(*args, &@block)
35
+ @job
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ module Dragonfly
2
+ class JobDefinitions < Module
3
+
4
+ def initialize
5
+ @job_definitions = {}
6
+ end
7
+
8
+ def add(name, &definition_proc)
9
+ job_definitions[name] = JobBuilder.new(&definition_proc)
10
+ jd = job_definitions # Needed because we're about to change 'self'
11
+
12
+ define_method name do |*args|
13
+ jd[name].build(self, *args)
14
+ end
15
+
16
+ define_method "#{name}!" do |*args|
17
+ jd[name].build!(self, *args)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :job_definitions
24
+
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ module Dragonfly
2
+ class JobEndpoint
3
+
4
+ def initialize(job)
5
+ @job = job
6
+ end
7
+
8
+ def call(env={})
9
+ Response.new(job, env).to_response
10
+ end
11
+
12
+ attr_reader :job
13
+
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ require 'logger'
2
+
3
+ module Dragonfly
4
+ module Loggable
5
+
6
+ def log
7
+ case @log_object
8
+ when nil
9
+ @log_object = Logger.new($stdout)
10
+ when Proc
11
+ @log_object[]
12
+ when Logger
13
+ @log_object
14
+ end
15
+ end
16
+
17
+ def log=(object)
18
+ @log_object = object
19
+ end
20
+
21
+ attr_reader :log_object
22
+
23
+ def use_same_log_as(object)
24
+ self.log = proc{ object.log }
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,34 @@
1
+ module Dragonfly
2
+ class Middleware
3
+
4
+ def initialize(app, dragonfly_app_name, path_prefix)
5
+ @app = app
6
+ @endpoint = Rack::Builder.new {
7
+ map path_prefix do
8
+ run Dragonfly[dragonfly_app_name]
9
+ end
10
+ }.to_app
11
+ end
12
+
13
+ def call(env)
14
+ response = @endpoint.call(env)
15
+ if route_not_found?(response)
16
+ @app.call(env)
17
+ else
18
+ response
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def route_not_found?(response)
25
+ response[1]['X-Cascade'] == 'pass' ||
26
+ (rack_version_doesnt_support_x_cascade? && response[0] == 404)
27
+ end
28
+
29
+ def rack_version_doesnt_support_x_cascade?
30
+ Rack.version < '1.1'
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,99 @@
1
+ module Dragonfly
2
+ module Processing
3
+ class ImageMagickProcessor
4
+
5
+ GRAVITIES = {
6
+ 'nw' => 'NorthWest',
7
+ 'n' => 'North',
8
+ 'ne' => 'NorthEast',
9
+ 'w' => 'West',
10
+ 'c' => 'Center',
11
+ 'e' => 'East',
12
+ 'sw' => 'SouthWest',
13
+ 's' => 'South',
14
+ 'se' => 'SouthEast'
15
+ }
16
+
17
+ # Geometry string patterns
18
+ RESIZE_GEOMETRY = /^\d*x\d*[><%^!]?$|^\d+@$/ # e.g. '300x200!'
19
+ CROPPED_RESIZE_GEOMETRY = /^(\d+)x(\d+)#(\w{1,2})?$/ # e.g. '20x50#ne'
20
+ CROP_GEOMETRY = /^(\d+)x(\d+)([+-]\d+)?([+-]\d+)?(\w{1,2})?$/ # e.g. '30x30+10+10'
21
+ THUMB_GEOMETRY = Regexp.union RESIZE_GEOMETRY, CROPPED_RESIZE_GEOMETRY, CROP_GEOMETRY
22
+
23
+ include ImageMagickUtils
24
+
25
+ def resize(temp_object, geometry)
26
+ convert(temp_object, "-resize '#{geometry}'")
27
+ end
28
+
29
+ def crop(temp_object, opts={})
30
+ width = opts[:width]
31
+ height = opts[:height]
32
+ gravity = GRAVITIES[opts[:gravity]]
33
+ x = "#{opts[:x] || 0}"
34
+ x = '+' + x unless x[/^[+-]/]
35
+ y = "#{opts[:y] || 0}"
36
+ y = '+' + y unless y[/^[+-]/]
37
+
38
+ convert(temp_object, "-crop #{width}x#{height}#{x}#{y}#{" -gravity #{gravity}" if gravity}")
39
+ end
40
+
41
+ def flip(temp_object)
42
+ convert(temp_object, "-flip")
43
+ end
44
+
45
+ def flop(temp_object)
46
+ convert(temp_object, "-flop")
47
+ end
48
+
49
+ def greyscale(temp_object)
50
+ convert(temp_object, "-colorspace Gray")
51
+ end
52
+ alias grayscale greyscale
53
+
54
+ def resize_and_crop(temp_object, opts={})
55
+ attrs = identify(temp_object)
56
+ current_width = attrs[:width].to_i
57
+ current_height = attrs[:height].to_i
58
+
59
+ width = opts[:width] ? opts[:width].to_i : current_width
60
+ height = opts[:height] ? opts[:height].to_i : current_height
61
+ gravity = opts[:gravity] || 'c'
62
+
63
+ if width != current_width || height != current_height
64
+ scale = [width.to_f / current_width, height.to_f / current_height].max
65
+ temp_object = TempObject.new(resize(temp_object, "#{(scale * current_width).ceil}x#{(scale * current_height).ceil}"))
66
+ end
67
+
68
+ crop(temp_object, :width => width, :height => height, :gravity => gravity)
69
+ end
70
+
71
+ def rotate(temp_object, amount, opts={})
72
+ convert(temp_object, "-rotate '#{amount}#{opts[:qualifier]}'")
73
+ end
74
+
75
+ def thumb(temp_object, geometry)
76
+ case geometry
77
+ when RESIZE_GEOMETRY
78
+ resize(temp_object, geometry)
79
+ when CROPPED_RESIZE_GEOMETRY
80
+ resize_and_crop(temp_object, :width => $1, :height => $2, :gravity => $3)
81
+ when CROP_GEOMETRY
82
+ crop(temp_object,
83
+ :width => $1,
84
+ :height => $2,
85
+ :x => $3,
86
+ :y => $4,
87
+ :gravity => $5
88
+ )
89
+ else raise ArgumentError, "Didn't recognise the geometry string #{geometry}"
90
+ end
91
+ end
92
+
93
+ def convert(temp_object, args='', format=nil)
94
+ format ? [super, {:format => format.to_sym}] : super
95
+ end
96
+
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,126 @@
1
+ require 'RMagick'
2
+
3
+ module Dragonfly
4
+ module Processing
5
+ class RMagickProcessor
6
+
7
+ GRAVITIES = {
8
+ 'nw' => Magick::NorthWestGravity,
9
+ 'n' => Magick::NorthGravity,
10
+ 'ne' => Magick::NorthEastGravity,
11
+ 'w' => Magick::WestGravity,
12
+ 'c' => Magick::CenterGravity,
13
+ 'e' => Magick::EastGravity,
14
+ 'sw' => Magick::SouthWestGravity,
15
+ 's' => Magick::SouthGravity,
16
+ 'se' => Magick::SouthEastGravity
17
+ }
18
+
19
+ # Geometry string patterns
20
+ RESIZE_GEOMETRY = /^\d*x\d*[><%^!]?$|^\d+@$/ # e.g. '300x200!'
21
+ CROPPED_RESIZE_GEOMETRY = /^(\d+)x(\d+)#(\w{1,2})?$/ # e.g. '20x50#ne'
22
+ CROP_GEOMETRY = /^(\d+)x(\d+)([+-]\d+)?([+-]\d+)?(\w{1,2})?$/ # e.g. '30x30+10+10'
23
+ THUMB_GEOMETRY = Regexp.union RESIZE_GEOMETRY, CROPPED_RESIZE_GEOMETRY, CROP_GEOMETRY
24
+
25
+ include RMagickUtils
26
+ include Configurable
27
+
28
+ configurable_attr :use_filesystem, true
29
+
30
+ def crop(temp_object, opts={})
31
+ x = opts[:x].to_i
32
+ y = opts[:y].to_i
33
+ gravity = GRAVITIES[opts[:gravity]] || Magick::ForgetGravity
34
+ width = opts[:width].to_i
35
+ height = opts[:height].to_i
36
+
37
+ rmagick_image(temp_object) do |image|
38
+ # RMagick throws an error if the cropping area is bigger than the image,
39
+ # when the gravity is something other than nw
40
+ width = image.columns - x if x + width > image.columns
41
+ height = image.rows - y if y + height > image.rows
42
+ image.crop(gravity, x, y, width, height)
43
+ end
44
+ end
45
+
46
+ def flip(temp_object)
47
+ rmagick_image(temp_object) do |image|
48
+ image.flip!
49
+ end
50
+ end
51
+
52
+ def flop(temp_object)
53
+ rmagick_image(temp_object) do |image|
54
+ image.flop!
55
+ end
56
+ end
57
+
58
+ def greyscale(temp_object, opts={})
59
+ depth = opts[:depth] || 256
60
+ rmagick_image(temp_object) do |image|
61
+ image.quantize(depth, Magick::GRAYColorspace)
62
+ end
63
+ end
64
+ alias grayscale greyscale
65
+
66
+ def resize(temp_object, geometry)
67
+ rmagick_image(temp_object) do |image|
68
+ image.change_geometry!(geometry) do |cols, rows, img|
69
+ img.resize!(cols, rows)
70
+ end
71
+ end
72
+ end
73
+
74
+ def resize_and_crop(temp_object, opts={})
75
+ rmagick_image(temp_object) do |image|
76
+
77
+ width = opts[:width] ? opts[:width].to_i : image.columns
78
+ height = opts[:height] ? opts[:height].to_i : image.rows
79
+ gravity = GRAVITIES[opts[:gravity]] || Magick::CenterGravity
80
+
81
+ image.crop_resized(width, height, gravity)
82
+ end
83
+ end
84
+
85
+ def rotate(temp_object, amount, opts={})
86
+ args = [amount.to_f]
87
+ args << opts[:qualifier] if opts[:qualifier]
88
+ rmagick_image(temp_object) do |image|
89
+ image.background_color = opts[:background_colour] if opts[:background_colour]
90
+ image.background_color = opts[:background_color] if opts[:background_color]
91
+ image.rotate(*args) || temp_object
92
+ end
93
+ end
94
+
95
+ def thumb(temp_object, geometry)
96
+ case geometry
97
+ when RESIZE_GEOMETRY
98
+ resize(temp_object, geometry)
99
+ when CROPPED_RESIZE_GEOMETRY
100
+ resize_and_crop(temp_object, :width => $1, :height => $2, :gravity => $3)
101
+ when CROP_GEOMETRY
102
+ crop(temp_object,
103
+ :width => $1,
104
+ :height => $2,
105
+ :x => $3,
106
+ :y => $4,
107
+ :gravity => $5
108
+ )
109
+ else raise ArgumentError, "Didn't recognise the geometry string #{geometry}"
110
+ end
111
+ end
112
+
113
+ def vignette(temp_object, opts={})
114
+ x = opts[:x].to_f || temp_object.width * 0.1
115
+ y = opts[:y].to_f || temp_object.height * 0.1
116
+ radius = opts[:radius].to_f || 0.0
117
+ sigma = opts[:sigma].to_f || 10.0
118
+
119
+ rmagick_image(temp_object) do |image|
120
+ image.vignette(x, y, radius, sigma)
121
+ end
122
+ end
123
+
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,9 @@
1
+ module Dragonfly
2
+ class Processor < FunctionManager
3
+
4
+ def process(temp_object, method, *args)
5
+ call_last(method, temp_object, *args)
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,48 @@
1
+ require 'tempfile'
2
+
3
+ module Dragonfly
4
+ module RMagickUtils
5
+
6
+ include Loggable
7
+
8
+ private
9
+
10
+ # Requires the extended object to respond to 'use_filesystem'
11
+ def rmagick_image(temp_object, &block)
12
+ imagelist = use_filesystem ? Magick::Image.read(temp_object.path) : Magick::Image.from_blob(temp_object.data)
13
+ image = imagelist.first
14
+ result = block.call(image)
15
+ case result
16
+ when Magick::Image, Magick::ImageList
17
+ content = use_filesystem ? write_to_tempfile(result) : result.to_blob
18
+ result.destroy!
19
+ else
20
+ content = result
21
+ end
22
+ image.destroy!
23
+ content
24
+ rescue Magick::ImageMagickError => e
25
+ log.warn("Unable to handle content in #{self.class} - got:\n#{e}")
26
+ throw :unable_to_handle
27
+ end
28
+
29
+ def ping_rmagick_image(temp_object, &block)
30
+ imagelist = use_filesystem ? Magick::Image.ping(temp_object.path) : Magick::Image.from_blob(temp_object.data)
31
+ image = imagelist.first
32
+ result = block.call(image)
33
+ image.destroy!
34
+ result
35
+ rescue Magick::ImageMagickError => e
36
+ log.warn("Unable to handle content in #{self.class} - got:\n#{e}")
37
+ throw :unable_to_handle
38
+ end
39
+
40
+ def write_to_tempfile(rmagick_image)
41
+ tempfile = Tempfile.new('dragonfly')
42
+ tempfile.close
43
+ rmagick_image.write(tempfile.path)
44
+ tempfile
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,22 @@
1
+ require 'dragonfly'
2
+ require 'rack/cache'
3
+ require 'uri'
4
+
5
+ ### The dragonfly app ###
6
+ app = Dragonfly[:images]
7
+ app.configure_with(:rails)
8
+ app.configure_with(:imagemagick)
9
+
10
+ ### Extend active record ###
11
+ app.define_macro(ActiveRecord::Base, :image_accessor)
12
+
13
+ ### Insert the middleware ###
14
+ # Where the middleware is depends on the version of Rails
15
+ middleware = Rails.respond_to?(:application) ? Rails.application.middleware : ActionController::Dispatcher.middleware
16
+
17
+ middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :images, app.url_path_prefix
18
+ middleware.insert_before 'Dragonfly::Middleware', 'Rack::Cache', {
19
+ :verbose => true,
20
+ :metastore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/meta"), # URI encoded because Windows
21
+ :entitystore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/body") # has problems with spaces
22
+ }