Sha256: 75343792cb20e0bca39d033b92e5d7e335e5f4c7fbdba87ae5c7bfe6590127ea

Contents?: true

Size: 1004 Bytes

Versions: 12

Compression:

Stored size: 1004 Bytes

Contents

module Rack

  class TryStatic

    def initialize(app, options)
      @app = app
      @try = ['', *options.delete(:try)]
      @static = ::Rack::Static.new(lambda { [404, {}, []] }, options)
    end

    def call(env)
      orig_path = Rack::Utils.unescape env['PATH_INFO']
      found = nil
      @try.each do |path|
        resp = @static.call(env.merge!({'PATH_INFO' => orig_path + path}))
        break if 404 != resp[0] && found = resp
      end
      found or @app.call(env.merge!('PATH_INFO' => orig_path))
    end

  end

end

def start_rack(root, not_found)
  use Rack::TryStatic, :root => root, :urls => %w[/], :try => ['.html', 'index.html', '/index.html']

  # Run your own Rack app here or use this one to serve 404 messages:
  run lambda{ |env|
    not_found_page = File.exist?(not_found) ? [File.read(not_found)] : ['404 - page not found']
    [ 404, { 'Content-Type'  => 'text/html' }, not_found_page ]
  }
end

root = ENV['RACK_ROOT'] || '_site'

start_rack  root, "#{root}/404.html"

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
guard-jekyll-plus-2.0.2 lib/rack/config.ru
guard-jekyll-plus-2.0.1 lib/rack/config.ru
guard-jekyll-plus-2.0.0 lib/rack/config.ru
guard-jekyll-plus-1.4.10 lib/rack/config.ru
guard-jekyll-plus-1.4.9 lib/rack/config.ru
guard-jekyll-plus-1.4.8 lib/rack/config.ru
guard-jekyll-plus-1.4.7 lib/rack/config.ru
guard-jekyll-plus-1.4.6 lib/rack/config.ru
guard-jekyll-plus-1.4.5 lib/rack/config.ru
guard-jekyll-plus-1.4.4 lib/rack/config.ru
guard-jekyll-plus-1.4.3 lib/rack/config.ru
guard-jekyll-plus-1.4.2 lib/rack/config.ru