serve 0.9.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.tar.gz.sig ADDED
@@ -0,0 +1 @@
1
+ SQ��!��꾩��:3��;ar�����X �O;`X�JhtE�VP�b�w��%զh��n(<���,=ѝ���ydba�s�ҿ�wGY�ָC����u_83[�w �A���`w�*����w�f�N��;��v���^V�wՠ���tR ,3Lj0v�~U�H��[�&��:�-y���S�����C���y����|O�&�� 8���L��pTFn�+Gt����`�^��b�� M�f˿M�
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ == 0.9.0 (September 17, 2007)
2
+
3
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 John W. Long
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,22 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ bin/serve
7
+ config/hoe.rb
8
+ config/requirements.rb
9
+ lib/serve.rb
10
+ lib/serve/version.rb
11
+ lib/webrick/extensions.rb
12
+ log/debug.log
13
+ script/destroy
14
+ script/generate
15
+ setup.rb
16
+ spec/serve_spec.rb
17
+ spec/spec.opts
18
+ spec/spec_helper.rb
19
+ tasks/deployment.rake
20
+ tasks/environment.rake
21
+ tasks/rspec.rake
22
+ tasks/website.rake
data/README.txt ADDED
@@ -0,0 +1,64 @@
1
+ == What is Serve?
2
+
3
+ Serve is a small Ruby script that makes it easy to start up an HTTP server
4
+ in any directory. This is ideal for everything from HTML prototyping to simple
5
+ file sharing.
6
+
7
+
8
+ == Usage
9
+
10
+ At a command prompt all you need to type to start serve is:
11
+
12
+ $ serve
13
+
14
+ This will launch a WEBrick server which you can access from any Web browser at
15
+ the following address:
16
+
17
+ http://localhost:3000
18
+
19
+ Once the server is going it will output a running log of its activity. To
20
+ stop the server at any time, type CTRL+C at the command prompt. By default the
21
+ serve command serves up files from the current directory. To change this
22
+ behavior, `cd` to the appropriate directory before starting serve.
23
+
24
+
25
+ == Advanced Options
26
+
27
+ The serve command automatically binds to 0.0.0.0 (localhost) and uses port
28
+ 3000 by default. To serve files over a different IP (that is bound to your
29
+ computer) or port specify those options on the command line:
30
+
31
+ $ serve 4000 # a custom port
32
+
33
+ $ serve 192.168.1.6 # a custom IP
34
+
35
+ $ serve 192.168.1.6:4000 # a custom IP and port
36
+
37
+
38
+ == Rails Applications
39
+
40
+ For your convenience if the file "script/server" exists in the current
41
+ directory the serve command will start that instead of launching a WEBrick
42
+ server. You can specify the environment that you want to start the server
43
+ with as an option on the command line:
44
+
45
+ $ serve production # start script/server in production mode
46
+
47
+
48
+ == Installation and Setup
49
+
50
+ It is recommended that you install serve via RubyGems:
51
+
52
+ $ sudo gem install serve
53
+
54
+
55
+ == License
56
+
57
+ Serve is released under the MIT license and is copyright (c) John W. Long.
58
+ A copy of the MIT license can be found in the LICENSE.txt file.
59
+
60
+
61
+ Enjoy!
62
+
63
+ --
64
+ John Long :: http://wiseheartdesign.com
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/bin/serve ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.dirname(__FILE__) + '/../lib'
4
+ if File.file?(lib + '/serve/version.rb')
5
+ $LOAD_PATH << lib
6
+ else
7
+ require 'rubygems'
8
+ gem 'serve'
9
+ end
10
+ require 'serve'
11
+
12
+ args = ARGV.join(' ')
13
+ args.gsub!(%r{http://}, '')
14
+ args = args.split(/[ :]/).compact
15
+
16
+ help = args.delete('--help') || args.delete('-h') || false
17
+ version = args.delete('--version') || args.delete('-v') || false
18
+ environment = args.delete('production') || args.delete('test') || args.delete('test') || 'development'
19
+ port = args.pop || 3000
20
+ address = args.pop || '0.0.0.0'
21
+ script = Dir.pwd + '/script/server'
22
+
23
+ if args.size > 0
24
+ puts "invalid arguments"
25
+ puts ""
26
+ help = true
27
+ end
28
+
29
+ case
30
+ when version
31
+ puts "Serve #{Serve.version}"
32
+ when help
33
+ program = File.basename($0)
34
+ puts "Usage:"
35
+ puts " #{program} [port] [environment]"
36
+ puts " #{program} [address:port] [environment]"
37
+ puts " #{program} [options]"
38
+ puts " "
39
+ puts "Description:"
40
+ puts " Starts a WEBrick server on the specified address and port with its document "
41
+ puts " root set to the current working directory. By default the command uses "
42
+ puts " 0.0.0.0 for the address and 3000 for the port. This means that once the "
43
+ puts " command has been started you can access the documents in the current "
44
+ puts " directory with any Web browser at"
45
+ puts " "
46
+ puts " http://localhost:3000/"
47
+ puts " "
48
+ puts " If the Rails command script/server exists in the current directory the "
49
+ puts " script will start that instead with the specified environment or the "
50
+ puts " development environment if none is specified."
51
+ puts " "
52
+ puts " If the haml, redcloth, or bluecloth gems are installed the command can serve "
53
+ puts " Haml, Sass, Textile, and Markdown for documents with haml, sass, textile, "
54
+ puts " and markdown file extensions."
55
+ puts " "
56
+ puts "Options:"
57
+ puts " -h, --help Show this message and quit."
58
+ puts " -v, --version Show the program version number and quit."
59
+ else
60
+ unless File.file?(script) and File.executable?(script)
61
+ server = Serve::Server.new(
62
+ :Port => port,
63
+ :BindAddress => address,
64
+ :DocumentRoot => Dir.pwd,
65
+ :DirectoryIndex => %w(index.html index.txt index.text index.haml index.textile index.markdown),
66
+ :AppendExtensions => %w(html txt text haml textile markdown)
67
+ )
68
+ trap("INT") { server.shutdown }
69
+ server.start
70
+ else
71
+ system "#{script} -p #{port} -b #{address} -e #{environment}"
72
+ end
73
+ end
data/config/hoe.rb ADDED
@@ -0,0 +1,70 @@
1
+ require 'serve/version'
2
+
3
+ AUTHOR = 'John W. Long' # can also be an array of Authors
4
+ EMAIL = "me@johnwlong.com"
5
+ DESCRIPTION = "Serve is a small Ruby script that makes it easy to start up a WEBrick server in any directory. This is ideal for everything from HTML prototyping to simple file sharing."
6
+ GEM_NAME = 'serve' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'serve' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "jlong"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = Serve::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'serve documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README.txt",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.author = AUTHOR
52
+ p.description = DESCRIPTION
53
+ p.email = EMAIL
54
+ p.summary = DESCRIPTION
55
+ p.url = HOMEPATH
56
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
57
+ p.test_globs = ["test/**/test_*.rb"]
58
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
59
+
60
+ # == Optional
61
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\\n\\n")
62
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
63
+
64
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
65
+
66
+ end
67
+
68
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
69
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
70
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
+
17
+ require 'serve'
data/lib/serve.rb ADDED
@@ -0,0 +1,94 @@
1
+ require 'serve/version'
2
+ require 'webrick/extensions'
3
+
4
+ module Serve #:nodoc:
5
+ class FileTypeHandler < WEBrick::HTTPServlet::AbstractServlet #:nodoc:
6
+
7
+ def self.extension(extension)
8
+ WEBrick::HTTPServlet::FileHandler.add_handler(extension, self)
9
+ end
10
+
11
+ def initialize(server, name)
12
+ super
13
+ @script_filename = name
14
+ end
15
+
16
+ def do_GET(req, res)
17
+ begin
18
+ data = open(@script_filename){|io| io.read }
19
+ res.body = parse(data)
20
+ res['content-type'] = content_type
21
+ rescue StandardError => ex
22
+ raise
23
+ rescue Exception => ex
24
+ @logger.error(ex)
25
+ raise WEBrick::HTTPStatus::InternalServerError, ex.message
26
+ end
27
+ end
28
+
29
+ alias do_POST do_GET
30
+
31
+ protected
32
+
33
+ def content_type
34
+ 'text/html'
35
+ end
36
+
37
+ def parse(string)
38
+ string.dup
39
+ end
40
+
41
+ end
42
+
43
+ class TextileHandler < FileTypeHandler #:nodoc:
44
+ extension 'textile'
45
+
46
+ def parse(string)
47
+ require 'redcloth'
48
+ "<html><body>#{ RedCloth.new(string).to_html }</body></html>"
49
+ end
50
+ end
51
+
52
+ class MarkdownHandler < FileTypeHandler #:nodoc:
53
+ extension 'markdown'
54
+
55
+ def parse(string)
56
+ require 'bluecloth'
57
+ "<html><body>#{ BlueCloth.new(string).to_html }</body></html>"
58
+ end
59
+ end
60
+
61
+ class HamlHandler < FileTypeHandler #:nodoc:
62
+ extension 'haml'
63
+
64
+ def parse(string)
65
+ require 'haml'
66
+ engine = Haml::Engine.new(string,
67
+ :attr_wrapper => '"',
68
+ :filename => @script_filename
69
+ )
70
+ engine.render
71
+ end
72
+ end
73
+
74
+ class SassHandler < FileTypeHandler #:nodoc:
75
+ extension 'sass'
76
+
77
+ def parse(string)
78
+ require 'sass'
79
+ engine = Sass::Engine.new(string,
80
+ :style => :expanded,
81
+ :filename => @script_filename
82
+ )
83
+ engine.render
84
+ end
85
+
86
+ def content_type
87
+ 'text/css'
88
+ end
89
+ end
90
+
91
+ class Server < WEBrick::HTTPServer #:nodoc:
92
+ end
93
+
94
+ end
@@ -0,0 +1,13 @@
1
+ module Serve #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 9
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+
10
+ def self.version
11
+ VERSION::STRING
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ require 'webrick'
2
+
3
+ module Serve #:nodoc:
4
+ module FileHandlerExtensions
5
+
6
+ def self.included(base)
7
+ base.extend(self)
8
+ base.class_eval do
9
+ alias :search_file_without_auto_appending :search_file
10
+ alias :search_file :search_file_with_auto_appending
11
+ end
12
+ end
13
+
14
+ def search_file_with_auto_appending(req, res, basename)
15
+ if result = search_file_without_auto_appending(req, res, basename)
16
+ return result
17
+ end
18
+ extensions = @config[:AppendExtensions]
19
+ basename = $1 if basename =~ %r{^(.*?)/$}
20
+ if extensions
21
+ extensions.each do |ext|
22
+ if result = search_file_without_auto_appending(req, res, "#{basename}.#{ext}")
23
+ return result
24
+ end
25
+ end
26
+ end
27
+ return nil
28
+ end
29
+
30
+ end
31
+ end
32
+
33
+ WEBrick::HTTPServlet::FileHandler.class_eval { include Serve::FileHandlerExtensions }
data/log/debug.log ADDED
File without changes
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)