Class: Workbench::DynamicHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/work_bench/dynamic_handler.rb

Overview

Класс для обработки запросов к нестатическим файлам

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ DynamicHandler

Returns a new instance of DynamicHandler.

Parameters:

  • path (String)

    текущий каталог



8
9
10
# File 'lib/work_bench/dynamic_handler.rb', line 8

def initialize path
  @path = path
end

Instance Method Details

#call(env) ⇒ Object

Вызывается на каждый нестатический запрос



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/work_bench/dynamic_handler.rb', line 13

def call(env)
			req = Rack::Request.new(env)
  filename = File.join(@path, 'haml', resolve_file(req.path))
  file_ext = File.extname(filename)
			if File.exists?(filename) && '.haml' != file_ext
Rack::File.new(File.join(@path, 'haml')).call(env)
			else
if File.exists? filename
	[ 200, {'Content-Type' => 'text/html'}, [Workbench::HamlRenderer.render(filename)] ]
else
	[ 404, {'Content-Type' => 'text/html'}, ['File not found: '+req.path] ]
end
			end
end