ouvrages_file_uploader 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +40 -0
  5. data/app/assets/javascripts/uploaded_files.js.coffee +39 -0
  6. data/app/assets/stylesheets/uploaded_files.css +15 -0
  7. data/app/controllers/uploaded_files_controller.rb +23 -0
  8. data/app/helpers/uploaded_files_helper.rb +2 -0
  9. data/app/models/uploaded_file.rb +5 -0
  10. data/app/views/uploaded_files/_file_upload.html.haml +10 -0
  11. data/config/routes.rb +3 -0
  12. data/db/migrate/20150805074343_create_uploaded_files.rb +8 -0
  13. data/db/migrate/20150805074626_add_attachment_file_to_uploaded_files.rb +9 -0
  14. data/lib/ouvrages_file_uploader/engine.rb +4 -0
  15. data/lib/ouvrages_file_uploader/version.rb +3 -0
  16. data/lib/ouvrages_file_uploader.rb +31 -0
  17. data/lib/tasks/ouvrages_file_uploader_tasks.rake +4 -0
  18. data/test/controllers/uploaded_files_controller_test.rb +7 -0
  19. data/test/dummy/README.rdoc +261 -0
  20. data/test/dummy/Rakefile +7 -0
  21. data/test/dummy/app/assets/javascripts/application.js +16 -0
  22. data/test/dummy/app/assets/javascripts/posts.js +2 -0
  23. data/test/dummy/app/assets/stylesheets/application.css +14 -0
  24. data/test/dummy/app/assets/stylesheets/posts.css +4 -0
  25. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  26. data/test/dummy/app/controllers/application_controller.rb +3 -0
  27. data/test/dummy/app/controllers/posts_controller.rb +83 -0
  28. data/test/dummy/app/helpers/application_helper.rb +2 -0
  29. data/test/dummy/app/helpers/posts_helper.rb +2 -0
  30. data/test/dummy/app/models/post.rb +6 -0
  31. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  32. data/test/dummy/app/views/posts/_form.html.erb +28 -0
  33. data/test/dummy/app/views/posts/edit.html.erb +6 -0
  34. data/test/dummy/app/views/posts/index.html.erb +25 -0
  35. data/test/dummy/app/views/posts/new.html.erb +5 -0
  36. data/test/dummy/app/views/posts/show.html.erb +19 -0
  37. data/test/dummy/config/application.rb +59 -0
  38. data/test/dummy/config/boot.rb +10 -0
  39. data/test/dummy/config/database.yml +25 -0
  40. data/test/dummy/config/environment.rb +5 -0
  41. data/test/dummy/config/environments/development.rb +37 -0
  42. data/test/dummy/config/environments/production.rb +67 -0
  43. data/test/dummy/config/environments/test.rb +37 -0
  44. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  45. data/test/dummy/config/initializers/inflections.rb +15 -0
  46. data/test/dummy/config/initializers/mime_types.rb +5 -0
  47. data/test/dummy/config/initializers/secret_token.rb +7 -0
  48. data/test/dummy/config/initializers/session_store.rb +8 -0
  49. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  50. data/test/dummy/config/locales/en.yml +5 -0
  51. data/test/dummy/config/routes.rb +61 -0
  52. data/test/dummy/config.ru +4 -0
  53. data/test/dummy/db/development.sqlite3 +0 -0
  54. data/test/dummy/db/migrate/20150805074930_create_uploaded_files.ouvrages_file_uploader_engine.rb +9 -0
  55. data/test/dummy/db/migrate/20150805074931_add_attachment_file_to_uploaded_files.ouvrages_file_uploader_engine.rb +10 -0
  56. data/test/dummy/db/migrate/20150805091643_create_posts.rb +10 -0
  57. data/test/dummy/db/migrate/20150805091701_add_attachment_image_to_posts.rb +9 -0
  58. data/test/dummy/db/schema.rb +36 -0
  59. data/test/dummy/db/test.sqlite3 +0 -0
  60. data/test/dummy/log/development.log +38268 -0
  61. data/test/dummy/public/404.html +26 -0
  62. data/test/dummy/public/422.html +26 -0
  63. data/test/dummy/public/500.html +25 -0
  64. data/test/dummy/public/favicon.ico +0 -0
  65. data/test/dummy/public/system/uploaded_files/files/000/000/452/original/1.pptx +0 -0
  66. data/test/dummy/public/system/uploaded_files/files/000/000/453/original/135.JPG +0 -0
  67. data/test/dummy/public/system/uploaded_files/files/000/000/454/original/135.JPG +0 -0
  68. data/test/dummy/public/system/uploaded_files/files/000/000/455/original/4.jpg +0 -0
  69. data/test/dummy/script/rails +6 -0
  70. data/test/dummy/test/fixtures/posts.yml +9 -0
  71. data/test/dummy/test/functional/posts_controller_test.rb +49 -0
  72. data/test/dummy/test/unit/helpers/posts_helper_test.rb +4 -0
  73. data/test/dummy/test/unit/post_test.rb +7 -0
  74. data/test/dummy/tmp/cache/assets/C21/3A0/sprockets%2Fc559895302f747c37b21c8700b970051 +0 -0
  75. data/test/dummy/tmp/cache/assets/C23/BF0/sprockets%2F0e1494c611e0484922f4445c387c1199 +0 -0
  76. data/test/dummy/tmp/cache/assets/C7D/5C0/sprockets%2F416f106b644d79d1262e68ca572c4073 +0 -0
  77. data/test/dummy/tmp/cache/assets/C8C/B80/sprockets%2F371bf96e99717688ed7313a0c53f4212 +0 -0
  78. data/test/dummy/tmp/cache/assets/C8D/DE0/sprockets%2F1f98920f65a2e62c64c92518527c1c96 +0 -0
  79. data/test/dummy/tmp/cache/assets/CA5/410/sprockets%2Fe992772e06894cc640ba879ef2299587 +0 -0
  80. data/test/dummy/tmp/cache/assets/CA7/840/sprockets%2F9a211e8759d357ae3f42262a51fa1451 +0 -0
  81. data/test/dummy/tmp/cache/assets/CB8/340/sprockets%2F89558955c55c20a74bd1c3444f3ec662 +0 -0
  82. data/test/dummy/tmp/cache/assets/CBC/770/sprockets%2Fdaf9852b07673e9d2852c941a1576f33 +0 -0
  83. data/test/dummy/tmp/cache/assets/CC7/220/sprockets%2Fd066c004d1fd26ae76a61303a7a18145 +0 -0
  84. data/test/dummy/tmp/cache/assets/CC9/030/sprockets%2F29d56d794f95c975aa8395b172149dc3 +0 -0
  85. data/test/dummy/tmp/cache/assets/CCA/400/sprockets%2F2390bb254327e06a3c3b521daa0f5687 +0 -0
  86. data/test/dummy/tmp/cache/assets/CD3/DB0/sprockets%2F654362a25821675623bcaea3d32e84ac +0 -0
  87. data/test/dummy/tmp/cache/assets/CD5/B70/sprockets%2F416150dc3ac35079c94273cc46e90aa6 +0 -0
  88. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  89. data/test/dummy/tmp/cache/assets/CDF/AE0/sprockets%2F2ffa370043fc750b9569048f2a9bd470 +0 -0
  90. data/test/dummy/tmp/cache/assets/CE0/8C0/sprockets%2F009df73dbd4116f48667bb49256a2d70 +0 -0
  91. data/test/dummy/tmp/cache/assets/CE1/740/sprockets%2Ff5ed509926027a190c5d3738c43d04ef +0 -0
  92. data/test/dummy/tmp/cache/assets/CED/790/sprockets%2F170c6d8f21de588659bc8d4ac8510756 +0 -0
  93. data/test/dummy/tmp/cache/assets/CF0/1D0/sprockets%2F6fc757c2c8329244ca95d6909865bbc2 +0 -0
  94. data/test/dummy/tmp/cache/assets/CF1/0C0/sprockets%2Feb061eefaf8598134946f33a388d4753 +0 -0
  95. data/test/dummy/tmp/cache/assets/CF5/DD0/sprockets%2F56004407c600e0ccea2163ef0fd3282e +0 -0
  96. data/test/dummy/tmp/cache/assets/CFD/370/sprockets%2Fcc6ca1020424a9385ce3e6701c5177cb +0 -0
  97. data/test/dummy/tmp/cache/assets/D01/E80/sprockets%2F1c42c70c1c45bf164783ec1542bd83e2 +0 -0
  98. data/test/dummy/tmp/cache/assets/D12/A70/sprockets%2F2918be152d13c0ed16add36948925dd9 +0 -0
  99. data/test/dummy/tmp/cache/assets/D19/A40/sprockets%2F916d8130b75e35a749097d5bd5bedb84 +0 -0
  100. data/test/dummy/tmp/cache/assets/D1A/310/sprockets%2F5384ad85f52d3272dbc64d46ef3876a4 +0 -0
  101. data/test/dummy/tmp/cache/assets/D1B/280/sprockets%2F998fde5cf7214c00b0794419580e5aef +0 -0
  102. data/test/dummy/tmp/cache/assets/D20/AE0/sprockets%2Fd3e961702e626d8db481b9c73c8fa199 +0 -0
  103. data/test/dummy/tmp/cache/assets/D22/F50/sprockets%2Ffe32653ea391edf92f7f9b7a79190335 +0 -0
  104. data/test/dummy/tmp/cache/assets/D25/DB0/sprockets%2F2e3f46d2b3623f90b350a3208dbad51a +0 -0
  105. data/test/dummy/tmp/cache/assets/D27/B50/sprockets%2F0d6b3f65f101f0f0132dc3e27ad212f9 +0 -0
  106. data/test/dummy/tmp/cache/assets/D30/730/sprockets%2Ffcd1017a36bf3184d3550e817fbbf321 +0 -0
  107. data/test/dummy/tmp/cache/assets/D30/C50/sprockets%2F107f4a4a0ad5084baa467c756d8e21d4 +0 -0
  108. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  109. data/test/dummy/tmp/cache/assets/D3A/150/sprockets%2F94d5308b3136c0f5d2beddf31b0956f5 +0 -0
  110. data/test/dummy/tmp/cache/assets/D3A/710/sprockets%2Fc454a64ea86d50111bec53fc4f3b4975 +0 -0
  111. data/test/dummy/tmp/cache/assets/D4C/550/sprockets%2F9a4f52d5dac2f6892e5e247cf063296d +0 -0
  112. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  113. data/test/dummy/tmp/cache/assets/D59/330/sprockets%2F1bfe97c00ac8dca04d47435b33713b1c +0 -0
  114. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  115. data/test/dummy/tmp/cache/assets/D5F/610/sprockets%2F51aff0153b694de711bda7f5b054a19a +0 -0
  116. data/test/dummy/tmp/cache/assets/D67/C20/sprockets%2Fce6471356e27d2af0096fe5bd112dfb3 +0 -0
  117. data/test/dummy/tmp/cache/assets/D69/C00/sprockets%2Fbc56c6aa4ba782431a9f10939adfb726 +0 -0
  118. data/test/dummy/tmp/cache/assets/D72/A10/sprockets%2Fb15368142cd476ded90e0be2c97cd75d +0 -0
  119. data/test/dummy/tmp/cache/assets/D73/540/sprockets%2F4b9d461d6dce445d2f9b12b577b1b9b7 +0 -0
  120. data/test/dummy/tmp/cache/assets/D73/870/sprockets%2F1eab18a071ce659d6383140fe8cd8ef6 +0 -0
  121. data/test/dummy/tmp/cache/assets/D77/9B0/sprockets%2F5074e3f949ef1fc278b26d7a7dc1eb14 +0 -0
  122. data/test/dummy/tmp/cache/assets/D7B/220/sprockets%2F8326cee111196f890dffc1d3ef95a69a +0 -0
  123. data/test/dummy/tmp/cache/assets/D83/6F0/sprockets%2F80f7f1ae77e8ac704763c8c96e44fba8 +0 -0
  124. data/test/dummy/tmp/cache/assets/D98/5C0/sprockets%2Fac6794409c7b8c4da4054bef5d420dca +0 -0
  125. data/test/dummy/tmp/cache/assets/D9B/E70/sprockets%2F07f8c2dfc80703f90d343df3d8cd0dc2 +0 -0
  126. data/test/dummy/tmp/cache/assets/D9C/CD0/sprockets%2Fc85016e7bbd4f3adbb7635d01f85d39b +0 -0
  127. data/test/dummy/tmp/cache/assets/D9E/ED0/sprockets%2F0e96b358d65dd43580c7bccd2d0dbe91 +0 -0
  128. data/test/dummy/tmp/cache/assets/D9F/D10/sprockets%2Fa57e4263b0296d712c5e298eccabea7f +0 -0
  129. data/test/dummy/tmp/cache/assets/DA5/AD0/sprockets%2Fa54624bdbc8550c8df5905a9bfa9af56 +0 -0
  130. data/test/dummy/tmp/cache/assets/DA8/A00/sprockets%2Fbdade36c866f0e4b747a8f95440ad6c6 +0 -0
  131. data/test/dummy/tmp/cache/assets/DAF/A00/sprockets%2F018f66c0eab757b966dfd7a83bc93d8e +0 -0
  132. data/test/dummy/tmp/cache/assets/DAF/AE0/sprockets%2F1b013a3af0e75cf8c341a07ade442bea +0 -0
  133. data/test/dummy/tmp/cache/assets/DB3/810/sprockets%2F2c02bf9befbfff85f9155f468b6177a7 +0 -0
  134. data/test/dummy/tmp/cache/assets/DC1/3E0/sprockets%2F7eed9c3edcabb034a146d1299c3cf122 +0 -0
  135. data/test/dummy/tmp/cache/assets/DC8/680/sprockets%2Fc512b0cfa37dd3cd04e9bada9189c818 +0 -0
  136. data/test/dummy/tmp/cache/assets/DD1/EC0/sprockets%2F63b58b3cfb1bbc71c7e1ef648f3b5c58 +0 -0
  137. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  138. data/test/dummy/tmp/cache/assets/DDF/650/sprockets%2Fd22c1269fb8899fecc3291aefd83e5eb +0 -0
  139. data/test/dummy/tmp/cache/assets/DF1/670/sprockets%2Faf1215a25cde8b1b9f36fc535a5ce3bc +0 -0
  140. data/test/dummy/tmp/cache/assets/DFD/CA0/sprockets%2Fbc31935ea9e82a68a9caaea6d7ba416f +0 -0
  141. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  142. data/test/dummy/tmp/cache/assets/E0B/F70/sprockets%2Ffae70ae574e68ccd3cf9204bb4fc896f +0 -0
  143. data/test/dummy/tmp/cache/assets/E2A/670/sprockets%2F23540cc1ced374dd5ec6caff4bec839b +0 -0
  144. data/test/dummy/tmp/cache/assets/E54/800/sprockets%2F3e8c1ea8e7b5ccfcf15bd04f51faae41 +0 -0
  145. data/test/dummy/tmp/cache/assets/E79/CE0/sprockets%2Fefe77efad35dc92f58159e8dd8b5ecfa +0 -0
  146. data/test/dummy/tmp/data/meta_request/0a4d17b7626c1939d010592ed60eca2d.json +1 -0
  147. data/test/dummy/tmp/data/meta_request/15bc2818962b844384424d481eec9517.json +1 -0
  148. data/test/dummy/tmp/data/meta_request/3481e256aa984b864200a62ab2026056.json +1 -0
  149. data/test/dummy/tmp/data/meta_request/436a7666545296be87a1a3d4339f933c.json +1 -0
  150. data/test/dummy/tmp/data/meta_request/4fc141472e2de8d7d212b1352b9f60e2.json +1 -0
  151. data/test/dummy/tmp/data/meta_request/51b876e5ea5a4bba19532f46d2909f18.json +1 -0
  152. data/test/dummy/tmp/data/meta_request/56e93e20dbb183c226e62e8fb665b8ab.json +1 -0
  153. data/test/dummy/tmp/data/meta_request/843cd09295b195ec53babfb7b625bd60.json +1 -0
  154. data/test/dummy/tmp/data/meta_request/bb074b2848c73aa8df59be32febcc413.json +1 -0
  155. data/test/dummy/tmp/data/meta_request/d93859d3c64bf924e69a353f1ab74ec1.json +1 -0
  156. data/test/fixtures/uploaded_files.yml +11 -0
  157. data/test/helpers/uploaded_files_helper_test.rb +4 -0
  158. data/test/integration/navigation_test.rb +10 -0
  159. data/test/ouvrages_file_uploader_test.rb +7 -0
  160. data/test/test_helper.rb +15 -0
  161. data/test/unit/uploaded_file_test.rb +7 -0
  162. metadata +446 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6246d62691e5914b474187fe130fb0009ce6ed0d
4
+ data.tar.gz: 48c83ea71149c23dcabf8011dcc29fbd9ae5c046
5
+ SHA512:
6
+ metadata.gz: 5171760a05d5d3409ea3524f9fe04d29a4afadc0efbd29dbb559d9158e28a479c55940084a00acb1e7b0c65346c3d28dab497e1597e2189abc2c7bd11cce56a1
7
+ data.tar.gz: 4396bef025636b7c206a30bce541a9d5a67c5199baaaf8126a586b405b852d72abad0e9795ce6d8132fbd848d9917129263fee612c5f5b8639fe4c6258deeb45
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = OuvragesFileUploader
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -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 = 'OuvragesFileUploader'
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,39 @@
1
+ #= require jquery-fileupload
2
+
3
+ $.fn.ouvragesFileUpload = ->
4
+ this.each ->
5
+ $(this).find('.ofu-input').fileupload(
6
+ autoUpload: true
7
+ url: $(this).closest('.ofu-field').data('url')
8
+ uploadTemplateId: null
9
+ downloadTemplateId: null
10
+ paramName: 'files[]'
11
+ progressall: (e, data) ->
12
+ progress = parseInt(data.loaded / data.total * 100, 10)
13
+ $(this).closest('.ofu-field').find('.ofu-progress-bar').css('width', progress + "%").text(progress + "%")
14
+ ).bind('fileuploadstart', (e, data) ->
15
+ window.ofuFileCount++
16
+ $(this).closest('.ofu-field').find('.ofu-files-container').empty()
17
+ $(this).closest('.ofu-field').find('.ofu-files-container').append("<div class='progress'><div class='ofu-progress-bar bar' style='width: 0;'></div></div>")
18
+ return
19
+ ).bind('fileuploaddone', (e, data) ->
20
+ $(this).closest('.ofu-field').find('input[type=hidden]').val(data.result.files[0].id)
21
+
22
+ window.ofuFileCount--
23
+ return
24
+ ).bind('fileuploadfail', (e, data) ->
25
+ window.ofuFileCount--
26
+ return
27
+ ).bind('fileuploadadd', (e, data) ->
28
+ $(this).closest('.ofu-field').find('.ofu-files-container').empty()
29
+ return
30
+ )
31
+
32
+ window.ofuFileCount = 0
33
+
34
+ $(document).ready ->
35
+ $('.ofu-field[data-auto=true]').ouvragesFileUpload()
36
+
37
+ $(window).bind 'beforeunload', ->
38
+ if window.ofuFileCount > 0
39
+ console.log("PREVENT")
@@ -0,0 +1,15 @@
1
+ /*
2
+ *= require jquery.fileupload
3
+ *= require jquery.fileupload-ui
4
+ */
5
+
6
+ .ofu-progress-bar .bar {
7
+ background-color: #51a351;
8
+ height: 20px;
9
+ color: white;
10
+ text-align: center;
11
+ }
12
+
13
+ .ofu-files-container {
14
+ width: 225px;
15
+ }
@@ -0,0 +1,23 @@
1
+ class UploadedFilesController < ApplicationController
2
+ def file_upload
3
+ uploaded_file = UploadedFile.new(file: params[:files][0])
4
+ if uploaded_file.save
5
+ render json: {
6
+ files: [
7
+ {
8
+ "name" => uploaded_file.read_attribute(:file_file_name),
9
+ "size" => uploaded_file.read_attribute(:file_file_size),
10
+ "url" => uploaded_file.file.url,
11
+ "id" => uploaded_file.id
12
+ }
13
+ ]
14
+ }
15
+ else
16
+ render json: {
17
+ error: {
18
+ "message" => "An error prevents the uploaded file to be saved"
19
+ }
20
+ }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,2 @@
1
+ module UploadedFilesHelper
2
+ end
@@ -0,0 +1,5 @@
1
+ class UploadedFile < ActiveRecord::Base
2
+ attr_accessible :file
3
+ has_attached_file :file
4
+ do_not_validate_attachment_file_type :file
5
+ end
@@ -0,0 +1,10 @@
1
+ %div.ofu-field{data: {auto: options.fetch(:auto, true) ? "true" : "false", url: file_upload_path} }
2
+ - options = options.dup
3
+ - classes = (options.delete(:class) || "").split
4
+ - classes << "ofu-input"
5
+ - data = (options.delete(:data) || {})
6
+ - data["files-container"] = ".ofu-files-container"
7
+ - options = options.merge(class: classes.join(" "), data: data)
8
+ = form.file_field attachment, options
9
+ = form.hidden_field "#{attachment}_uploaded_file_id"
10
+ .ofu-files-container
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ match "file_upload" => "uploaded_files#file_upload", as: :file_upload
3
+ end
@@ -0,0 +1,8 @@
1
+ class CreateUploadedFiles < ActiveRecord::Migration
2
+ def change
3
+ create_table :uploaded_files do |t|
4
+
5
+ t.timestamps
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ class AddAttachmentFileToUploadedFiles < ActiveRecord::Migration
2
+ def self.up
3
+ add_attachment :uploaded_files, :file
4
+ end
5
+
6
+ def self.down
7
+ remove_attachment :uploaded_files, :file
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ module OuvragesFileUploader
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module OuvragesFileUploader
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,31 @@
1
+ Gem.loaded_specs['ouvrages_file_uploader'].dependencies.each do |dependency|
2
+ require dependency.name
3
+ end
4
+
5
+ require "ouvrages_file_uploader/engine"
6
+
7
+ module OuvragesFileUploader
8
+ module ActiveRecordHelpers
9
+ def accepts_uploaded_file_for(attachment)
10
+ attachment_uploaded_file_id = "#{attachment}_uploaded_file_id"
11
+ attr_reader attachment_uploaded_file_id.to_sym
12
+ attr_accessible attachment_uploaded_file_id.to_sym
13
+ define_method("#{attachment_uploaded_file_id}=") do |id|
14
+ unless id.blank?
15
+ instance_variable_set("@#{attachment_uploaded_file_id}", id)
16
+ if uploaded_file = UploadedFile.where(id: id).first
17
+ self.send("#{attachment}=", File.open(uploaded_file.file.path))
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ module Helpers
24
+ def file_upload(form, attachment, options = {})
25
+ render partial: "/uploaded_files/file_upload", locals: { form: form, attachment: attachment, options: options.with_indifferent_access}
26
+ end
27
+ end
28
+ end
29
+
30
+ ActiveRecord::Base.extend OuvragesFileUploader::ActiveRecordHelpers
31
+ ActionController::Base.send(:helper, OuvragesFileUploader::Helpers)
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :ouvrages_file_uploader do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class UploadedFilesControllerTest < ActionController::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,261 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb"
7
+ templates that are primarily responsible for inserting pre-built data in between
8
+ HTML tags. The model contains the "smart" domain objects (such as Account,
9
+ Product, Person, Post) that holds all the business logic and knows how to
10
+ persist themselves to a database. The controller handles the incoming requests
11
+ (such as Save New Account, Update Product, Show Post) by manipulating the model
12
+ and directing data to the view.
13
+
14
+ In Rails, the model is handled by what's called an object-relational mapping
15
+ layer entitled Active Record. This layer allows you to present the data from
16
+ database rows as objects and embellish these data objects with business logic
17
+ methods. You can read more about Active Record in
18
+ link:files/vendor/rails/activerecord/README.html.
19
+
20
+ The controller and view are handled by the Action Pack, which handles both
21
+ layers by its two parts: Action View and Action Controller. These two layers
22
+ are bundled in a single package due to their heavy interdependence. This is
23
+ unlike the relationship between the Active Record and Action Pack that is much
24
+ more separate. Each of these packages can be used independently outside of
25
+ Rails. You can read more about Action Pack in
26
+ link:files/vendor/rails/actionpack/README.html.
27
+
28
+
29
+ == Getting Started
30
+
31
+ 1. At the command prompt, create a new Rails application:
32
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
33
+
34
+ 2. Change directory to <tt>myapp</tt> and start the web server:
35
+ <tt>cd myapp; rails server</tt> (run with --help for options)
36
+
37
+ 3. Go to http://localhost:3000/ and you'll see:
38
+ "Welcome aboard: You're riding Ruby on Rails!"
39
+
40
+ 4. Follow the guidelines to start developing your application. You can find
41
+ the following resources handy:
42
+
43
+ * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44
+ * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45
+
46
+
47
+ == Debugging Rails
48
+
49
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
50
+ will help you debug it and get it back on the rails.
51
+
52
+ First area to check is the application log files. Have "tail -f" commands
53
+ running on the server.log and development.log. Rails will automatically display
54
+ debugging and runtime information to these files. Debugging info will also be
55
+ shown in the browser on requests from 127.0.0.1.
56
+
57
+ You can also log your own messages directly into the log file from your code
58
+ using the Ruby logger class from inside your controllers. Example:
59
+
60
+ class WeblogController < ActionController::Base
61
+ def destroy
62
+ @weblog = Weblog.find(params[:id])
63
+ @weblog.destroy
64
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65
+ end
66
+ end
67
+
68
+ The result will be a message in your log file along the lines of:
69
+
70
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71
+
72
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
73
+
74
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75
+ several books available online as well:
76
+
77
+ * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79
+
80
+ These two books will bring you up to speed on the Ruby language and also on
81
+ programming in general.
82
+
83
+
84
+ == Debugger
85
+
86
+ Debugger support is available through the debugger command when you start your
87
+ Mongrel or WEBrick server with --debugger. This means that you can break out of
88
+ execution at any point in the code, investigate and change the model, and then,
89
+ resume execution! You need to install ruby-debug to run the server in debugging
90
+ mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
91
+
92
+ class WeblogController < ActionController::Base
93
+ def index
94
+ @posts = Post.all
95
+ debugger
96
+ end
97
+ end
98
+
99
+ So the controller will accept the action, run the first line, then present you
100
+ with a IRB prompt in the server window. Here you can do things like:
101
+
102
+ >> @posts.inspect
103
+ => "[#<Post:0x14a6be8
104
+ @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
105
+ #<Post:0x14a6620
106
+ @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107
+ >> @posts.first.title = "hello from a debugger"
108
+ => "hello from a debugger"
109
+
110
+ ...and even better, you can examine how your runtime objects actually work:
111
+
112
+ >> f = @posts.first
113
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
114
+ >> f.
115
+ Display all 152 possibilities? (y or n)
116
+
117
+ Finally, when you're ready to resume execution, you can enter "cont".
118
+
119
+
120
+ == Console
121
+
122
+ The console is a Ruby shell, which allows you to interact with your
123
+ application's domain model. Here you'll have all parts of the application
124
+ configured, just like it is when the application is running. You can inspect
125
+ domain models, change values, and save to the database. Starting the script
126
+ without arguments will launch it in the development environment.
127
+
128
+ To start the console, run <tt>rails console</tt> from the application
129
+ directory.
130
+
131
+ Options:
132
+
133
+ * Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
134
+ made to the database.
135
+ * Passing an environment name as an argument will load the corresponding
136
+ environment. Example: <tt>rails console production</tt>.
137
+
138
+ To reload your controllers and models after launching the console run
139
+ <tt>reload!</tt>
140
+
141
+ More information about irb can be found at:
142
+ link:http://www.rubycentral.org/pickaxe/irb.html
143
+
144
+
145
+ == dbconsole
146
+
147
+ You can go to the command line of your database directly through <tt>rails
148
+ dbconsole</tt>. You would be connected to the database with the credentials
149
+ defined in database.yml. Starting the script without arguments will connect you
150
+ to the development database. Passing an argument will connect you to a different
151
+ database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
152
+ PostgreSQL and SQLite 3.
153
+
154
+ == Description of Contents
155
+
156
+ The default directory structure of a generated Ruby on Rails application:
157
+
158
+ |-- app
159
+ | |-- assets
160
+ | | |-- images
161
+ | | |-- javascripts
162
+ | | `-- stylesheets
163
+ | |-- controllers
164
+ | |-- helpers
165
+ | |-- mailers
166
+ | |-- models
167
+ | `-- views
168
+ | `-- layouts
169
+ |-- config
170
+ | |-- environments
171
+ | |-- initializers
172
+ | `-- locales
173
+ |-- db
174
+ |-- doc
175
+ |-- lib
176
+ | |-- assets
177
+ | `-- tasks
178
+ |-- log
179
+ |-- public
180
+ |-- script
181
+ |-- test
182
+ | |-- fixtures
183
+ | |-- functional
184
+ | |-- integration
185
+ | |-- performance
186
+ | `-- unit
187
+ |-- tmp
188
+ | `-- cache
189
+ | `-- assets
190
+ `-- vendor
191
+ |-- assets
192
+ | |-- javascripts
193
+ | `-- stylesheets
194
+ `-- plugins
195
+
196
+ app
197
+ Holds all the code that's specific to this particular application.
198
+
199
+ app/assets
200
+ Contains subdirectories for images, stylesheets, and JavaScript files.
201
+
202
+ app/controllers
203
+ Holds controllers that should be named like weblogs_controller.rb for
204
+ automated URL mapping. All controllers should descend from
205
+ ApplicationController which itself descends from ActionController::Base.
206
+
207
+ app/models
208
+ Holds models that should be named like post.rb. Models descend from
209
+ ActiveRecord::Base by default.
210
+
211
+ app/views
212
+ Holds the template files for the view that should be named like
213
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
214
+ eRuby syntax by default.
215
+
216
+ app/views/layouts
217
+ Holds the template files for layouts to be used with views. This models the
218
+ common header/footer method of wrapping views. In your views, define a layout
219
+ using the <tt>layout :default</tt> and create a file named default.html.erb.
220
+ Inside default.html.erb, call <% yield %> to render the view using this
221
+ layout.
222
+
223
+ app/helpers
224
+ Holds view helpers that should be named like weblogs_helper.rb. These are
225
+ generated for you automatically when using generators for controllers.
226
+ Helpers can be used to wrap functionality for your views into methods.
227
+
228
+ config
229
+ Configuration files for the Rails environment, the routing map, the database,
230
+ and other dependencies.
231
+
232
+ db
233
+ Contains the database schema in schema.rb. db/migrate contains all the
234
+ sequence of Migrations for your schema.
235
+
236
+ doc
237
+ This directory is where your application documentation will be stored when
238
+ generated using <tt>rake doc:app</tt>
239
+
240
+ lib
241
+ Application specific libraries. Basically, any kind of custom code that
242
+ doesn't belong under controllers, models, or helpers. This directory is in
243
+ the load path.
244
+
245
+ public
246
+ The directory available for the web server. Also contains the dispatchers and the
247
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
248
+ server.
249
+
250
+ script
251
+ Helper scripts for automation and generation.
252
+
253
+ test
254
+ Unit and functional tests along with fixtures. When using the rails generate
255
+ command, template test files will be generated for you and placed in this
256
+ directory.
257
+
258
+ vendor
259
+ External libraries that the application depends on. Also includes the plugins
260
+ subdirectory. If the app has frozen rails, those gems also go here, under
261
+ vendor/rails/. This directory is in the load path.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,16 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require uploaded_files
16
+ //= 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,14 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require uploaded_files
13
+ *= require_tree .
14
+ */
@@ -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,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end