universal_s3_uploader 0.0.9 → 0.1.0

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2afa7fb47ca9bbf0f491f66fb111a96719cbdc51
4
- data.tar.gz: c231e4e729768f9a4435a3cf1c427f383f26d955
3
+ metadata.gz: 73f63e41f9b6f24c596350c0bca808fe50e11c1b
4
+ data.tar.gz: 4b3f18c431c25c02d01920cdd2fc8bed9b2da69c
5
5
  SHA512:
6
- metadata.gz: 0791030c19dce94ff8140e3bb63009525f4f6c6121e25c5d2dd446f29c68bb553a4bb716c8ac276063f88d32fbdc0347fc5b863e17a7b2e4990f3d63b5c38e2e
7
- data.tar.gz: 873e03c3affcf548645e5a653820b9bbb8923c093f5490cfcc17aa5d5601f91c2f1b57c9bd9808623f2976541f81cf15830e490c071e22b80cbb805c21412b9c
6
+ metadata.gz: 93e288b7fe0f14291dc9040ec6e6e98c7fd19b3cfe55fed8c8840a56d6c03e5a0d266f751d0a29da266542957bf56e845d48a663a459ca1ab2c12026c07b0eb3
7
+ data.tar.gz: 518f68496c4e1e4c7e77fc1902641ed0bf76bd681280f8a3cbe6949c2137cc01999ac8b3aec58b0a09b6c7a616f577b6d3bb75cb8e358eb34c10e786477c9def
@@ -1,3 +1,3 @@
1
1
  module UniversalS3Uploader
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,11 +1,9 @@
1
1
  module UniversalS3Uploader
2
2
  module ViewHelper
3
- def universal_s3_uploader_tag(key, policy_name, options = {})
3
+ def universal_s3_uploader_tag(key, policy_name, id)
4
4
  uh = UploaderHelper.new(policy_name)
5
5
 
6
- form_tag(uh.url, {method: 'POST', enctype: 'multipart/form-data', authenticity_token: false, class: 'universal_s3_uploader'}.merge(options)) do
7
- uh.tags(key).html_safe
8
- end
6
+ uh.tags(key, id).html_safe
9
7
  end
10
8
 
11
9
  class UploaderHelper
@@ -20,7 +18,7 @@ module UniversalS3Uploader
20
18
  @policy = @config[policy_name]
21
19
  @policy['conditions'] << ["starts-with", "$Filename", ""] # for Flash upload
22
20
  if @policy['expiration'] == '' || @policy['expiration'].nil?
23
- @policy['expiration'] = 1.hour.from_now.iso8601
21
+ @policy['expiration'] = 1.hour.from_now.gmtime.iso8601
24
22
  end
25
23
  end
26
24
 
@@ -36,30 +34,36 @@ module UniversalS3Uploader
36
34
  raise 'No bucket name in policy Exception'
37
35
  end
38
36
 
39
- def tags(key)
37
+ def tags(key, id)
40
38
  av = ActionView::Base.new
41
- tag = ''
39
+
40
+ def div_tag(name, value)
41
+ "<div class=#{name} data-value=#{value}></div>"
42
+ end
43
+
44
+ tag = "<div class='universal_s3_uploader' id='#{id}' action='#{url}'>"
42
45
 
43
46
  ([{key: key}] + @policy['conditions']).each do |condition|
44
47
  if condition.class == Hash
45
- tag += av.hidden_field_tag condition.keys.first, condition.values.first, id: nil
48
+ tag += div_tag condition.keys.first, condition.values.first
46
49
  elsif condition.class == Array
47
50
  if condition[0] == 'eq' || condition[0] == 'starts-with'
48
- tag += av.hidden_field_tag condition[1][1..-1], condition[2], id: nil unless condition[1] == '$key'
51
+ tag += div_tag condition[1][1..-1], condition[2] unless condition[1] == '$key'
49
52
  end
50
53
  else
51
54
  raise 'Something in policy unexpected'
52
55
  end
53
56
  end
54
- tag += av.hidden_field_tag :AWSAccessKeyId, @config['access_key_id'], id: nil
55
- tag += av.hidden_field_tag :Policy, policy_encoded, id: nil
56
- tag += av.hidden_field_tag :Signature, signature, id: nil
57
+ tag += div_tag 'AWSAccessKeyId', @config['access_key_id']
58
+ tag += div_tag 'Policy', policy_encoded
59
+ tag += div_tag 'Signature', signature
57
60
  tag += av.file_field_tag :file, multiple: true, accept: 'image/*'
58
61
 
59
62
  tag += '<object id="flashUploader" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=11,1,0,0">'
60
63
  tag += '<param name="movie" value="/assets/UniversalS3Uploader.swf">'
61
64
  tag += '<param name="wmode" value="transparent">'
62
65
  tag += '</object>'
66
+ tag += '</div>'
63
67
  end
64
68
 
65
69
  def bucket
@@ -49,8 +49,6 @@
49
49
 
50
50
  UniversalS3Uploader.prototype.init = function()
51
51
  {
52
- this.element.children('div').remove();
53
-
54
52
  if (supportFormData) // if supports HTML5 FormData
55
53
  {
56
54
  this.element.children('object#flashUploader').remove();
@@ -80,9 +78,10 @@
80
78
  {
81
79
  var flashObject = this.element.children('object').get(0);
82
80
 
83
- this.element.children('input[type=hidden]').each(function ()
81
+ flashObject.sendDivId(this.element.attr('id'));
82
+ this.element.children('div').each(function ()
84
83
  {
85
- flashObject.sendFormData(this.name, this.value);
84
+ flashObject.sendFormData(this.className, $(this).data('value'));
86
85
  });
87
86
  }
88
87
  };
@@ -101,9 +100,9 @@
101
100
  UniversalS3Uploader.prototype.upload = function(file, index)
102
101
  {
103
102
  var fd = new FormData();
104
- this.element.children('input[type=hidden]').each(function()
103
+ this.element.children('div').each(function()
105
104
  {
106
- fd.append(this.name, this.value);
105
+ fd.append(this.className, $(this).data('value'));
107
106
  });
108
107
  fd.append('file', file);
109
108
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: universal_s3_uploader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dohan Kim