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
|
# File 'lib/guides/preview.rb', line 24
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({ :production => @production })
source_file = Dir["#{source_templates}/#{name}.{#{Guides::Generator::EXTENSIONS.join(",")}}"].first
unless source_file
return [404, {"Content-Type" => "text/html"}, ["#{name} not found in #{source_templates}: #{Guides.root}"]]
end
source_base = File.basename(source_file)
if generator.construction?(source_base) && @production
return [404, {"Content-Type" => "text/html"}, ["#{name} is under construction and not available in production"]]
end
generator.send(:generate_guide, source_base, "#{name}.html")
return @output.call(env)
else
source = @source.call(env)
return source if source.first == 200
return @local.call(env)
end
end
|