dynamic_paperclip 0.0.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 (53) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +150 -0
  3. data/Rakefile +40 -0
  4. data/app/controllers/dynamic_paperclip/attachment_styles_controller.rb +40 -0
  5. data/lib/dynamic_paperclip/attachment.rb +64 -0
  6. data/lib/dynamic_paperclip/config.rb +5 -0
  7. data/lib/dynamic_paperclip/engine.rb +4 -0
  8. data/lib/dynamic_paperclip/errors.rb +18 -0
  9. data/lib/dynamic_paperclip/has_attached_file.rb +47 -0
  10. data/lib/dynamic_paperclip/paperclip_shim.rb +7 -0
  11. data/lib/dynamic_paperclip/url_security.rb +11 -0
  12. data/lib/dynamic_paperclip/version.rb +3 -0
  13. data/lib/dynamic_paperclip.rb +16 -0
  14. data/lib/generators/dynamic_paperclip/install_generator.rb +11 -0
  15. data/test/controllers/attachment_style_controller_test.rb +144 -0
  16. data/test/dummy/Rakefile +7 -0
  17. data/test/dummy/app/controllers/application_controller.rb +3 -0
  18. data/test/dummy/app/models/photo.rb +3 -0
  19. data/test/dummy/config/application.rb +59 -0
  20. data/test/dummy/config/boot.rb +10 -0
  21. data/test/dummy/config/database.yml +25 -0
  22. data/test/dummy/config/environment.rb +5 -0
  23. data/test/dummy/config/environments/test.rb +37 -0
  24. data/test/dummy/config/initializers/dynamic_paperclip.rb +1 -0
  25. data/test/dummy/config/initializers/secret_token.rb +7 -0
  26. data/test/dummy/config/initializers/session_store.rb +8 -0
  27. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  28. data/test/dummy/config/locales/en.yml +5 -0
  29. data/test/dummy/config/routes.rb +2 -0
  30. data/test/dummy/config.ru +4 -0
  31. data/test/dummy/db/development.sqlite3 +0 -0
  32. data/test/dummy/db/migrate/20131102002336_create_photos.rb +9 -0
  33. data/test/dummy/db/schema.rb +24 -0
  34. data/test/dummy/db/test.sqlite3 +0 -0
  35. data/test/dummy/log/development.log +24 -0
  36. data/test/dummy/log/test.log +14470 -0
  37. data/test/dummy/public/404.html +26 -0
  38. data/test/dummy/public/422.html +26 -0
  39. data/test/dummy/public/500.html +25 -0
  40. data/test/dummy/public/favicon.ico +0 -0
  41. data/test/dummy/public/system/photos/images/000/000/001/dynamic_42x42/rails.png +0 -0
  42. data/test/dummy/public/system/photos/images/000/000/001/original/rails.png +0 -0
  43. data/test/dummy/script/rails +6 -0
  44. data/test/dynamic_paperclip_test.rb +7 -0
  45. data/test/fixtures/photos.yml +4 -0
  46. data/test/fixtures/rails.png +0 -0
  47. data/test/generators/install_generator_test.rb +20 -0
  48. data/test/integration/dynamic_attachment_styles_test.rb +26 -0
  49. data/test/test_helper.rb +21 -0
  50. data/test/tmp/config/initializers/dynamic_paperclip.rb +1 -0
  51. data/test/unit/attachment_test.rb +41 -0
  52. data/test/unit/has_attached_file_test.rb +29 -0
  53. metadata +216 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class DynamicPaperclipTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, DynamicPaperclip
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ rails:
2
+ id: 1
3
+ image_file_name: 'rails.png'
4
+ image_content_type: 'image/png'
Binary file
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+ require 'rails/generators/test_case'
3
+ require 'generators/dynamic_paperclip/install_generator.rb'
4
+
5
+ class InstallGeneratorTest < Rails::Generators::TestCase
6
+ tests DynamicPaperclip::InstallGenerator
7
+ destination File.expand_path("../../tmp", __FILE__)
8
+
9
+ setup :prepare_destination
10
+
11
+ test 'generates secret and configures DynamicPaperclip to use it' do
12
+ SecureRandom.expects(:urlsafe_base64).with(50).returns('supersecurestring')
13
+
14
+ run_generator
15
+
16
+ assert_file "config/initializers/dynamic_paperclip.rb", <<-init
17
+ DynamicPaperclip.config.secret = 'supersecurestring'
18
+ init
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ class DynamicAttachmentStylesTest < ActionDispatch::IntegrationTest
4
+ fixtures :photos
5
+
6
+ should 'generate dynamic style and send it to the client' do
7
+ photo = photos(:rails)
8
+
9
+ path_to_dynamic_style = photo.image.path('dynamic_100x100')
10
+
11
+ # This style should not exist yet
12
+ assert !File.exists?(path_to_dynamic_style)
13
+
14
+ # The style should be created right now when we request it
15
+ get photo.image.dynamic_url('100x100')
16
+
17
+ assert_response :success
18
+ assert_equal 'image/png', @response.headers['Content-Type']
19
+
20
+ # Make sure we respond with the style that previously did not exist
21
+ assert FileUtils.compare_stream StringIO.new(@response.body), open(path_to_dynamic_style)
22
+
23
+ # Clean up dynamic style we just created
24
+ FileUtils.rm_rf File.dirname path_to_dynamic_style
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+ require 'shoulda'
7
+ require 'mocha/setup'
8
+
9
+ Rails.backtrace_cleaner.remove_silencers!
10
+
11
+ # Load support files
12
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
13
+
14
+ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
15
+
16
+ # Load fixtures from the engine
17
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
18
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
19
+ end
20
+
21
+ FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
@@ -0,0 +1 @@
1
+ DynamicPaperclip.config.secret = 'supersecurestring'
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ class AttachmentTest < ActiveSupport::TestCase
4
+ fixtures :photos
5
+
6
+ should 'use DynamicPaperclip::Attachment for dynamic attachments' do
7
+ assert Photo.new.image.is_a?(DynamicPaperclip::Attachment)
8
+ end
9
+
10
+ should 'generate correct secure attachment URL when given a style definition' do
11
+ DynamicPaperclip::Config.any_instance.stubs(:secret).returns('abc123')
12
+
13
+ assert_equal "/system/photos/images/000/000/001/dynamic_50x50%2523/rails.png?s=#{Digest::SHA1.hexdigest("abc123dynamic_50x50%23")}", photos(:rails).image.dynamic_url('50x50#')
14
+ end
15
+
16
+ should 'raise error if no secret has been configured' do
17
+ DynamicPaperclip::Config.any_instance.stubs(:secret).returns(nil)
18
+
19
+ assert_raises(DynamicPaperclip::Errors::SecretNotSet) { photos(:rails).image.dynamic_url('50x50#') }
20
+ end
21
+
22
+ should 'include existing dynamic styles in #styles' do
23
+ assert photos(:rails).image.styles.has_key?(:thumb)
24
+ assert photos(:rails).image.styles.has_key?(:dynamic_42x42)
25
+ end
26
+
27
+ should 'only include dynamic styles in #dynamic_styles' do
28
+ assert photos(:rails).image.dynamic_styles.has_key?(:dynamic_42x42)
29
+ assert !photos(:rails).image.dynamic_styles.has_key?(:thumb)
30
+ end
31
+
32
+ should 'add dynamic style to #styles and reprocess it when a dynamic style name is passed to #process_dynamic_style' do
33
+ attachment = photos(:rails).image
34
+
35
+ attachment.expects(:reprocess!).with('dynamic_42x42').once
36
+
37
+ attachment.process_dynamic_style 'dynamic_42x42'
38
+
39
+ assert_equal '42x42', attachment.styles[:dynamic_42x42].geometry
40
+ end
41
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ class Foo; end
4
+
5
+ class HasAttachedFileTest < Test::Unit::TestCase
6
+ should 'glob id_partition' do
7
+ DynamicPaperclip::HasAttachedFile.new Foo, :bar, { url: '/system/foos/bars/:id_partition/:style/:filename' }
8
+
9
+ assert Rails.application.routes.routes.any? do |route|
10
+ route.path.spec == '/system/foos/bars/*id_partition/:style/:filename(.:format)'
11
+ end
12
+ end
13
+
14
+ should 'interpolate :class' do
15
+ DynamicPaperclip::HasAttachedFile.new Foo, :bar, { url: '/system/:class/bars/:id/:style/:filename' }
16
+
17
+ assert Rails.application.routes.routes.any? do |route|
18
+ route.path.spec == '/system/foos/bars/:id/:style/:filename(.:format)'
19
+ end
20
+ end
21
+
22
+ should "use Paperclip's default URL if none is specified" do
23
+ DynamicPaperclip::HasAttachedFile.new Foo, :bar, {}
24
+
25
+ assert Rails.application.routes.routes.any? do |route|
26
+ route.path.spec == '/system/foos/:attachment/*id_partition/:style/:filename(.:format)'
27
+ end
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,216 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dynamic_paperclip
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jim Ryan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>'
20
+ - !ruby/object:Gem::Version
21
+ version: '3.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>'
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: paperclip
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 3.5.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.5.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: sqlite3
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: shoulda
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: mocha
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Let's your views define attachment styles, and delays processing all
95
+ the way to the first user who requests it.
96
+ email:
97
+ - jim@room118solutions.com
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - app/controllers/dynamic_paperclip/attachment_styles_controller.rb
103
+ - lib/dynamic_paperclip/attachment.rb
104
+ - lib/dynamic_paperclip/config.rb
105
+ - lib/dynamic_paperclip/engine.rb
106
+ - lib/dynamic_paperclip/errors.rb
107
+ - lib/dynamic_paperclip/has_attached_file.rb
108
+ - lib/dynamic_paperclip/paperclip_shim.rb
109
+ - lib/dynamic_paperclip/url_security.rb
110
+ - lib/dynamic_paperclip/version.rb
111
+ - lib/dynamic_paperclip.rb
112
+ - lib/generators/dynamic_paperclip/install_generator.rb
113
+ - MIT-LICENSE
114
+ - Rakefile
115
+ - README.md
116
+ - test/controllers/attachment_style_controller_test.rb
117
+ - test/dummy/app/controllers/application_controller.rb
118
+ - test/dummy/app/models/photo.rb
119
+ - test/dummy/config/application.rb
120
+ - test/dummy/config/boot.rb
121
+ - test/dummy/config/database.yml
122
+ - test/dummy/config/environment.rb
123
+ - test/dummy/config/environments/test.rb
124
+ - test/dummy/config/initializers/dynamic_paperclip.rb
125
+ - test/dummy/config/initializers/secret_token.rb
126
+ - test/dummy/config/initializers/session_store.rb
127
+ - test/dummy/config/initializers/wrap_parameters.rb
128
+ - test/dummy/config/locales/en.yml
129
+ - test/dummy/config/routes.rb
130
+ - test/dummy/config.ru
131
+ - test/dummy/db/development.sqlite3
132
+ - test/dummy/db/migrate/20131102002336_create_photos.rb
133
+ - test/dummy/db/schema.rb
134
+ - test/dummy/db/test.sqlite3
135
+ - test/dummy/log/development.log
136
+ - test/dummy/log/test.log
137
+ - test/dummy/public/404.html
138
+ - test/dummy/public/422.html
139
+ - test/dummy/public/500.html
140
+ - test/dummy/public/favicon.ico
141
+ - test/dummy/public/system/photos/images/000/000/001/dynamic_42x42/rails.png
142
+ - test/dummy/public/system/photos/images/000/000/001/original/rails.png
143
+ - test/dummy/Rakefile
144
+ - test/dummy/script/rails
145
+ - test/dynamic_paperclip_test.rb
146
+ - test/fixtures/photos.yml
147
+ - test/fixtures/rails.png
148
+ - test/generators/install_generator_test.rb
149
+ - test/integration/dynamic_attachment_styles_test.rb
150
+ - test/test_helper.rb
151
+ - test/tmp/config/initializers/dynamic_paperclip.rb
152
+ - test/unit/attachment_test.rb
153
+ - test/unit/has_attached_file_test.rb
154
+ homepage: http://github.com/room118solutions/dynamic_paperclip
155
+ licenses: []
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - ! '>='
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ requirements: []
173
+ rubyforge_project:
174
+ rubygems_version: 1.8.25
175
+ signing_key:
176
+ specification_version: 3
177
+ summary: Generate Paperclip attachment styles on the fly
178
+ test_files:
179
+ - test/controllers/attachment_style_controller_test.rb
180
+ - test/dummy/app/controllers/application_controller.rb
181
+ - test/dummy/app/models/photo.rb
182
+ - test/dummy/config/application.rb
183
+ - test/dummy/config/boot.rb
184
+ - test/dummy/config/database.yml
185
+ - test/dummy/config/environment.rb
186
+ - test/dummy/config/environments/test.rb
187
+ - test/dummy/config/initializers/dynamic_paperclip.rb
188
+ - test/dummy/config/initializers/secret_token.rb
189
+ - test/dummy/config/initializers/session_store.rb
190
+ - test/dummy/config/initializers/wrap_parameters.rb
191
+ - test/dummy/config/locales/en.yml
192
+ - test/dummy/config/routes.rb
193
+ - test/dummy/config.ru
194
+ - test/dummy/db/development.sqlite3
195
+ - test/dummy/db/migrate/20131102002336_create_photos.rb
196
+ - test/dummy/db/schema.rb
197
+ - test/dummy/db/test.sqlite3
198
+ - test/dummy/log/development.log
199
+ - test/dummy/log/test.log
200
+ - test/dummy/public/404.html
201
+ - test/dummy/public/422.html
202
+ - test/dummy/public/500.html
203
+ - test/dummy/public/favicon.ico
204
+ - test/dummy/public/system/photos/images/000/000/001/dynamic_42x42/rails.png
205
+ - test/dummy/public/system/photos/images/000/000/001/original/rails.png
206
+ - test/dummy/Rakefile
207
+ - test/dummy/script/rails
208
+ - test/dynamic_paperclip_test.rb
209
+ - test/fixtures/photos.yml
210
+ - test/fixtures/rails.png
211
+ - test/generators/install_generator_test.rb
212
+ - test/integration/dynamic_attachment_styles_test.rb
213
+ - test/test_helper.rb
214
+ - test/tmp/config/initializers/dynamic_paperclip.rb
215
+ - test/unit/attachment_test.rb
216
+ - test/unit/has_attached_file_test.rb