GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Fork of jlong/serve
Description: Serve is a rapid prototyping framework for Rails applications. It is designed to compliment Rails development and enforce a strict separation of concerns between designer and developer. Using Serve with Rails allows the designer to happily work in his own space creating an HTML prototype of the application, while the developer works on the Rails application and copies over HTML from the prototype as needed. This allows the designer to focus on presentation and flow while the developer can focus on the implementation.
Homepage: http://rubyforge.org/projects/serve/
Clone URL: git://github.com/Lawjoskar/serve.git
rearranged lib directory and brok lib/serve.rb into several files

git-svn-id: svn+ssh://rubyforge.org/var/svn/serve/trunk/serve@17 
bc0a7ee4-b4f2-4507-b10a-a3dd5181224c
jlong (author)
Tue Feb 19 18:54:44 -0800 2008
commit  93713c33b7e86c969b0cd4b275b641e01d2005c2
tree    c8cf5249333acbfd4fc691eea0fe0ecd6d207293
parent  cb07eba4de8ff94c62aa56bacac7c22c2cf7217e
...
7
8
9
 
 
 
 
 
 
 
10
11
 
12
13
14
 
15
16
17
...
19
20
21
 
22
...
7
8
9
10
11
12
13
14
15
16
17
 
18
19
20
21
22
23
24
25
...
27
28
29
30
31
0
@@ -7,11 +7,19 @@ bin/serve
0
 config/hoe.rb
0
 config/requirements.rb
0
 lib/serve.rb
0
+lib/serve/handlers/email_handler.rb
0
+lib/serve/handlers/file_type_handler.rb
0
+lib/serve/handlers/haml_handler.rb
0
+lib/serve/handlers/markdown_handler.rb
0
+lib/serve/handlers/redirect_handler.rb
0
+lib/serve/handlers/sass_handler.rb
0
+lib/serve/handlers/textile_handler.rb
0
 lib/serve/version.rb
0
-lib/webrick/extensions.rb
0
+lib/serve/webrick/extensions.rb
0
 log/debug.log
0
 script/destroy
0
 script/generate
0
+script/txt2html
0
 setup.rb
0
 spec/serve_spec.rb
0
 spec/spec.opts
0
@@ -19,4 +27,5 @@ spec/spec_helper.rb
0
 tasks/deployment.rake
0
 tasks/environment.rake
0
 tasks/rspec.rake
0
+tasks/undefine.rake
0
 tasks/website.rake
...
1
2
3
4
5
 
 
 
 
 
 
 
 
 
 
6
...
1
2
3
 
4
5
6
7
8
9
10
11
12
13
14
15
0
@@ -1,4 +1,13 @@
0
 require 'config/requirements'
0
 require 'config/hoe' # setup Hoe + all gem configuration
0
 
0
-Dir['tasks/**/*.rake'].each { |rake| load rake }
0
\ No newline at end of file
0
+Dir['tasks/**/*.rake'].each { |rake| load rake }
0
+
0
+undefine_task %w(
0
+ default
0
+ test
0
+ test_deps
0
+ config_hoe
0
+)
0
+
0
+task :default => :spec
0
\ No newline at end of file
...
 
1
2
 
 
 
 
 
 
 
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
 
232
...
1
2
 
3
4
5
6
7
8
9
10
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
13
 
 
14
15
0
@@ -1,231 +1,14 @@
0
+require 'webrick'
0
 require 'serve/version'
0
-require 'webrick/extensions'
0
+require 'serve/handlers/file_type_handler'
0
+require 'serve/handlers/textile_handler'
0
+require 'serve/handlers/markdown_handler'
0
+require 'serve/handlers/haml_handler'
0
+require 'serve/handlers/sass_handler'
0
+require 'serve/handlers/email_handler'
0
+require 'serve/handlers/redirect_handler'
0
 
0
 module Serve #:nodoc:
0
- class FileTypeHandler < WEBrick::HTTPServlet::AbstractServlet #:nodoc:
0
-
0
- def self.extension(extension)
0
- WEBrick::HTTPServlet::FileHandler.add_handler(extension, self)
0
- end
0
-
0
- def initialize(server, name)
0
- super
0
- @script_filename = name
0
- end
0
-
0
- def process(req, res)
0
- data = open(@script_filename){|io| io.read }
0
- res['content-type'] = content_type
0
- res.body = parse(data)
0
- end
0
-
0
- def do_GET(req, res)
0
- begin
0
- process(req, res)
0
- rescue StandardError => ex
0
- raise
0
- rescue Exception => ex
0
- @logger.error(ex)
0
- raise WEBrick::HTTPStatus::InternalServerError, ex.message
0
- end
0
- end
0
-
0
- alias do_POST do_GET
0
-
0
- protected
0
-
0
- def content_type
0
- 'text/html'
0
- end
0
-
0
- def parse(string)
0
- string.dup
0
- end
0
-
0
- end
0
-
0
- class TextileHandler < FileTypeHandler #:nodoc:
0
- extension 'textile'
0
-
0
- def parse(string)
0
- require 'redcloth'
0
- "<html><body>#{ RedCloth.new(string).to_html }</body></html>"
0
- end
0
- end
0
-
0
- class MarkdownHandler < FileTypeHandler #:nodoc:
0
- extension 'markdown'
0
-
0
- def parse(string)
0
- require 'bluecloth'
0
- "<html><body>#{ BlueCloth.new(string).to_html }</body></html>"
0
- end
0
- end
0
-
0
- class HamlHandler < FileTypeHandler #:nodoc:
0
- extension 'haml'
0
-
0
- def parse(string)
0
- require 'haml'
0
- engine = Haml::Engine.new(string,
0
- :attr_wrapper => '"',
0
- :filename => @script_filename
0
- )
0
- layout = find_layout(@script_filename)
0
- if layout
0
- lines = IO.read(layout)
0
- context = Context.new(Dir.pwd, @script_filename, engine.options.dup)
0
- context.content = engine.render(context) do |*args|
0
- context.get_content_for(*args)
0
- end
0
- layout_engine = Haml::Engine.new(lines, engine.options.dup)
0
- layout_engine.render(context) do |*args|
0
- context.get_content_for(*args)
0
- end
0
- else
0
- engine.render
0
- end
0
- end
0
-
0
- def find_layout(filename)
0
- root = Dir.pwd
0
- path = filename[root.size..-1]
0
- layout = nil
0
- begin
0
- path = File.dirname(path)
0
- l = File.join(root, path, '_layout.haml')
0
- layout = l if File.file?(l)
0
- end until layout or path == "/"
0
- layout
0
- end
0
-
0
- class Context
0
- attr_accessor :content
0
-
0
- def initialize(root, script_filename, engine_options)
0
- @root, @script_filename, @engine_options = root, script_filename, engine_options
0
- end
0
-
0
- # Content_for methods
0
-
0
- def content_for(symbol, &block)
0
- set_content_for(symbol, capture_haml(&block))
0
- end
0
-
0
- def content_for?(symbol)
0
- !(get_content_for(symbol)).nil?
0
- end
0
-
0
- def get_content_for(symbol = :content)
0
- if symbol.to_s.intern == :content
0
- @content
0
- else
0
- instance_variable_get("@content_for_#{symbol}") || instance_variable_get("@#{symbol}")
0
- end
0
- end
0
-
0
- def set_content_for(symbol, value)
0
- instance_variable_set("@content_for_#{symbol}", value)
0
- end
0
-
0
- # Render methods
0
-
0
- def render(options)
0
- partial = options.delete(:partial)
0
- template = options.delete(:template)
0
- case
0
- when partial
0
- render_partial(partial)
0
- when template
0
- render_template(template)
0
- else
0
- raise "render options not supported #{options.inspect}"
0
- end
0
- end
0
-
0
- def render_partial(partial)
0
- render_template(partial, :partial => true)
0
- end
0
-
0
- def render_template(template, options={})
0
- path = File.dirname(@script_filename)
0
- if template =~ %r{^/}
0
- template = template[1..-1]
0
- path = @root
0
- end
0
- filename = template_filename(File.join(path, template), :partial => options.delete(:partial))
0
- if File.file?(filename)
0
- lines = IO.read(filename)
0
- engine = Haml::Engine.new(lines, @engine_options)
0
- engine.render(self) do |*args|
0
- get_content_for(*args)
0
- end
0
- else
0
- raise "File does not exist #{filename.inspect}"
0
- end
0
- end
0
-
0
- def template_filename(name, options)
0
- path = File.dirname(name)
0
- template = File.basename(name)
0
- template = "_" + template if options.delete(:partial)
0
- template += ".haml" unless name =~ /\.haml$/
0
- File.join(path, template)
0
- end
0
- end
0
- end
0
-
0
- class SassHandler < FileTypeHandler #:nodoc:
0
- extension 'sass'
0
-
0
- def parse(string)
0
- require 'sass'
0
- engine = Sass::Engine.new(string,
0
- :style => :expanded,
0
- :filename => @script_filename
0
- )
0
- engine.render
0
- end
0
-
0
- def content_type
0
- 'text/css'
0
- end
0
- end
0
-
0
- class EmailHandler < FileTypeHandler #:nodoc:
0
- extension 'email'
0
-
0
- def parse(string)
0
- title = "E-mail"
0
- title = $1 + " #{title}" if string =~ /^Subject:\s*(\S.*?)$/im
0
- head, body = string.split("\n\n", 2)
0
- output = []
0
- output << "<html><head><title>#{title}</title></head>"
0
- output << '<body style="font-family: Arial; line-height: 1.2em; font-size: 90%; margin: 0; padding: 0">'
0
- output << '<div id="head" style="background-color: #E9F2FA; padding: 1em">'
0
- head.each do |line|
0
- key, value = line.split(":", 2).map { |a| a.strip }
0
- output << "<div><strong>#{key}:</strong> #{value}</div>"
0
- end
0
- output << '</div><pre id="body" style="font-size: 110%; padding: 1em">'
0
- output << body
0
- output << '</pre></body></html>'
0
- output.join("\n")
0
- end
0
- end
0
-
0
- class RedirectHandler < FileTypeHandler #:nodoc:
0
- extension 'redirect'
0
-
0
- def process(req, res)
0
- data = super
0
- res['location'] = data.strip
0
- res.body = ''
0
- raise WEBrick::HTTPStatus::Found
0
- end
0
- end
0
-
0
   class Server < WEBrick::HTTPServer #:nodoc:
0
   end
0
-
0
-end
0
+end
0
\ No newline at end of file
...
1
2
3
4
5
 
6
7
8
 
 
 
 
9
10
11
12
...
1
2
 
 
 
3
4
 
 
5
6
7
8
9
10
11
12
0
@@ -1,11 +1,11 @@
0
 require File.dirname(__FILE__) + '/spec_helper.rb'
0
 
0
-# Time to add your specs!
0
-# http://rspec.rubyforge.org/
0
-describe "Place your specs here" do
0
+describe "Serve" do
0
   
0
- it "find this spec in spec directory" do
0
- violated "Be sure to write your specs"
0
+ it "should register all of the file type handlers" do
0
+ handlers = ["cgi", "email", "haml", "markdown", "redirect", "rhtml", "sass", "textile"]
0
+ table = WEBrick::HTTPServlet::FileHandler::HandlerTable
0
+ table.keys.sort.should == handlers
0
   end
0
   
0
 end
0
\ No newline at end of file
...
4
5
6
7
8
 
 
 
 
 
9
...
4
5
6
 
7
8
9
10
11
12
13
0
@@ -4,4 +4,8 @@ rescue LoadError
0
   require 'rubygems'
0
   gem 'rspec'
0
   require 'spec'
0
-end
0
\ No newline at end of file
0
+end
0
+
0
+$: << File.join(File.dirname(__FILE__), '..', 'lib')
0
+
0
+require 'serve'
0
\ No newline at end of file
...
18
19
20
21
 
22
...
18
19
20
 
21
22
0
@@ -18,4 +18,4 @@ desc "Run the specs under spec/models"
0
 Spec::Rake::SpecTask.new do |t|
0
   t.spec_opts = ['--options', "spec/spec.opts"]
0
   t.spec_files = FileList['spec/*_spec.rb']
0
-end
0
+end
0
\ No newline at end of file

Comments

    No one has commented yet.