oahu-dragonfly 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. data/.rspec +1 -0
  2. data/.yardopts +24 -0
  3. data/Gemfile +30 -0
  4. data/History.md +323 -0
  5. data/LICENSE +20 -0
  6. data/README.md +88 -0
  7. data/Rakefile +50 -0
  8. data/VERSION +1 -0
  9. data/config.ru +14 -0
  10. data/docs.watchr +1 -0
  11. data/dragonfly.gemspec +297 -0
  12. data/extra_docs/Analysers.md +66 -0
  13. data/extra_docs/Caching.md +23 -0
  14. data/extra_docs/Configuration.md +124 -0
  15. data/extra_docs/Couch.md +49 -0
  16. data/extra_docs/DataStorage.md +153 -0
  17. data/extra_docs/Encoding.md +67 -0
  18. data/extra_docs/GeneralUsage.md +121 -0
  19. data/extra_docs/Generators.md +60 -0
  20. data/extra_docs/Heroku.md +50 -0
  21. data/extra_docs/ImageMagick.md +125 -0
  22. data/extra_docs/Index.md +33 -0
  23. data/extra_docs/MimeTypes.md +40 -0
  24. data/extra_docs/Models.md +272 -0
  25. data/extra_docs/Mongo.md +45 -0
  26. data/extra_docs/Processing.md +77 -0
  27. data/extra_docs/Rack.md +52 -0
  28. data/extra_docs/Rails2.md +57 -0
  29. data/extra_docs/Rails3.md +62 -0
  30. data/extra_docs/Sinatra.md +25 -0
  31. data/extra_docs/URLs.md +169 -0
  32. data/features/images.feature +47 -0
  33. data/features/no_processing.feature +14 -0
  34. data/features/rails_3.0.5.feature +8 -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 +28 -0
  38. data/features/support/env.rb +13 -0
  39. data/features/support/setup.rb +32 -0
  40. data/fixtures/rails_3.0.5/files/app/models/album.rb +7 -0
  41. data/fixtures/rails_3.0.5/files/app/views/albums/new.html.erb +7 -0
  42. data/fixtures/rails_3.0.5/files/app/views/albums/show.html.erb +6 -0
  43. data/fixtures/rails_3.0.5/files/config/initializers/dragonfly.rb +4 -0
  44. data/fixtures/rails_3.0.5/files/features/manage_album_images.feature +38 -0
  45. data/fixtures/rails_3.0.5/files/features/step_definitions/helper_steps.rb +7 -0
  46. data/fixtures/rails_3.0.5/files/features/step_definitions/image_steps.rb +25 -0
  47. data/fixtures/rails_3.0.5/files/features/support/paths.rb +17 -0
  48. data/fixtures/rails_3.0.5/files/features/text_images.feature +7 -0
  49. data/fixtures/rails_3.0.5/template.rb +20 -0
  50. data/irbrc.rb +18 -0
  51. data/lib/dragonfly.rb +55 -0
  52. data/lib/dragonfly/active_model_extensions.rb +13 -0
  53. data/lib/dragonfly/active_model_extensions/attachment.rb +250 -0
  54. data/lib/dragonfly/active_model_extensions/attachment_class_methods.rb +148 -0
  55. data/lib/dragonfly/active_model_extensions/class_methods.rb +95 -0
  56. data/lib/dragonfly/active_model_extensions/instance_methods.rb +28 -0
  57. data/lib/dragonfly/active_model_extensions/validations.rb +41 -0
  58. data/lib/dragonfly/analyser.rb +58 -0
  59. data/lib/dragonfly/analysis/file_command_analyser.rb +32 -0
  60. data/lib/dragonfly/analysis/image_magick_analyser.rb +6 -0
  61. data/lib/dragonfly/app.rb +172 -0
  62. data/lib/dragonfly/config/heroku.rb +19 -0
  63. data/lib/dragonfly/config/image_magick.rb +6 -0
  64. data/lib/dragonfly/config/rails.rb +20 -0
  65. data/lib/dragonfly/configurable.rb +207 -0
  66. data/lib/dragonfly/core_ext/array.rb +7 -0
  67. data/lib/dragonfly/core_ext/hash.rb +7 -0
  68. data/lib/dragonfly/core_ext/object.rb +12 -0
  69. data/lib/dragonfly/core_ext/string.rb +9 -0
  70. data/lib/dragonfly/core_ext/symbol.rb +9 -0
  71. data/lib/dragonfly/data_storage.rb +9 -0
  72. data/lib/dragonfly/data_storage/couch_data_store.rb +64 -0
  73. data/lib/dragonfly/data_storage/file_data_store.rb +141 -0
  74. data/lib/dragonfly/data_storage/mongo_data_store.rb +86 -0
  75. data/lib/dragonfly/data_storage/s3data_store.rb +145 -0
  76. data/lib/dragonfly/encoder.rb +13 -0
  77. data/lib/dragonfly/encoding/image_magick_encoder.rb +6 -0
  78. data/lib/dragonfly/function_manager.rb +71 -0
  79. data/lib/dragonfly/generation/image_magick_generator.rb +6 -0
  80. data/lib/dragonfly/generator.rb +9 -0
  81. data/lib/dragonfly/hash_with_css_style_keys.rb +21 -0
  82. data/lib/dragonfly/image_magick/analyser.rb +51 -0
  83. data/lib/dragonfly/image_magick/config.rb +41 -0
  84. data/lib/dragonfly/image_magick/encoder.rb +57 -0
  85. data/lib/dragonfly/image_magick/generator.rb +145 -0
  86. data/lib/dragonfly/image_magick/processor.rb +99 -0
  87. data/lib/dragonfly/image_magick/utils.rb +72 -0
  88. data/lib/dragonfly/image_magick_utils.rb +4 -0
  89. data/lib/dragonfly/job.rb +451 -0
  90. data/lib/dragonfly/job_builder.rb +39 -0
  91. data/lib/dragonfly/job_definitions.rb +26 -0
  92. data/lib/dragonfly/job_endpoint.rb +15 -0
  93. data/lib/dragonfly/loggable.rb +28 -0
  94. data/lib/dragonfly/middleware.rb +20 -0
  95. data/lib/dragonfly/processing/image_magick_processor.rb +6 -0
  96. data/lib/dragonfly/processor.rb +9 -0
  97. data/lib/dragonfly/rails/images.rb +27 -0
  98. data/lib/dragonfly/response.rb +97 -0
  99. data/lib/dragonfly/routed_endpoint.rb +40 -0
  100. data/lib/dragonfly/serializer.rb +32 -0
  101. data/lib/dragonfly/server.rb +113 -0
  102. data/lib/dragonfly/simple_cache.rb +23 -0
  103. data/lib/dragonfly/temp_object.rb +175 -0
  104. data/lib/dragonfly/url_mapper.rb +78 -0
  105. data/samples/beach.png +0 -0
  106. data/samples/egg.png +0 -0
  107. data/samples/round.gif +0 -0
  108. data/samples/sample.docx +0 -0
  109. data/samples/taj.jpg +0 -0
  110. data/spec/dragonfly/active_model_extensions/model_spec.rb +1426 -0
  111. data/spec/dragonfly/active_model_extensions/spec_helper.rb +91 -0
  112. data/spec/dragonfly/analyser_spec.rb +123 -0
  113. data/spec/dragonfly/analysis/file_command_analyser_spec.rb +48 -0
  114. data/spec/dragonfly/app_spec.rb +135 -0
  115. data/spec/dragonfly/configurable_spec.rb +461 -0
  116. data/spec/dragonfly/core_ext/array_spec.rb +19 -0
  117. data/spec/dragonfly/core_ext/hash_spec.rb +19 -0
  118. data/spec/dragonfly/core_ext/string_spec.rb +17 -0
  119. data/spec/dragonfly/core_ext/symbol_spec.rb +17 -0
  120. data/spec/dragonfly/data_storage/couch_data_store_spec.rb +76 -0
  121. data/spec/dragonfly/data_storage/file_data_store_spec.rb +296 -0
  122. data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +57 -0
  123. data/spec/dragonfly/data_storage/s3_data_store_spec.rb +258 -0
  124. data/spec/dragonfly/data_storage/shared_data_store_examples.rb +77 -0
  125. data/spec/dragonfly/function_manager_spec.rb +154 -0
  126. data/spec/dragonfly/hash_with_css_style_keys_spec.rb +24 -0
  127. data/spec/dragonfly/image_magick/analyser_spec.rb +64 -0
  128. data/spec/dragonfly/image_magick/encoder_spec.rb +41 -0
  129. data/spec/dragonfly/image_magick/generator_spec.rb +172 -0
  130. data/spec/dragonfly/image_magick/processor_spec.rb +233 -0
  131. data/spec/dragonfly/image_magick/utils_spec.rb +18 -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 +173 -0
  135. data/spec/dragonfly/job_spec.rb +1046 -0
  136. data/spec/dragonfly/loggable_spec.rb +80 -0
  137. data/spec/dragonfly/middleware_spec.rb +47 -0
  138. data/spec/dragonfly/routed_endpoint_spec.rb +48 -0
  139. data/spec/dragonfly/serializer_spec.rb +61 -0
  140. data/spec/dragonfly/server_spec.rb +278 -0
  141. data/spec/dragonfly/simple_cache_spec.rb +27 -0
  142. data/spec/dragonfly/temp_object_spec.rb +306 -0
  143. data/spec/dragonfly/url_mapper_spec.rb +126 -0
  144. data/spec/functional/deprecations_spec.rb +51 -0
  145. data/spec/functional/image_magick_app_spec.rb +27 -0
  146. data/spec/functional/model_urls_spec.rb +85 -0
  147. data/spec/functional/remote_on_the_fly_spec.rb +51 -0
  148. data/spec/functional/to_response_spec.rb +31 -0
  149. data/spec/spec_helper.rb +51 -0
  150. data/spec/support/argument_matchers.rb +19 -0
  151. data/spec/support/image_matchers.rb +47 -0
  152. data/spec/support/simple_matchers.rb +53 -0
  153. data/yard/handlers/configurable_attr_handler.rb +38 -0
  154. data/yard/setup.rb +15 -0
  155. data/yard/templates/default/fulldoc/html/css/common.css +107 -0
  156. data/yard/templates/default/layout/html/layout.erb +89 -0
  157. data/yard/templates/default/module/html/configuration_summary.erb +31 -0
  158. data/yard/templates/default/module/setup.rb +17 -0
  159. metadata +544 -0
@@ -0,0 +1,47 @@
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 we are using the app for images
7
+ Given a stored image "beach.png" with dimensions 200x100
8
+
9
+ Scenario: Go to url for original
10
+ When I go to the url for "beach.png", with format 'png'
11
+ Then the response should be OK
12
+ And the response should have mime-type 'image/png'
13
+ And the image should have width '200'
14
+ And the image should have height '100'
15
+ And the image should have format 'png'
16
+
17
+ Scenario: Go to url for changed format version
18
+ When I go to the url for "beach.png", with format 'gif'
19
+ Then the response should be OK
20
+ And the response should have mime-type 'image/gif'
21
+ And the image should have width '200'
22
+ And the image should have height '100'
23
+ And the image should have format 'gif'
24
+
25
+ Scenario: Go to url for soft resized version
26
+ When I go to the url for "beach.png", with format 'png' and resize geometry '100x150'
27
+ Then the response should be OK
28
+ And the response should have mime-type 'image/png'
29
+ And the image should have width '100'
30
+ And the image should have height '50'
31
+ And the image should have format 'png'
32
+
33
+ Scenario: Go to url for hard resized version
34
+ When I go to the url for "beach.png", with format 'png' and resize geometry '100x150!'
35
+ Then the response should be OK
36
+ And the response should have mime-type 'image/png'
37
+ And the image should have width '100'
38
+ And the image should have height '150'
39
+ And the image should have format 'png'
40
+
41
+ Scenario: use a parameters shortcut
42
+ When I go to the url for "beach.png", with shortcut '100x150!'
43
+ Then the response should be OK
44
+ And the response should have mime-type 'image/png'
45
+ And the image should have width '100'
46
+ And the image should have height '150'
47
+ And the image should have format 'png'
@@ -0,0 +1,14 @@
1
+ Feature: winner uses dragonfly to serve different kinds of files
2
+ In order to be a winner
3
+ As a potential loser
4
+ I want to be a winner
5
+
6
+ Background:
7
+ Given we are using the app for files
8
+
9
+ Scenario: Go to url for original, without extension
10
+ Given a stored file "sample.docx"
11
+ When I go to the url for "sample.docx"
12
+ Then the response should be OK
13
+ And the response should have mime-type 'application/zip'
14
+ And the response should have the same content as the file "sample.docx"
@@ -0,0 +1,8 @@
1
+ Feature: champion uses dragonfly in his Rails 3.0.5 application
2
+ In order to be a champion
3
+ A user uses dragonfly in his Rails 3.0.5 application
4
+
5
+ Scenario: Set up dragonfly using initializer
6
+ Given a Rails 3.0.5 application set up for using dragonfly
7
+ Then the manage_album_images cucumber features in my Rails 3.0.5 app should pass
8
+ And the text_images cucumber features in my Rails 3.0.5 app should pass
@@ -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,66 @@
1
+ require 'tempfile'
2
+
3
+ Given /^we are using the app for (\w+)$/ do |app_name|
4
+ $app = Dragonfly[app_name.to_sym]
5
+ end
6
+
7
+ Given /^a stored file "(.+?)"$/ do |name|
8
+ file = File.new(File.dirname(__FILE__) + "/../../samples/#{name}")
9
+ uid = $app.store(file)
10
+ TEMP_FILES[name] = uid
11
+ end
12
+
13
+ Given /^a stored image "(.+?)" with dimensions (\d+)x(\d+)$/ do |name, width, height|
14
+ tempfile = Tempfile.new(name)
15
+ `convert -resize #{width}x#{height}! #{SAMPLE_IMAGE_PATH} #{tempfile.path}`
16
+ uid = $app.store(tempfile)
17
+ TEMP_FILES[name] = uid
18
+ end
19
+
20
+ When /^I go to the url for "(.+?)"$/ do |name|
21
+ uid = TEMP_FILES[name]
22
+ make_request $app.fetch(uid)
23
+ end
24
+
25
+ When /^I go to the url for "(.+?)", with format '([^']+?)'$/ do |name, format|
26
+ uid = TEMP_FILES[name]
27
+ make_request $app.fetch(uid).encode(format)
28
+ end
29
+
30
+ When /^I go to the url for "(.+?)", with format '(.+?)' and resize geometry '(.+?)'$/ do |name, format, geometry|
31
+ uid = TEMP_FILES[name]
32
+ make_request $app.fetch(uid).process(:resize, geometry).encode(format)
33
+ end
34
+
35
+ When /^I go to the url for "(.+?)", with shortcut '([^']+?)'$/ do |name, geometry|
36
+ uid = TEMP_FILES[name]
37
+ make_request $app.fetch(uid).thumb(geometry)
38
+ end
39
+
40
+ Then "the response should be OK" do
41
+ @response.status.should == 200
42
+ end
43
+
44
+ Then /the response should have mime-type '(.+?)'/ do |mime_type|
45
+ @response.headers['Content-Type'].should == mime_type
46
+ end
47
+
48
+ Then /^the image should have width '(.+?)'$/ do |width|
49
+ @response.body.should have_width(width.to_i)
50
+ end
51
+
52
+ Then /^the image should have height '(.+?)'$/ do |height|
53
+ @response.body.should have_height(height.to_i)
54
+ end
55
+
56
+ Then /^the image should have format '(.+?)'$/ do |format|
57
+ @response.body.should have_format(format)
58
+ end
59
+
60
+ Then /^the response should have the same content as the file "([^\"]*)"$/ do |name|
61
+ if RUBY_VERSION =~ /^1\.8/
62
+ @response.body.should == $app.fetch(TEMP_FILES[name]).data
63
+ else
64
+ @response.body.force_encoding('BINARY').should == $app.fetch(TEMP_FILES[name]).data.force_encoding('BINARY')
65
+ end
66
+ end
@@ -0,0 +1,28 @@
1
+ RAILS_APP_NAME = 'tmp_app'
2
+ FIXTURES_PATH = ROOT_PATH + "/fixtures"
3
+
4
+ def fixture_path(version)
5
+ "#{FIXTURES_PATH}/rails_#{version}"
6
+ end
7
+
8
+ def app_path(version)
9
+ "#{fixture_path(version)}/#{RAILS_APP_NAME}"
10
+ end
11
+
12
+ ##############################################################################
13
+
14
+ Given "a Rails 3.0.5 application set up for using dragonfly" do
15
+ raise "Problem setting up Rails app" unless `
16
+ cd #{fixture_path('3.0.5')} &&
17
+ rm -rf #{RAILS_APP_NAME} &&
18
+ bundle exec rails new #{RAILS_APP_NAME} -m template.rb`
19
+ end
20
+
21
+ Then /^the (.+) cucumber features in my Rails (.+) app should pass$/ do |filename, version|
22
+ puts "\n*** RUNNING FEATURES IN THE RAILS APP... ***\n"
23
+ path = File.join(fixture_path(version), RAILS_APP_NAME)
24
+ `cd #{path} && RAILS_ENV=cucumber rake db:migrate`
25
+ features_passed = system "cd #{path} && cucumber features/#{filename}.feature"
26
+ puts "\n*** FINISHED RUNNING FEATURES IN THE RAILS APP ***\n"
27
+ raise "Features failed" unless features_passed
28
+ end
@@ -0,0 +1,13 @@
1
+ require 'bundler'
2
+ begin
3
+ Bundler.setup(:default, :cucumber)
4
+ rescue Bundler::BundlerError => e
5
+ $stderr.puts e.message
6
+ $stderr.puts "Run `bundle install` to install missing gems"
7
+ exit e.status_code
8
+ end
9
+
10
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
11
+ require 'dragonfly'
12
+
13
+ require 'rspec/expectations'
@@ -0,0 +1,32 @@
1
+ ROOT_PATH = File.expand_path(File.dirname(__FILE__) + "/../..")
2
+
3
+ require ROOT_PATH + '/spec/support/image_matchers.rb'
4
+
5
+ # A hash of <name for reference> => <dragonfly uid> pairs
6
+ TEMP_FILES = {}
7
+
8
+ Dragonfly[:images].configure_with(:imagemagick)
9
+ Dragonfly[:files].configure do |c|
10
+ c.analyser.register(Dragonfly::Analysis::FileCommandAnalyser)
11
+ end
12
+
13
+ SAMPLE_IMAGE_PATH = ROOT_PATH + '/samples/beach.png'
14
+
15
+ Before do
16
+ # Remove temporary images
17
+ TEMP_FILES.each do |name, uid|
18
+ $app.datastore.destroy(uid)
19
+ TEMP_FILES.delete(name)
20
+ end
21
+ end
22
+
23
+ module MyHelpers
24
+
25
+ def make_request(job)
26
+ request = Rack::MockRequest.new($app)
27
+ @response = request.get(job.url)
28
+ end
29
+
30
+ end
31
+
32
+ World(MyHelpers)
@@ -0,0 +1,7 @@
1
+ class Album < ActiveRecord::Base
2
+ validates_property :format, :of => :cover_image, :in => [:jpg, :png, :gif]
3
+ validates_length_of :name, :in => 0..5
4
+ image_accessor :cover_image do
5
+ retain
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ <%= form_for @album, :html => {:multipart => true} do |f| %>
2
+ <%= @album.errors.full_messages %>
3
+ <%= f.text_field :name %>
4
+ <%= f.file_field :cover_image %>
5
+ <%= f.hidden_field :retained_cover_image %>
6
+ <%= f.submit :value => 'Create' %>
7
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <%= flash[:notice] %>
2
+ <%= @album.name %>
3
+ Look at this cover image!
4
+ <%= image_tag @album.cover_image.thumb('200x100!').url %>
5
+ <%= image_tag @album.cover_image.remote_url %>
6
+ <%= link_to 'Index', albums_path %>
@@ -0,0 +1,4 @@
1
+ # This is a hack to get the generated rails apps to use the version of dragonfly being worked on.
2
+ $:.unshift(File.expand_path(File.dirname(__FILE__)+'/../../../../../lib'))
3
+ require 'dragonfly/rails/images'
4
+
@@ -0,0 +1,38 @@
1
+ Feature: champion adds cover images to his albums
2
+ In order to be a champion
3
+ A user adds an image to his album
4
+
5
+ Scenario: Add and view image
6
+ When I go to the new album page
7
+ And I attach the file "../../../samples/beach.png" to "album[cover_image]"
8
+ And I press "Create"
9
+ Then I should see "successfully created"
10
+ And I should see "Look at this cover image!"
11
+ When I look at the generated image
12
+ Then I should see a PNG image of size 200x100
13
+
14
+ Scenario: validation fails
15
+ When I go to the new album page
16
+ And I attach the file "../../../samples/sample.docx" to "album[cover_image]"
17
+ And I press "Create"
18
+ Then I should see "Cover image format is incorrect. It needs to be one of 'jpg', 'png', 'gif', but was 'docx'"
19
+
20
+ Scenario: other validation fails
21
+ When I go to the new album page
22
+ And I fill in "album[name]" with "too long"
23
+ And I attach the file "../../../samples/beach.png" to "album[cover_image]"
24
+ And I press "Create"
25
+ Then I should see "Name is too long"
26
+ When I fill in "album[name]" with "short"
27
+ And I press "Create"
28
+ Then I should see "successfully created"
29
+ And I should see "short"
30
+ And I should see "Look at this cover image!"
31
+ When I look at the generated image
32
+ Then I should see a PNG image of size 200x100
33
+
34
+ Scenario: view remote image
35
+ Given an album "good" with attached file "beach.png"
36
+ When I go to the page for album "good"
37
+ And I look at the original image
38
+ Then I should see a PNG image of size 280x355
@@ -0,0 +1,7 @@
1
+ Then "show me the html" do
2
+ puts page.body
3
+ end
4
+
5
+ Then 'show "(.*)"' do |code|
6
+ eval "puts #{code}"
7
+ end
@@ -0,0 +1,25 @@
1
+ Given /^an album "(.+)" with attached file "(.+)"$/ do |name, filename|
2
+ Album.create! :name => name, :cover_image => Rails.root.join('../../../samples', filename)
3
+ end
4
+
5
+ When /^I look at the generated image$/ do
6
+ page.body =~ %r{src="(/media[^"]+?)"}
7
+ url = $1
8
+ visit(url)
9
+ end
10
+
11
+ When /^I look at the original image$/ do
12
+ page.body =~ %r{src="(/system[^"]+?)"}
13
+ url = $1
14
+ visit(url)
15
+ end
16
+
17
+ Then /^I should see a (.+) image of size (.+)$/ do |format, size|
18
+ tempfile = Tempfile.new('wicked')
19
+ page.body.force_encoding('UTF-8').encode! if page.body.respond_to?(:force_encoding) # For some reason need this on Ruby 1.9.2
20
+ tempfile.write page.body
21
+ tempfile.close
22
+ output = `identify #{tempfile.path}`.split(' ')
23
+ output[1].should == format
24
+ output[2].should == size
25
+ end
@@ -0,0 +1,17 @@
1
+ module NavigationHelpers
2
+ def path_to(page_name)
3
+ case page_name
4
+ when "the new album page"
5
+ '/albums/new'
6
+ when /^the page for album "(.+)"$/
7
+ album_path(Album.find_by_name($1))
8
+ when /^the image for text "(.+)", size "(.+)"$/
9
+ "/text/#{$1}/#{$2}"
10
+ else
11
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
12
+ "Now, go and add a mapping in #{__FILE__}"
13
+ end
14
+ end
15
+ end
16
+
17
+ World(NavigationHelpers)
@@ -0,0 +1,7 @@
1
+ Feature: champion adds text images to his app
2
+ In order to be a champion
3
+ A user adds text images to his app
4
+
5
+ Scenario: View text image
6
+ When I go to the image for text "Hello", size "300x150!"
7
+ Then I should see a PNG image of size 300x150
@@ -0,0 +1,20 @@
1
+ gem 'rack-cache', :require => 'rack/cache'
2
+
3
+ gem 'capybara'
4
+ gem 'cucumber-rails'
5
+ gem 'cucumber', '0.8.5'
6
+
7
+ generate 'cucumber:install'
8
+
9
+ generate 'scaffold albums cover_image_uid:string name:string'
10
+ rake 'db:migrate'
11
+
12
+ # Copy over all files from the template dir
13
+ files_dir = File.expand_path(File.dirname(__FILE__) + '/files')
14
+ run "cp -r #{files_dir}/** ."
15
+
16
+ route <<ROUTES
17
+ match '/text/:text/:size' => Dragonfly[:images].endpoint{|params, app|
18
+ app.generate(:text, params[:text]).thumb(params[:size])
19
+ }
20
+ ROUTES
@@ -0,0 +1,18 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ $:.unshift(File.expand_path('../lib', __FILE__))
4
+ require 'dragonfly'
5
+ APP = Dragonfly[:images].configure_with(:imagemagick)
6
+
7
+ # available_uids = `find #{APP.datastore.root_path} ! -type d`.split("\n").map do |file|
8
+ # file.sub("#{APP.datastore.root_path}/", '')
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 constants:\n"
17
+ puts "APP"
18
+ puts
@@ -0,0 +1,55 @@
1
+ # AUTOLOAD EVERYTHING IN THE DRAGONFLY DIRECTORY TREE
2
+
3
+ # The convention is that dirs are modules
4
+ # so declare them here and autoload any modules/classes inside them
5
+ # All paths here are absolute
6
+ def camelize(path)
7
+ # e.g. 'test/this_one' => Test::ThisOne
8
+ "#{path}".
9
+ chomp('/').
10
+ gsub('/','::').
11
+ gsub(/([^a-z])(\w)/){ "#{$1}#{$2.upcase}" }.
12
+ gsub('_','').
13
+ sub(/^(\w)/){ $1.upcase }
14
+ end
15
+ def autoload_files_in_dir(path, namespace)
16
+ # Define the module
17
+ eval("module #{namespace}; end")
18
+ # Autoload modules/classes in that module
19
+ Dir.glob("#{path}/*.rb").each do |file|
20
+ file = File.expand_path(file)
21
+ sub_const_name = camelize( File.basename(file, '.rb') )
22
+ eval("#{namespace}.autoload('#{sub_const_name}', '#{file}')")
23
+ end
24
+ # Recurse on subdirectories
25
+ Dir.glob("#{path}/*/").each do |dir|
26
+ sub_namespace = camelize( File.basename(dir) )
27
+ autoload_files_in_dir(dir, "#{namespace}::#{sub_namespace}")
28
+ end
29
+ end
30
+
31
+ autoload_files_in_dir("#{File.dirname(__FILE__)}/dragonfly", 'Dragonfly')
32
+
33
+ require 'dragonfly/core_ext/object'
34
+ require 'dragonfly/core_ext/string'
35
+ require 'dragonfly/core_ext/symbol'
36
+ require 'dragonfly/core_ext/array'
37
+ require 'dragonfly/core_ext/hash'
38
+
39
+ module Dragonfly
40
+ class << self
41
+
42
+ def [](*args)
43
+ App[*args]
44
+ end
45
+
46
+ # Register saved configurations so we can do e.g.
47
+ # Dragonfly[:my_app].configure_with(:image_magick)
48
+ App.register_configuration(:imagemagick){ ImageMagick::Config }
49
+ App.register_configuration(:image_magick){ ImageMagick::Config }
50
+ App.register_configuration(:rails){ Config::Rails }
51
+ App.register_configuration(:s3){ Config::S3 }
52
+ App.register_configuration(:heroku){ Config::Heroku }
53
+
54
+ end
55
+ end