Class: Spar::Rewrite

Inherits:
Object
  • Object
show all
Defined in:
lib/spar/rewrite.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Rewrite

Returns a new instance of Rewrite.



8
9
10
# File 'lib/spar/rewrite.rb', line 8

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/spar/rewrite.rb', line 12

def call(env)

  if env['HTTP_ACCEPT'] =~ /text\/html/
    if env['PATH_INFO'] == '/'
      env['PATH_INFO'] = '/index.html'
    else
      unless env['PATH_INFO'] =~ /\.[a-zA-Z]+$/
        env['PATH_INFO'] << '.html'
      end
    end
  end

  @app.call(env)
end