vienna 0.4.0 → 0.4.1
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.
- checksums.yaml +4 -4
- data/.gitignore +17 -0
- data/LICENSE.txt +1 -1
- data/Rakefile +1 -1
- data/lib/vienna.rb +57 -20
- data/lib/vienna/version.rb +1 -1
- data/spec/spec.rb +44 -17
- data/vienna.gemspec +10 -9
- metadata +20 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7f4271e15a1b4077b68429a001cc73fba108126
|
4
|
+
data.tar.gz: 022c9950cbea50197c164edcb715ff3a47b930bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7969d4e0ca2c708fdb928b3e9b5f64562619e1591d4ac3b5539d2b6c2314b80fe210d60c191241f686fa1f16ad4a70e20ded51190a2aebe707ab986337509ee
|
7
|
+
data.tar.gz: 6497716a18152e8da414ea8a31f914e34e7ede4bff649559b7cc7c8cd971d75c9d37b68b1c058a07280074dddf01fcdbf1b103344f54d4df896c1ec731da8ec4
|
data/.gitignore
ADDED
data/LICENSE.txt
CHANGED
data/Rakefile
CHANGED
data/lib/vienna.rb
CHANGED
@@ -3,7 +3,7 @@ require 'rack'
|
|
3
3
|
|
4
4
|
##
|
5
5
|
# Zero-configuration convenience wrapper around `Vienna::Application`.
|
6
|
-
# Add this to `config.ru`:
|
6
|
+
# Add this to your `config.ru`:
|
7
7
|
#
|
8
8
|
# require 'vienna'
|
9
9
|
# run Vienna
|
@@ -19,11 +19,54 @@ module Vienna
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
##
|
23
|
+
# `Vienna::Static` is just a wrapper for `Rack::Static` with
|
24
|
+
# sane and opinionated options.
|
25
|
+
#
|
26
|
+
# It serves all files under the given `root` and doesn't passes on requests
|
27
|
+
# for files that don't exist.
|
28
|
+
#
|
29
|
+
# Examples
|
30
|
+
#
|
31
|
+
# use Vienna::Static, 'public'
|
32
|
+
#
|
33
|
+
|
34
|
+
class Static
|
35
|
+
def initialize(app, root)
|
36
|
+
@app = app
|
37
|
+
@root = root
|
38
|
+
end
|
39
|
+
|
40
|
+
def urls
|
41
|
+
Dir.glob("#{root}/*").map { |f| f.sub(root, '') }
|
42
|
+
end
|
43
|
+
|
44
|
+
def root
|
45
|
+
@root
|
46
|
+
end
|
47
|
+
|
48
|
+
def index
|
49
|
+
'index.html'
|
50
|
+
end
|
51
|
+
|
52
|
+
def header_rules
|
53
|
+
[[:all, {'Cache-Control' => 'public, max-age=3600'}]]
|
54
|
+
end
|
55
|
+
|
56
|
+
def options
|
57
|
+
{urls: urls, root: root, index: index, header_rules: header_rules}
|
58
|
+
end
|
59
|
+
|
60
|
+
def call(env)
|
61
|
+
Rack::Static.new(@app, options).call(env)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
22
65
|
##
|
23
66
|
# `Vienna::NotFound` is a default endpoint not unlike `Rack::NotFound`.
|
24
|
-
# Initialize it with the path to a 404 page and
|
25
|
-
# The difference is that if a 404 page doesn't exist, a default
|
26
|
-
#
|
67
|
+
# Initialize it with the path to a 404 page and its contents will be served.
|
68
|
+
# The difference is that if a 404 page doesn't exist, a default response,
|
69
|
+
# 'Not Found' will be served.
|
27
70
|
#
|
28
71
|
# Examples
|
29
72
|
#
|
@@ -35,23 +78,22 @@ module Vienna
|
|
35
78
|
class NotFound
|
36
79
|
def initialize(path = '')
|
37
80
|
@path = path
|
38
|
-
@content = 'Not Found'
|
39
81
|
end
|
40
82
|
|
41
83
|
def call(env)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
length
|
46
|
-
[404, {'Content-Type' => 'text/html', 'Content-Length' => length}, [@content]]
|
84
|
+
content = File.exist?(@path) ? File.read(@path) : 'Not Found'
|
85
|
+
length = content.length.to_s
|
86
|
+
|
87
|
+
[404, {'Content-Type' => 'text/html', 'Content-Length' => length}, [content]]
|
47
88
|
end
|
48
89
|
end
|
49
90
|
|
50
91
|
##
|
51
|
-
# `Vienna::Application` serves all files under the given
|
52
|
-
# using `
|
53
|
-
#
|
54
|
-
#
|
92
|
+
# `Vienna::Application` serves all files under the given root directory
|
93
|
+
# using `Vienna::Static`. If a file/path doen't exist, `Vienna::NotFound`
|
94
|
+
# is run, which always returns a status of `404` and the contents of
|
95
|
+
# `404.html` or `'Not Found'` if one does not exist.
|
96
|
+
#
|
55
97
|
# Examples
|
56
98
|
#
|
57
99
|
# run Vienna::Application.new('_site')
|
@@ -62,12 +104,7 @@ module Vienna
|
|
62
104
|
class Application
|
63
105
|
def initialize(root = 'public')
|
64
106
|
@app = Rack::Builder.new do
|
65
|
-
use
|
66
|
-
:urls => Dir.glob("#{root}/*").map { |fn| fn.gsub(/#{root}/, '')},
|
67
|
-
:root => root,
|
68
|
-
:index => 'index.html',
|
69
|
-
:header_rules => [[:all, {'Cache-Control' => 'public, max-age=3600'}]]
|
70
|
-
|
107
|
+
use Static, root
|
71
108
|
run NotFound.new("#{root}/404.html")
|
72
109
|
end
|
73
110
|
end
|
data/lib/vienna/version.rb
CHANGED
data/spec/spec.rb
CHANGED
@@ -8,30 +8,57 @@ describe Vienna do
|
|
8
8
|
use Rack::Lint
|
9
9
|
run Vienna
|
10
10
|
end
|
11
|
+
|
11
12
|
@request = Rack::MockRequest.new(app)
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
describe 'when requesting the root directory' do
|
16
|
+
before do
|
17
|
+
@res = @request.get('/')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should serve the index path' do
|
21
|
+
@res.body.chomp.must_equal 'index'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should return a valid status code, that is 200: OK or 304: Not Modified' do
|
25
|
+
[200, 304].must_include @res.status
|
26
|
+
end
|
24
27
|
end
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
@
|
29
|
+
describe 'when requesting the path of a subdirectory of the root directory' do
|
30
|
+
before do
|
31
|
+
@paths = {
|
32
|
+
'/css/style.css' => 'style',
|
33
|
+
'/images/image.svg' => 'image',
|
34
|
+
'/about.html' => 'about'
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should serve the contents of the paths' do
|
39
|
+
@paths.each do |path, body|
|
40
|
+
@request.get(path).body.chomp.must_equal body
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should cache all responses for a an hour' do
|
45
|
+
@paths.each do |path, body|
|
46
|
+
@request.get(path).headers['Cache-Control'].must_equal 'public, max-age=3600'
|
47
|
+
end
|
29
48
|
end
|
30
49
|
end
|
31
50
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
51
|
+
describe 'when requesting a path that does not exist' do
|
52
|
+
before do
|
53
|
+
@res = @request.get('/path')
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should serve the contents of `404.html` if the file exists' do
|
57
|
+
@res.body.chomp.must_equal '404'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should return the status code 404: Not Found' do
|
61
|
+
@res.status.must_equal 404
|
62
|
+
end
|
36
63
|
end
|
37
64
|
end
|
data/vienna.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
4
|
require 'vienna/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
@@ -8,19 +8,20 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Vienna::VERSION
|
9
9
|
spec.authors = ['Mikael Konutgan']
|
10
10
|
spec.email = ['me@kmikael.com']
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
11
|
+
spec.description = 'Tiny, zero-configuration static file server built on top of rack'
|
12
|
+
spec.summary = 'Tiny, zero-configuration static file server built on top of rack'
|
13
13
|
spec.homepage = 'https://github.com/kmikael/vienna'
|
14
14
|
spec.license = 'MIT'
|
15
|
-
|
16
|
-
spec.files = `git ls-files`.split
|
17
|
-
spec.executables = spec.files.grep(
|
18
|
-
spec.test_files = spec.files.grep(
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split
|
17
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_runtime_dependency 'rack', '~> 1.5'
|
22
|
-
|
23
|
-
spec.add_development_dependency '
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.0'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
25
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
25
26
|
spec.add_development_dependency 'yard', '~> 0.8'
|
26
27
|
end
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vienna
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikael Konutgan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
40
|
+
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '10.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '10.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '5.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '5.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: yard
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0.8'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.8'
|
83
83
|
description: Tiny, zero-configuration static file server built on top of rack
|
@@ -87,6 +87,7 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
+
- ".gitignore"
|
90
91
|
- Gemfile
|
91
92
|
- LICENSE.txt
|
92
93
|
- README.md
|
@@ -110,17 +111,17 @@ require_paths:
|
|
110
111
|
- lib
|
111
112
|
required_ruby_version: !ruby/object:Gem::Requirement
|
112
113
|
requirements:
|
113
|
-
- -
|
114
|
+
- - ">="
|
114
115
|
- !ruby/object:Gem::Version
|
115
116
|
version: '0'
|
116
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
118
|
requirements:
|
118
|
-
- -
|
119
|
+
- - ">="
|
119
120
|
- !ruby/object:Gem::Version
|
120
121
|
version: '0'
|
121
122
|
requirements: []
|
122
123
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.4.5
|
124
125
|
signing_key:
|
125
126
|
specification_version: 4
|
126
127
|
summary: Tiny, zero-configuration static file server built on top of rack
|