send_file 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gems +3 -0
- data/LICENSE +19 -0
- data/README.md +51 -0
- data/lib/send_file.rb +8 -0
- data/send_file.gemspec +16 -0
- data/test/cuba.rb +29 -0
- data/test/foo.txt +1 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d128b6c5360b9eed68445296dea58ebc5fb57a75
|
4
|
+
data.tar.gz: 5dda0b3d9e750714f44ffb31888b9ef133fbf6a9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e531dec674c04e74b2f3f46c8e0f417b913f8c51402a8b82bdbfb3f2f5ace3b650e7c7343122aaf4805d54be67b464788ad2c2a8600c951ec87b16173cdf5293
|
7
|
+
data.tar.gz: d07d1fc5ae750f0b4c77f6933f582eb097b9f0c20225feffef47dcc13cecd49b4edced8192a3fb332cc25263f48353db2a9eed6782e61a1eb16597b7f24162e7
|
data/.gems
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Francesco Rodríguez
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
send_file
|
2
|
+
=========
|
3
|
+
|
4
|
+
File sending for Rack applications.
|
5
|
+
|
6
|
+
Usage
|
7
|
+
-----
|
8
|
+
|
9
|
+
Make sure your application implements two methods: `env` and `halt`,
|
10
|
+
where `env` returns a hash with the Rack environment and `halt` returns
|
11
|
+
an array response like `[status, headers, [body]]`.
|
12
|
+
|
13
|
+
The next example uses [Cuba][cuba]:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require "cuba"
|
17
|
+
require "send_file"
|
18
|
+
|
19
|
+
Cuba.plugin(SendFile)
|
20
|
+
|
21
|
+
Cuba.define do
|
22
|
+
on "foo" do
|
23
|
+
send_file("foo.pdf")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
Attachments
|
29
|
+
-----------
|
30
|
+
|
31
|
+
For **attachments**, it's recommended to use the HTML5 [download][download] attribute.
|
32
|
+
|
33
|
+
```html
|
34
|
+
<a href="/foo" download>Download foo</a>
|
35
|
+
```
|
36
|
+
|
37
|
+
You can specify a filename too:
|
38
|
+
|
39
|
+
```html
|
40
|
+
<a href="/foo" download="bar.pdf">Download bar</a>
|
41
|
+
```
|
42
|
+
|
43
|
+
Installation
|
44
|
+
------------
|
45
|
+
|
46
|
+
```
|
47
|
+
$ gem install send_file
|
48
|
+
```
|
49
|
+
|
50
|
+
[cuba]: https://github.com/soveran/cuba
|
51
|
+
[download]: http://davidwalsh.name/download-attribute
|
data/lib/send_file.rb
ADDED
data/send_file.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "send_file"
|
3
|
+
s.version = "1.0.0"
|
4
|
+
s.summary = "File sending for Rack applications."
|
5
|
+
s.description = s.summary
|
6
|
+
s.authors = ["Francesco Rodríguez"]
|
7
|
+
s.email = ["frodsan@me.com"]
|
8
|
+
s.homepage = "https://github.com/frodsan/send_file"
|
9
|
+
s.license = "MIT"
|
10
|
+
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
|
13
|
+
s.add_development_dependency "cuba"
|
14
|
+
s.add_development_dependency "cutest"
|
15
|
+
s.add_development_dependency "rack-test"
|
16
|
+
end
|
data/test/cuba.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "cuba/test"
|
2
|
+
require_relative "../lib/send_file"
|
3
|
+
|
4
|
+
FILE = File.join(__dir__, "foo.txt")
|
5
|
+
|
6
|
+
Cuba.plugin(SendFile)
|
7
|
+
|
8
|
+
Cuba.define do
|
9
|
+
on root do
|
10
|
+
send_file(FILE)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
scope do
|
15
|
+
test "sends the contents of the file" do
|
16
|
+
get "/"
|
17
|
+
|
18
|
+
assert_equal 200, last_response.status
|
19
|
+
assert_equal "Hello World\n", last_response.body
|
20
|
+
end
|
21
|
+
|
22
|
+
test "sets response headers" do
|
23
|
+
get "/"
|
24
|
+
|
25
|
+
assert_equal "text/plain", last_response["Content-Type"]
|
26
|
+
assert_equal "Hello World\n".length.to_s, last_response["Content-Length"]
|
27
|
+
assert_equal File.mtime(FILE).httpdate, last_response["Last-Modified"]
|
28
|
+
end
|
29
|
+
end
|
data/test/foo.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Hello World
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: send_file
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Francesco Rodríguez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cuba
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: cutest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rack-test
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: File sending for Rack applications.
|
56
|
+
email:
|
57
|
+
- frodsan@me.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gems
|
63
|
+
- LICENSE
|
64
|
+
- README.md
|
65
|
+
- lib/send_file.rb
|
66
|
+
- send_file.gemspec
|
67
|
+
- test/cuba.rb
|
68
|
+
- test/foo.txt
|
69
|
+
homepage: https://github.com/frodsan/send_file
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.0.14
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: File sending for Rack applications.
|
93
|
+
test_files: []
|