vienna 0.4.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0641d490c3333bf03dc99312ac8f32822255b77a
4
+ data.tar.gz: 755f234ad7c27ca4ff42a1563251d4cd2fe77e85
5
+ SHA512:
6
+ metadata.gz: ae8eca143875c44fccd4a77259a51eaa68c1bc618a73dc438538e2b2b542ee651d3408ca6b2af6cc03a6127b4acda30270029d2ec2d5d0e9d0d6176f14fd5b65
7
+ data.tar.gz: 95f410c94e304d0cf72f1e34c00fcd2bb02e28a26f2ff359cd71ee3efc8dc687d12f6ebd01705b27a4db3414a93c5491d9603e665e55cf14449949fdbe45a323
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mikael Konutgan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # Vienna
2
+
3
+ `Vienna` is a tiny, zero-configuration static file server built on top of `rack`.
4
+ The goal is to place everything in `/public`, add two lines to our `config.ru`
5
+ and let `Vienna` take care of the rest.
6
+
7
+ Why Vienna? Because it's an awesome city and It's the first thing that came to my mind.
8
+ (I must have gotten the idea from [Cuba](http://cuba.is).)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'vienna'
15
+
16
+ And then execute:
17
+
18
+ bundle
19
+
20
+ Or install it yourself, run:
21
+
22
+ gem install vienna
23
+
24
+ ## Usage
25
+
26
+ Place your static files in `/public`, optionally create `/public/404.html`
27
+ and add this to your `config.ru`:
28
+
29
+ require 'vienna'
30
+ run Vienna
31
+
32
+ You're done. Now you can deploy to `heroku` or any other place that supports
33
+ rack-based apps. This should also work for most apps built with
34
+ [Jekyll](http://jekyllrb.com) or [Middleman](http://middlemanapp.com) as long as
35
+ you follow the conventions stated above.
36
+
37
+ If you absolutely must change the root folder for some reason. You can use e.g.
38
+ `run Vienna::Application.new('_site')` instead of `run Vienna`.
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
@@ -0,0 +1,15 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'yard'
3
+
4
+ task :default => :test
5
+
6
+ desc 'Test'
7
+ task :test do
8
+ Dir.chdir 'spec'
9
+ system 'ruby -I ../lib spec.rb'
10
+ end
11
+
12
+ YARD::Rake::YardocTask.new do |t|
13
+ t.files = ['lib/**/*.rb']
14
+ t.options = ['--markup=markdown']
15
+ end
@@ -0,0 +1,79 @@
1
+ require 'vienna/version'
2
+ require 'rack'
3
+
4
+ ##
5
+ # Zero-configuration convenience wrapper around `Vienna::Application`.
6
+ # Add this to `config.ru`:
7
+ #
8
+ # require 'vienna'
9
+ # run Vienna
10
+ #
11
+ # Your static site in `public` will be served.
12
+ #
13
+
14
+ module Vienna
15
+
16
+ class << self
17
+ def call(env)
18
+ Application.new.call(env)
19
+ end
20
+ end
21
+
22
+ ##
23
+ # `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.
27
+ #
28
+ # Examples
29
+ #
30
+ # run Vienna::NotFound.new('public/404.html')
31
+ #
32
+ # run Vienna::NotFound.new # Always return 'Not Found'
33
+ #
34
+
35
+ class NotFound
36
+ def initialize(path = '')
37
+ @path = path
38
+ @content = 'Not Found'
39
+ end
40
+
41
+ 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]]
47
+ end
48
+ end
49
+
50
+ ##
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
+ #
55
+ # Examples
56
+ #
57
+ # run Vienna::Application.new('_site')
58
+ #
59
+ # run Vienna::Application.new # The root defaults to 'public'
60
+ #
61
+
62
+ class Application
63
+ def initialize(root = 'public')
64
+ @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
+
71
+ run NotFound.new("#{root}/404.html")
72
+ end
73
+ end
74
+
75
+ def call(env)
76
+ @app.call(env)
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,3 @@
1
+ module Vienna
2
+ VERSION = '0.4.0'
3
+ end
@@ -0,0 +1 @@
1
+ 404
@@ -0,0 +1 @@
1
+ about
@@ -0,0 +1 @@
1
+ style
@@ -0,0 +1 @@
1
+ image
@@ -0,0 +1 @@
1
+ index
@@ -0,0 +1,37 @@
1
+ require 'minitest/autorun'
2
+ require 'rack/mock'
3
+ require 'vienna'
4
+
5
+ describe Vienna do
6
+ before do
7
+ app = Rack::Builder.new do
8
+ use Rack::Lint
9
+ run Vienna
10
+ end
11
+ @request = Rack::MockRequest.new(app)
12
+ end
13
+
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'
24
+ end
25
+
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
+ end
30
+ end
31
+
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
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vienna/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'vienna'
8
+ spec.version = Vienna::VERSION
9
+ spec.authors = ['Mikael Konutgan']
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}
13
+ spec.homepage = 'https://github.com/kmikael/vienna'
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)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'rack', '~> 1.5'
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'minitest', '~> 5.0'
25
+ spec.add_development_dependency 'yard', '~> 0.8'
26
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vienna
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Mikael Konutgan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.8'
83
+ description: Tiny, zero-configuration static file server built on top of rack
84
+ email:
85
+ - me@kmikael.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - Gemfile
91
+ - LICENSE.txt
92
+ - README.md
93
+ - Rakefile
94
+ - lib/vienna.rb
95
+ - lib/vienna/version.rb
96
+ - spec/public/404.html
97
+ - spec/public/about.html
98
+ - spec/public/css/style.css
99
+ - spec/public/images/image.svg
100
+ - spec/public/index.html
101
+ - spec/spec.rb
102
+ - vienna.gemspec
103
+ homepage: https://github.com/kmikael/vienna
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.0.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Tiny, zero-configuration static file server built on top of rack
127
+ test_files:
128
+ - spec/public/404.html
129
+ - spec/public/about.html
130
+ - spec/public/css/style.css
131
+ - spec/public/images/image.svg
132
+ - spec/public/index.html
133
+ - spec/spec.rb
134
+ has_rdoc: