Class: Frozen::Rack::RequestController

Inherits:
Object
  • Object
show all
Defined in:
lib/frozen/rack/request_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ RequestController



5
6
7
# File 'lib/frozen/rack/request_controller.rb', line 5

def initialize(site)
  @site = site
end

Instance Attribute Details

#siteObject

Returns the value of attribute site.



4
5
6
# File 'lib/frozen/rack/request_controller.rb', line 4

def site
  @site
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/frozen/rack/request_controller.rb', line 8

def call(env)
  file_path = env["PATH_INFO"]
  engine = get_stylesheet(file_path) if get_stylesheet(file_path)
  engine = get_view(file_path) if get_view(file_path)
  engine = get_javascript(file_path) if get_javascript(file_path)
  return [200, {"Content-Type" => "text/html"}, [engine.render]]
end

#get_javascript(file_path) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/frozen/rack/request_controller.rb', line 27

def get_javascript(file_path)
  site.javascripts.find { |v|
    site.javascripts.find { |i|
      i.build_file_path == file_path.sub(/^\//,'')
    }
  }
end

#get_stylesheet(file_path) ⇒ Object



15
16
17
18
19
# File 'lib/frozen/rack/request_controller.rb', line 15

def get_stylesheet(file_path)
  site.stylesheets.find { |s|
    s.build_file_path == file_path.sub(/^\//,'')
  }
end

#get_view(file_path) ⇒ Object



20
21
22
23
24
25
# File 'lib/frozen/rack/request_controller.rb', line 20

def get_view(file_path)
  site.views.find { |v|
    v.build_file_path ==  file_path.sub(/^\//,'') ||
      v.build_file_path == File.join(file_path, "index.html").sub(/^\//,'')
  }
end