s3lurp 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/README.md +2 -0
- data/lib/s3lurp.rb +1 -1
- data/lib/s3lurp/version.rb +1 -1
- data/lib/s3lurp/view_helpers.rb +17 -7
- data/spec/s3lurp_spec.rb +69 -0
- metadata +4 -4
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -135,6 +135,8 @@ to the helper in a hash.
|
|
135
135
|
|__:submit\_tag__ | HTML string containing code for the input or button that will handle form submission. This is optional and if not included a basic submit tag will be generated for the form. |
|
136
136
|
|__:submit\_tag\_value__ | Override the value of the standard generated submit tag. _Default:_ "Upload" |
|
137
137
|
|__:submit\_tag\_options__ | Hash of options passed to the submit_tag generator. |
|
138
|
+
|__:no\_file\_input__ | When set to true, will not generate ae file field input. Useful when combined with form_fields_only |
|
139
|
+
|__:form\_fields\_only__ | Will generate only the form fields and not the form tag or the submit tag. Useful for customization. |
|
138
140
|
|
139
141
|
|
140
142
|
### Examples
|
data/lib/s3lurp.rb
CHANGED
@@ -10,7 +10,7 @@ module S3lurp
|
|
10
10
|
:success_action_redirect, :success_action_status,
|
11
11
|
:min_file_size, :max_file_size,
|
12
12
|
:amz_meta_tags, :minutes_valid,
|
13
|
-
:form_html_options, :file_field_tag_accept, :multiple_files,
|
13
|
+
:form_html_options, :file_field_tag_accept, :multiple_files, :form_fields_only, :no_file_input,
|
14
14
|
:submit_tag, :submit_tag_value, :submit_tag_options,
|
15
15
|
:file, :key].freeze
|
16
16
|
class << self
|
data/lib/s3lurp/version.rb
CHANGED
data/lib/s3lurp/view_helpers.rb
CHANGED
@@ -19,9 +19,14 @@ module S3lurp
|
|
19
19
|
NON_FIELD_OPTIONS = %w( s3_bucket aws_secret_key
|
20
20
|
max_file_size min_file_size
|
21
21
|
amz_meta_tags minutes_valid
|
22
|
-
form_html_options file_field_tag_accept multiple_files
|
22
|
+
form_html_options file_field_tag_accept multiple_files form_fields_only no_file_input
|
23
23
|
submit_tag submit_tag_value submit_tag_options).map(&:to_sym)
|
24
24
|
|
25
|
+
def s3_direct_form_fields(opt ={})
|
26
|
+
s3_direct_form_tag(opt.merge!({:form_fields_only => true}))
|
27
|
+
end
|
28
|
+
|
29
|
+
|
25
30
|
def s3_direct_form_tag(opt = {})
|
26
31
|
options = (NON_FIELD_OPTIONS + HIDDEN_FIELD_MAP.keys).each_with_object({}) do |i, h|
|
27
32
|
h[i] = opt[i] || S3lurp.config.send(i)
|
@@ -60,13 +65,18 @@ module S3lurp
|
|
60
65
|
amz_meta_tags.merge! security_fields
|
61
66
|
submit = s3_generate_submit_tag(options)
|
62
67
|
file = s3_generate_file_field_tag(options)
|
63
|
-
|
64
|
-
(
|
68
|
+
form_content = (
|
65
69
|
hidden_fields.map{|k,v| hidden_field_tag(HIDDEN_FIELD_MAP[k],v, {:id => nil})}.join.html_safe +
|
66
|
-
amz_meta_tags.map{|k,v| hidden_field_tag(k,v,{:id => nil})}.join.html_safe
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
+
amz_meta_tags.map{|k,v| hidden_field_tag(k,v,{:id => nil})}.join.html_safe
|
71
|
+
)
|
72
|
+
form_content << field_set_tag(nil,:class=>"s3lurp_file") {file} unless options[:no_file_input]
|
73
|
+
if options[:form_fields_only]
|
74
|
+
form_content
|
75
|
+
else
|
76
|
+
form_tag("http://s3.amazonaws.com/#{options[:s3_bucket]}", {:authenticity_token => false, :method => 'POST', :multipart => true}.merge(options[:form_html_options])) do
|
77
|
+
( form_content +
|
78
|
+
field_set_tag(nil,:class=>"s3lurp_submit") {submit.html_safe} )
|
79
|
+
end
|
70
80
|
end
|
71
81
|
end
|
72
82
|
|
data/spec/s3lurp_spec.rb
CHANGED
@@ -23,6 +23,40 @@ describe S3lurp::ViewHelpers do
|
|
23
23
|
form.should include(%(name="file"), %(type="file"))
|
24
24
|
end
|
25
25
|
|
26
|
+
it "should return just fields and no form tag when form_fields_only is set" do
|
27
|
+
S3lurp.configure do |config|
|
28
|
+
config.aws_access_key = nil
|
29
|
+
config.aws_secret_key = nil
|
30
|
+
end
|
31
|
+
form = view.s3_direct_form_tag({:key => '/files/s3lurp/lib/s3lurp.rb', :form_fields_only => true})
|
32
|
+
(!!form.match(/<form.*?>/)).should be_false
|
33
|
+
form.should include(%(name="key"), %(type="hidden"))
|
34
|
+
form.should include(%(name="file"), %(type="file"))
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return just fields and no form tag when s3_direct_form_fields is called" do
|
38
|
+
S3lurp.configure do |config|
|
39
|
+
config.aws_access_key = nil
|
40
|
+
config.aws_secret_key = nil
|
41
|
+
end
|
42
|
+
form = view.s3_direct_form_fields({:key => '/files/s3lurp/lib/s3lurp.rb'})
|
43
|
+
(!!form.match(/<form.*?>/)).should be_false
|
44
|
+
form.should include(%(name="key"), %(type="hidden"))
|
45
|
+
form.should include(%(name="file"), %(type="file"))
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return a form without a file input when no_file_input is set" do
|
49
|
+
S3lurp.configure do |config|
|
50
|
+
config.aws_access_key = nil
|
51
|
+
config.aws_secret_key = nil
|
52
|
+
end
|
53
|
+
form = view.s3_direct_form_tag({:key => '/files/s3lurp/lib/s3lurp.rb', :no_file_input => true})
|
54
|
+
(!!form.match(/<form.*?>/)).should be_true
|
55
|
+
form.should include(%(name="key"), %(type="hidden"))
|
56
|
+
form.should_not include(%(name="file"), %(type="file"))
|
57
|
+
end
|
58
|
+
|
59
|
+
|
26
60
|
it "should return a form with a policy and signature and my meta tags" do
|
27
61
|
S3lurp.configure do |config|
|
28
62
|
config.s3_bucket = "bucket_o_stuff"
|
@@ -57,6 +91,41 @@ describe S3lurp::ViewHelpers do
|
|
57
91
|
|
58
92
|
end
|
59
93
|
|
94
|
+
it "should return fields with a policy and signature and my meta tags" do
|
95
|
+
S3lurp.configure do |config|
|
96
|
+
config.s3_bucket = "bucket_o_stuff"
|
97
|
+
config.aws_access_key = 'oingoboingo'
|
98
|
+
config.aws_secret_key = "qwerty5678_"
|
99
|
+
end
|
100
|
+
form = view.s3_direct_form_fields({
|
101
|
+
:key => '/some/key.pl',
|
102
|
+
:acl => 'public-read',
|
103
|
+
:success_action_redirect => 'http://foobar.com/thanks',
|
104
|
+
:success_action_status => 204,
|
105
|
+
:content_disposition => "attachment",
|
106
|
+
:min_file_size => 1024,
|
107
|
+
:max_file_size => 6291456,
|
108
|
+
:minutes_valid => 333,
|
109
|
+
:amz_meta_tags => {
|
110
|
+
:foo => "bar",
|
111
|
+
:parent_id => 42
|
112
|
+
},
|
113
|
+
:form_html_options => {:class => "myclass", :id => "s3lurp_form"}
|
114
|
+
})
|
115
|
+
(!!form.match(/<form.*?>/)).should be_false
|
116
|
+
form.should_not include(%(class="myclass"))
|
117
|
+
form.should_not include(%(id="s3lurp_form"))
|
118
|
+
form.should include(%(name="key"), %(value="/some/key.pl"))
|
119
|
+
form.should include(%(name="AWSAccessKeyId"), %(value="oingoboingo"))
|
120
|
+
form.should include(%(name="file"), %(type="file"))
|
121
|
+
form.should include(%(name="policy"), %(type="hidden"))
|
122
|
+
form.should include(%(name="x-amz-meta-foo"), %(value="bar"))
|
123
|
+
form.should include(%(name="x-amz-meta-parent_id"), %(value="42"))
|
124
|
+
form.should include(%(name="Content-Disposition"), %(type="hidden"), %(value="attachment"))
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
|
60
129
|
it 'should return valid json from the generate policy method and should have the keys I send it' do
|
61
130
|
json = view.s3_generate_policy({:key => "/foo/bar/${filename}", :acl => 'public-read'},
|
62
131
|
{:bucket => 'mybucket',
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3lurp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -128,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '0'
|
129
129
|
segments:
|
130
130
|
- 0
|
131
|
-
hash:
|
131
|
+
hash: 914430202827229729
|
132
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
133
|
none: false
|
134
134
|
requirements:
|
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
137
|
version: '0'
|
138
138
|
segments:
|
139
139
|
- 0
|
140
|
-
hash:
|
140
|
+
hash: 914430202827229729
|
141
141
|
requirements: []
|
142
142
|
rubyforge_project:
|
143
143
|
rubygems_version: 1.8.25
|