lib/bolt/serve.rb in benofsky-bolt-0.4.5 vs lib/bolt/serve.rb in benofsky-bolt-0.4.7

- old
+ new

@@ -43,10 +43,12 @@ def initialize(current_page) @current_page = current_page end end + class NotFound404 < Exception; end; + class Serve < Build attr_accessor :pages def initialize super @@ -80,21 +82,26 @@ page_name = request['GET'].gsub(/\.html/,'')[1..-1] page_name = "index" if page_name == "" page = @pages[page_name] - if(!page.nil?) + # Handle subdirectories + page = @pages[page_name + "index"] if page.nil? + page = @pages[page_name + "/index"] if page.nil? + + if(!page.nil?) # A tad hacky, otherwise @current_page isn't set properly and all hell breaks loose body = PageBinding.new(page_name).instance_eval(&page) @server.reply(body) elsif(File.exists?(d($config.resources) + request['GET'])) f = File.new(d($config.resources) + request['GET']) @server.reply(f.to_s, 200, 'Content-Type' => f.content_type) else - # want to raise an exception here - @server.reply(File.new(@errors_base + '404.html').to_s, 404) + raise NotFound404 end end + rescue NotFound404 + @server.reply(File.new(@errors_base + '404.html').to_s, 404) rescue Exception => e puts "Error: #{e}" puts e.backtrace @server.reply(File.new(@errors_base + '500.html').to_s, 500) retry \ No newline at end of file