adsf 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +3 -0
- data/LICENSE +19 -0
- data/NEWS.rdoc +5 -0
- data/README.rdoc +27 -0
- data/Rakefile +6 -0
- data/bin/adsf +63 -0
- data/lib/adsf.rb +7 -0
- data/lib/adsf/package.rb +52 -0
- data/lib/adsf/rack.rb +8 -0
- data/lib/adsf/rack/index_file_finder.rb +40 -0
- metadata +64 -0
data/ChangeLog
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2009 Denis Defreyne
|
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 all
|
11
|
+
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 THE
|
19
|
+
SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
= adsf
|
2
|
+
|
3
|
+
adsf (A Dead Simple Fileserver) is a tiny static file server that you can launch instantly in any directory, like this:
|
4
|
+
|
5
|
+
attignawantan ✓ ~/my_site ▸ ls -l
|
6
|
+
total 0
|
7
|
+
drwxr-xr-x 2 ddfreyne staff 68 May 29 10:04 about
|
8
|
+
drwxr-xr-x 2 ddfreyne staff 68 May 29 10:04 contact
|
9
|
+
-rw-r--r-- 1 ddfreyne staff 0 May 29 10:04 index.html
|
10
|
+
drwxr-xr-x 2 ddfreyne staff 68 May 29 10:04 projects
|
11
|
+
attignawantan ✓ ~/my_site ▸ adsf
|
12
|
+
2009-05-29 10:04:44] INFO WEBrick 1.3.1
|
13
|
+
[2009-05-29 10:04:44] INFO ruby 1.8.7 (2008-08-11) [i686-darwin9.6.1]
|
14
|
+
[2009-05-29 10:04:44] INFO WEBrick::HTTPServer#start: pid=2757 port=3000
|
15
|
+
|
16
|
+
… and now you can go to http://localhost:3000/ and start browsing.
|
17
|
+
|
18
|
+
Some more details about adsf:
|
19
|
+
|
20
|
+
* adsf has only one feature and that is serving static files.
|
21
|
+
* The only documentation you'll get is from the --help commandline option. :)
|
22
|
+
* Rack is the only dependency.
|
23
|
+
* It is licenced under the MIT licence.
|
24
|
+
|
25
|
+
== Contact
|
26
|
+
|
27
|
+
You can reach me at <denis.defreyne@stoneship.org>.
|
data/Rakefile
ADDED
data/bin/adsf
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
|
4
|
+
|
5
|
+
require 'rack'
|
6
|
+
require 'optparse'
|
7
|
+
require 'adsf'
|
8
|
+
|
9
|
+
# Parse options
|
10
|
+
options = {
|
11
|
+
:handler => nil,
|
12
|
+
:port => 3000,
|
13
|
+
:root => '.'
|
14
|
+
}
|
15
|
+
OptionParser.new do |opts|
|
16
|
+
opts.banner = "Usage: adsf [options]"
|
17
|
+
|
18
|
+
opts.separator ''
|
19
|
+
opts.separator 'Specific options:'
|
20
|
+
|
21
|
+
# handler
|
22
|
+
opts.on('-H', '--handler [handler]', 'Specify the handler to use') do |o|
|
23
|
+
options[:handler] = o
|
24
|
+
end
|
25
|
+
|
26
|
+
# help
|
27
|
+
opts.on('-h', '--help', 'Display help') do |o|
|
28
|
+
puts opts
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
|
32
|
+
# port
|
33
|
+
opts.on('-p', '--port [port]', Integer, 'Specify the port number to use') do |o|
|
34
|
+
options[:port] = o
|
35
|
+
end
|
36
|
+
|
37
|
+
# root
|
38
|
+
opts.on('-r', '--root [root]', 'Specify the web root to use') do |o|
|
39
|
+
options[:root] = o
|
40
|
+
end
|
41
|
+
end.parse!
|
42
|
+
|
43
|
+
# Find handler
|
44
|
+
handler = Rack::Handler.get(options[:handler])
|
45
|
+
if handler.nil?
|
46
|
+
begin
|
47
|
+
handler = Rack::Handler::Mongrel
|
48
|
+
rescue LoadError
|
49
|
+
handler = Rack::Handler::WEBrick
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Create app
|
54
|
+
app = Rack::Builder.new do
|
55
|
+
use Rack::CommonLogger
|
56
|
+
use Rack::ShowExceptions
|
57
|
+
use Rack::Lint
|
58
|
+
use Adsf::Rack::IndexFileFinder, :root => options[:root]
|
59
|
+
run Rack::File.new(options[:root])
|
60
|
+
end.to_app
|
61
|
+
|
62
|
+
# Run
|
63
|
+
handler.run(app, :Port => options[:port])
|
data/lib/adsf.rb
ADDED
data/lib/adsf/package.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Adsf
|
4
|
+
|
5
|
+
# Adsf::Package is a singleton that contains metadata about the adsf
|
6
|
+
# project, which is used for packaging releases.
|
7
|
+
class Package
|
8
|
+
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
# The name of the application.
|
12
|
+
def name
|
13
|
+
'adsf'
|
14
|
+
end
|
15
|
+
|
16
|
+
# The files to include in the package. This is also the list of files that
|
17
|
+
# will be included in the documentation (with the exception of the files
|
18
|
+
# in undocumented_files).
|
19
|
+
def files
|
20
|
+
@files ||= (%w( ChangeLog LICENSE NEWS.rdoc Rakefile README.rdoc ) +
|
21
|
+
Dir['bin/**/*'] +
|
22
|
+
Dir['lib/**/*']).reject { |f| File.directory?(f) }
|
23
|
+
end
|
24
|
+
|
25
|
+
# The Gem::Specification used for packaging.
|
26
|
+
def gem_spec
|
27
|
+
@gem_spec ||= Gem::Specification.new do |s|
|
28
|
+
s.name = self.name
|
29
|
+
s.version = Adsf::VERSION
|
30
|
+
s.platform = Gem::Platform::RUBY
|
31
|
+
s.summary = 'a tiny static file server'
|
32
|
+
s.description = s.summary
|
33
|
+
s.homepage = 'http://adsf.stoneship.org/'
|
34
|
+
s.rubyforge_project = 'adsf'
|
35
|
+
|
36
|
+
s.author = 'Denis Defreyne'
|
37
|
+
s.email = 'denis.defreyne@stoneship.org'
|
38
|
+
|
39
|
+
s.required_ruby_version = '>= 1.8.5'
|
40
|
+
|
41
|
+
s.has_rdoc = false
|
42
|
+
|
43
|
+
s.files = self.files
|
44
|
+
s.executables = [ 'adsf' ]
|
45
|
+
s.require_path = 'lib'
|
46
|
+
s.bindir = 'bin'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/lib/adsf/rack.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Adsf::Rack
|
2
|
+
|
3
|
+
class IndexFileFinder
|
4
|
+
|
5
|
+
def initialize(app, options)
|
6
|
+
@app = app
|
7
|
+
@root = options[:root] or raise ArgumentError, ':root option is required but was not given'
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
# Get path
|
12
|
+
path_info = ::Rack::Utils.unescape(env['PATH_INFO'])
|
13
|
+
path = ::File.join(@root, path_info)
|
14
|
+
|
15
|
+
# Redirect if necessary
|
16
|
+
if ::File.directory?(path) && path_info !~ /\/$/
|
17
|
+
new_path_info = path_info + '/'
|
18
|
+
return [
|
19
|
+
302,
|
20
|
+
{ 'Location' => new_path_info, 'Content-Type' => 'text/html' },
|
21
|
+
[ "Redirecting you to #{new_path_info}…" ]
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
25
|
+
# Add index file if necessary
|
26
|
+
new_env = env.dup
|
27
|
+
if ::File.directory?(path)
|
28
|
+
path_to_index = ::File.join(path, 'index.html')
|
29
|
+
if ::File.file?(path_to_index)
|
30
|
+
new_env['PATH_INFO'] = ::File.join(path_info, 'index.html')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Pass on
|
35
|
+
@app.call(new_env)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adsf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "1.0"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Denis Defreyne
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-29 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: a tiny static file server
|
17
|
+
email: denis.defreyne@stoneship.org
|
18
|
+
executables:
|
19
|
+
- adsf
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- ChangeLog
|
26
|
+
- LICENSE
|
27
|
+
- NEWS.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- README.rdoc
|
30
|
+
- bin/adsf
|
31
|
+
- lib/adsf/package.rb
|
32
|
+
- lib/adsf/rack/index_file_finder.rb
|
33
|
+
- lib/adsf/rack.rb
|
34
|
+
- lib/adsf.rb
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://adsf.stoneship.org/
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.8.5
|
49
|
+
version:
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project: adsf
|
59
|
+
rubygems_version: 1.3.3
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: a tiny static file server
|
63
|
+
test_files: []
|
64
|
+
|