static_server 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/Rakefile +9 -0
- data/lib/static_server/static_config.rb +15 -11
- data/lib/static_server/static_server.rb +6 -8
- data/public/index.html +1 -0
- data/static_server.gemspec +2 -2
- data/test/integration/other_dir/init.html +1 -0
- data/test/integration/other_dir/some_html.html +1 -0
- data/test/integration/test_basic.rb +19 -0
- data/test/integration/test_configuration.rb +36 -0
- data/test/test_static_config.rb +53 -0
- metadata +17 -9
- data/.static_server.gemspec.swp +0 -0
- data/lib/.static_config.rb.swp +0 -0
- data/lib/.static_s.swp +0 -0
- data/lib/.static_server.gemspec.swp +0 -0
data/.gitignore
ADDED
data/Rakefile
ADDED
@@ -1,26 +1,30 @@
|
|
1
1
|
class StaticConfig
|
2
|
-
|
3
|
-
|
4
|
-
@
|
2
|
+
attr_reader :base_dir, :forwards, :redirects
|
3
|
+
def initialize(base_dir = nil)
|
4
|
+
@base_dir = base_dir
|
5
|
+
@base_dir ||= 'public'
|
6
|
+
|
7
|
+
@redirects = {}
|
8
|
+
@forwards = {}
|
9
|
+
@root = 'index.html'
|
5
10
|
end
|
6
11
|
|
7
12
|
def redirect(opt)
|
8
13
|
validate_params(opt)
|
9
|
-
@
|
14
|
+
@redirects.merge! opt
|
10
15
|
end
|
16
|
+
|
11
17
|
def forward(opt)
|
12
18
|
validate_params(opt)
|
13
|
-
@
|
19
|
+
@forwards.merge! opt
|
14
20
|
end
|
15
21
|
|
16
|
-
def
|
17
|
-
@
|
22
|
+
def root(path = nil)
|
23
|
+
@root = path if path
|
24
|
+
@root
|
18
25
|
end
|
19
26
|
|
20
|
-
|
21
|
-
@redirect
|
22
|
-
end
|
23
|
-
private
|
27
|
+
private
|
24
28
|
def validate_params(opt)
|
25
29
|
raise "Invalid param" if opt.size != 1
|
26
30
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
class StaticServer
|
2
|
-
def self.
|
3
|
-
|
4
|
-
options.merge!(params)
|
5
|
-
config = StaticConfig.new
|
2
|
+
def self.start(base_dir = nil)
|
3
|
+
config = StaticConfig.new(base_dir)
|
6
4
|
|
7
5
|
yield config if block_given?
|
8
6
|
|
@@ -15,12 +13,12 @@ class StaticServer
|
|
15
13
|
end
|
16
14
|
|
17
15
|
if env["PATH_INFO"] == '/'
|
18
|
-
env["PATH_INFO"] =
|
16
|
+
env["PATH_INFO"] = config.root
|
19
17
|
end
|
20
|
-
|
21
|
-
Rack::File.new("./#{
|
18
|
+
|
19
|
+
Rack::File.new("./#{config.base_dir}").call(env)
|
22
20
|
end
|
23
21
|
}
|
24
|
-
|
22
|
+
|
25
23
|
end
|
26
24
|
end
|
data/public/index.html
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<html>Index</html>
|
data/static_server.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'static_server'
|
3
|
-
s.version = '0.0.
|
4
|
-
s.date = '2011-05-
|
3
|
+
s.version = '0.0.2'
|
4
|
+
s.date = '2011-05-28'
|
5
5
|
s.summary = "A simple way to provide static files using rack"
|
6
6
|
s.description = "A simple way to provide static files using rack"
|
7
7
|
s.authors = ["David Paniz"]
|
@@ -0,0 +1 @@
|
|
1
|
+
<html>init</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<html>some_html</html>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'static_server'
|
3
|
+
require "rack/test"
|
4
|
+
|
5
|
+
class BasicTest < Test::Unit::TestCase
|
6
|
+
include Rack::Test::Methods
|
7
|
+
|
8
|
+
def app
|
9
|
+
# will load files ffrom 'public' dir in the project root
|
10
|
+
StaticServer.start
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_starting_server
|
14
|
+
get "/"
|
15
|
+
|
16
|
+
assert last_response.ok?
|
17
|
+
assert_equal "<html>Index</html>\n", last_response.body
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'static_server'
|
3
|
+
require "rack/test"
|
4
|
+
|
5
|
+
class ConfigurationTest < Test::Unit::TestCase
|
6
|
+
include Rack::Test::Methods
|
7
|
+
|
8
|
+
def app
|
9
|
+
StaticServer.start('test/integration/other_dir') {|map|
|
10
|
+
map.root 'init.html'
|
11
|
+
map.redirect '/test_redirect' => 'http://www.caelum.com.br'
|
12
|
+
map.forward '/some' => 'some_html.html'
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_root_server
|
17
|
+
get "/"
|
18
|
+
|
19
|
+
assert last_response.ok?
|
20
|
+
assert_equal "<html>init</html>\n", last_response.body
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_forward_server
|
24
|
+
get "/some"
|
25
|
+
|
26
|
+
assert last_response.ok?
|
27
|
+
assert_equal "<html>some_html</html>\n", last_response.body
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_redirect_server
|
31
|
+
get "/test_redirect"
|
32
|
+
|
33
|
+
assert_equal "http://www.caelum.com.br", last_response.original_headers["Location"]
|
34
|
+
assert_equal 302, last_response.status
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'static_server'
|
3
|
+
|
4
|
+
class StaticConfigTest < Test::Unit::TestCase
|
5
|
+
def test_deafult_values
|
6
|
+
conf = StaticConfig.new
|
7
|
+
assert_equal "index.html", conf.root
|
8
|
+
assert_equal 'public', conf.base_dir
|
9
|
+
assert_equal( {}, conf.redirects)
|
10
|
+
assert_equal( {}, conf.forwards)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_adding_forward
|
14
|
+
conf = StaticConfig.new
|
15
|
+
conf.forward '/paniz' => 'www.davidpaniz.com'
|
16
|
+
assert_equal( {'/paniz' => 'www.davidpaniz.com'}, conf.forwards)
|
17
|
+
|
18
|
+
conf.forward '/caelum' => 'www.caelum.com.br'
|
19
|
+
assert_equal( {'/paniz' => 'www.davidpaniz.com', '/caelum' => 'www.caelum.com.br'}, conf.forwards)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_adding_redirect
|
23
|
+
conf = StaticConfig.new
|
24
|
+
conf.redirect '/paniz' => '/paniz.html'
|
25
|
+
assert_equal( {'/paniz' => '/paniz.html'}, conf.redirects)
|
26
|
+
|
27
|
+
conf.redirect '/caelum' => '/caelum.html'
|
28
|
+
assert_equal( {'/paniz' => '/paniz.html', '/caelum' => '/caelum.html'}, conf.redirects)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_configuring_root
|
32
|
+
conf = StaticConfig.new
|
33
|
+
conf.root 'new_index.html'
|
34
|
+
assert_equal 'new_index.html', conf.root
|
35
|
+
|
36
|
+
conf.root 'new_index2.html'
|
37
|
+
assert_equal 'new_index2.html', conf.root
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_configuring_base_dir
|
41
|
+
conf = StaticConfig.new()
|
42
|
+
assert_equal 'public', conf.base_dir
|
43
|
+
|
44
|
+
conf = StaticConfig.new(nil)
|
45
|
+
assert_equal 'public', conf.base_dir
|
46
|
+
|
47
|
+
conf = StaticConfig.new('my_dir')
|
48
|
+
assert_equal 'my_dir', conf.base_dir
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: static_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- David Paniz
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-28 00:00:00 -03:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -23,16 +23,20 @@ extensions: []
|
|
23
23
|
extra_rdoc_files: []
|
24
24
|
|
25
25
|
files:
|
26
|
-
- .
|
26
|
+
- .gitignore
|
27
27
|
- README
|
28
|
-
-
|
29
|
-
- lib/.static_s.swp
|
30
|
-
- lib/.static_server.gemspec.swp
|
28
|
+
- Rakefile
|
31
29
|
- lib/static_server.rb
|
30
|
+
- lib/static_server/.static_server.rb.swp
|
32
31
|
- lib/static_server/static_config.rb
|
33
32
|
- lib/static_server/static_server.rb
|
34
|
-
-
|
33
|
+
- public/index.html
|
35
34
|
- static_server.gemspec
|
35
|
+
- test/integration/other_dir/init.html
|
36
|
+
- test/integration/other_dir/some_html.html
|
37
|
+
- test/integration/test_basic.rb
|
38
|
+
- test/integration/test_configuration.rb
|
39
|
+
- test/test_static_config.rb
|
36
40
|
has_rdoc: true
|
37
41
|
homepage: http://github.com/davidpaniz/StaticServer
|
38
42
|
licenses: []
|
@@ -61,5 +65,9 @@ rubygems_version: 1.5.2
|
|
61
65
|
signing_key:
|
62
66
|
specification_version: 3
|
63
67
|
summary: A simple way to provide static files using rack
|
64
|
-
test_files:
|
65
|
-
|
68
|
+
test_files:
|
69
|
+
- test/integration/other_dir/init.html
|
70
|
+
- test/integration/other_dir/some_html.html
|
71
|
+
- test/integration/test_basic.rb
|
72
|
+
- test/integration/test_configuration.rb
|
73
|
+
- test/test_static_config.rb
|
data/.static_server.gemspec.swp
DELETED
Binary file
|
data/lib/.static_config.rb.swp
DELETED
Binary file
|
data/lib/.static_s.swp
DELETED
Binary file
|
Binary file
|