Class: Orange::Middleware::RootDir

Inherits:
Base show all
Defined in:
lib/orange-core/middleware/root_dir.rb

Overview

This middleware handles sites in subdirs

Instance Method Summary collapse

Methods inherited from Base

#call, #init, #initialize, #inspect, #orange, #pass, #recapture

Constructor Details

This class inherits a constructor from Orange::Middleware::Base

Instance Method Details

#packet_call(packet) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/orange-core/middleware/root_dir.rb', line 6

def packet_call(packet)
  request = packet.request
  path_info = packet['route.path'] || packet.env['PATH_INFO']
  unless(orange.options['root_dir'].blank? || packet['route.root_dir'])
    root = orange.options['root_dir']
    packet['route.root_dir'] = root
    my_regex = root.kind_of?(Regexp) ? root : /^#{orange.options['root_dir']}/
    path_info = path_info.sub(my_regex, "/")
    packet['route.path'] = path_info.blank? ? "/" : path_info
  end
  pass packet
end