23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/guides/preview.rb', line 23
def call(env)
path = env["PATH_INFO"]
case path
when "/"
env["PATH_INFO"] = "/index.html"
return call(env)
when /\/(.*).html/
name = $1
generator = Guides::Generator.new({})
source_file = Dir["#{source_templates}/#{name}.{html.erb,textile}"].first
unless source_file
return [404, {"Content-Type" => "text/html"}, ["#{name} not found in #{source_templates}: #{Guides.root}"]]
end
generator.send(:generate_guide, File.basename(source_file), "#{name}.html")
return @output.call(env)
else
source = @source.call(env)
return source if source.first == 200
return @local.call(env)
end
end
|