s3_form_presenter 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +33 -6
- data/lib/s3_form_presenter.rb +3 -2
- data/lib/s3_form_presenter/version.rb +1 -1
- data/test/form_test.rb +6 -0
- metadata +4 -3
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg/*
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,37 @@
|
|
1
|
-
|
1
|
+
## S3 Form Presenter
|
2
2
|
|
3
3
|
Generates a simple form that is compatible with S3's form API. You can upload S3 assets directly to S3 without hitting your server.
|
4
4
|
|
5
|
-
|
5
|
+
## Usage
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
```ruby
|
8
|
+
<% S3FormPresenter::Form.new("some/key/path.ext") do %>
|
9
|
+
<input name="file" type="file">
|
10
|
+
<input type="submit" value="Save File">
|
11
|
+
<% end %>
|
12
|
+
```
|
13
|
+
|
14
|
+
## Sinatra Integration (this will be put in a module one day)
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
helpers do
|
18
|
+
def s3_form(*args, &block)
|
19
|
+
buff = capture_erb(*args, &block)
|
20
|
+
form = S3FormPresenter::Form.new(*args)
|
21
|
+
form.inner_content = buff
|
22
|
+
@_out_buf << form.to_html
|
23
|
+
end
|
24
|
+
|
25
|
+
def capture_erb(*args, &block)
|
26
|
+
erb_with_output_buffer { block_given? && block.call(*args) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def erb_with_output_buffer(buf = '') #:nodoc:
|
30
|
+
@_out_buf, old_buffer = buf, @_out_buf
|
31
|
+
yield
|
32
|
+
@_out_buf
|
33
|
+
ensure
|
34
|
+
@_out_buf = old_buffer
|
35
|
+
end
|
36
|
+
end
|
37
|
+
```
|
data/lib/s3_form_presenter.rb
CHANGED
@@ -7,7 +7,7 @@ module S3FormPresenter
|
|
7
7
|
HIDDEN_FIELD_NAMES = :key, :access_key, :secret_key, :acl, :redirect_url, :policy, :signature
|
8
8
|
ACCESSOR_FIELDS = HIDDEN_FIELD_NAMES - [:policy, :signature]
|
9
9
|
RENAMED_FIELDS = {:redirect_url => "success_action_redirect", :access_key => "AWSAccessKeyId"}
|
10
|
-
attr_accessor :bucket, :inner_content
|
10
|
+
attr_accessor :bucket, :inner_content, :extra_form_attributes
|
11
11
|
|
12
12
|
def initialize(key, options={}, &block)
|
13
13
|
@key = key
|
@@ -15,6 +15,7 @@ module S3FormPresenter
|
|
15
15
|
@secret_key = options[:secret_key] || ENV["AWS_SECRET_ACCESS_KEY"]
|
16
16
|
@bucket = options[:bucket] || ENV["AWS_S3_BUCKET"]
|
17
17
|
@acl = options[:acl]
|
18
|
+
@extra_form_attributes = options[:extra_form_attributes]
|
18
19
|
if block_given?
|
19
20
|
@inner_content = block.call
|
20
21
|
else
|
@@ -24,7 +25,7 @@ module S3FormPresenter
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def header
|
27
|
-
%Q(<form action="http://#{bucket}.s3.amazonaws.com/" method="post" enctype="multipart/form-data">)
|
28
|
+
%Q(<form action="http://#{bucket}.s3.amazonaws.com/" method="post" enctype="multipart/form-data"#{extra_form_attributes}>)
|
28
29
|
end
|
29
30
|
|
30
31
|
def footer
|
data/test/form_test.rb
CHANGED
@@ -106,4 +106,10 @@ describe S3FormPresenter::Form do
|
|
106
106
|
@form.to_html.must_equal content
|
107
107
|
end
|
108
108
|
end
|
109
|
+
|
110
|
+
describe "extra_form_attributes" do
|
111
|
+
it "generates extra form attributes when provided in options" do
|
112
|
+
Form.new("some/key.ext", :extra_form_attributes => %Q( class="form-horizontal")).header.must_equal %Q(<form action="http://.s3.amazonaws.com/" method="post" enctype="multipart/form-data" class="form-horizontal">)
|
113
|
+
end
|
114
|
+
end
|
109
115
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3_form_presenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -19,6 +19,7 @@ executables: []
|
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
+
- .gitignore
|
22
23
|
- Gemfile
|
23
24
|
- Gemfile.lock
|
24
25
|
- LICENSE
|
@@ -43,7 +44,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
43
44
|
version: '0'
|
44
45
|
segments:
|
45
46
|
- 0
|
46
|
-
hash:
|
47
|
+
hash: 1039604683610752818
|
47
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
49
|
none: false
|
49
50
|
requirements:
|
@@ -52,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
53
|
version: '0'
|
53
54
|
segments:
|
54
55
|
- 0
|
55
|
-
hash:
|
56
|
+
hash: 1039604683610752818
|
56
57
|
requirements: []
|
57
58
|
rubyforge_project: s3_form_presenter
|
58
59
|
rubygems_version: 1.8.15
|