Class Index [+]

Quicksearch

Merb::Rack::Static

Public Class Methods

new(app,directory) click to toggle source

:api: private

   # File lib/merb-core/rack/middleware/static.rb, line 6
6:       def initialize(app,directory)
7:         super(app)
8:         @static_server = ::Rack::File.new(directory)
9:       end

Public Instance Methods

call(env) click to toggle source

:api: plugin

    # File lib/merb-core/rack/middleware/static.rb, line 12
12:       def call(env)        
13:         path = if env[Merb::Const::PATH_INFO]
14:                  env[Merb::Const::PATH_INFO].chomp(Merb::Const::SLASH)
15:                else
16:                  Merb::Const::EMPTY_STRING
17:                end
18:         cached_path = (path.empty? ? 'index' : path) + '.html'
19:         
20:         if file_exist?(path) && env[Merb::Const::REQUEST_METHOD] =~ /GET|HEAD/ # Serve the file if it's there and the request method is GET or HEAD
21:           serve_static(env)
22:         elsif file_exist?(cached_path) && env[Merb::Const::REQUEST_METHOD] =~ /GET|HEAD/ # Serve the page cache if it's there and the request method is GET or HEAD
23:           env[Merb::Const::PATH_INFO] = cached_path
24:           serve_static(env)
25:         elsif path =~ /favicon\.ico/
26:           return [404, { Merb::Const::CONTENT_TYPE => Merb::Const::TEXT_SLASH_HTML }, "404 Not Found."]
27:         else
28:           @app.call(env)
29:         end
30:       end
file_exist?(path) click to toggle source

Parameters

path

The path to the file relative to the server root.

Returns

Boolean

True if file exists under the server root and is readable.

:api: private

    # File lib/merb-core/rack/middleware/static.rb, line 39
39:         def file_exist?(path)
40:           full_path = ::File.join(@static_server.root, ::Merb::Parse.unescape(path))
41:           ::File.file?(full_path) && ::File.readable?(full_path)
42:         end
serve_static(env) click to toggle source

Parameters

env

Environment variables to pass on to the server.

:api: private

    # File lib/merb-core/rack/middleware/static.rb, line 48
48:         def serve_static(env)
49:           env[Merb::Const::PATH_INFO] = ::Merb::Parse.unescape(env[Merb::Const::PATH_INFO])
50:           @static_server.call(env)
51:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.