Module: Rack::Blogengine::ApplicationRouter
- Defined in:
- lib/rack/blogengine/application_router.rb
Overview
ApplicationRouter routes the request to the proper, parsed .content (layout.html + .content) file
Class Method Summary collapse
-
.errorpage(request, documents) ⇒ Object
Returns the errorpage.
-
.map_route(request, documents) ⇒ Hash
Maps documents to routes.
Class Method Details
.errorpage(request, documents) ⇒ Object
Returns the errorpage
39 40 41 42 43 44 |
# File 'lib/rack/blogengine/application_router.rb', line 39 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 |
.map_route(request, documents) ⇒ Hash
Maps documents to routes.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rack/blogengine/application_router.rb', line 14 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 |