serve 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,5 @@
1
+ == 0.9.2 (January 17, 2008)
2
+
1
3
  * Added support for redirects
2
4
 
3
5
  == 0.9.1 (October 19, 2007)
data/README.txt CHANGED
@@ -52,13 +52,12 @@ with as an option on the command line:
52
52
 
53
53
  Serve presently does special processing for files with following extensions:
54
54
 
55
- textile :: Evaluates the document as Textile (requires the Redcloth gem)
56
- markdown :: Evaluates the document as Markdown (requires the Bluecloth gem)
57
- haml :: Evaluates the document as Haml (requires the Haml gem)
58
- sass :: Evaluates the document as Sass (requires the Haml gem)
59
- email :: Evaluates the document as if it is an e-mail message; the format
60
- is identicle to a plain/text e-mail message's source
61
- redirect :: Redirects to the URL contained in the document
55
+ textile :: Evaluates the document as Textile (requires the Redcloth gem)
56
+ markdown :: Evaluates the document as Markdown (requires the Bluecloth gem)
57
+ haml :: Evaluates the document as Haml (requires the Haml gem)
58
+ sass :: Evaluates the document as Sass (requires the Haml gem)
59
+ email :: Evaluates the document as if it is an e-mail message; the format is identicle to a plain/text e-mail message's source
60
+ redirect :: Redirects to the URL contained in the document
62
61
 
63
62
 
64
63
  === Installation and Setup
data/bin/serve CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  lib = File.dirname(__FILE__) + '/../lib'
4
+ require 'rubygems'
4
5
  if File.file?(lib + '/serve/version.rb')
5
6
  $LOAD_PATH << lib
6
7
  else
7
- require 'rubygems'
8
8
  gem 'serve'
9
9
  end
10
10
  require 'serve'
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 = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/serve.rb CHANGED
@@ -3,11 +3,11 @@ require 'webrick/extensions'
3
3
 
4
4
  module Serve #:nodoc:
5
5
  class FileTypeHandler < WEBrick::HTTPServlet::AbstractServlet #:nodoc:
6
-
6
+
7
7
  def self.extension(extension)
8
8
  WEBrick::HTTPServlet::FileHandler.add_handler(extension, self)
9
9
  end
10
-
10
+
11
11
  def initialize(server, name)
12
12
  super
13
13
  @script_filename = name
@@ -29,55 +29,136 @@ module Serve #:nodoc:
29
29
  raise WEBrick::HTTPStatus::InternalServerError, ex.message
30
30
  end
31
31
  end
32
-
32
+
33
33
  alias do_POST do_GET
34
-
34
+
35
35
  protected
36
-
36
+
37
37
  def content_type
38
38
  'text/html'
39
39
  end
40
-
40
+
41
41
  def parse(string)
42
42
  string.dup
43
43
  end
44
-
44
+
45
45
  end
46
-
46
+
47
47
  class TextileHandler < FileTypeHandler #:nodoc:
48
48
  extension 'textile'
49
-
49
+
50
50
  def parse(string)
51
51
  require 'redcloth'
52
52
  "<html><body>#{ RedCloth.new(string).to_html }</body></html>"
53
53
  end
54
54
  end
55
-
55
+
56
56
  class MarkdownHandler < FileTypeHandler #:nodoc:
57
57
  extension 'markdown'
58
-
58
+
59
59
  def parse(string)
60
60
  require 'bluecloth'
61
61
  "<html><body>#{ BlueCloth.new(string).to_html }</body></html>"
62
62
  end
63
63
  end
64
-
64
+
65
65
  class HamlHandler < FileTypeHandler #:nodoc:
66
66
  extension 'haml'
67
-
67
+
68
68
  def parse(string)
69
69
  require 'haml'
70
70
  engine = Haml::Engine.new(string,
71
71
  :attr_wrapper => '"',
72
72
  :filename => @script_filename
73
73
  )
74
- engine.render
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)
79
+ layout_engine = Haml::Engine.new(lines, engine.options.dup)
80
+ layout_engine.render(context) do |*args|
81
+ context.get_content_for(*args)
82
+ end
83
+ else
84
+ engine.render
85
+ end
86
+ end
87
+
88
+ def find_layout(filename)
89
+ root = Dir.pwd
90
+ path = filename[root.size..-1]
91
+ layout = nil
92
+ begin
93
+ path = File.dirname(path)
94
+ l = File.join(root, path, '_layout.haml')
95
+ layout = l if File.file?(l)
96
+ end until layout or path == "/"
97
+ layout
98
+ end
99
+
100
+ class Context
101
+ attr_accessor :content
102
+
103
+ def initialize(root, script_filename, engine_options)
104
+ @root, @script_filename, @engine_options = root, script_filename, engine_options
105
+ end
106
+
107
+ # Content_for methods
108
+
109
+ def content_for(symbol, &block)
110
+ set_content_for(symbol, capture_haml(&block))
111
+ end
112
+
113
+ def content_for?(symbol)
114
+ !(get_content_for(symbol)).nil?
115
+ end
116
+
117
+ def get_content_for(symbol = :content)
118
+ if symbol.to_s.intern == :content
119
+ @content
120
+ else
121
+ instance_variable_get("@content_for_#{symbol}") || instance_variable_get("@#{symbol}")
122
+ end
123
+ end
124
+
125
+ def set_content_for(symbol, value)
126
+ instance_variable_set("@content_for_#{symbol}", value)
127
+ end
128
+
129
+ # Render methods
130
+
131
+ def render(options)
132
+ partial = options.delete(:partial)
133
+ case
134
+ when partial
135
+ render_partial(partial)
136
+ else
137
+ raise "render options not supported #{options.inspect}"
138
+ end
139
+ end
140
+
141
+ def render_partial(partial)
142
+ path = File.dirname(@script_filename)
143
+ if partial =~ %r{^/}
144
+ partial = partial[1..-1]
145
+ path = @root
146
+ end
147
+ filename = File.join(path, "_" + partial + ".haml")
148
+ if File.file?(filename)
149
+ lines = IO.read(filename)
150
+ engine = Haml::Engine.new(lines, @engine_options)
151
+ engine.render(self)
152
+ else
153
+ raise "File does not exist #{filename.inspect}"
154
+ end
155
+ end
75
156
  end
76
157
  end
77
-
158
+
78
159
  class SassHandler < FileTypeHandler #:nodoc:
79
160
  extension 'sass'
80
-
161
+
81
162
  def parse(string)
82
163
  require 'sass'
83
164
  engine = Sass::Engine.new(string,
@@ -86,7 +167,7 @@ module Serve #:nodoc:
86
167
  )
87
168
  engine.render
88
169
  end
89
-
170
+
90
171
  def content_type
91
172
  'text/css'
92
173
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: serve
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.9.2
7
- date: 2008-01-17 00:00:00 -05:00
6
+ version: 0.9.3
7
+ date: 2008-01-23 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
metadata.gz.sig CHANGED
Binary file