Class: Workbench::DynamicHandler
- Inherits:
-
Object
- Object
- Workbench::DynamicHandler
- Defined in:
- lib/work_bench/dynamic_handler.rb
Overview
Класс для обработки запросов к нестатическим файлам
Instance Method Summary collapse
-
#call(env) ⇒ Object
Вызывается на каждый нестатический запрос.
-
#initialize(path) ⇒ DynamicHandler
constructor
A new instance of DynamicHandler.
Constructor Details
#initialize(path) ⇒ DynamicHandler
Returns a new instance of DynamicHandler.
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 |