webify 0.1.1 → 0.2.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.
- data/lib/webify.rb +7 -44
- data/lib/webify/backend/mongrel.rb +26 -0
- data/lib/webify/backend/webrick.rb +24 -0
- data/lib/webify/runner.rb +52 -0
- data/lib/webify/version.rb +3 -0
- metadata +5 -1
data/lib/webify.rb
CHANGED
@@ -1,47 +1,10 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'webify/version'
|
2
|
+
require 'webify/runner'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def self.start(options={})
|
10
|
-
dir = File.expand_path(options[:dir] || Dir::pwd)
|
11
|
-
port = options[:port] || DEFAULT_PORT
|
12
|
-
|
13
|
-
msg = "Serving: #{dir}\nURL: http://#{Socket.gethostname}:#{port}"
|
14
|
-
|
15
|
-
puts "="*80
|
16
|
-
puts "#{msg}\n"
|
17
|
-
puts ("="*80)+"\n\n"
|
18
|
-
|
19
|
-
server = HTTPServer.new(
|
20
|
-
:Port => port,
|
21
|
-
:DocumentRoot => dir
|
22
|
-
)
|
23
|
-
|
24
|
-
trap('INT') { server.shutdown }
|
25
|
-
server.start
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
options = {
|
30
|
-
:port => Webify::DEFAULT_PORT,
|
31
|
-
:dir => Dir.pwd
|
32
|
-
}
|
33
|
-
|
34
|
-
options_parser = OptionParser.new do |opts|
|
35
|
-
opts.banner = "Webify -- serve any directory to your browser\n"+
|
36
|
-
"Usage: webify [options]"
|
37
|
-
|
38
|
-
opts.separator ""
|
39
|
-
opts.separator "Server options:"
|
40
|
-
|
41
|
-
opts.on('-p', '--port PORT', "Use PORT (default: #{options[:port]})") {|val| options[:port] = val }
|
42
|
-
opts.on('-d', '--dir DIRECTORY', "Document root DIRECTORY (default: #{options[:dir]})") {|val| options[:dir] = val }
|
43
|
-
opts.on('-h', '--help', 'Display this help message') { puts opts; exit! }
|
4
|
+
module Webify
|
5
|
+
DEFAULT_BACKEND = 'Webrick'
|
6
|
+
DEFAULT_PORT = 3000
|
7
|
+
DEFAULT_DIR = Dir::pwd
|
44
8
|
end
|
45
|
-
options_parser.parse!(ARGV)
|
46
9
|
|
47
|
-
Webify.start
|
10
|
+
Webify::Runner.start!
|
@@ -0,0 +1,26 @@
|
|
1
|
+
begin
|
2
|
+
require 'mongrel'
|
3
|
+
rescue LoadError => ex
|
4
|
+
$stderr.puts "Oops.. can't load Mongrel, try: gem install mongrel"
|
5
|
+
exit!
|
6
|
+
end
|
7
|
+
|
8
|
+
module Webify
|
9
|
+
module Backend
|
10
|
+
|
11
|
+
class Mongrel
|
12
|
+
def self.start!(options={})
|
13
|
+
dir = File.expand_path(options[:dir] || Webify::DEFAULT_DIR)
|
14
|
+
port = options[:port] || Webify::DEFAULT_PORT
|
15
|
+
throttle = options[:throttle] || 0
|
16
|
+
|
17
|
+
server = ::Mongrel::HttpServer.new("0.0.0.0", port, 950, throttle.to_i, 60)
|
18
|
+
server.register("/", ::Mongrel::DirHandler.new(dir))
|
19
|
+
|
20
|
+
trap('INT') { server.stop }
|
21
|
+
server.run.join
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'webrick'
|
2
|
+
|
3
|
+
module Webify
|
4
|
+
module Backend
|
5
|
+
|
6
|
+
class Webrick
|
7
|
+
include ::WEBrick
|
8
|
+
|
9
|
+
def self.start!(options={})
|
10
|
+
dir = File.expand_path(options[:dir] || Webify::DEFAULT_DIR)
|
11
|
+
port = options[:port] || Webify::DEFAULT_PORT
|
12
|
+
|
13
|
+
server = HTTPServer.new(
|
14
|
+
:Port => port,
|
15
|
+
:DocumentRoot => dir
|
16
|
+
)
|
17
|
+
|
18
|
+
trap('INT') { server.shutdown }
|
19
|
+
server.start
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module Webify
|
4
|
+
class Runner
|
5
|
+
|
6
|
+
def self.start!
|
7
|
+
options = {
|
8
|
+
:backend => Webify::DEFAULT_BACKEND,
|
9
|
+
:port => Webify::DEFAULT_PORT,
|
10
|
+
:dir => Webify::DEFAULT_DIR,
|
11
|
+
:throttle => 0
|
12
|
+
}
|
13
|
+
|
14
|
+
options_parser = OptionParser.new do |opts|
|
15
|
+
opts.banner = "Webify -- serve any directory to your browser\n"+
|
16
|
+
"Usage: webify [options]"
|
17
|
+
|
18
|
+
opts.separator ""
|
19
|
+
opts.separator "Server options:"
|
20
|
+
|
21
|
+
opts.on('-m', '--mongrel', "Use Mongrel as the backend (default: #{options[:backend]})") { options[:backend] = 'Mongrel' }
|
22
|
+
opts.on('-d', '--dir DIRECTORY', "Document root DIRECTORY (default: #{options[:dir]})") {|val| options[:dir] = val }
|
23
|
+
opts.on('-p', '--port PORT', "Use PORT (default: #{options[:port]})") {|val| options[:port] = val }
|
24
|
+
opts.on('-h', '--help', 'Display this help message') { puts opts; exit! }
|
25
|
+
|
26
|
+
opts.separator ""
|
27
|
+
opts.separator "Mongrel backend options:"
|
28
|
+
opts.on('-t', '--throttle TIME', "Time to pause (in hundredths of a second) between accepting clients. (default: #{options[:throttle]})") {|val| options[:throttle] = val }
|
29
|
+
end
|
30
|
+
options_parser.parse!(ARGV)
|
31
|
+
|
32
|
+
# Load the backend
|
33
|
+
begin
|
34
|
+
require "webify/backend/#{options[:backend].downcase}"
|
35
|
+
rescue LoadError => ex
|
36
|
+
$stderr.puts "Error! Cannot load backend #{options[:backend]}"
|
37
|
+
exit
|
38
|
+
end
|
39
|
+
|
40
|
+
backend_klass = instance_eval("Webify::Backend::" + options[:backend])
|
41
|
+
|
42
|
+
# Booting up the server
|
43
|
+
msg = "Serving: #{options[:dir]}\nURL: http://#{Socket.gethostname}:#{options[:port]}"
|
44
|
+
puts "="*80
|
45
|
+
puts "#{msg}\n"
|
46
|
+
puts ("="*80)+"\n\n"
|
47
|
+
|
48
|
+
backend_klass.start!(options)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -22,6 +22,10 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
files:
|
24
24
|
- README.md
|
25
|
+
- lib/webify/backend/mongrel.rb
|
26
|
+
- lib/webify/backend/webrick.rb
|
27
|
+
- lib/webify/runner.rb
|
28
|
+
- lib/webify/version.rb
|
25
29
|
- lib/webify.rb
|
26
30
|
- bin/webify
|
27
31
|
homepage: http://github.com/nulayer/webify
|