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
|
# File 'lib/usmu/ui/rack_server.rb', line 11
def call(env)
generator = @configuration.generator
path = env['PATH_INFO'][1...env['PATH_INFO'].length]
@log.info "Received a request for: #{path}"
path = File.join(path, @index) if File.directory? File.join(@configuration.source_path, path)
path = path[1...path.length] if path[0] == '/'
@log.info "Serving: #{path}"
valid = generator.renderables.select {|r| r.output_filename == path }
if valid.length > 0
generator.refresh
page = valid[0]
type = case page.output_filename[page.output_filename.rindex('.')...page.output_filename.length]
when '.html', '.php'
'text/html'
when '.css'
'text/css'
when '.js'
'text/javascript'
else
'text/plain'
end
['200', {'Content-Type' => type}, [page.render]]
else
['404', {'Content-Type' => 'text/html'}, ['<!DOCTYPE html><h1>File not found.</h1>']]
end
end
|