cuba-sendfile 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -8
- data/cuba-sendfile.gemspec +2 -2
- data/lib/cuba/send_file.rb +5 -9
- data/test/send_file.rb +1 -11
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54b99567f95e4589cd7887ec97b1dd3720ea18cc
|
4
|
+
data.tar.gz: 24dea4bfd2c0cf32ff09a406c150490372e509ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cb2f5f844556602a43341d7c55985ca6041e4a13f67343ac6d6b071c020404fc592075ec12f9ccc4f6be7d98d8b627008d5d45bd2096abcd9ac5e08b98fe5e5
|
7
|
+
data.tar.gz: fe91e2e44c214c41a58bbb1da138bb252b55f4482ba950bb4dcf2edab1c39307268546f4de826b6b0ca4289d5a9bfc8fe1f0d69b30c698b02ca63d81f6aeca13
|
data/README.md
CHANGED
@@ -10,23 +10,32 @@ Usage
|
|
10
10
|
require "cuba"
|
11
11
|
require "cuba/send_file"
|
12
12
|
|
13
|
-
Cuba.plugin(
|
13
|
+
Cuba.plugin(SendFile)
|
14
14
|
|
15
15
|
Cuba.define do
|
16
|
-
on
|
17
|
-
send_file("foo.
|
18
|
-
end
|
19
|
-
|
20
|
-
on "/download" do
|
21
|
-
disposition = 'attachment; filename="foo.png"'
|
22
|
-
send_file("foo.png", "Content-Disposition" => disposition)
|
16
|
+
on "foo" do
|
17
|
+
send_file("foo.pdf")
|
23
18
|
end
|
24
19
|
end
|
25
20
|
```
|
26
21
|
|
22
|
+
For **attachments**, it's recommended to use the HTML5 [download][download] attribute.
|
23
|
+
|
24
|
+
```html
|
25
|
+
<a href="/foo" download>Download foo</a>
|
26
|
+
```
|
27
|
+
|
28
|
+
You can specify a filename too:
|
29
|
+
|
30
|
+
```html
|
31
|
+
<a href="/foo" download="bar.pdf">Download bar</a>
|
32
|
+
```
|
33
|
+
|
27
34
|
Installation
|
28
35
|
------------
|
29
36
|
|
30
37
|
```
|
31
38
|
$ gem install cuba-sendfile
|
32
39
|
```
|
40
|
+
|
41
|
+
[download]: http://davidwalsh.name/download-attribute
|
data/cuba-sendfile.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "cuba-sendfile"
|
3
|
-
s.version = "0.0.
|
4
|
-
s.summary = "File sending for Cuba"
|
3
|
+
s.version = "0.0.2"
|
4
|
+
s.summary = "File sending for Cuba."
|
5
5
|
s.description = s.summary
|
6
6
|
s.authors = ["Francesco Rodríguez"]
|
7
7
|
s.email = ["frodsan@me.com"]
|
data/lib/cuba/send_file.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
file.path = path
|
1
|
+
module SendFile
|
2
|
+
def send_file(path)
|
3
|
+
file = Rack::File.new(nil)
|
4
|
+
file.path = path
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
halt([result[0], result[1], file])
|
10
|
-
end
|
6
|
+
halt(file.serving(env))
|
11
7
|
end
|
12
8
|
end
|
data/test/send_file.rb
CHANGED
@@ -3,16 +3,12 @@ require_relative "../lib/cuba/send_file"
|
|
3
3
|
|
4
4
|
FILE = __dir__ + "/foo.txt"
|
5
5
|
|
6
|
-
Cuba.plugin(
|
6
|
+
Cuba.plugin(SendFile)
|
7
7
|
|
8
8
|
Cuba.define do
|
9
9
|
on root do
|
10
10
|
send_file(FILE)
|
11
11
|
end
|
12
|
-
|
13
|
-
on "custom" do
|
14
|
-
send_file(FILE, "Content-Disposition" => "disposition")
|
15
|
-
end
|
16
12
|
end
|
17
13
|
|
18
14
|
scope do
|
@@ -30,10 +26,4 @@ scope do
|
|
30
26
|
assert_equal "Hello World\n".length.to_s, last_response["Content-Length"]
|
31
27
|
assert_equal File.mtime(FILE).httpdate, last_response["Last-Modified"]
|
32
28
|
end
|
33
|
-
|
34
|
-
test "sets custom header" do
|
35
|
-
get "/custom"
|
36
|
-
|
37
|
-
assert_equal "disposition", last_response["Content-Disposition"]
|
38
|
-
end
|
39
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuba-sendfile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francesco Rodríguez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cuba
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description: File sending for Cuba
|
55
|
+
description: File sending for Cuba.
|
56
56
|
email:
|
57
57
|
- frodsan@me.com
|
58
58
|
executables: []
|
@@ -89,5 +89,5 @@ rubyforge_project:
|
|
89
89
|
rubygems_version: 2.2.0
|
90
90
|
signing_key:
|
91
91
|
specification_version: 4
|
92
|
-
summary: File sending for Cuba
|
92
|
+
summary: File sending for Cuba.
|
93
93
|
test_files: []
|