Sha256: 08afe4e31baaf0c81e072e0eb29b5f9e8e6c834ed61356d4e21d45687d2c2574

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 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(env, documents)
          success_status = 200
          header = { 'Content-Type' => 'text/html; charset=UTF-8' }
          path = env['PATH_INFO']

          # Iterate through available docs, if nothing matched return nil
          documents.each do |doc|
            if doc[:path] == path
              route_response = {
                'path' => path,
                'response' => [success_status, header, [doc[:html]]]
              }

              return route_response
            end
          end

          { 'path' => '/error',
            'response' =>
            [404, { 'Content-Type' => 'text/html; charset=UTF-8' }, ['Page not found && no error page found']]
          }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-blogengine-0.2.2 lib/rack/blogengine/application_router.rb