lib/spire/router.rb in spire-0.2.3 vs lib/spire/router.rb in spire-0.2.4

- old
+ new

@@ -1,9 +1,9 @@ module Spire class Router def initialize(base_path, routes) - @base_path = base_path + $base_path = base_path @routes = routes @app = {} end def disect(env) @@ -33,27 +33,34 @@ end end end unless @app["controller"] - return Error.new(nil ,404) + return Error.new :status => 404 end return self.run end def return_file - # still need to add checks for mime types. this will be done in a seperate class once i get round to it - return Response.new(File.open("/public/#{@request["action"]}", "r").read) + result = Public.new :file => "test.html", :render => true + file = result.extension_check + return Response.new(file[:file], file[:content_type], 200) end def run - require "#{@base_path}/controllers/#{@app["controller"]}Controller" - @class = Kernel.const_get(@app["controller"]).new(@base_path) + require "#{$base_path}/controllers/#{@app["controller"]}Controller" + @class = Kernel.const_get(@app["controller"]).new() result = @class.method(@app["action"]).call + if result.is_a? Hash + if result[:file] + return Response.new(result[:file], result[:content_type], 200) + end + end + content_type = "text/html;" status = 200 if @class.instance_variable_get(:@status) status = @class.instance_variable_get(:@status) @@ -71,9 +78,11 @@ response = self.route puts response if response response.to_rack + else + Error.new :status => 444 end end end end