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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0641d490c3333bf03dc99312ac8f32822255b77a
4
- data.tar.gz: 755f234ad7c27ca4ff42a1563251d4cd2fe77e85
3
+ metadata.gz: c7f4271e15a1b4077b68429a001cc73fba108126
4
+ data.tar.gz: 022c9950cbea50197c164edcb715ff3a47b930bc
5
5
  SHA512:
6
- metadata.gz: ae8eca143875c44fccd4a77259a51eaa68c1bc618a73dc438538e2b2b542ee651d3408ca6b2af6cc03a6127b4acda30270029d2ec2d5d0e9d0d6176f14fd5b65
7
- data.tar.gz: 95f410c94e304d0cf72f1e34c00fcd2bb02e28a26f2ff359cd71ee3efc8dc687d12f6ebd01705b27a4db3414a93c5491d9603e665e55cf14449949fdbe45a323
6
+ metadata.gz: d7969d4e0ca2c708fdb928b3e9b5f64562619e1591d4ac3b5539d2b6c2314b80fe210d60c191241f686fa1f16ad4a70e20ded51190a2aebe707ab986337509ee
7
+ data.tar.gz: 6497716a18152e8da414ea8a31f914e34e7ede4bff649559b7cc7c8cd971d75c9d37b68b1c058a07280074dddf01fcdbf1b103344f54d4df896c1ec731da8ec4
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Mikael Konutgan
1
+ Copyright (c) 2013-2015 Mikael Konutgan
2
2
 
3
3
  MIT License
4
4
 
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'yard'
3
3
 
4
4
  task :default => :test
5
5
 
6
- desc 'Test'
6
+ desc 'Run tests'
7
7
  task :test do
8
8
  Dir.chdir 'spec'
9
9
  system 'ruby -I ../lib spec.rb'
@@ -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 it will get returned.
25
- # The difference is that if a 404 page doesn't exist, a default
26
- # response, 'Not Found' will be returned.
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
- if ::File.exist?(@path)
43
- @content = ::File.read(@path)
44
- end
45
- length = @content.length.to_s
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 `root`
52
- # using `Rack::Static`. If a file/path doen't exist,
53
- # `Vienna::NotFound` is run, which always returns `404`.
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 Rack::Static,
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
@@ -1,3 +1,3 @@
1
1
  module Vienna
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
@@ -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
- it 'should serve the index when getting root' do
15
- res = @request.get '/'
16
- res.body.chomp.must_equal 'index'
17
- [200, 304].must_include res.status
18
- end
19
-
20
- it 'should serve all files in the public directory' do
21
- @request.get('/css/style.css').body.chomp.must_equal 'style'
22
- @request.get('/images/image.svg').body.chomp.must_equal 'image'
23
- @request.get('/about.html').body.chomp.must_equal 'about'
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
- it 'should cache all files' do
27
- ['/', '/css/style.css', '/images/image.svg', 'about.html'].each do |path|
28
- @request.get(path).headers['Cache-Control'].must_equal 'public, max-age=3600'
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
- it 'should serve `404-html` for pages that aren\'t found' do
33
- res = @request.get '/path'
34
- res.body.chomp.must_equal '404'
35
- res.status.must_equal 404
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
@@ -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 = %q{Tiny, zero-configuration static file server built on top of rack}
12
- spec.summary = %q{Tiny, zero-configuration static file server built on top of rack}
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(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
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
- spec.add_development_dependency 'bundler', '~> 1.3'
23
- spec.add_development_dependency 'rake'
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.0
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: 2013-05-28 00:00:00.000000000 Z
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.3'
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.3'
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.0.3
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