actionverb_s3_direct_upload 0.0.12 → 0.0.13

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWI4NjA5NDYwNWIwZmZiN2FmMDk4ODBlNmU3OTM0MDc1ZjlmZTgzYQ==
4
+ MDkwMzEwYjRhYjY4ZjQ3MmY1YWEzNmY2MmU2ODk3ODUzZWM3NjUxMw==
5
5
  data.tar.gz: !binary |-
6
- NTZlOTIzNGJiNDdkYzUzMzFjODY2ZWZlNjEzODhkMmY4MTE0NTYyMg==
6
+ NzJlMDhjMWU4YTljNzhkOTU5ZTBkZDM5ZjZlMDUxNzEzMzRiZmVjNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ODNhYTZhNmM0MmQ5NmQ1Mjg0YjkwOWI3ZjZlMjRmNjZmMDJjOTdlZjAxMGMw
10
- ZjFkODFlNTA1MmJmMTZjZjc5YjZmN2JhOWE2NTlkOTk1ZTNlODc4MzdjZGM1
11
- OGY0OGM3MjNmZWY0YjNmYmJiZmUxNjlhNTdhYWZmNWE0ZGY2ZDE=
9
+ OGZmNzljOWI4ODFjZjBkNDM4ZDBjNzlkNmEwMTRkMTFlMmI1YzUxMGJhM2U3
10
+ ODViOTNhYjNiZjY5YWFiNmExY2NmNjQ3NWEzMzY3MmVlYjZjNDI0NWI3YjEz
11
+ MWYzYjBjNTJiNDA3YzU1NTAyNTY3NWNkOGQxZjEwNDk5ZTljYzA=
12
12
  data.tar.gz: !binary |-
13
- NDU5ZTkwOWQ2NzM2NmY4MTMyNDMzM2ZkMTA5ODNiZWNjNmI4ZmY0OWU1MmQ1
14
- NjA1ODY0MjY4NDUxMDU3ODI5OWVmMzNhMzNhZDIyYmI4YWFhZTlmZGM3YmMz
15
- YTNjNjc3YThmNTRkZTcxNWU1YWMzYWQwZmFiNjNjNTVjMGRkN2Q=
13
+ ZDg5Y2ViMWVhNGZkNmM1NGYyMjkwYWRmZmUwNGVmOTZjNWNhNjA0MDIxYzc5
14
+ ODNkNDFmZjYwMzU2MWVhMTQwOWRmNjliNWU4ZTdkMjMxODRjMjdiMzdlOGQz
15
+ MWY0M2EyYTJlMWY3NTZmNjdkNzI1ZDhkMmYwNGNhNTgxZmM3NmE=
@@ -16,8 +16,8 @@ $.fn.S3Uploader = (options) ->
16
16
 
17
17
  settings =
18
18
  path: ''
19
+ add: null
19
20
  additional_data: null
20
- before_add: null
21
21
  remove_completed_progress_bar: true
22
22
  progress_container: $uploadForm
23
23
 
@@ -35,30 +35,27 @@ $.fn.S3Uploader = (options) ->
35
35
  add: (e, data) ->
36
36
  current_files.push data
37
37
  file = data.files[0]
38
- unless settings.before_add and not settings.before_add(data)
39
- data.context = $(tmpl("template-upload", file)) if $('#template-upload').length > 0
40
- settings['progress_container'].append(data.context)
41
- data.submit()
38
+ settings.add(data)
42
39
 
43
40
  progress: (e, data) ->
44
- if data.context
45
- progress = parseInt(data.loaded / data.total * 100, 10)
46
- data.context.find('.bar').css('width', progress + '%')
41
+ progress = parseInt(data.loaded / data.total * 100, 10)
42
+ data.context.find('.bar').css('width', progress + '%')
47
43
 
48
44
  done: (e, data) ->
45
+ completed_upload = (data, content) =>
46
+ data.context.remove() if data.context && settings.remove_completed_progress_bar # remove progress bar
47
+ $uploadForm.trigger("s3_upload_complete", [content])
48
+
49
+ current_files.splice($.inArray(data, current_files), 1) # remove that element from the array
50
+ if current_files.length == 0
51
+ $(document).trigger("s3_uploads_complete")
52
+
49
53
  content = build_content_object $uploadForm, data.files[0]
50
-
51
- to = $uploadForm.data('post')
52
- if to
53
- content[$uploadForm.data('as')] = content.url
54
- $.post(to, content)
55
-
56
- data.context.remove() if data.context && settings.remove_completed_progress_bar # remove progress bar
57
- $uploadForm.trigger("s3_upload_complete", [content])
58
54
 
59
- current_files.splice($.inArray(data, current_files), 1) # remove that element from the array
60
- if current_files.length == 0
61
- $(document).trigger("s3_uploads_complete")
55
+ #once an upload completes, post to the server designated in the "data-post" attribute of the s3_upload_form
56
+ to = $uploadForm.data('post')
57
+ content[$uploadForm.data('as')] = content.url
58
+ $.post(to, content, completed_upload(data, content)).error(=> fail(data))
62
59
 
63
60
  fail: (e, data) ->
64
61
  content = build_content_object $uploadForm, data.files[0]
@@ -80,7 +77,11 @@ $.fn.S3Uploader = (options) ->
80
77
 
81
78
  build_content_object = ($uploadForm, file) ->
82
79
  domain = $uploadForm.attr('action')
83
- path = settings.path + $uploadForm.find('input[name=key]').val().replace('/${filename}', '')
80
+
81
+ if !file.upload_path
82
+ file.upload_path = $uploadForm.find('input[name=key]').val().replace('/${filename}', '')
83
+
84
+ path = settings.path + file.upload_path
84
85
  content = {}
85
86
  content.url = domain + path + '/' + file.name
86
87
  content.filename = file.name
@@ -0,0 +1,118 @@
1
+ // Generated by CoffeeScript 1.3.3
2
+ var $;
3
+
4
+ $ = jQuery;
5
+
6
+ $.fn.S3Uploader = function(options) {
7
+ var $uploadForm, build_content_object, current_files, setUploadForm, settings;
8
+ if (this.length > 1) {
9
+ this.each(function() {
10
+ return $(this).S3Uploader(options);
11
+ });
12
+ return this;
13
+ }
14
+ $uploadForm = this;
15
+ settings = {
16
+ path: '',
17
+ add: null,
18
+ additional_data: null,
19
+ remove_completed_progress_bar: true,
20
+ progress_container: $uploadForm
21
+ };
22
+ $.extend(settings, options);
23
+ current_files = [];
24
+ setUploadForm = function() {
25
+ return $uploadForm.fileupload({
26
+ start: function(e) {
27
+ return $uploadForm.trigger("s3_uploads_start", [e]);
28
+ },
29
+ add: function(e, data) {
30
+ var file;
31
+ current_files.push(data);
32
+ file = data.files[0];
33
+ return settings.add(data);
34
+ },
35
+ progress: function(e, data) {
36
+ var progress;
37
+ progress = parseInt(data.loaded / data.total * 100, 10);
38
+ return data.context.find('.bar').css('width', progress + '%');
39
+ },
40
+ done: function(e, data) {
41
+ var completed_upload, content, to,
42
+ _this = this;
43
+ completed_upload = function(data, content) {
44
+ if (data.context && settings.remove_completed_progress_bar) {
45
+ data.context.remove();
46
+ }
47
+ $uploadForm.trigger("s3_upload_complete", [content]);
48
+ current_files.splice($.inArray(data, current_files), 1);
49
+ if (current_files.length === 0) {
50
+ return $(document).trigger("s3_uploads_complete");
51
+ }
52
+ };
53
+ content = build_content_object($uploadForm, data.files[0]);
54
+ to = $uploadForm.data('post');
55
+ content[$uploadForm.data('as')] = content.url;
56
+ return $.post(to, content, completed_upload(data, content)).error(function() {
57
+ return fail(data);
58
+ });
59
+ },
60
+ fail: function(e, data) {
61
+ var content;
62
+ content = build_content_object($uploadForm, data.files[0]);
63
+ content.error_thrown = data.errorThrown;
64
+ return $uploadForm.trigger("s3_upload_failed", [content]);
65
+ },
66
+ formData: function(form) {
67
+ var data, fileType;
68
+ data = form.serializeArray();
69
+ fileType = "";
70
+ if ("type" in this.files[0]) {
71
+ fileType = this.files[0].type;
72
+ }
73
+ data.push({
74
+ name: "Content-Type",
75
+ value: fileType
76
+ });
77
+ data[1].value = settings.path + data[1].value;
78
+ return data;
79
+ }
80
+ });
81
+ };
82
+ build_content_object = function($uploadForm, file) {
83
+ var content, domain, path;
84
+ domain = $uploadForm.attr('action');
85
+ if (!file.upload_path) {
86
+ file.upload_path = $uploadForm.find('input[name=key]').val().replace('/${filename}', '');
87
+ }
88
+ path = settings.path + file.upload_path;
89
+ content = {};
90
+ content.url = domain + path + '/' + file.name;
91
+ content.filename = file.name;
92
+ content.filepath = path;
93
+ if ('size' in file) {
94
+ content.filesize = file.size;
95
+ }
96
+ if ('type' in file) {
97
+ content.filetype = file.type;
98
+ }
99
+ if ('relativePath' in file) {
100
+ content.filerelativepath = file.relativePath;
101
+ }
102
+ if (settings.additional_data) {
103
+ content = $.extend(content, settings.additional_data);
104
+ }
105
+ return content;
106
+ };
107
+ this.initialize = function() {
108
+ setUploadForm();
109
+ return this;
110
+ };
111
+ this.path = function(new_path) {
112
+ return settings.path = new_path;
113
+ };
114
+ this.additional_data = function(new_data) {
115
+ return settings.additional_data = new_data;
116
+ };
117
+ return this.initialize();
118
+ };
@@ -1,3 +1,3 @@
1
1
  module S3DirectUpload
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionverb_s3_direct_upload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wayne Hoover
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-18 00:00:00.000000000 Z
11
+ date: 2013-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -74,13 +74,14 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - lib/actionverb_s3_direct_upload.rb
77
- - lib/s3_direct_upload.rb
78
- - lib/s3_direct_upload/form_helper.rb
77
+ - lib/s3_direct_upload/config_aws.rb
79
78
  - lib/s3_direct_upload/engine.rb
79
+ - lib/s3_direct_upload/form_helper.rb
80
80
  - lib/s3_direct_upload/version.rb
81
- - lib/s3_direct_upload/config_aws.rb
82
- - app/assets/stylesheets/s3_direct_upload_progress_bars.css.scss
81
+ - lib/s3_direct_upload.rb
83
82
  - app/assets/javascripts/s3_direct_upload.js.coffee
83
+ - app/assets/javascripts/s3_direct_upload.js.js
84
+ - app/assets/stylesheets/s3_direct_upload_progress_bars.css.scss
84
85
  - LICENSE
85
86
  - README.md
86
87
  homepage: ''
@@ -108,3 +109,4 @@ specification_version: 4
108
109
  summary: Gives a form helper for Rails which allows direct uploads to s3. Based on
109
110
  RailsCast#383
110
111
  test_files: []
112
+ has_rdoc: