Sha256: 09aa4ebe209aad65b01fdb23d0b8503f88a2b735d2804fffe79cbdaf1f7751fb

Contents?: true

Size: 1017 Bytes

Versions: 6

Compression:

Stored size: 1017 Bytes

Contents

module Frank
  class Statik
 
    def initialize(app, options={})
      @app = app
      frank_root = File.expand_path(File.dirname(__FILE__)) + '/templates'
      root = options[:root] || Dir.pwd
      @frank_server = Rack::File.new(frank_root)
      @static_server = Rack::File.new(root)
    end
 
    # handles serving from __frank__
    # looks for static access, if not found,
    # passes request to frank
    def call(env)
      path = env['PATH_INFO'].dup
 
      if path.include? '__frank__'
        env['PATH_INFO'].gsub!('/__frank__', '')
        result = @frank_server.call(env)
      else
        env['PATH_INFO'] << '/' unless path.match(/(\.\w+|\/)$/)
        env['PATH_INFO'] << 'index.html' if path[-1..-1] == '/'
        result = @static_server.call(env)
      end
      
      # return if static assets found
      # else reset the path and pass to frank
      if result[0] == 200
        result
      else
        env['PATH_INFO'] = path
        @app.call(env)
      end
      
    end
 
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
frank-0.2.6 lib/frank/statik.rb
frank-0.2.5 lib/frank/statik.rb
frank-0.2.4 lib/frank/statik.rb
frank-0.2.3 lib/frank/statik.rb
frank-0.2.2 lib/frank/statik.rb
frank-0.2.1 lib/frank/statik.rb