Sha256: cf0179810d2f7529dcabdf5ee01e511250f7182747b21dfc408fea728bb5a194
Contents?: true
Size: 1.42 KB
Versions: 1
Compression:
Stored size: 1.42 KB
Contents
module Rack module Blogengine # # ApplicationRouter routes the request to the proper, parsed .content (layout.html + .content) file # # @author [benny] # module ApplicationRouter # Maps documents to routes. # @param env Env Contains path info etc... # @param documents Documents which will be looked at # @return [Hash] route Hash {:path => "/foo", :response => [Array]} class << self def map_route(request, documents) header = { 'Content-Type' => 'text/html; charset=UTF-8' } # Iterate through available docs, if nothing matched return nil documents.each do |doc| if doc[:path] == request.path response = Rack::Response.new(doc[:html], 200, header) route_response = { 'path' => request.path, 'response' => response # 'response' => [200, header, [doc[:html]]] } return route_response end end # if no document matches -> return error page errorpage(request, documents) end def errorpage(request, documents) header = { 'Content-Type' => 'text/html; charset=UTF-8' } response = Rack::Response.new('Page not found', 404, header) { 'path' => request.path, 'response' => response } end private :errorpage end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rack-blogengine-0.2.5 | lib/rack/blogengine/application_router.rb |