up 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. data/LICENSE +19 -0
  2. data/README.md +48 -0
  3. data/Rakefile +75 -0
  4. data/bin/up +84 -0
  5. data/lib/up/version.rb +4 -0
  6. data/lib/up.rb +29 -0
  7. data/man/up.1.ronn +41 -0
  8. metadata +68 -0
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Henrik Hodne
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
11
+ all 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
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ Up
2
+ ==
3
+
4
+ Up is a super-simple web server that only hosts static files.
5
+
6
+
7
+ Usage
8
+ -----
9
+
10
+ Just give it a directory to host, and optionally a port and a host to
11
+ listen to:
12
+
13
+ up foo/ -p 8080 -h 127.0.0.1
14
+
15
+
16
+ Installation
17
+ ------------
18
+
19
+ ### [RubyGems](http://rubygems.org/)
20
+
21
+ $ gem install up
22
+
23
+
24
+ Contributing
25
+ ------------
26
+
27
+ Once you've made your great commits:
28
+
29
+ 1. [Fork][fk] Up
30
+ 2. Create a topic branch - `git checkout -b my_branch`
31
+ 3. Push to your branch - `git push origin my_branch`
32
+ 4. Create an [Issue][is] with a link to your branch
33
+ 5. That's it!
34
+
35
+ You might want to checkout Defender's [Contributing][cb] wiki page for information
36
+ on coding standards, new features, etc.
37
+
38
+
39
+ Meta
40
+ ----
41
+
42
+ * Code: `git checkout git://github.com/dvyjones/up.git`
43
+ * Bugs: <http://github.com/dvyjones/up/issues>
44
+ * Gems: <http://rubygems.org/gems/up>
45
+
46
+ [cb]: http://wiki.github.com/dvyjones/defender/contributing
47
+ [fk]: http://help.github.com/forking/
48
+ [is]: http://github.com/dvyjones/defender/issues
data/Rakefile ADDED
@@ -0,0 +1,75 @@
1
+ require 'sdoc'
2
+ require 'rake/rdoctask'
3
+
4
+ #
5
+ # Helpers
6
+ #
7
+
8
+ def command?(command)
9
+ system("type #{command} > /dev/null")
10
+ end
11
+
12
+
13
+ #
14
+ # Ronn
15
+ #
16
+
17
+ if command? :ronn
18
+ desc "Show the manual"
19
+ task :man => "man:build" do
20
+ exec "man man/mustache.1"
21
+ end
22
+
23
+ desc "Build the manual"
24
+ task "man:build" do
25
+ sh "ronn -br5 --organization=DVYJONES --manual='Up Manual' man/*.ronn"
26
+ end
27
+ end
28
+
29
+
30
+ #
31
+ # Gems
32
+ #
33
+
34
+ desc "Push a new version to Gemcutter and publish docs."
35
+ task :publish do
36
+ require File.dirname(__FILE__) + '/lib/up/version'
37
+
38
+ system "git tag v#{Up::Version}"
39
+ sh "gem build up.gemspec"
40
+ sh "gem push up-#{Up::Version}.gem"
41
+ sh "git push origin master --tags"
42
+ sh "git clean -fd"
43
+ exec "rake pages"
44
+ end
45
+
46
+
47
+ #
48
+ # Documentation
49
+ #
50
+
51
+ Rake::RDocTask.new do |rdoc|
52
+ rdoc.main = 'README.md'
53
+ rdoc.rdoc_files = [ 'README.md', 'LICENSE', 'lib' ]
54
+ rdoc.rdoc_dir = 'docs'
55
+ end
56
+
57
+ namespace :pages do
58
+ task :publish => [ :check_dirty, "man:build", :rerdoc ] do
59
+ `git checkout gh-pages`
60
+ `ls -1 | grep -v docs | grep -v man | xargs rm -rf`
61
+ `git add .; git commit -m "update docs"; git push origin gh-pages`
62
+ `git checkout master`
63
+ puts :done
64
+ end
65
+
66
+ task :check_dirty do
67
+ if !`git status`.include?('nothing to commit')
68
+ abort "dirty index - not publishing!"
69
+ end
70
+ end
71
+ end
72
+
73
+ desc "Build and publish documentation using GitHub Pages."
74
+ task :pages => "pages:publish"
75
+
data/bin/up ADDED
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ require 'up'
6
+ require 'up/version'
7
+
8
+ class Up
9
+ class CLI
10
+ # Return a structure describing the options.
11
+ def self.parse_options(args)
12
+ options = { :port => 1234, :host => '0.0.0.0', :server => 'thin,mongrel,webrick' }
13
+ opts = OptionParser.new do |opts|
14
+ opts.banner = "Usage: up [-p PORT] [-o HOST] FILE"
15
+
16
+ opts.separator " "
17
+
18
+ opts.separator "Examples:"
19
+ opts.separator " $ up docs/"
20
+ opts.separator " $ up -p 8080 public_html"
21
+
22
+ opts.separator " "
23
+
24
+ opts.separator " See up(1) or " +
25
+ "http://dvyjones.github.com/up/up.1.html"
26
+ opts.separator " for more details."
27
+
28
+ opts.separator " "
29
+ opts.separator "Options:"
30
+
31
+ opts.on("-p", "--port PORT",
32
+ "Listen to a given port (default 1234).") do |port|
33
+ options[:port] = port.to_i
34
+ end
35
+
36
+ opts.on("-o", "--host HOST",
37
+ "The IP to listen to (default 0.0.0.0).") do |host|
38
+ options[:host] = host
39
+ end
40
+
41
+ opts.on("-s", "--server SERVER",
42
+ "The Rack handler to use (default thin,mongrel,webrick).",
43
+ "Use a comma-separated list") do |server|
44
+ options[:server] = server
45
+ end
46
+
47
+ opts.separator "Common Options:"
48
+
49
+ opts.on("-v", "--version", "Print the version") do |v|
50
+ puts "Up v#{Up::Version}"
51
+ exit
52
+ end
53
+
54
+ opts.on_tail("-h", "--help", "Show this message") do
55
+ puts opts
56
+ exit
57
+ end
58
+ end
59
+
60
+ opts.separator ""
61
+
62
+ [opts.parse!(args), options]
63
+ end
64
+ end
65
+ end
66
+
67
+ # Help is the default.
68
+ ARGV << '-h' if ARGV.empty? && $stdin.tty?
69
+
70
+ # Process options
71
+ dir, options = Up::CLI.parse_options(ARGV) if $stdin.tty?
72
+
73
+ # Now - serve stuff
74
+ begin
75
+ puts "== Up/#{Up::Version} is starting " +
76
+ "on #{options[:port]}"
77
+ handler = Up.detect_rack_handler(options[:server])
78
+ handler.run(Up::Application.new(dir.first), :Host => options[:host], :Port => options[:port]) do |server|
79
+ [:INT, :TERM].each { |sig| trap(sig) { Up::Application.quit!(server) } }
80
+ end
81
+ rescue Errno::EADDRINUSE => e
82
+ puts "== Port #{options[:port]} is already in use!"
83
+ end
84
+
data/lib/up/version.rb ADDED
@@ -0,0 +1,4 @@
1
+ class Up
2
+ Version = VERSION = '0.0.1'
3
+ end
4
+
data/lib/up.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'rack'
2
+
3
+ class Up
4
+ def self.detect_rack_handler(server)
5
+ servers = server.split(',')
6
+ servers.each do |server_name|
7
+ begin
8
+ return Rack::Handler.get(server_name.downcase)
9
+ rescue LoadError
10
+ rescue NameError
11
+ end
12
+ end
13
+ fail "Server handler (#{servers.join(',')}) not found."
14
+ end
15
+
16
+ class Application
17
+ def self.quit!(server)
18
+ ## Use thins' hard #stop! if available, otherwise just #stop
19
+ server.respond_to?(:stop!) ? server.stop! : server.stop
20
+ puts "\n== Up has stopped"
21
+ end
22
+
23
+ def self.new(dir)
24
+ Rack::Builder.new do
25
+ run Rack::Directory.new(dir)
26
+ end
27
+ end
28
+ end
29
+ end
data/man/up.1.ronn ADDED
@@ -0,0 +1,41 @@
1
+ up(1) -- Static web server
2
+ ==========================
3
+
4
+ ## SYNOPSIS
5
+
6
+ up [OPTIONS] <DIR>
7
+
8
+
9
+ ## DESCRIPTION
10
+
11
+ Up is a super-simple static web server that hosts static files.
12
+ It uses Rack::Directory to do this and generates a nice directory
13
+ index if only a directory, not a file is specified.
14
+
15
+
16
+ ## OPTIONS
17
+
18
+ * `-p`, `--port PORT`:
19
+ Set the port that Up should listen to. The default port is
20
+ 1234.
21
+
22
+ * `-o`, `--host HOST`:
23
+ Set the host/IP that Up should bind to. Default is 0.0.0.0.
24
+
25
+
26
+ ## INSTALLATION
27
+
28
+ If you have RubyGems installed:
29
+
30
+ gem install up
31
+
32
+
33
+ ## EXAMPLES
34
+
35
+ $ up docs/
36
+
37
+
38
+ ## COPYRIGHT
39
+
40
+ Up is Copyright (C) 2010 Henrik Hodne
41
+
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: up
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Henrik Hodne
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-30 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description:
22
+ email: dvyjones@binaryhex.com
23
+ executables:
24
+ - up
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - README.md
31
+ - Rakefile
32
+ - LICENSE
33
+ - lib/up/version.rb
34
+ - lib/up.rb
35
+ - bin/up
36
+ - man/up.1.ronn
37
+ has_rdoc: true
38
+ homepage: http://github.com/dvyjones/up
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.6
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Up is a super-simple no-frills static web server.
67
+ test_files: []
68
+