plupload-rails3 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +38 -0
  4. data/README.md +100 -0
  5. data/Rakefile +23 -0
  6. data/init.rb +3 -0
  7. data/install.rb +9 -0
  8. data/lib/.DS_Store +0 -0
  9. data/lib/app/.DS_Store +0 -0
  10. data/lib/app/controllers/plupload_rails_controller.rb +38 -0
  11. data/lib/app/helpers/plupload_helper.rb +14 -0
  12. data/lib/app/middleware/plupload_params_renamer.rb +38 -0
  13. data/lib/app/views/.DS_Store +0 -0
  14. data/lib/app/views/plupload/_uploader_scripts.html.erb +72 -0
  15. data/lib/plupload-rails3.rb +20 -0
  16. data/lib/plupload-rails3/asset_mover.rb +54 -0
  17. data/lib/plupload-rails3/railtie.rb +12 -0
  18. data/lib/plupload-rails3/version.rb +5 -0
  19. data/lib/public/.DS_Store +0 -0
  20. data/lib/public/images/.DS_Store +0 -0
  21. data/lib/public/images/plupload-rails3/.DS_Store +0 -0
  22. data/lib/public/images/plupload-rails3/plupload/backgrounds.gif +0 -0
  23. data/lib/public/images/plupload-rails3/plupload/buttons-disabled.png +0 -0
  24. data/lib/public/images/plupload-rails3/plupload/buttons.png +0 -0
  25. data/lib/public/images/plupload-rails3/plupload/delete.gif +0 -0
  26. data/lib/public/images/plupload-rails3/plupload/done.gif +0 -0
  27. data/lib/public/images/plupload-rails3/plupload/error.gif +0 -0
  28. data/lib/public/images/plupload-rails3/plupload/transp50.png +0 -0
  29. data/lib/public/javascripts/.DS_Store +0 -0
  30. data/lib/public/javascripts/plupload-rails3/.DS_Store +0 -0
  31. data/lib/public/javascripts/plupload-rails3/jquery-ui.min.js +406 -0
  32. data/lib/public/javascripts/plupload-rails3/jquery.min.js +16 -0
  33. data/lib/public/javascripts/plupload-rails3/plupload/.DS_Store +0 -0
  34. data/lib/public/javascripts/plupload-rails3/plupload/changelog.txt +152 -0
  35. data/lib/public/javascripts/plupload-rails3/plupload/examples/.DS_Store +0 -0
  36. data/lib/public/javascripts/plupload-rails3/plupload/examples/bg.jpg +0 -0
  37. data/lib/public/javascripts/plupload-rails3/plupload/examples/custom.html +94 -0
  38. data/lib/public/javascripts/plupload-rails3/plupload/examples/dump.php +36 -0
  39. data/lib/public/javascripts/plupload-rails3/plupload/examples/jquery/events.html +196 -0
  40. data/lib/public/javascripts/plupload-rails3/plupload/examples/jquery/jquery_ui_widget.html +103 -0
  41. data/lib/public/javascripts/plupload-rails3/plupload/examples/jquery/queue_widget.html +174 -0
  42. data/lib/public/javascripts/plupload-rails3/plupload/examples/jquery/s3.php +158 -0
  43. data/lib/public/javascripts/plupload-rails3/plupload/examples/upload.php +124 -0
  44. data/lib/public/javascripts/plupload-rails3/plupload/js/.DS_Store +0 -0
  45. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/.DS_Store +0 -0
  46. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/css/jquery.plupload.queue.css +177 -0
  47. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/img/backgrounds.gif +0 -0
  48. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/img/buttons-disabled.png +0 -0
  49. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/img/buttons.png +0 -0
  50. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/img/delete.gif +0 -0
  51. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/img/done.gif +0 -0
  52. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/img/error.gif +0 -0
  53. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/img/throbber.gif +0 -0
  54. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/img/transp50.png +0 -0
  55. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/jquery.plupload.queue.js +1 -0
  56. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.ui.plupload/.DS_Store +0 -0
  57. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.ui.plupload/css/jquery.ui.plupload.css +139 -0
  58. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.ui.plupload/img/plupload-bw.png +0 -0
  59. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.ui.plupload/img/plupload.png +0 -0
  60. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.ui.plupload/jquery.ui.plupload.js +1 -0
  61. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.browserplus.js +1 -0
  62. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.flash.js +1 -0
  63. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.flash.swf +0 -0
  64. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.full.js +2 -0
  65. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.gears.js +1 -0
  66. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.html4.js +1 -0
  67. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.html5.js +1 -0
  68. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.js +2 -0
  69. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.silverlight.js +1 -0
  70. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.silverlight.xap +0 -0
  71. data/lib/public/javascripts/plupload-rails3/plupload/license.txt +339 -0
  72. data/lib/public/javascripts/plupload-rails3/plupload/readme.md +46 -0
  73. data/lib/public/stylesheets/.DS_Store +0 -0
  74. data/lib/public/stylesheets/.gitkeep +0 -0
  75. data/lib/public/stylesheets/plupload-rails3/jquery-ui.custom.css +578 -0
  76. data/lib/public/stylesheets/plupload-rails3/plupload.queue.3.1.css +171 -0
  77. data/lib/public/stylesheets/plupload-rails3/plupload.queue.css +171 -0
  78. data/lib/tasks/asset_mover.rake +15 -0
  79. data/plupload-rails3.gemspec +24 -0
  80. data/test/plupload_rails3_test.rb +29 -0
  81. data/test/test_helper.rb +3 -0
  82. data/uninstall.rb +3 -0
  83. metadata +131 -0
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in plupload-rails3.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,38 @@
1
+ Copyright (c) 2011 Sammy Larbi MIT License for plupload-rails3:
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.
21
+
22
+ -------------------
23
+
24
+ Plupload and components Licenses:
25
+
26
+ Plupload uses GPLv2, and its Silverlight components use:
27
+
28
+ FJCore (MIT License) (http://code.google.com/p/fjcore/) that includes
29
+ The Independent JPEG Group's JPEG software (IJG.txt) and
30
+ Java Advanced Imaging IO by Sun Microsystems (JAI.txt)
31
+
32
+ PngEncoder (http://www.gnu.org/licenses/lgpl-2.1.txt)
33
+
34
+ ZipLib (http://www.icsharpcode.net/OpenSource/SharpZipLib/)
35
+
36
+ -------------------
37
+
38
+ JQuery lets you choose between MIT and GPL licenses.
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ plupload-rails3
2
+ ==============
3
+
4
+ [Plupload](http://www.plupload.com/) lets you upload multiple files at a time and even allows drag and drop from the local file system into the browser (with Firefox and Safari).
5
+
6
+ This plugin tries to make its integration with Rails 3 very simple.
7
+
8
+ To install as a plugin (from inside your project's directory):
9
+
10
+ rails plugin install git://github.com/codeodor/plupload-rails3.git
11
+
12
+ To remove the plugin:
13
+
14
+ rails plugin uninstall plupload-rails3
15
+
16
+
17
+ To install as a gem:
18
+
19
+ 1. Put `gem 'plupload-rails3'` in your application's Gemfile
20
+ 2. Run `bundle install` from the command line inside your application's directory
21
+ 3. Run `bundle exec rake plupload_rails3:install_assets` from the command line inside your application's directory
22
+
23
+ To remove the gem from your project, remove the line in your Gemfile. You can remove the assets that got copied to your application by running `bundle exec rake plupload_rails3:uninstall_assets` from the command line inside your application's directory.
24
+
25
+ For Rails 3.1, you'll also need to tell the asset pipeline about the new assets.
26
+
27
+ In assets/javascripts/application.js make sure your application provides URL access to the plupload scripts, CSS, and images:
28
+
29
+ //= provide_tree ../../../vendor/assets/javascripts/plupload-rails3
30
+ //= provide_tree ../../../vendor/assets/stylesheets/plupload-rails3
31
+ //= provide_tree ../../../vendor/assets/images/plupload-rails3
32
+
33
+
34
+
35
+
36
+
37
+ To use:
38
+
39
+ <%= plupload(model, method, options={:plupload_container=>'uploader'}) %>
40
+ <div id="uploader" name="uploader" style="width: 100%;"></div>
41
+
42
+
43
+ If you are using a nested resource, model can be an array like you'd use for url_for. For example: `model = [@folder, @file]` where `@file` is the model you're interested in uploading, but it is nested under `@folder`.
44
+
45
+
46
+ Options can be:
47
+
48
+ * :params => A hash of params you want submitted with each uploaded file.
49
+ * :plupload_container => The name of the div or whatever where plupload is going to render itself. Defaults to 'uploader'
50
+ * :max_file_size => An integer indicating the number of megabytes to allow. Defaults to 10.
51
+ * :filters => An array of hashes with :title and :extension keys specifying the files to look for. Defaults to [], which will show all files.
52
+ * :pluploader => a value of `true` indicates that you want to have the files submitted with your form instead of in individual requests. To make this work, you need to add `match 'plupload_rails/_plupload_uploader', :controller=>'plupload_rails', :action=>'_plupload_uploader', :as=>'pluploader'` to your config/routes.rb file so plupload can upload the files, and then this plugin will insert some extra form fields into your page via JavaScript. Those fields tell the middleware how to form the request parameters before they get to your controller.
53
+ * :field_name => the name of the field, which defaults to model_name[method_name]
54
+
55
+ Example filter:
56
+
57
+ :filters=>[{:title=>'Images', :extensions=>'jpg,gif,png'},{:title=>'PDF', :extensions=>'pdf'}])
58
+
59
+
60
+ Note: Most of the plupload code in lib/app/views/plupload/_uploader_scripts.html.erb is from http://www.theroamingcoder.com/node/50, where I learned how to use Plupload with Rails.
61
+
62
+
63
+ Example 1: Uploading the files hitting the action once for each file
64
+ ====================================================================
65
+
66
+ In your view:
67
+
68
+ <%= plupload(@library_file, :payload, {:params=>{:library_file=>{:title=>"some title"}}}) %>
69
+
70
+ Also in the view, you'll need to tell it where to go:
71
+
72
+ <div id="uploader" name="uploader" style="width: 100%;"></div>
73
+
74
+ @library_file should be your model, where :payload is the method which holds the file contents, so that when plupload uploads the files (it hits #create once for each file) it will put the uploaded file in params[:library_file][:payload] which you can then read like this in your controller:
75
+
76
+ params[:library_file][:payload] = params[:library_file][:payload].read
77
+
78
+ Then if you're storing it in the DB, you let it continue on to
79
+
80
+ @library_file = LibraryFile.new(params[:library_file])
81
+
82
+
83
+ Example 2: Uploading the files for a has_many relationship with accepts_nested_attributes_for
84
+ =============================================================================================
85
+ Consider the common case of an Album which has_many Photos.
86
+
87
+ In your form for an album, you can use:
88
+
89
+ <%= plupload(@album, :photos, options={:plupload_container=>'uploader', :pluploader=>true, :field_name=>'album[photos][][payload]'}) %>
90
+ <div id="uploader" name="uploader" style="width: 100%;"></div>
91
+
92
+
93
+ What this does is tells the plugin to use the pluploader (which needs a route: `match 'plupload_rails/_plupload_uploader', :controller=>'plupload_rails', :action=>'_plupload_uploader', :as=>'pluploader'`) and tells it what to name the field - in this case the Album `has_many` Photos, and the method we want on photo is called `payload`.
94
+
95
+
96
+
97
+
98
+
99
+ Copyright (c) 2011 [Sammy Larbi](http://www.codeodor.com), released under the MIT license
100
+ (with Plupload and it's components using other licenses -- see LICENSE file)
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the plupload_rails3 plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the plupload_rails3 plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'PluploadRails3'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
data/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'plupload-rails3'
2
+
3
+ config.middleware.use(ActionDispatch::PluploadParamsRenamer)
data/install.rb ADDED
@@ -0,0 +1,9 @@
1
+ asset_mover_file = File.join(File.dirname(__FILE__), 'lib/plupload-rails3/asset_mover')
2
+
3
+ if File.exists?(asset_mover_file)
4
+ require asset_mover_file
5
+ else #to install locally, I have to use rails runner instead of rails plugin install, and it gives a messed up path
6
+ require File.join(Rails.root, File.dirname(__FILE__), 'lib/plupload-rails3/asset_mover')
7
+ end
8
+
9
+ install_plupload_assets
data/lib/.DS_Store ADDED
Binary file
data/lib/app/.DS_Store ADDED
Binary file
@@ -0,0 +1,38 @@
1
+ class PluploadRailsController < ActionController::Base
2
+ def _plupload_uploader
3
+ plupload_temp_path = "tmp/plupload-rails3/#{File.basename(params[:file].tempfile.path)}"
4
+ FileUtils.mv(params[:file].tempfile, plupload_temp_path)
5
+ add_fields_for_files_to_forms =<<END
6
+ function _pluploadRails_addFieldsForFilesToForms(){
7
+ for(var i=0; document.forms.length; i++) {
8
+ var theForm = document.forms[i];
9
+ var input = document.createElement("input");
10
+ input.name='_plupload_files[]';
11
+ input.type='hidden';
12
+ input.value='#{File.expand_path(params[:file].tempfile.path)}';
13
+ theForm.appendChild(input);
14
+
15
+ var input = document.createElement("input");
16
+ input.name='_plupload_original_names[]';
17
+ input.type='hidden';
18
+ input.value='#{params[:file].original_filename}';
19
+ theForm.appendChild(input);
20
+
21
+ var input = document.createElement("input");
22
+ input.name='_plupload_content_types[]';
23
+ input.type='hidden';
24
+ input.value='#{params[:file].content_type}';
25
+ theForm.appendChild(input);
26
+
27
+ var input = document.createElement("input");
28
+ input.name='_plupload_upload';
29
+ input.type='hidden';
30
+ input.value='#{params[:_plupload_upload]}';
31
+ if(document.getElementsByName(input.name).length == 0) theForm.appendChild(input);
32
+ }
33
+ }
34
+ _pluploadRails_addFieldsForFilesToForms();
35
+ END
36
+ render :text=>add_fields_for_files_to_forms
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+ module PluploadHelper
2
+ def plupload(model_object, model_object_method, options={})
3
+ options[:plupload_container] ||= 'uploader'
4
+ options[:max_file_size] ||= 10
5
+ options[:filters] ||= []
6
+ options[:params] ||= {}
7
+ options[:field_name] ||= [model_object].flatten.pop.class.name.underscore.downcase + "[#{model_object_method}]"
8
+ render :partial=>'plupload/uploader_scripts', :locals=>{
9
+ :model_object=>model_object,
10
+ :model_object_method=>model_object_method,
11
+ :options=>options
12
+ }
13
+ end
14
+ end
@@ -0,0 +1,38 @@
1
+ require 'action_dispatch/http/request'
2
+ module ActionDispatch
3
+ class PluploadParamsRenamer
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ req = Rack::Request.new(env)
10
+ form_hash = Rails.version < "3.1" ? req.POST : env['rack.request.form_hash']
11
+ form_hash ||= {}
12
+
13
+ if form_hash["_plupload_upload"]
14
+ object, method = form_hash["_plupload_upload"].split(/[\[\]]/)
15
+ submethod = form_hash["_plupload_upload"].split(/[\[\]]/)[-1]
16
+ form_hash[object] ||= {}
17
+ if form_hash["_plupload_files"]
18
+ form_hash[object][method] = []
19
+ form_hash["_plupload_files"].each_with_index do |file, i|
20
+ plupload_temp_path = "tmp/plupload-rails3/#{File.basename(file)}"
21
+ FileUtils.mv(plupload_temp_path, file)
22
+
23
+ original_filename = form_hash["_plupload_original_names"][i]
24
+ content_type = form_hash["_plupload_content_types"][i]
25
+
26
+ uploaded_file = ActionDispatch::Http::UploadedFile.new(:tempfile=>File.new(file), :content_type=>content_type, :filename=>original_filename)
27
+
28
+ form_hash[object][method] << {submethod=>uploaded_file}
29
+ end
30
+ else
31
+ form_hash[object][method] = form_hash["file"]
32
+ end
33
+ end
34
+
35
+ @app.call(env)
36
+ end
37
+ end
38
+ end
Binary file
@@ -0,0 +1,72 @@
1
+ <% if Rails.version < "3.1" %>
2
+ <!-- load JQuery if not loaded -->
3
+ <script type="text/javascript" src="http://www.google.com/jsapi"></script>
4
+ <script type="text/javascript">
5
+ if(typeof jQuery === 'undefined') google.load("jquery", "1.3");
6
+ </script>
7
+
8
+ <!-- Load Queue widget CSS and jQuery -->
9
+ <style type="text/css">@import url(/stylesheets/plupload-rails3/plupload.queue.css);</style>
10
+
11
+ <!-- Load plupload and all it's runtimes and finally the jQuery queue widget -->
12
+ <script type="text/javascript" src="/javascripts/plupload-rails3/plupload/js/plupload.full.js"></script>
13
+ <script type="text/javascript" src="/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/jquery.plupload.queue.js"></script>
14
+
15
+ <!-- Thirdparty intialization scripts, needed for the Google Gears and BrowserPlus runtimes -->
16
+ <script type="text/javascript" src="http://bp.yahooapis.com/2.4.21/browserplus-min.js"></script>
17
+ <script type="text/javascript" src="/javascripts/plupload-rails3/plupload/js/plupload.gears.js"></script>
18
+ <% else %>
19
+
20
+ <style type="text/css">@import url(/assets/plupload-rails3/plupload.queue.3.1.css);</style>
21
+ <%= stylesheet_link_tag 'plupload-rails3/plupload/js/plupload.full.js' %>
22
+ <%= javascript_include_tag 'plupload-rails3/plupload/js/plupload.full.js' %>
23
+ <%= javascript_include_tag 'plupload-rails3/plupload/js/jquery.plupload.queue/jquery.plupload.queue.js' %>
24
+ <%= javascript_include_tag 'plupload-rails3/plupload/js/plupload.gears.js' %>
25
+
26
+ <% end %>
27
+
28
+
29
+ <script type="text/javascript">
30
+
31
+ // Convert divs to queue widgets when the DOM is ready
32
+ $(function() {
33
+ var authtoken = $("input[name=authenticity_token]").val();
34
+ $("#<%= options[:plupload_container] %>").pluploadQueue({
35
+ // General settings
36
+ runtimes : 'html5,flash,silverlight,gears,browserplus',
37
+ <% unless options[:pluploader] %>
38
+ url : '<%= url_for(model_object) %>',
39
+ <% else %>
40
+ url : '<%= pluploader_path %>',
41
+ <% end %>
42
+ max_file_size : '<%= options[:max_file_size] %>mb',
43
+ //chunk_size : '1mb',
44
+ //unique_names : true,
45
+ multipart: true,
46
+ multipart_params :
47
+ $.extend({
48
+ <% if options[:params].count > 0 %>'<%= CGI::unescape(options[:params].to_query.split("=").join("':'")) %>'<% end %>
49
+ },
50
+ {
51
+ authenticity_token : authtoken,
52
+ "_method" : "<%= [model_object].flatten.pop.new_record? ? 'post' : 'put' %>",
53
+ "_plupload_upload" : "<%= options[:field_name] %>"
54
+ }
55
+ ),
56
+ <% if options[:filters].count > 0 %>
57
+ filters : <%= options[:filters].to_json.to_s.html_safe %>,
58
+ <% end %>
59
+ flash_swf_url : '/javascripts/plupload-rails3/plupload/js/plupload.flash.swf',
60
+ silverlight_xap_url : '/javascripts/plupload-rails3/plupload/js/plupload.silverlight.xap'
61
+ <% if options[:pluploader] %>
62
+ ,
63
+ init: {
64
+ FileUploaded: function(up, file, info) {
65
+ eval(info.response);
66
+ }
67
+ }
68
+ <% end %>
69
+ });
70
+
71
+ });
72
+ </script>
@@ -0,0 +1,20 @@
1
+ require "plupload-rails3/version"
2
+ require "plupload-rails3/railtie"
3
+
4
+ require 'app/helpers/plupload_helper'
5
+ require 'app/middleware/plupload_params_renamer'
6
+ require 'app/controllers/plupload_rails_controller'
7
+
8
+ %w{ middleware helpers controllers }.each do |dir|
9
+ path = File.join(File.dirname(__FILE__), 'app', dir)
10
+ $LOAD_PATH << path
11
+ ActiveSupport::Dependencies.autoload_paths << path
12
+ ActiveSupport::Dependencies.autoload_once_paths.delete(path)
13
+ end
14
+
15
+ ActionController::Base.append_view_path File.expand_path(File.join(File.dirname(__FILE__), 'app', 'views'))
16
+
17
+ #ActionView::Base.send :include, PluploadHelper
18
+ ActionController::Base.helper(PluploadHelper)
19
+
20
+ #ActionController::Dispatcher.middleware.insert_before(ActionDispatch::ParamsParser, ActionDispatch::PluploadParamsRenamer)
@@ -0,0 +1,54 @@
1
+ require 'fileutils'
2
+
3
+ def plupload_asset_destination
4
+ if Rails.version < "3.1"
5
+ dest = {
6
+ :img => "public/images",
7
+ :js => "public/javascripts",
8
+ :css => "public/stylesheets"
9
+ }
10
+ else
11
+ dest = {
12
+ :img => "vendor/assets/images",
13
+ :js => "vendor/assets/javascripts",
14
+ :css => "vendor/assets/stylesheets"
15
+ }
16
+ end
17
+ return dest
18
+ end
19
+
20
+ def install_plupload_assets
21
+ plupload_asset_destination.keys.each do |asset_type|
22
+ directory = File.join(Rails.root, plupload_asset_destination[asset_type])
23
+ puts "Making directory: #{directory}/plupload-rails3"
24
+ FileUtils.mkdir_p(directory)
25
+ end
26
+
27
+ dest = File.join(Rails.root, plupload_asset_destination[:img])
28
+ puts "Copying image assets to #{dest}/plupload-rails3"
29
+ FileUtils.cp_r(File.join(File.dirname(__FILE__), '../public/images/plupload-rails3'), dest)
30
+
31
+ dest = File.join(Rails.root, plupload_asset_destination[:js])
32
+ puts "Copying javascript assets to #{dest}"
33
+ FileUtils.cp_r(File.join(File.dirname(__FILE__), '../public/javascripts/plupload-rails3'), dest)
34
+
35
+ dest = File.join(Rails.root, plupload_asset_destination[:css])
36
+ puts "Copying stylesheet assets to #{dest}"
37
+ FileUtils.cp_r(File.join(File.dirname(__FILE__), '../public/stylesheets/plupload-rails3'), dest)
38
+
39
+ dest = File.join(Rails.root, 'tmp/plupload-rails3')
40
+ puts "Creating tmp folder at #{dest}"
41
+ FileUtils.mkdir(dest)
42
+ end
43
+
44
+ def uninstall_plupload_assets
45
+ plupload_asset_destination.keys.each do |asset_type|
46
+ directory = File.join(Rails.root, plupload_asset_destination[asset_type], "plupload-rails3")
47
+ puts "Removing directory #{directory} and its contents"
48
+ FileUtils.rm_r(directory)
49
+ end
50
+
51
+ directory = File.join(Rails.root,'tmp/plupload-rails3')
52
+ puts "Removing directory #{directory} and its contents"
53
+ FileUtils.rm_r(directory)
54
+ end
@@ -0,0 +1,12 @@
1
+ module PluploadRails3
2
+ class Railtie < Rails::Railtie
3
+ initializer "plupload-rails3.configure_middleware" do |app|
4
+ app.middleware.use ActionDispatch::PluploadParamsRenamer
5
+ end
6
+
7
+ rake_tasks do
8
+ Dir[File.join(File.dirname(__FILE__),'../tasks/*.rake')].each { |f| load f }
9
+ end
10
+
11
+ end
12
+ end