serve 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.9.6 (February 20, 2008)
2
+
3
+ * Changed default port to 4000 so that serve plays nicely with Rails apps.
4
+ * Rearranged source.
5
+
1
6
  == 0.9.5 (February 19, 2008)
2
7
 
3
8
  * Added support for rendering other files with the following syntax:
data/Manifest.txt CHANGED
@@ -7,11 +7,19 @@ bin/serve
7
7
  config/hoe.rb
8
8
  config/requirements.rb
9
9
  lib/serve.rb
10
+ lib/serve/handlers/email_handler.rb
11
+ lib/serve/handlers/file_type_handler.rb
12
+ lib/serve/handlers/haml_handler.rb
13
+ lib/serve/handlers/markdown_handler.rb
14
+ lib/serve/handlers/redirect_handler.rb
15
+ lib/serve/handlers/sass_handler.rb
16
+ lib/serve/handlers/textile_handler.rb
10
17
  lib/serve/version.rb
11
- lib/webrick/extensions.rb
18
+ lib/serve/webrick/extensions.rb
12
19
  log/debug.log
13
20
  script/destroy
14
21
  script/generate
22
+ script/txt2html
15
23
  setup.rb
16
24
  spec/serve_spec.rb
17
25
  spec/spec.opts
@@ -19,4 +27,5 @@ spec/spec_helper.rb
19
27
  tasks/deployment.rake
20
28
  tasks/environment.rake
21
29
  tasks/rspec.rake
30
+ tasks/undefine.rake
22
31
  tasks/website.rake
data/README.txt CHANGED
@@ -1,7 +1,5 @@
1
1
  == Serve
2
2
 
3
- === What is Serve?
4
-
5
3
  Serve is a small Ruby script that makes it easy to start up a WEBrick server
6
4
  in any directory. Serve is ideal for HTML prototyping and simple file sharing.
7
5
  If the haml, redcloth, and bluecloth gems are installed serve can handle Haml,
@@ -17,7 +15,7 @@ At a command prompt all you need to type to start serve is:
17
15
  This will launch a WEBrick server which you can access from any Web browser at
18
16
  the following address:
19
17
 
20
- http://localhost:3000
18
+ http://localhost:4000
21
19
 
22
20
  Once the server is going it will output a running log of its activity. To
23
21
  stop the server at any time, type CTRL+C at the command prompt. By default the
@@ -28,7 +26,7 @@ behavior, `cd` to the appropriate directory before starting serve.
28
26
  === Advanced Options
29
27
 
30
28
  The serve command automatically binds to 0.0.0.0 (localhost) and uses port
31
- 3000 by default. To serve files over a different IP (that is bound to your
29
+ 4000 by default. To serve files over a different IP (that is bound to your
32
30
  computer) or port specify those options on the command line:
33
31
 
34
32
  $ serve 4000 # a custom port
@@ -67,10 +65,22 @@ It is recommended that you install serve via RubyGems:
67
65
  $ sudo gem install serve
68
66
 
69
67
 
68
+ === More Information
69
+
70
+ For more information, be sure to look through the documentation over at
71
+ RubyForge:
72
+
73
+ http://serve.rubyforge.org/
74
+
75
+ Or visit the project page here:
76
+
77
+ http://rubyforge.org/projects/serve/
78
+
79
+
70
80
  === License
71
81
 
72
- Serve is released under the MIT license and is copyright (c) John W. Long.
73
- A copy of the MIT license can be found in the License.txt file.
82
+ Serve is released under the MIT license and is copyright (c) 2006-2007
83
+ John W. Long. A copy of the MIT license can be found in the License.txt file.
74
84
 
75
85
 
76
86
  Enjoy!
data/Rakefile CHANGED
@@ -1,4 +1,13 @@
1
1
  require 'config/requirements'
2
2
  require 'config/hoe' # setup Hoe + all gem configuration
3
3
 
4
- Dir['tasks/**/*.rake'].each { |rake| load rake }
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
5
+
6
+ undefine_task %w(
7
+ default
8
+ test
9
+ test_deps
10
+ config_hoe
11
+ )
12
+
13
+ task :default => :spec
data/bin/serve CHANGED
@@ -16,7 +16,7 @@ args = args.split(/[ :]/).compact
16
16
  help = args.delete('--help') || args.delete('-h') || false
17
17
  version = args.delete('--version') || args.delete('-v') || false
18
18
  environment = args.delete('production') || args.delete('test') || args.delete('test') || 'development'
19
- port = args.pop || 3000
19
+ port = args.pop
20
20
  address = args.pop || '0.0.0.0'
21
21
  script = Dir.pwd + '/script/server'
22
22
 
@@ -39,25 +39,27 @@ when help
39
39
  puts "Description:"
40
40
  puts " Starts a WEBrick server on the specified address and port with its document "
41
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 "
42
+ puts " 0.0.0.0 for the address and 4000 for the port. This means that once the "
43
43
  puts " command has been started you can access the documents in the current "
44
44
  puts " directory with any Web browser at:"
45
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."
46
+ puts " http://localhost:4000/"
51
47
  puts " "
52
48
  puts " If the haml, redcloth, or bluecloth gems are installed the command can serve "
53
49
  puts " Haml, Sass, Textile, and Markdown for documents with haml, sass, textile, "
54
50
  puts " and markdown file extensions."
55
51
  puts " "
52
+ puts " If the Rails command script/server exists in the current directory the "
53
+ puts " script will start that instead with the specified environment or the "
54
+ puts " development environment if none is specified. Rails apps are started by "
55
+ puts " default on port 3000."
56
+ puts " "
56
57
  puts "Options:"
57
58
  puts " -h, --help Show this message and quit."
58
59
  puts " -v, --version Show the program version number and quit."
59
60
  else
60
61
  unless File.file?(script) and File.executable?(script)
62
+ port ||= 4000
61
63
  server = Serve::Server.new(
62
64
  :Port => port,
63
65
  :BindAddress => address,
@@ -68,6 +70,7 @@ else
68
70
  trap("INT") { server.shutdown }
69
71
  server.start
70
72
  else
73
+ port ||= 3000
71
74
  system "#{script} -p #{port} -b #{address} -e #{environment}"
72
75
  end
73
76
  end
data/lib/serve.rb CHANGED
@@ -1,231 +1,15 @@
1
+ require 'webrick'
1
2
  require 'serve/version'
2
- require 'webrick/extensions'
3
+ require 'serve/webrick/extensions'
4
+ require 'serve/handlers/file_type_handler'
5
+ require 'serve/handlers/textile_handler'
6
+ require 'serve/handlers/markdown_handler'
7
+ require 'serve/handlers/haml_handler'
8
+ require 'serve/handlers/sass_handler'
9
+ require 'serve/handlers/email_handler'
10
+ require 'serve/handlers/redirect_handler'
3
11
 
4
12
  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 process(req, res)
17
- data = open(@script_filename){|io| io.read }
18
- res['content-type'] = content_type
19
- res.body = parse(data)
20
- end
21
-
22
- def do_GET(req, res)
23
- begin
24
- process(req, res)
25
- rescue StandardError => ex
26
- raise
27
- rescue Exception => ex
28
- @logger.error(ex)
29
- raise WEBrick::HTTPStatus::InternalServerError, ex.message
30
- end
31
- end
32
-
33
- alias do_POST do_GET
34
-
35
- protected
36
-
37
- def content_type
38
- 'text/html'
39
- end
40
-
41
- def parse(string)
42
- string.dup
43
- end
44
-
13
+ class Server < ::WEBrick::HTTPServer #:nodoc:
45
14
  end
46
-
47
- class TextileHandler < FileTypeHandler #:nodoc:
48
- extension 'textile'
49
-
50
- def parse(string)
51
- require 'redcloth'
52
- "<html><body>#{ RedCloth.new(string).to_html }</body></html>"
53
- end
54
- end
55
-
56
- class MarkdownHandler < FileTypeHandler #:nodoc:
57
- extension 'markdown'
58
-
59
- def parse(string)
60
- require 'bluecloth'
61
- "<html><body>#{ BlueCloth.new(string).to_html }</body></html>"
62
- end
63
- end
64
-
65
- class HamlHandler < FileTypeHandler #:nodoc:
66
- extension 'haml'
67
-
68
- def parse(string)
69
- require 'haml'
70
- engine = Haml::Engine.new(string,
71
- :attr_wrapper => '"',
72
- :filename => @script_filename
73
- )
74
- layout = find_layout(@script_filename)
75
- if layout
76
- lines = IO.read(layout)
77
- context = Context.new(Dir.pwd, @script_filename, engine.options.dup)
78
- context.content = engine.render(context) do |*args|
79
- context.get_content_for(*args)
80
- end
81
- layout_engine = Haml::Engine.new(lines, engine.options.dup)
82
- layout_engine.render(context) do |*args|
83
- context.get_content_for(*args)
84
- end
85
- else
86
- engine.render
87
- end
88
- end
89
-
90
- def find_layout(filename)
91
- root = Dir.pwd
92
- path = filename[root.size..-1]
93
- layout = nil
94
- begin
95
- path = File.dirname(path)
96
- l = File.join(root, path, '_layout.haml')
97
- layout = l if File.file?(l)
98
- end until layout or path == "/"
99
- layout
100
- end
101
-
102
- class Context
103
- attr_accessor :content
104
-
105
- def initialize(root, script_filename, engine_options)
106
- @root, @script_filename, @engine_options = root, script_filename, engine_options
107
- end
108
-
109
- # Content_for methods
110
-
111
- def content_for(symbol, &block)
112
- set_content_for(symbol, capture_haml(&block))
113
- end
114
-
115
- def content_for?(symbol)
116
- !(get_content_for(symbol)).nil?
117
- end
118
-
119
- def get_content_for(symbol = :content)
120
- if symbol.to_s.intern == :content
121
- @content
122
- else
123
- instance_variable_get("@content_for_#{symbol}") || instance_variable_get("@#{symbol}")
124
- end
125
- end
126
-
127
- def set_content_for(symbol, value)
128
- instance_variable_set("@content_for_#{symbol}", value)
129
- end
130
-
131
- # Render methods
132
-
133
- def render(options)
134
- partial = options.delete(:partial)
135
- template = options.delete(:template)
136
- case
137
- when partial
138
- render_partial(partial)
139
- when template
140
- render_template(template)
141
- else
142
- raise "render options not supported #{options.inspect}"
143
- end
144
- end
145
-
146
- def render_partial(partial)
147
- render_template(partial, :partial => true)
148
- end
149
-
150
- def render_template(template, options={})
151
- path = File.dirname(@script_filename)
152
- if template =~ %r{^/}
153
- template = template[1..-1]
154
- path = @root
155
- end
156
- filename = template_filename(File.join(path, template), :partial => options.delete(:partial))
157
- if File.file?(filename)
158
- lines = IO.read(filename)
159
- engine = Haml::Engine.new(lines, @engine_options)
160
- engine.render(self) do |*args|
161
- get_content_for(*args)
162
- end
163
- else
164
- raise "File does not exist #{filename.inspect}"
165
- end
166
- end
167
-
168
- def template_filename(name, options)
169
- path = File.dirname(name)
170
- template = File.basename(name)
171
- template = "_" + template if options.delete(:partial)
172
- template += ".haml" unless name =~ /\.haml$/
173
- File.join(path, template)
174
- end
175
- end
176
- end
177
-
178
- class SassHandler < FileTypeHandler #:nodoc:
179
- extension 'sass'
180
-
181
- def parse(string)
182
- require 'sass'
183
- engine = Sass::Engine.new(string,
184
- :style => :expanded,
185
- :filename => @script_filename
186
- )
187
- engine.render
188
- end
189
-
190
- def content_type
191
- 'text/css'
192
- end
193
- end
194
-
195
- class EmailHandler < FileTypeHandler #:nodoc:
196
- extension 'email'
197
-
198
- def parse(string)
199
- title = "E-mail"
200
- title = $1 + " #{title}" if string =~ /^Subject:\s*(\S.*?)$/im
201
- head, body = string.split("\n\n", 2)
202
- output = []
203
- output << "<html><head><title>#{title}</title></head>"
204
- output << '<body style="font-family: Arial; line-height: 1.2em; font-size: 90%; margin: 0; padding: 0">'
205
- output << '<div id="head" style="background-color: #E9F2FA; padding: 1em">'
206
- head.each do |line|
207
- key, value = line.split(":", 2).map { |a| a.strip }
208
- output << "<div><strong>#{key}:</strong> #{value}</div>"
209
- end
210
- output << '</div><pre id="body" style="font-size: 110%; padding: 1em">'
211
- output << body
212
- output << '</pre></body></html>'
213
- output.join("\n")
214
- end
215
- end
216
-
217
- class RedirectHandler < FileTypeHandler #:nodoc:
218
- extension 'redirect'
219
-
220
- def process(req, res)
221
- data = super
222
- res['location'] = data.strip
223
- res.body = ''
224
- raise WEBrick::HTTPStatus::Found
225
- end
226
- end
227
-
228
- class Server < WEBrick::HTTPServer #:nodoc:
229
- end
230
-
231
- end
15
+ end
@@ -0,0 +1,23 @@
1
+ module Serve #:nodoc:
2
+ class EmailHandler < FileTypeHandler #:nodoc:
3
+ extension 'email'
4
+
5
+ def parse(string)
6
+ title = "E-mail"
7
+ title = $1 + " #{title}" if string =~ /^Subject:\s*(\S.*?)$/im
8
+ head, body = string.split("\n\n", 2)
9
+ output = []
10
+ output << "<html><head><title>#{title}</title></head>"
11
+ output << '<body style="font-family: Arial; line-height: 1.2em; font-size: 90%; margin: 0; padding: 0">'
12
+ output << '<div id="head" style="background-color: #E9F2FA; padding: 1em">'
13
+ head.each do |line|
14
+ key, value = line.split(":", 2).map { |a| a.strip }
15
+ output << "<div><strong>#{key}:</strong> #{value}</div>"
16
+ end
17
+ output << '</div><pre id="body" style="font-size: 110%; padding: 1em">'
18
+ output << body
19
+ output << '</pre></body></html>'
20
+ output.join("\n")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ module Serve #:nodoc:
2
+ class FileTypeHandler < ::WEBrick::HTTPServlet::AbstractServlet #:nodoc:
3
+
4
+ def self.extension(extension)
5
+ ::WEBrick::HTTPServlet::FileHandler.add_handler(extension, self)
6
+ end
7
+
8
+ def initialize(server, name)
9
+ super
10
+ @script_filename = name
11
+ end
12
+
13
+ def process(req, res)
14
+ data = open(@script_filename){|io| io.read }
15
+ res['content-type'] = content_type
16
+ res.body = parse(data)
17
+ end
18
+
19
+ def do_GET(req, res)
20
+ begin
21
+ process(req, res)
22
+ rescue StandardError => ex
23
+ raise
24
+ rescue Exception => ex
25
+ @logger.error(ex)
26
+ raise ::WEBrick::HTTPStatus::InternalServerError, ex.message
27
+ end
28
+ end
29
+
30
+ alias do_POST do_GET
31
+
32
+ protected
33
+
34
+ def content_type
35
+ 'text/html'
36
+ end
37
+
38
+ def parse(string)
39
+ string.dup
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,114 @@
1
+ module Serve #:nodoc:
2
+ class HamlHandler < FileTypeHandler #:nodoc:
3
+ extension 'haml'
4
+
5
+ def parse(string)
6
+ require 'haml'
7
+ engine = Haml::Engine.new(string,
8
+ :attr_wrapper => '"',
9
+ :filename => @script_filename
10
+ )
11
+ layout = find_layout(@script_filename)
12
+ if layout
13
+ lines = IO.read(layout)
14
+ context = Context.new(Dir.pwd, @script_filename, engine.options.dup)
15
+ context.content = engine.render(context) do |*args|
16
+ context.get_content_for(*args)
17
+ end
18
+ layout_engine = Haml::Engine.new(lines, engine.options.dup)
19
+ layout_engine.render(context) do |*args|
20
+ context.get_content_for(*args)
21
+ end
22
+ else
23
+ engine.render
24
+ end
25
+ end
26
+
27
+ def find_layout(filename)
28
+ root = Dir.pwd
29
+ path = filename[root.size..-1]
30
+ layout = nil
31
+ begin
32
+ path = File.dirname(path)
33
+ l = File.join(root, path, '_layout.haml')
34
+ layout = l if File.file?(l)
35
+ end until layout or path == "/"
36
+ layout
37
+ end
38
+
39
+ class Context #:nodoc:
40
+ attr_accessor :content
41
+
42
+ def initialize(root, script_filename, engine_options)
43
+ @root, @script_filename, @engine_options = root, script_filename, engine_options
44
+ end
45
+
46
+ # Content_for methods
47
+
48
+ def content_for(symbol, &block)
49
+ set_content_for(symbol, capture_haml(&block))
50
+ end
51
+
52
+ def content_for?(symbol)
53
+ !(get_content_for(symbol)).nil?
54
+ end
55
+
56
+ def get_content_for(symbol = :content)
57
+ if symbol.to_s.intern == :content
58
+ @content
59
+ else
60
+ instance_variable_get("@content_for_#{symbol}") || instance_variable_get("@#{symbol}")
61
+ end
62
+ end
63
+
64
+ def set_content_for(symbol, value)
65
+ instance_variable_set("@content_for_#{symbol}", value)
66
+ end
67
+
68
+ # Render methods
69
+
70
+ def render(options)
71
+ partial = options.delete(:partial)
72
+ template = options.delete(:template)
73
+ case
74
+ when partial
75
+ render_partial(partial)
76
+ when template
77
+ render_template(template)
78
+ else
79
+ raise "render options not supported #{options.inspect}"
80
+ end
81
+ end
82
+
83
+ def render_partial(partial)
84
+ render_template(partial, :partial => true)
85
+ end
86
+
87
+ def render_template(template, options={})
88
+ path = File.dirname(@script_filename)
89
+ if template =~ %r{^/}
90
+ template = template[1..-1]
91
+ path = @root
92
+ end
93
+ filename = template_filename(File.join(path, template), :partial => options.delete(:partial))
94
+ if File.file?(filename)
95
+ lines = IO.read(filename)
96
+ engine = Haml::Engine.new(lines, @engine_options)
97
+ engine.render(self) do |*args|
98
+ get_content_for(*args)
99
+ end
100
+ else
101
+ raise "File does not exist #{filename.inspect}"
102
+ end
103
+ end
104
+
105
+ def template_filename(name, options)
106
+ path = File.dirname(name)
107
+ template = File.basename(name)
108
+ template = "_" + template if options.delete(:partial)
109
+ template += ".haml" unless name =~ /\.haml$/
110
+ File.join(path, template)
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,10 @@
1
+ module Serve #:nodoc:
2
+ class MarkdownHandler < FileTypeHandler #:nodoc:
3
+ extension 'markdown'
4
+
5
+ def parse(string)
6
+ require 'bluecloth'
7
+ "<html><body>#{ BlueCloth.new(string).to_html }</body></html>"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ module Serve #:nodoc:
2
+ class RedirectHandler < FileTypeHandler #:nodoc:
3
+ extension 'redirect'
4
+
5
+ def process(req, res)
6
+ data = super
7
+ res['location'] = data.strip
8
+ res.body = ''
9
+ raise ::WEBrick::HTTPStatus::Found
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ module Serve #:nodoc:
2
+ class SassHandler < FileTypeHandler #:nodoc:
3
+ extension 'sass'
4
+
5
+ def parse(string)
6
+ require 'sass'
7
+ engine = Sass::Engine.new(string,
8
+ :style => :expanded,
9
+ :filename => @script_filename
10
+ )
11
+ engine.render
12
+ end
13
+
14
+ def content_type
15
+ 'text/css'
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ module Serve #:nodoc:
2
+ class TextileHandler < FileTypeHandler #:nodoc:
3
+ extension 'textile'
4
+
5
+ def parse(string)
6
+ require 'redcloth'
7
+ "<html><body>#{ RedCloth.new(string).to_html }</body></html>"
8
+ end
9
+ end
10
+ end
data/lib/serve/version.rb CHANGED
@@ -2,7 +2,7 @@ module Serve #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 9
5
- TINY = 5
5
+ TINY = 6
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,33 @@
1
+ module Serve #:nodoc:
2
+ module WEBrick #:nodoc:
3
+ module FileHandlerExtensions #:nodoc:
4
+
5
+ def self.included(base)
6
+ base.extend(self)
7
+ base.class_eval do
8
+ alias :search_file_without_auto_appending :search_file
9
+ alias :search_file :search_file_with_auto_appending
10
+ end
11
+ end
12
+
13
+ def search_file_with_auto_appending(req, res, basename)
14
+ if result = search_file_without_auto_appending(req, res, basename)
15
+ return result
16
+ end
17
+ extensions = @config[:AppendExtensions]
18
+ basename = $1 if basename =~ %r{^(.*?)/$}
19
+ if extensions
20
+ extensions.each do |ext|
21
+ if result = search_file_without_auto_appending(req, res, "#{basename}.#{ext}")
22
+ return result
23
+ end
24
+ end
25
+ end
26
+ return nil
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+
33
+ WEBrick::HTTPServlet::FileHandler.class_eval { include Serve::WEBrick::FileHandlerExtensions }
data/script/txt2html ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ begin
5
+ require 'newgem'
6
+ rescue LoadError
7
+ puts "\n\nGenerating the website requires the newgem RubyGem"
8
+ puts "Install: gem install newgem\n\n"
9
+ exit(1)
10
+ end
11
+ require 'redcloth'
12
+ require 'syntax/convertors/html'
13
+ require 'erb'
14
+ require File.dirname(__FILE__) + '/../lib/serve/version.rb'
15
+
16
+ version = Serve::VERSION::STRING
17
+ download = 'http://rubyforge.org/projects/serve'
18
+
19
+ class Fixnum
20
+ def ordinal
21
+ # teens
22
+ return 'th' if (10..19).include?(self % 100)
23
+ # others
24
+ case self % 10
25
+ when 1: return 'st'
26
+ when 2: return 'nd'
27
+ when 3: return 'rd'
28
+ else return 'th'
29
+ end
30
+ end
31
+ end
32
+
33
+ class Time
34
+ def pretty
35
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
36
+ end
37
+ end
38
+
39
+ def convert_syntax(syntax, source)
40
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
41
+ end
42
+
43
+ if ARGV.length >= 1
44
+ src, template = ARGV
45
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
46
+
47
+ else
48
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
49
+ exit!
50
+ end
51
+
52
+ template = ERB.new(File.open(template).read)
53
+
54
+ title = nil
55
+ body = nil
56
+ File.open(src) do |fsrc|
57
+ title_text = fsrc.readline
58
+ body_text = fsrc.read
59
+ syntax_items = []
60
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
61
+ ident = syntax_items.length
62
+ element, syntax, source = $1, $2, $3
63
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
64
+ "syntax-temp-#{ident}"
65
+ }
66
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
67
+ body = RedCloth.new(body_text).to_html
68
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
69
+ end
70
+ stat = File.stat(src)
71
+ created = stat.ctime
72
+ modified = stat.mtime
73
+
74
+ $stdout << template.result(binding)
data/spec/serve_spec.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
- # Time to add your specs!
4
- # http://rspec.rubyforge.org/
5
- describe "Place your specs here" do
3
+ describe "Serve" do
6
4
 
7
- it "find this spec in spec directory" do
8
- violated "Be sure to write your specs"
5
+ it "should register all of the file type handlers" do
6
+ handlers = ["cgi", "email", "haml", "markdown", "redirect", "rhtml", "sass", "textile"]
7
+ table = WEBrick::HTTPServlet::FileHandler::HandlerTable
8
+ table.keys.sort.should == handlers
9
9
  end
10
10
 
11
11
  end
data/spec/spec_helper.rb CHANGED
@@ -4,4 +4,8 @@ rescue LoadError
4
4
  require 'rubygems'
5
5
  gem 'rspec'
6
6
  require 'spec'
7
- end
7
+ end
8
+
9
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
10
+
11
+ require 'serve'
data/tasks/rspec.rake CHANGED
@@ -18,4 +18,4 @@ desc "Run the specs under spec/models"
18
18
  Spec::Rake::SpecTask.new do |t|
19
19
  t.spec_opts = ['--options', "spec/spec.opts"]
20
20
  t.spec_files = FileList['spec/*_spec.rb']
21
- end
21
+ end
@@ -0,0 +1,5 @@
1
+ def undefine_task(*names)
2
+ app = Rake.application
3
+ tasks = app.instance_variable_get('@tasks')
4
+ names.flatten.each { |name| tasks.delete(name) }
5
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: serve
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.9.5
7
- date: 2008-02-19 00:00:00 -05:00
6
+ version: 0.9.6
7
+ date: 2008-02-20 00:00:00 -05:00
8
8
  summary: Serve is a small Ruby script that makes it easy to start up a WEBrick server in any directory. Serve is ideal for HTML prototyping and simple file sharing. If the haml, redcloth, and bluecloth gems are installed serve can handle Haml, Sass, Textile, and Markdown (in addition to HTML).
9
9
  require_paths:
10
10
  - lib
@@ -60,11 +60,19 @@ files:
60
60
  - config/hoe.rb
61
61
  - config/requirements.rb
62
62
  - lib/serve.rb
63
+ - lib/serve/handlers/email_handler.rb
64
+ - lib/serve/handlers/file_type_handler.rb
65
+ - lib/serve/handlers/haml_handler.rb
66
+ - lib/serve/handlers/markdown_handler.rb
67
+ - lib/serve/handlers/redirect_handler.rb
68
+ - lib/serve/handlers/sass_handler.rb
69
+ - lib/serve/handlers/textile_handler.rb
63
70
  - lib/serve/version.rb
64
- - lib/webrick/extensions.rb
71
+ - lib/serve/webrick/extensions.rb
65
72
  - log/debug.log
66
73
  - script/destroy
67
74
  - script/generate
75
+ - script/txt2html
68
76
  - setup.rb
69
77
  - spec/serve_spec.rb
70
78
  - spec/spec.opts
@@ -72,6 +80,7 @@ files:
72
80
  - tasks/deployment.rake
73
81
  - tasks/environment.rake
74
82
  - tasks/rspec.rake
83
+ - tasks/undefine.rake
75
84
  - tasks/website.rake
76
85
  test_files: []
77
86
 
metadata.gz.sig CHANGED
Binary file
@@ -1,33 +0,0 @@
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 }