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
|
# File 'lib/yodel/application/request_handler.rb', line 4
def call(env)
request = Rack::Request.new(env)
response = Rack::Response.new
site = env['yodel.site']
env['rack.session']['a'] = 1
components = PATH_FORMAT_REGEX.match(request.path.downcase)
return fail_with "Unable to parse request path: #{request.path}" if components.nil?
path, format = components.captures
path = path[0...-1] if path.end_with?('/') && path.length != 1
mime_type = Yodel.mime_types.mime_type_for_request(format, request.env['HTTP_ACCEPT'])
page = site.pages.where(path: path).first
if page.nil?
site.glob_pages.all.each do |glob_page|
if path.start_with?(glob_page.path)
page = glob_page
request.params['glob'] = path[glob_page.path.length..-1]
break
end
end
return fail_with "File (#{request.path}) not found." if page.nil?
end
Layout.reload_layouts(site) if Yodel.env.development? page.respond_to_request(request, response, mime_type)
if page.response.respond_to?(:finish)
page.response.finish
else
page.response
end
end
|