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.

Files changed (203) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -8
  3. data/.travis.yml +11 -0
  4. data/Gemfile +1 -0
  5. data/History.md +52 -2
  6. data/LICENSE +1 -1
  7. data/README.md +38 -95
  8. data/dev/grid.jpg +0 -0
  9. data/dev/irbrc.rb +27 -0
  10. data/dev/rails_template.rb +38 -0
  11. data/dev/test.ru +56 -0
  12. data/dev/test_rails +19 -0
  13. data/dragonfly.gemspec +3 -21
  14. data/lib/dragonfly.rb +45 -44
  15. data/lib/dragonfly/app.rb +175 -96
  16. data/lib/dragonfly/configurable.rb +71 -170
  17. data/lib/dragonfly/content.rb +211 -0
  18. data/lib/dragonfly/core_ext/object.rb +1 -6
  19. data/lib/dragonfly/file_data_store.rb +197 -0
  20. data/lib/dragonfly/image_magick/analysers/image_properties.rb +23 -0
  21. data/lib/dragonfly/image_magick/generators/convert.rb +19 -0
  22. data/lib/dragonfly/image_magick/generators/plain.rb +26 -0
  23. data/lib/dragonfly/image_magick/generators/plasma.rb +25 -0
  24. data/lib/dragonfly/image_magick/generators/text.rb +127 -0
  25. data/lib/dragonfly/image_magick/plugin.rb +83 -0
  26. data/lib/dragonfly/image_magick/processors/convert.rb +29 -0
  27. data/lib/dragonfly/image_magick/processors/encode.rb +18 -0
  28. data/lib/dragonfly/image_magick/processors/thumb.rb +76 -0
  29. data/lib/dragonfly/job.rb +118 -134
  30. data/lib/dragonfly/job_endpoint.rb +2 -0
  31. data/lib/dragonfly/memory_data_store.rb +34 -0
  32. data/lib/dragonfly/middleware.rb +5 -3
  33. data/lib/dragonfly/{active_model_extensions.rb → model.rb} +5 -3
  34. data/lib/dragonfly/{active_model_extensions → model}/attachment.rb +40 -35
  35. data/lib/dragonfly/{active_model_extensions → model}/attachment_class_methods.rb +36 -40
  36. data/lib/dragonfly/model/class_methods.rb +109 -0
  37. data/lib/dragonfly/{active_model_extensions → model}/instance_methods.rb +2 -2
  38. data/lib/dragonfly/{active_model_extensions → model}/validations.rb +17 -12
  39. data/lib/dragonfly/railtie.rb +8 -6
  40. data/lib/dragonfly/register.rb +27 -0
  41. data/lib/dragonfly/response.rb +47 -52
  42. data/lib/dragonfly/routed_endpoint.rb +4 -0
  43. data/lib/dragonfly/serializer.rb +15 -5
  44. data/lib/dragonfly/server.rb +56 -29
  45. data/lib/dragonfly/shell.rb +12 -23
  46. data/lib/dragonfly/spec/data_store_examples.rb +64 -0
  47. data/lib/dragonfly/temp_object.rb +32 -47
  48. data/lib/dragonfly/url_attributes.rb +19 -22
  49. data/lib/dragonfly/url_mapper.rb +3 -0
  50. data/lib/dragonfly/utils.rb +12 -0
  51. data/lib/dragonfly/version.rb +1 -1
  52. data/lib/dragonfly/whitelist.rb +19 -0
  53. data/lib/rails/generators/dragonfly/USAGE +8 -0
  54. data/lib/rails/generators/dragonfly/dragonfly_generator.rb +24 -0
  55. data/lib/rails/generators/dragonfly/templates/initializer.rb.erb +27 -0
  56. data/samples/gif.gif +0 -0
  57. data/spec/dragonfly/app_spec.rb +270 -64
  58. data/spec/dragonfly/configurable_spec.rb +142 -418
  59. data/spec/dragonfly/content_spec.rb +353 -0
  60. data/spec/dragonfly/cookie_monster_spec.rb +2 -1
  61. data/spec/dragonfly/file_data_store_spec.rb +301 -0
  62. data/spec/dragonfly/image_magick/analysers/image_properties_spec.rb +20 -0
  63. data/spec/dragonfly/image_magick/generators/convert_spec.rb +19 -0
  64. data/spec/dragonfly/image_magick/generators/plain_spec.rb +50 -0
  65. data/spec/dragonfly/image_magick/generators/plasma_spec.rb +32 -0
  66. data/spec/dragonfly/image_magick/generators/text_spec.rb +77 -0
  67. data/spec/dragonfly/image_magick/plugin_spec.rb +131 -0
  68. data/spec/dragonfly/image_magick/processors/convert_spec.rb +56 -0
  69. data/spec/dragonfly/image_magick/processors/thumb_spec.rb +173 -0
  70. data/spec/dragonfly/job_endpoint_spec.rb +30 -73
  71. data/spec/dragonfly/job_spec.rb +280 -608
  72. data/spec/dragonfly/memory_data_store_spec.rb +20 -0
  73. data/spec/dragonfly/middleware_spec.rb +47 -27
  74. data/spec/dragonfly/{active_model_extensions → model}/model_spec.rb +331 -555
  75. data/spec/dragonfly/model/validations_spec.rb +196 -0
  76. data/spec/dragonfly/register_spec.rb +35 -0
  77. data/spec/dragonfly/routed_endpoint_spec.rb +6 -6
  78. data/spec/dragonfly/serializer_spec.rb +13 -15
  79. data/spec/dragonfly/server_spec.rb +122 -46
  80. data/spec/dragonfly/shell_spec.rb +43 -24
  81. data/spec/dragonfly/temp_object_spec.rb +69 -94
  82. data/spec/dragonfly/url_attributes_spec.rb +49 -0
  83. data/spec/dragonfly/utils_spec.rb +32 -0
  84. data/spec/dragonfly/whitelist_spec.rb +30 -0
  85. data/spec/dragonfly_spec.rb +43 -0
  86. data/spec/fixtures/deprecated_stored_content/eggs.bonus +1 -0
  87. data/spec/fixtures/deprecated_stored_content/eggs.bonus.meta +1 -0
  88. data/spec/functional/configuration_spec.rb +19 -0
  89. data/spec/functional/model_urls_spec.rb +43 -41
  90. data/spec/functional/remote_on_the_fly_spec.rb +14 -16
  91. data/spec/functional/shell_commands_spec.rb +24 -14
  92. data/spec/functional/to_response_spec.rb +10 -10
  93. data/spec/functional/urls_spec.rb +5 -3
  94. data/spec/spec_helper.rb +23 -28
  95. data/spec/support/argument_matchers.rb +7 -8
  96. data/spec/support/image_matchers.rb +14 -36
  97. data/spec/support/model_helpers.rb +97 -0
  98. data/spec/support/simple_matchers.rb +12 -0
  99. metadata +92 -393
  100. data/.yardopts +0 -29
  101. data/Rakefile +0 -36
  102. data/config.ru +0 -14
  103. data/docs.watchr +0 -1
  104. data/extra_docs/Analysers.md +0 -68
  105. data/extra_docs/Caching.md +0 -23
  106. data/extra_docs/Configuration.md +0 -149
  107. data/extra_docs/Couch.md +0 -49
  108. data/extra_docs/DataStorage.md +0 -226
  109. data/extra_docs/Encoding.md +0 -67
  110. data/extra_docs/ExampleUseCases.md +0 -116
  111. data/extra_docs/GeneralUsage.md +0 -105
  112. data/extra_docs/Generators.md +0 -68
  113. data/extra_docs/Heroku.md +0 -50
  114. data/extra_docs/ImageMagick.md +0 -136
  115. data/extra_docs/Index.md +0 -33
  116. data/extra_docs/MimeTypes.md +0 -40
  117. data/extra_docs/Models.md +0 -441
  118. data/extra_docs/Mongo.md +0 -42
  119. data/extra_docs/Processing.md +0 -77
  120. data/extra_docs/Rack.md +0 -52
  121. data/extra_docs/Rails2.md +0 -57
  122. data/extra_docs/Rails3.md +0 -56
  123. data/extra_docs/ServingRemotely.md +0 -104
  124. data/extra_docs/Sinatra.md +0 -25
  125. data/extra_docs/URLs.md +0 -203
  126. data/features/images.feature +0 -47
  127. data/features/no_processing.feature +0 -14
  128. data/features/rails.feature +0 -8
  129. data/features/steps/common_steps.rb +0 -8
  130. data/features/steps/dragonfly_steps.rb +0 -66
  131. data/features/steps/rails_steps.rb +0 -40
  132. data/features/support/env.rb +0 -13
  133. data/features/support/setup.rb +0 -41
  134. data/fixtures/rails/files/app/models/album.rb +0 -6
  135. data/fixtures/rails/files/app/views/albums/new.html.erb +0 -7
  136. data/fixtures/rails/files/app/views/albums/show.html.erb +0 -6
  137. data/fixtures/rails/files/config/initializers/dragonfly.rb +0 -4
  138. data/fixtures/rails/files/features/manage_album_images.feature +0 -38
  139. data/fixtures/rails/files/features/step_definitions/helper_steps.rb +0 -7
  140. data/fixtures/rails/files/features/step_definitions/image_steps.rb +0 -25
  141. data/fixtures/rails/files/features/step_definitions/web_steps.rb +0 -189
  142. data/fixtures/rails/files/features/support/paths.rb +0 -17
  143. data/fixtures/rails/files/features/text_images.feature +0 -7
  144. data/fixtures/rails/template.rb +0 -20
  145. data/irbrc.rb +0 -19
  146. data/lib/dragonfly/active_model_extensions/class_methods.rb +0 -98
  147. data/lib/dragonfly/analyser.rb +0 -58
  148. data/lib/dragonfly/analysis/file_command_analyser.rb +0 -33
  149. data/lib/dragonfly/analysis/image_magick_analyser.rb +0 -6
  150. data/lib/dragonfly/config/heroku.rb +0 -26
  151. data/lib/dragonfly/config/image_magick.rb +0 -6
  152. data/lib/dragonfly/config/rails.rb +0 -20
  153. data/lib/dragonfly/data_storage.rb +0 -11
  154. data/lib/dragonfly/data_storage/couch_data_store.rb +0 -83
  155. data/lib/dragonfly/data_storage/file_data_store.rb +0 -144
  156. data/lib/dragonfly/data_storage/mongo_data_store.rb +0 -96
  157. data/lib/dragonfly/data_storage/s3data_store.rb +0 -168
  158. data/lib/dragonfly/encoder.rb +0 -13
  159. data/lib/dragonfly/encoding/image_magick_encoder.rb +0 -6
  160. data/lib/dragonfly/function_manager.rb +0 -67
  161. data/lib/dragonfly/generation/image_magick_generator.rb +0 -6
  162. data/lib/dragonfly/generator.rb +0 -9
  163. data/lib/dragonfly/image_magick/analyser.rb +0 -53
  164. data/lib/dragonfly/image_magick/config.rb +0 -44
  165. data/lib/dragonfly/image_magick/encoder.rb +0 -57
  166. data/lib/dragonfly/image_magick/generator.rb +0 -147
  167. data/lib/dragonfly/image_magick/processor.rb +0 -114
  168. data/lib/dragonfly/image_magick/utils.rb +0 -46
  169. data/lib/dragonfly/image_magick_utils.rb +0 -4
  170. data/lib/dragonfly/job_builder.rb +0 -39
  171. data/lib/dragonfly/job_definitions.rb +0 -30
  172. data/lib/dragonfly/loggable.rb +0 -28
  173. data/lib/dragonfly/processing/image_magick_processor.rb +0 -6
  174. data/lib/dragonfly/processor.rb +0 -9
  175. data/lib/dragonfly/rails/images.rb +0 -32
  176. data/lib/dragonfly/simple_cache.rb +0 -23
  177. data/spec/dragonfly/active_model_extensions/spec_helper.rb +0 -95
  178. data/spec/dragonfly/analyser_spec.rb +0 -123
  179. data/spec/dragonfly/analysis/file_command_analyser_spec.rb +0 -49
  180. data/spec/dragonfly/data_storage/couch_data_store_spec.rb +0 -84
  181. data/spec/dragonfly/data_storage/file_data_store_spec.rb +0 -308
  182. data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +0 -81
  183. data/spec/dragonfly/data_storage/s3_data_store_spec.rb +0 -277
  184. data/spec/dragonfly/data_storage/shared_data_store_examples.rb +0 -77
  185. data/spec/dragonfly/function_manager_spec.rb +0 -154
  186. data/spec/dragonfly/image_magick/analyser_spec.rb +0 -73
  187. data/spec/dragonfly/image_magick/encoder_spec.rb +0 -46
  188. data/spec/dragonfly/image_magick/generator_spec.rb +0 -178
  189. data/spec/dragonfly/image_magick/processor_spec.rb +0 -293
  190. data/spec/dragonfly/job_builder_spec.rb +0 -37
  191. data/spec/dragonfly/job_definitions_spec.rb +0 -57
  192. data/spec/dragonfly/loggable_spec.rb +0 -80
  193. data/spec/dragonfly/simple_cache_spec.rb +0 -27
  194. data/spec/dragonfly/url_attributes.rb +0 -47
  195. data/spec/functional/deprecations_spec.rb +0 -51
  196. data/spec/functional/image_magick_app_spec.rb +0 -27
  197. data/spec/test_imagemagick.ru +0 -49
  198. data/yard/handlers/configurable_attr_handler.rb +0 -38
  199. data/yard/setup.rb +0 -15
  200. data/yard/templates/default/fulldoc/html/css/common.css +0 -109
  201. data/yard/templates/default/layout/html/layout.erb +0 -93
  202. data/yard/templates/default/module/html/configuration_summary.erb +0 -31
  203. data/yard/templates/default/module/setup.rb +0 -17
@@ -1,40 +1,29 @@
1
1
  require 'shellwords'
2
+ require 'open3'
3
+ require 'dragonfly'
2
4
 
3
5
  module Dragonfly
4
- module Shell
5
-
6
- include Configurable
7
- configurable_attr :log_commands, false
6
+ class Shell
8
7
 
9
8
  # Exceptions
10
9
  class CommandFailed < RuntimeError; end
11
10
 
12
- def run(command, args="")
13
- full_command = "#{command} #{escape_args(args)}"
14
- log.debug("Running command: #{full_command}") if log_commands
15
- begin
16
- result = `#{full_command}`
17
- rescue Errno::ENOENT
18
- raise_shell_command_failed(full_command)
11
+ def run(command, opts={})
12
+ command = escape_args(command) unless opts[:escape] == false
13
+ Dragonfly.debug("shell command: #{command}")
14
+ Open3.popen3 command do |stdin, stdout, stderr, wait_thread|
15
+ status = wait_thread.value
16
+ raise CommandFailed, "Command failed (#{command}) with exit status #{status.exitstatus} and stderr #{stderr.read}" unless status.success?
17
+ stdout.read
19
18
  end
20
- if $?.exitstatus == 1
21
- throw :unable_to_handle
22
- elsif !$?.success?
23
- raise_shell_command_failed(full_command)
24
- end
25
- result
26
- end
27
-
28
- def raise_shell_command_failed(command)
29
- raise CommandFailed, "Command failed (#{command}) with exit status #{$?.exitstatus}"
30
19
  end
31
-
20
+
32
21
  def escape_args(args)
33
22
  args.shellsplit.map do |arg|
34
23
  quote arg.gsub(/\\?'/, %q('\\\\''))
35
24
  end.join(' ')
36
25
  end
37
-
26
+
38
27
  def quote(string)
39
28
  q = Dragonfly.running_on_windows? ? '"' : "'"
40
29
  q + string + q
@@ -0,0 +1,64 @@
1
+ require 'dragonfly/content'
2
+
3
+ shared_examples_for "data_store" do
4
+
5
+ # Using these shared spec requires you to set the inst var @data_store
6
+ let (:app) { Dragonfly.app }
7
+ let (:content) { Dragonfly::Content.new(app, "gollum") }
8
+ let (:content2) { Dragonfly::Content.new(app, "gollum") }
9
+
10
+
11
+ describe "write" do
12
+ it "returns a unique identifier for each storage" do
13
+ @data_store.write(content).should_not == @data_store.write(content2)
14
+ end
15
+ it "should return a unique identifier for each storage even when the first is deleted" do
16
+ uid1 = @data_store.write(content)
17
+ @data_store.destroy(uid1)
18
+ uid2 = @data_store.write(content)
19
+ uid1.should_not == uid2
20
+ end
21
+ it "should allow for passing in options as a second argument" do
22
+ @data_store.write(content, :some => :option)
23
+ end
24
+ end
25
+
26
+ describe "read" do
27
+ before(:each) do
28
+ content.add_meta('bitrate' => 35, 'name' => 'danny.boy')
29
+ uid = @data_store.write(content)
30
+ stuff, meta = @data_store.read(uid)
31
+ @retrieved_content = Dragonfly::Content.new(app, stuff, meta)
32
+ end
33
+
34
+ it "should read the stored data" do
35
+ @retrieved_content.data.should == "gollum"
36
+ end
37
+
38
+ it "should return the stored meta" do
39
+ @retrieved_content.meta['bitrate'].should == 35
40
+ @retrieved_content.meta['name'].should == 'danny.boy'
41
+ end
42
+
43
+ it "should return nil if the data doesn't exist" do
44
+ @data_store.read('gooble').should be_nil
45
+ end
46
+ end
47
+
48
+ describe "destroy" do
49
+
50
+ it "should destroy the stored data" do
51
+ uid = @data_store.write(content)
52
+ @data_store.destroy(uid)
53
+ @data_store.read(uid).should be_nil
54
+ end
55
+
56
+ it "should do nothing if the data doesn't exist on destroy" do
57
+ uid = @data_store.write(content)
58
+ @data_store.destroy(uid)
59
+ @data_store.destroy(uid)
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -1,11 +1,12 @@
1
1
  require 'stringio'
2
2
  require 'tempfile'
3
3
  require 'pathname'
4
+ require 'fileutils'
4
5
 
5
6
  module Dragonfly
6
7
 
7
8
  # A TempObject is used for HOLDING DATA.
8
- # It's the thing that is passed between the datastore, the processor and the encoder, and is useful
9
+ # It's the thing that is passed between the datastore and the processor, and is useful
9
10
  # for separating how the data was created and how it is later accessed.
10
11
  #
11
12
  # You can initialize it various ways:
@@ -32,14 +33,12 @@ module Dragonfly
32
33
  #
33
34
  class TempObject
34
35
 
35
- include HasFilename
36
-
37
36
  # Exceptions
38
37
  class Closed < RuntimeError; end
39
38
 
40
39
  # Instance Methods
41
40
 
42
- def initialize(obj, meta={})
41
+ def initialize(obj)
43
42
  if obj.is_a? TempObject
44
43
  @data = obj.get_data
45
44
  @tempfile = obj.get_tempfile
@@ -57,9 +56,9 @@ module Dragonfly
57
56
  elsif obj.respond_to?(:path) # e.g. Rack::Test::UploadedFile
58
57
  @pathname = Pathname.new(obj.path)
59
58
  else
60
- raise ArgumentError, "#{self.class.name} must be initialized with a String, a Pathname, a File, a Tempfile, another TempObject, something that responds to .tempfile, or something that responds to .path"
59
+ raise ArgumentError, "#{self.class.name} must be initialized with a String, a Pathname, a File, a Tempfile, another TempObject, something that responds to .tempfile, or something that responds to .path - you gave #{obj.inspect}"
61
60
  end
62
-
61
+
63
62
  @tempfile.close if @tempfile
64
63
 
65
64
  # Original filename
@@ -68,21 +67,13 @@ module Dragonfly
68
67
  elsif @pathname
69
68
  @pathname.basename.to_s
70
69
  end
71
-
72
- # Meta
73
- @meta = meta
74
- @meta[:name] ||= @original_filename if @original_filename
75
70
  end
76
-
71
+
77
72
  attr_reader :original_filename
78
- attr_accessor :meta
79
-
80
- def name
81
- meta[:name]
82
- end
83
-
84
- def name=(name)
85
- meta[:name] = name
73
+
74
+ def ext
75
+ name = original_filename
76
+ name.split('.').last if name
86
77
  end
87
78
 
88
79
  def data
@@ -90,19 +81,6 @@ module Dragonfly
90
81
  @data ||= file{|f| f.read }
91
82
  end
92
83
 
93
- def tempfile
94
- raise Closed, "can't read from tempfile as TempObject has been closed" if closed?
95
- @tempfile ||= begin
96
- case
97
- when @data
98
- @tempfile = new_tempfile(@data)
99
- when @pathname
100
- @tempfile = copy_to_tempfile(@pathname.expand_path)
101
- end
102
- @tempfile
103
- end
104
- end
105
-
106
84
  def file(&block)
107
85
  f = tempfile.open
108
86
  tempfile.binmode
@@ -143,6 +121,12 @@ module Dragonfly
143
121
  File.new(path, 'rb')
144
122
  end
145
123
 
124
+ def to_tempfile
125
+ tempfile = copy_to_tempfile(path)
126
+ tempfile.open
127
+ tempfile
128
+ end
129
+
146
130
  def to_io(&block)
147
131
  @data ? StringIO.open(@data, 'rb', &block) : file(&block)
148
132
  end
@@ -168,45 +152,46 @@ module Dragonfly
168
152
  "<#{self.class.name} #{content_string} >"
169
153
  end
170
154
 
171
- def unique_id
172
- @unique_id ||= "#{object_id}#{rand(1000000)}"
173
- end
174
-
175
155
  protected
176
156
 
177
157
  # We don't use normal accessors here because #data etc. do more than just return the instance var
178
158
  def get_data
179
159
  @data
180
160
  end
181
-
161
+
182
162
  def get_pathname
183
163
  @pathname
184
164
  end
185
-
165
+
186
166
  def get_tempfile
187
167
  @tempfile
188
168
  end
189
169
 
190
170
  private
191
171
 
172
+ def tempfile
173
+ raise Closed, "can't read from tempfile as TempObject has been closed" if closed?
174
+ @tempfile ||= begin
175
+ case
176
+ when @data
177
+ @tempfile = Utils.new_tempfile(ext, @data)
178
+ when @pathname
179
+ @tempfile = copy_to_tempfile(@pathname.expand_path)
180
+ end
181
+ @tempfile
182
+ end
183
+ end
184
+
192
185
  def block_size
193
186
  8192
194
187
  end
195
188
 
196
189
  def copy_to_tempfile(path)
197
- tempfile = new_tempfile
190
+ tempfile = Utils.new_tempfile(ext)
198
191
  FileUtils.cp path, tempfile.path
199
192
  tempfile
200
193
  end
201
194
 
202
- def new_tempfile(content=nil)
203
- tempfile = ext ? Tempfile.new(['dragonfly', ".#{ext}"]) : Tempfile.new('dragonfly')
204
- tempfile.binmode
205
- tempfile.write(content) if content
206
- tempfile.close
207
- tempfile
208
- end
209
-
210
195
  def prepare_path(path)
211
196
  dir = File.dirname(path)
212
197
  FileUtils.mkdir_p(dir) unless File.exist?(dir)
@@ -1,30 +1,27 @@
1
- module Dragonfly
2
-
3
- # UrlAttributes is like a normal hash, but treats
4
- # :name, :ext and :basename specially -
5
- # updating ext/basename also updates the name
6
- class UrlAttributes < Hash
7
-
8
- SPECIAL_KEYS = [:name, :basename, :ext]
1
+ require 'ostruct'
2
+ require 'dragonfly/has_filename'
3
+ require 'dragonfly/utils'
9
4
 
10
- include HasFilename
5
+ module Dragonfly
6
+ class UrlAttributes < OpenStruct
7
+ include HasFilename # Updating ext / basename also updates the name
11
8
 
12
- def name
13
- self[:name]
9
+ def empty?
10
+ @table.reject{|k, v| v.nil? }.empty?
14
11
  end
15
-
16
- def name=(name)
17
- self[:name] = name
12
+
13
+ # Hack so we can use .send('format') and it not call the private Kernel method
14
+ def format
15
+ @table[:format]
18
16
  end
19
-
20
- def slice(*keys)
21
- keys.inject({}) do |hash, key|
22
- key = key.to_sym
23
- hash[key] = SPECIAL_KEYS.include?(key) ? send(key) : self[key]
24
- hash
17
+
18
+ def extract(keys)
19
+ keys.inject({}) do |attrs, key|
20
+ value = send(key)
21
+ attrs[key] = value unless Utils.blank?(value)
22
+ attrs
25
23
  end
26
24
  end
27
-
28
25
  end
29
-
30
26
  end
27
+
@@ -1,3 +1,6 @@
1
+ require 'rack'
2
+ require 'dragonfly/utils'
3
+
1
4
  module Dragonfly
2
5
  class UrlMapper
3
6
 
@@ -1,11 +1,16 @@
1
1
  require 'tempfile'
2
2
  require 'uri'
3
+ require 'rack'
3
4
 
4
5
  module Dragonfly
5
6
  module Utils
6
7
 
7
8
  module_function
8
9
 
10
+ def blank?(obj)
11
+ obj.respond_to?(:empty?) ? obj.empty? : !obj
12
+ end
13
+
9
14
  def new_tempfile(ext=nil, content=nil)
10
15
  tempfile = ext ? Tempfile.new(['dragonfly', ".#{ext}"]) : Tempfile.new('dragonfly')
11
16
  tempfile.binmode
@@ -21,6 +26,13 @@ module Dragonfly
21
26
  end
22
27
  end
23
28
 
29
+ def stringify_keys(hash)
30
+ hash.inject({}) do |new_hash, (key, value)|
31
+ new_hash[key.to_s] = value
32
+ new_hash
33
+ end
34
+ end
35
+
24
36
  def uri_escape_segment(string)
25
37
  Rack::Utils.escape_path(string)
26
38
  end
@@ -1,3 +1,3 @@
1
1
  module Dragonfly
2
- VERSION = '0.9.15'
2
+ VERSION = '1.0'
3
3
  end
@@ -0,0 +1,19 @@
1
+ require 'forwardable'
2
+
3
+ module Dragonfly
4
+ class Whitelist
5
+ extend Forwardable
6
+ def_delegators :patterns, :push
7
+
8
+ def initialize(patterns=[])
9
+ @patterns = patterns
10
+ end
11
+
12
+ attr_reader :patterns
13
+
14
+ def include?(string)
15
+ patterns.any?{|pattern| pattern === string }
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Initialize and configure a dragonfly 'app', ready for serving images and other content!
3
+
4
+ Example:
5
+ rails generate dragonfly
6
+
7
+ This will create:
8
+ config/initializers/dragonfly.rb
@@ -0,0 +1,24 @@
1
+ class DragonflyGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def create_initializer
5
+ template "initializer.rb.erb", "config/initializers/dragonfly.rb"
6
+ end
7
+
8
+ private
9
+
10
+ def generate_secret
11
+ rand(1e32).to_s(36)
12
+ end
13
+
14
+ if RUBY_VERSION > "1.9"
15
+ def hash_key(key)
16
+ "#{key}:"
17
+ end
18
+ else
19
+ def hash_key(key)
20
+ ":#{key} =>"
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,27 @@
1
+ require 'dragonfly'
2
+
3
+ # Configure
4
+ Dragonfly.app.configure do
5
+ plugin :imagemagick
6
+
7
+ protect_from_dos_attacks true
8
+ secret "<%= generate_secret %>"
9
+
10
+ url_format "/media/:job/:name"
11
+
12
+ datastore :file,
13
+ <%= hash_key(:root_path) %> Rails.root.join('public/system/dragonfly', Rails.env),
14
+ <%= hash_key(:server_root) %> Rails.root.join('public')
15
+ end
16
+
17
+ # Logger
18
+ Dragonfly.logger = Rails.logger
19
+
20
+ # Mount as middleware
21
+ Rails.application.middleware.use Dragonfly::Middleware
22
+
23
+ # Add model functionality
24
+ if defined?(ActiveRecord::Base)
25
+ ActiveRecord::Base.extend Dragonfly::Model
26
+ ActiveRecord::Base.extend Dragonfly::Model::Validations
27
+ end