Class: GuideEmUp::Browser

Inherits:
Goliath::API
  • Object
show all
Defined in:
lib/guide-em-up/browser.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Browser

Returns a new instance of Browser.



10
11
12
13
14
# File 'lib/guide-em-up/browser.rb', line 10

def initialize(dir)
  @root  = dir
  @data  = File.expand_path("../../../data", __FILE__)
  @theme = Theme.new(File.join @data, "themes")
end

Instance Method Details

#response(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/guide-em-up/browser.rb', line 16

def response(env)
  path_info = Rack::Utils.unescape(env["PATH_INFO"])
  filename  = File.join(@root, path_info)
  datafile  = File.join(@data, path_info)
  if File.file?(filename)
    serve_file(filename)
  elsif filename.include? ".."
    unauthorized_access
  elsif File.directory?(filename)
    serve_index(filename)
  elsif path_info =~ /\/g-e-u\/theme\/(\w+)$/
    @theme.current = $1
    redirect_to env["HTTP_REFERER"] || "http://#{env["HTTP_HOST"]}/"
  elsif path_info =~ /\/g-e-u\/(css|images|icons|js)\//
    serve_data(datafile.sub 'g-e-u', '')
  else
    page_not_found(path_info)
  end
end