another_uploader 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 (178) hide show
  1. data/MIT-LICENSE +21 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/images/another_uploader/doc.gif +0 -0
  5. data/app/assets/images/another_uploader/mp3.gif +0 -0
  6. data/app/assets/images/another_uploader/none.gif +0 -0
  7. data/app/assets/images/another_uploader/pdf.gif +0 -0
  8. data/app/assets/images/another_uploader/spreadsheet.gif +0 -0
  9. data/app/assets/images/another_uploader/text.gif +0 -0
  10. data/app/assets/javascripts/another_uploader/index.js +5 -0
  11. data/app/assets/javascripts/uploads.js +2 -0
  12. data/app/assets/stylesheets/another_uploader/index.css +5 -0
  13. data/app/assets/stylesheets/uploads.css +4 -0
  14. data/app/controllers/uploads_controller.rb +7 -0
  15. data/app/helpers/uploads_helper.rb +2 -0
  16. data/app/models/upload.rb +145 -0
  17. data/app/views/uploads/destroy.html.erb +2 -0
  18. data/app/views/uploads/uploadify.html.erb +2 -0
  19. data/config/routes.rb +6 -0
  20. data/db/migrate/20121115043827_create_uploads.rb +31 -0
  21. data/lib/another_uploader.rb +14 -0
  22. data/lib/another_uploader/configuration.rb +36 -0
  23. data/lib/another_uploader/engine.rb +4 -0
  24. data/lib/another_uploader/icons.rb +23 -0
  25. data/lib/another_uploader/image_processing.rb +29 -0
  26. data/lib/another_uploader/mime_type_getters.rb +17 -0
  27. data/lib/another_uploader/mime_type_groups.rb +17 -0
  28. data/lib/another_uploader/transliteration.rb +22 -0
  29. data/lib/another_uploader/version.rb +3 -0
  30. data/lib/tasks/another_uploader_tasks.rake +4 -0
  31. data/test/another_uploader_test.rb +7 -0
  32. data/test/dummy/README.rdoc +261 -0
  33. data/test/dummy/Rakefile +7 -0
  34. data/test/dummy/app/assets/javascripts/application.js +17 -0
  35. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  36. data/test/dummy/app/controllers/application_controller.rb +6 -0
  37. data/test/dummy/app/controllers/main_controller.rb +4 -0
  38. data/test/dummy/app/helpers/application_helper.rb +2 -0
  39. data/test/dummy/app/models/user.rb +6 -0
  40. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  41. data/test/dummy/app/views/main/index.html.erb +2 -0
  42. data/test/dummy/config.ru +4 -0
  43. data/test/dummy/config/application.rb +59 -0
  44. data/test/dummy/config/boot.rb +10 -0
  45. data/test/dummy/config/database.yml +25 -0
  46. data/test/dummy/config/environment.rb +5 -0
  47. data/test/dummy/config/environments/development.rb +37 -0
  48. data/test/dummy/config/environments/production.rb +67 -0
  49. data/test/dummy/config/environments/test.rb +37 -0
  50. data/test/dummy/config/initializers/another_uploader.rb +10 -0
  51. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  52. data/test/dummy/config/initializers/inflections.rb +15 -0
  53. data/test/dummy/config/initializers/mime_types.rb +5 -0
  54. data/test/dummy/config/initializers/secret_token.rb +7 -0
  55. data/test/dummy/config/initializers/session_store.rb +8 -0
  56. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  57. data/test/dummy/config/locales/en.yml +5 -0
  58. data/test/dummy/config/routes.rb +61 -0
  59. data/test/dummy/config/s3.yml +10 -0
  60. data/test/dummy/config/s3.yml.example +21 -0
  61. data/test/dummy/db/development.sqlite3 +0 -0
  62. data/test/dummy/db/migrate/20121115045546_create_users.easy_rails_authentication_engine.rb +12 -0
  63. data/test/dummy/db/migrate/20121115045547_create_password_recoveries.easy_rails_authentication_engine.rb +13 -0
  64. data/test/dummy/db/migrate/20121115045630_create_uploads.another_uploader_engine.rb +32 -0
  65. data/test/dummy/db/schema.rb +63 -0
  66. data/test/dummy/db/test.sqlite3 +0 -0
  67. data/test/dummy/log/development.log +53979 -0
  68. data/test/dummy/log/test.log +139363 -0
  69. data/test/dummy/public/404.html +26 -0
  70. data/test/dummy/public/422.html +26 -0
  71. data/test/dummy/public/500.html +25 -0
  72. data/test/dummy/public/favicon.ico +0 -0
  73. data/test/dummy/script/rails +6 -0
  74. data/test/dummy/test/functional/main_controller_test.rb +9 -0
  75. data/test/dummy/tmp/cache/assets/C1D/CB0/sprockets%2F1368a6c195444308f76a970b1127660b +0 -0
  76. data/test/dummy/tmp/cache/assets/C56/660/sprockets%2F9606c93013df9ec75112d323643686a9 +0 -0
  77. data/test/dummy/tmp/cache/assets/C64/2A0/sprockets%2F779fa4794d76f3083f442743352e247c +0 -0
  78. data/test/dummy/tmp/cache/assets/C80/910/sprockets%2F1da2794871f7097ea5246354ae85300b +0 -0
  79. data/test/dummy/tmp/cache/assets/C82/240/sprockets%2F625dc2916f00654e5351b054afc95678 +0 -0
  80. data/test/dummy/tmp/cache/assets/C9F/DD0/sprockets%2F1801bd89c75539c636659918883e8dea +0 -0
  81. data/test/dummy/tmp/cache/assets/CA9/ED0/sprockets%2F845117661057731bd942dc61ddda24f3 +0 -0
  82. data/test/dummy/tmp/cache/assets/CB1/030/sprockets%2F330d8361296be2294bcf4e8282473ab7 +0 -0
  83. data/test/dummy/tmp/cache/assets/CBD/D80/sprockets%2F65641a234ede6ff88b006594b1869b29 +0 -0
  84. data/test/dummy/tmp/cache/assets/CC1/4E0/sprockets%2F53d9bd83335f4bb9561087645769c5da +0 -0
  85. data/test/dummy/tmp/cache/assets/CD6/C50/sprockets%2Fd30f21629ea47cf66530fa0e347272b4 +0 -0
  86. data/test/dummy/tmp/cache/assets/CD7/B40/sprockets%2F21b71f8ea0f566175a551816b6f530cb +0 -0
  87. data/test/dummy/tmp/cache/assets/CD7/EE0/sprockets%2Fd677061accd85058216607c208b7a2bf +0 -0
  88. data/test/dummy/tmp/cache/assets/CD8/000/sprockets%2F12d162f45ae0036e177e4a67b926a92d +0 -0
  89. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  90. data/test/dummy/tmp/cache/assets/CD9/990/sprockets%2Fba64ae414cc39805ce695e2c40162807 +0 -0
  91. data/test/dummy/tmp/cache/assets/CDA/700/sprockets%2F2437e594d81db9b2b87b24411630dba8 +0 -0
  92. data/test/dummy/tmp/cache/assets/CE1/340/sprockets%2F0573a62b0251cc18c80949a9c9fe34d7 +0 -0
  93. data/test/dummy/tmp/cache/assets/CE1/C30/sprockets%2F6a2c53cf042c621806c77ada86288c77 +0 -0
  94. data/test/dummy/tmp/cache/assets/CE6/1A0/sprockets%2F41ce96883326a6a9313b408cdf80df74 +0 -0
  95. data/test/dummy/tmp/cache/assets/CE7/F50/sprockets%2F5118ca4d54388e2cc84e90c95f36048a +0 -0
  96. data/test/dummy/tmp/cache/assets/CED/B00/sprockets%2Fbde328b963290de060b7677fd155695e +0 -0
  97. data/test/dummy/tmp/cache/assets/CF2/4B0/sprockets%2Fb95901745337c00037e00a7f0cacaa3c +0 -0
  98. data/test/dummy/tmp/cache/assets/CF9/960/sprockets%2F69590f47d597a9ec070b6c0bc28e9876 +0 -0
  99. data/test/dummy/tmp/cache/assets/CFE/EE0/sprockets%2F1100a030f19d781dc98eb066ab6075ec +0 -0
  100. data/test/dummy/tmp/cache/assets/D00/D30/sprockets%2F08dc27f9a9ed399356a91d4069889c5d +0 -0
  101. data/test/dummy/tmp/cache/assets/D0A/760/sprockets%2F28d26ec78714eaf45198b0abab175117 +0 -0
  102. data/test/dummy/tmp/cache/assets/D0E/E90/sprockets%2Fa982198515b54c1f58f8aae30830f0ea +0 -0
  103. data/test/dummy/tmp/cache/assets/D12/7E0/sprockets%2F35c1a2211d6547b7c7ffa5ed813d7938 +0 -0
  104. data/test/dummy/tmp/cache/assets/D18/610/sprockets%2F66cc7f1b171e5729d4279bac1676de53 +0 -0
  105. data/test/dummy/tmp/cache/assets/D1A/AC0/sprockets%2F045847ba35c0701c01fa0b0ecf73d11a +0 -0
  106. data/test/dummy/tmp/cache/assets/D1B/810/sprockets%2F76112c598c956c07c4f4e91f6ee3ba80 +0 -0
  107. data/test/dummy/tmp/cache/assets/D1E/580/sprockets%2F5f965913df7a03e307dfd9326f9b06b7 +0 -0
  108. data/test/dummy/tmp/cache/assets/D21/CE0/sprockets%2F85c75ccf1618c6e9214374fa80ff6a78 +0 -0
  109. data/test/dummy/tmp/cache/assets/D23/8A0/sprockets%2F6175cb8fa517f52908739e3b478ef4bd +0 -0
  110. data/test/dummy/tmp/cache/assets/D24/DF0/sprockets%2F205e10fc11b2c5ed047b48e7d13ca262 +0 -0
  111. data/test/dummy/tmp/cache/assets/D25/860/sprockets%2Ff8260dc5f64465554e619b1e8d8e5fb7 +0 -0
  112. data/test/dummy/tmp/cache/assets/D27/BB0/sprockets%2F1ce3f0373575afde958376fec61658e8 +0 -0
  113. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  114. data/test/dummy/tmp/cache/assets/D35/000/sprockets%2F26017814dcf3891ad5be86ec7005a0ae +0 -0
  115. data/test/dummy/tmp/cache/assets/D38/250/sprockets%2F80644f3f31455068a51deebec0aa7a86 +0 -0
  116. data/test/dummy/tmp/cache/assets/D41/DF0/sprockets%2F86004b9b60de26aa7d87a1ff8b828f21 +0 -0
  117. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  118. data/test/dummy/tmp/cache/assets/D4F/1A0/sprockets%2F7901d59d8f722a5ebfff972429bb2d45 +0 -0
  119. data/test/dummy/tmp/cache/assets/D4F/4A0/sprockets%2F4fcb3c5126d2489feb99578dfa0c8507 +0 -0
  120. data/test/dummy/tmp/cache/assets/D52/E40/sprockets%2F04b1950fad18f3bcf64d30120da8b40b +0 -0
  121. data/test/dummy/tmp/cache/assets/D52/FD0/sprockets%2F19d7b68fb60b78d7519fc64d3c9a05f6 +0 -0
  122. data/test/dummy/tmp/cache/assets/D59/F30/sprockets%2F9dff7df99c759433823d4030cea998ac +0 -0
  123. data/test/dummy/tmp/cache/assets/D5A/850/sprockets%2F4015515d4be88de02aa43ff1b0abb594 +0 -0
  124. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  125. data/test/dummy/tmp/cache/assets/D5C/030/sprockets%2F85440ce896b9da860fd37bb1e58f978e +0 -0
  126. data/test/dummy/tmp/cache/assets/D65/DA0/sprockets%2Fd0515dae6856f8da160c5d3050aa8b8e +0 -0
  127. data/test/dummy/tmp/cache/assets/D68/CD0/sprockets%2F9d829309524cfa22a0bdddf62c817d2a +0 -0
  128. data/test/dummy/tmp/cache/assets/D6B/A10/sprockets%2Fe2054cdbee145cdb51eb971863f54c80 +0 -0
  129. data/test/dummy/tmp/cache/assets/D6C/4B0/sprockets%2F543f257da84ce9914a414c3ffc1ad5a5 +0 -0
  130. data/test/dummy/tmp/cache/assets/D6C/AC0/sprockets%2Ffc095dd6183c1fcdf793351aa0b9057c +0 -0
  131. data/test/dummy/tmp/cache/assets/D71/520/sprockets%2Fc8e0327abdc946f27d2a91311ddd868e +0 -0
  132. data/test/dummy/tmp/cache/assets/D72/B90/sprockets%2Fc267891912fff9a3fa22ae346ba4f82b +0 -0
  133. data/test/dummy/tmp/cache/assets/D7C/E70/sprockets%2F9cae95be6892da1bf96c244c0d58069c +0 -0
  134. data/test/dummy/tmp/cache/assets/D7D/750/sprockets%2F8755c9ddd1217ce9ab854a429c4f7e3d +0 -0
  135. data/test/dummy/tmp/cache/assets/D91/D00/sprockets%2Fc1e1b10c6a5879ae7a2a875b0dbd357a +0 -0
  136. data/test/dummy/tmp/cache/assets/D95/0C0/sprockets%2Ffce9642718191a3112260ccbc8cafefc +0 -0
  137. data/test/dummy/tmp/cache/assets/D9A/DE0/sprockets%2Fcd78fb20bde75dba85a0c62b4838542c +0 -0
  138. data/test/dummy/tmp/cache/assets/DBB/440/sprockets%2Fe68195d6a29fe5fd90ded7559fccb429 +0 -0
  139. data/test/dummy/tmp/cache/assets/DBB/A30/sprockets%2Fe70dc841dca9ceee2e413a1661ed0b03 +0 -0
  140. data/test/dummy/tmp/cache/assets/DBF/3A0/sprockets%2F3c82ed0abb7057c1e728ac0f2ca41df9 +0 -0
  141. data/test/dummy/tmp/cache/assets/DC0/490/sprockets%2F5e0aebe091b8cea050c89d4ea19e080b +0 -0
  142. data/test/dummy/tmp/cache/assets/DC9/380/sprockets%2F2aaba93d71e5b9e178b0ce2df59eb603 +0 -0
  143. data/test/dummy/tmp/cache/assets/DCC/450/sprockets%2Fb3392d6eaf0e4cc318e19b6beb59b33f +0 -0
  144. data/test/dummy/tmp/cache/assets/DD0/2F0/sprockets%2F2cb2d409afda49a014f5bfef65f75c67 +0 -0
  145. data/test/dummy/tmp/cache/assets/DD9/030/sprockets%2F22d64f8febf6fc918b3a9ff6ad40441f +0 -0
  146. data/test/dummy/tmp/cache/assets/DDA/760/sprockets%2F31d55e4ecf03fbd5d71d5d7fd6d6d586 +0 -0
  147. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  148. data/test/dummy/tmp/cache/assets/DDC/630/sprockets%2Fd23e663fbbe6dfdb81e7a5d86d87b507 +0 -0
  149. data/test/dummy/tmp/cache/assets/DEA/760/sprockets%2Fcf1c5cfb9b1239a5b3dee52a3dd5001e +0 -0
  150. data/test/dummy/tmp/cache/assets/DED/500/sprockets%2F6b8b0740ec26f31fe0bcaa5ecd1e75a4 +0 -0
  151. data/test/dummy/tmp/cache/assets/DF1/B80/sprockets%2Fae7705cefbeb7308c73ba3a7a42c6a1f +0 -0
  152. data/test/dummy/tmp/cache/assets/DF6/DE0/sprockets%2Fd4eb25c8857c4c413cacaf6e7a0ccd26 +0 -0
  153. data/test/dummy/tmp/cache/assets/DF8/1A0/sprockets%2F0f9b45b1ca394c1aedc6febec735820f +0 -0
  154. data/test/dummy/tmp/cache/assets/DFE/980/sprockets%2F3493099ba61bb24ebec3f59cddf08ead +0 -0
  155. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  156. data/test/dummy/tmp/cache/assets/E29/000/sprockets%2F6d13db8fbbd48dbce7392e43ac0ecb46 +0 -0
  157. data/test/dummy/tmp/cache/assets/E31/930/sprockets%2Ff68b89fd7200b23eccd9b1ba9afff3d3 +0 -0
  158. data/test/dummy/tmp/cache/assets/E79/780/sprockets%2Fd7e2d10be0ca0abfe06ecab1d3868dfd +0 -0
  159. data/test/fixtures/files/1000Hz-5sec.mp3 +0 -0
  160. data/test/fixtures/files/lorem-ipsum +7 -0
  161. data/test/fixtures/files/lorem-ipsum.jpg +0 -0
  162. data/test/fixtures/files/lorem-ipsum.ods +0 -0
  163. data/test/fixtures/files/lorem-ipsum.odt +0 -0
  164. data/test/fixtures/files/lorem-ipsum.pdf +0 -0
  165. data/test/fixtures/files/lorem-ipsum.txt +7 -0
  166. data/test/fixtures/users.yml +10 -0
  167. data/test/functional/uploads_controller_test.rb +14 -0
  168. data/test/integration/navigation_test.rb +10 -0
  169. data/test/test_helper.rb +52 -0
  170. data/test/unit/file_storage_test.rb +157 -0
  171. data/test/unit/helpers/uploads_helper_test.rb +4 -0
  172. data/test/unit/icon_and_thumb_test.rb +36 -0
  173. data/test/unit/mime_types_test.rb +74 -0
  174. data/test/unit/name_test.rb +51 -0
  175. data/test/unit/scope_test.rb +162 -0
  176. data/test/unit/upload_test.rb +7 -0
  177. data/test/upload_test_helper.rb +52 -0
  178. metadata +486 -0
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2009 Justin Ball
2
+ Copyright (c) 2012 Justin Ball, Isaac Betesh
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ = AnotherUploader
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'AnotherUploader'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -0,0 +1,5 @@
1
+ //= require jquery
2
+ //= require jquery-ui
3
+ //= require best_in_place
4
+ //= require uploadify
5
+ //= require_tree ../
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,5 @@
1
+ /*
2
+ *= require_self
3
+ *= require uploadify
4
+ *= require_tree ../
5
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,7 @@
1
+ class UploadsController < ApplicationController
2
+ def uploadify
3
+ end
4
+
5
+ def destroy
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ module UploadsHelper
2
+ end
@@ -0,0 +1,145 @@
1
+ require 'mime/types'
2
+ require 'paperclip'
3
+
4
+ module UploadBehavior
5
+ MTG = AnotherUploader::MimeTypeGroups
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ scope :newest, order("created_at DESC")
10
+ scope :by_filename, order("local_file_name ASC")
11
+ scope :is_public, where('is_public = ?', true)
12
+ image_types = comma_spliced_single_quoted(MTG::IMAGE_TYPES)
13
+ scope :images, where("local_content_type IN (#{image_types})")
14
+ scope :documents, where("local_content_type IN (#{comma_spliced_single_quoted(MTG::WORD_TYPES + MTG::EXCEL_TYPES + MTG::PDF_TYPES)})")
15
+ scope :files, where("local_content_type NOT IN (#{image_types})")
16
+ scope :recent, lambda { |*args| where("created_at > ?", args.first || 7.days.ago.to_s(:db)) }
17
+ scope :created_by, lambda { |creator_id| where("creator_id = ?", creator_id) }
18
+ scope :pending_s3_migrations, where("remote_file_name IS NULL").order('created_at DESC')
19
+ end
20
+
21
+ module ClassMethods
22
+ def comma_spliced_single_quoted array
23
+ array.collect{|type| "'#{type}'"}.join(',')
24
+ end
25
+ def file_name_exists? name
26
+ !where("local_file_name = ? OR remote_file_name = ?", name, name).count.zero?
27
+ end
28
+ end
29
+ end
30
+
31
+ class Upload < ActiveRecord::Base
32
+ include Paperclip::Glue
33
+ include UploadBehavior
34
+ belongs_to :uploadable, polymorphic: true
35
+ belongs_to :creator, class_name: 'User', foreign_key: 'creator_id'
36
+ has_attached_file :local, AnotherUploader.configuration.has_attached_file_options.merge(storage: :filesystem)
37
+ has_attached_file :remote, AnotherUploader.configuration.has_attached_file_options
38
+ validates_uniqueness_of :local_file_name, allow_nil: true
39
+ validates_uniqueness_of :remote_file_name, allow_nil: true
40
+ attr_accessible :caption, :description, :name
41
+
42
+ before_save :add_width_and_height
43
+ before_save :determine_immediate_send_to_remote
44
+ before_post_process :add_hash_to_duplicate_names
45
+ before_post_process :halt_nonimage_processing unless AnotherUploader.configuration.enable_nonimage_processing
46
+ before_post_process :transliterate_file_name # @TODO whole module requires unit testing
47
+
48
+ def exists_locally?; local.exists?; end
49
+ def exists_remotely?; remote.exists?; end
50
+
51
+ def file; file_attribute(""); end
52
+ def file_name; file_attribute(:file_name); end
53
+ def content_type; file_attribute(:content_type); end
54
+ def file_size; file_attribute(:file_size); end
55
+ def fingerprint; file_attribute(:fingerprint); end
56
+
57
+ def file=(f)
58
+ self.name = f.original_filename
59
+ f.content_type = MIME::Types.type_for(name)[0].to_s
60
+ self.remote = nil
61
+ self.local = f
62
+ end
63
+
64
+ def send_to_remote
65
+ raise Paperclip::Error, "The local file is dirty. Please save the upload before calling send_to_remote" if local.dirty?
66
+ if local_file_name
67
+ self.remote = Paperclip.io_adapters.for(local)
68
+ local.destroy if self.save && !AnotherUploader.configuration.keep_local_file && remote.exists?
69
+ end
70
+ end
71
+
72
+ def icon
73
+ self.is_image? ? self.file.url(:icon) : icon_path
74
+ end
75
+
76
+ def thumb
77
+ self.file.url(:thumb) if self.is_image?
78
+ end
79
+
80
+ # @TODO: unit test
81
+ def display_name
82
+ CGI::escapeHTML(self.file_name)
83
+ end
84
+
85
+ def can_edit?(user)
86
+ !user.blank? && user == self.creator
87
+ end
88
+
89
+ def width(style = :default); dimension :width, style; end
90
+
91
+ def height(style = :default); dimension :height, style; end
92
+
93
+ def size(style = :default)
94
+ return nil unless width || height
95
+ return "#{width}x#{height}" if style == :default
96
+ calculate_sizes(style.to_sym)
97
+ return @image_size
98
+ end
99
+
100
+ private :remote=, :local=, :remote, :local
101
+ private
102
+ include AnotherUploader::Icons
103
+ include AnotherUploader::ImageProcessing
104
+ include AnotherUploader::MimeTypeGetters
105
+ include AnotherUploader::Transliteration
106
+
107
+ def determine_immediate_send_to_remote
108
+ config = AnotherUploader.configuration
109
+ if config.enable_s3 && config.s3_no_wait
110
+ self.remote = queued_for_write
111
+ self.local = nil unless config.keep_local_file
112
+ end
113
+ true
114
+ end
115
+
116
+ def queued_for_write
117
+ self.file.queued_for_write[:original]
118
+ end
119
+
120
+ def add_width_and_height
121
+ return unless self.is_image?
122
+ queued_file = queued_for_write
123
+ if queued_file
124
+ geometry = Paperclip::Geometry.from_file queued_file
125
+ self[:width] = geometry.width.to_i
126
+ self[:height] = geometry.height.to_i
127
+ end
128
+ end
129
+
130
+ def halt_nonimage_processing
131
+ is_image?
132
+ end
133
+
134
+ def file_attribute attr
135
+ self.__send__("#{local_file_name ? :local : :remote}#{:_ if !attr.blank?}#{attr}")
136
+ end
137
+
138
+ def add_hash_to_duplicate_names
139
+ if self.new_record? && self.class.file_name_exists?(file_name)
140
+ ext = File.extname(file_name)
141
+ basename = File.basename(file_name, ext)
142
+ self.file.instance_write(:file_name, "#{basename}-#{SecureRandom.hex(4)}#{ext}")
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,2 @@
1
+ <h1>Uploads#destroy</h1>
2
+ <p>Find me in app/views/uploads/destroy.html.erb</p>
@@ -0,0 +1,2 @@
1
+ <h1>Uploads#uploadify</h1>
2
+ <p>Find me in app/views/uploads/uploadify.html.erb</p>
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+ get "uploads/uploadify"
3
+
4
+ get "uploads/destroy"
5
+
6
+ end
@@ -0,0 +1,31 @@
1
+ class CreateUploads < ActiveRecord::Migration
2
+ def change
3
+ create_table :uploads do |t|
4
+ t.integer :creator_id
5
+ t.string :name
6
+ t.string :caption, limit: 1000
7
+ t.text :description
8
+ t.boolean :is_public, default: true
9
+ t.integer :uploadable_id
10
+ t.string :uploadable_type
11
+ t.string :width
12
+ t.string :height
13
+ t.string :local_file_name
14
+ t.string :local_content_type
15
+ t.integer :local_file_size
16
+ t.datetime :local_updated_at
17
+ t.string :local_fingerprint
18
+ t.string :remote_file_name
19
+ t.string :remote_content_type
20
+ t.integer :remote_file_size
21
+ t.datetime :remote_updated_at
22
+ t.string :remote_fingerprint
23
+
24
+ t.timestamps
25
+ end
26
+ add_index :uploads, :creator_id
27
+ add_index :uploads, :uploadable_id
28
+ add_index :uploads, :uploadable_type
29
+ add_index :uploads, :local_file_name
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ require "best_in_place"
2
+ require "flash_cookie_session"
3
+ require "uploadify-rails"
4
+
5
+ require "another_uploader/configuration"
6
+ require "another_uploader/engine"
7
+ require "another_uploader/icons"
8
+ require "another_uploader/image_processing"
9
+ require "another_uploader/mime_type_getters"
10
+ require "another_uploader/mime_type_groups"
11
+ require "another_uploader/transliteration"
12
+
13
+ module AnotherUploader
14
+ end
@@ -0,0 +1,36 @@
1
+ module AnotherUploader
2
+ def self.configuration
3
+ @configuration ||= Configuration.new
4
+ end
5
+
6
+ def self.configure
7
+ self.configuration ||= Configuration.new
8
+ yield(configuration)
9
+ end
10
+
11
+ class Configuration
12
+ attr_accessor :has_attached_file_options
13
+ attr_accessor :enable_s3
14
+ attr_accessor :s3_no_wait
15
+ attr_accessor :keep_local_file
16
+ attr_accessor :enable_nonimage_processing
17
+ attr_accessor :temp_dir
18
+ attr_accessor :use_http_status_failures
19
+
20
+ def initialize
21
+ @enable_s3 = false
22
+ @s3_no_wait = false
23
+ @keep_local_file = true
24
+ @enable_nonimage_processing = false
25
+ @temp_dir = Dir::tmpdir
26
+ @use_http_status_failures = false
27
+ @has_attached_file_options = {
28
+ url: "/system/:attachment/:id_partition/:style/:filename",
29
+ path: ":rails_root/public:url",
30
+ styles: { icon: "30x30!", thumb: "100>", small: "150>", medium: "300>", large: "660>" },
31
+ default_url: "/images/default.jpg",
32
+ convert_options: { all: '-quality 80' }
33
+ }
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,4 @@
1
+ module AnotherUploader
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,23 @@
1
+ module AnotherUploader
2
+ module Icons
3
+ def icon_path
4
+ "another_uploader/#{icon_name}.gif"
5
+ end
6
+
7
+ def icon_name
8
+ if self.is_pdf?
9
+ :pdf
10
+ elsif self.is_word?
11
+ :doc
12
+ elsif self.is_mp3?
13
+ :mp3
14
+ elsif self.is_excel?
15
+ :spreadsheet
16
+ elsif self.is_text?
17
+ :text
18
+ else
19
+ :none
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ module AnotherUploader
2
+ module ImageProcessing
3
+ def dimension dim, style
4
+ return nil unless self[dim]
5
+ return self[dim] if style == :default
6
+ calculate_sizes(style.to_sym)
7
+ return instance_variable_get("@image_#{dim}").to_i
8
+ end
9
+
10
+ def image_ratio
11
+ @image_ratio ||= width.to_f / height.to_f
12
+ end
13
+
14
+ def max_dimension(style)
15
+ @max_dimension ||= Paperclip::Geometry.parse(self.local.styles[style][:geometry]).width.to_f
16
+ end
17
+
18
+ def calculate_sizes(style)
19
+ if image_ratio > 1
20
+ @image_width ||= [width, max_dimension(style)].min
21
+ @image_height ||= (@image_width / image_ratio).round
22
+ else
23
+ @image_height ||= [height, max_dimension(style)].min
24
+ @image_width ||= (@image_height * image_ratio).round
25
+ end
26
+ @image_size ||= "#{@image_width.to_i}x#{@image_height.to_i}"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ require "another_uploader/mime_type_groups"
2
+
3
+ module AnotherUploader
4
+ module MimeTypeGetters
5
+ MTG = MimeTypeGroups
6
+ def is_of_type? type_list
7
+ type_list.include?(self.local_content_type)
8
+ end
9
+
10
+ def is_image?; is_of_type?(MTG::IMAGE_TYPES); end
11
+ def is_pdf?; is_of_type?(MTG::PDF_TYPES); end
12
+ def is_word?; is_of_type?(MTG::WORD_TYPES); end
13
+ def is_mp3?; is_of_type?(MTG::MP3_TYPES); end
14
+ def is_excel?; is_of_type?(MTG::EXCEL_TYPES); end
15
+ def is_text?; is_of_type?(MTG::TEXT_TYPES); end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module AnotherUploader
2
+ module MimeTypeGroups
3
+ IMAGE_TYPES = ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg']
4
+ MP3_TYPES = ['audio/mpeg', 'audio/mpeg3', 'audio/x-mpeg-3', 'video/mpeg', 'video/x-mpeg']
5
+ EXCEL_TYPES = ['application/excel', 'application/excel', 'application/x-excel', 'application/x-msexcel', 'application/excel',
6
+ 'application/vnd.ms-excel', 'application/x-excel', 'application/excel', 'application/vnd.ms-excel',
7
+ 'application/x-excel', 'application/excel', 'application/x-excel', 'application/excel', 'application/x-excel', 'application/excel',
8
+ 'application/vnd.ms-excel', 'application/x-excel', 'application/excel', 'application/vnd.ms-excel',
9
+ 'application/x-excel', 'application/excel', 'application/vnd.ms-excel', 'application/x-excel',
10
+ 'application/x-msexcel', 'application/excel', 'application/x-excel', 'application/excel',
11
+ 'application/x-excel', 'application/excel', 'application/vnd.ms-excel', 'application/x-excel',
12
+ 'application/x-msexcel', 'application/vnd.oasis.opendocument.spreadsheet']
13
+ PDF_TYPES = ['application/pdf']
14
+ WORD_TYPES = ['application/msword', 'application/vnd.oasis.opendocument.text']
15
+ TEXT_TYPES = ['text/plain']
16
+ end
17
+ end