lib/siteleaf/server.rb in siteleaf-0.9.7 vs lib/siteleaf/server.rb in siteleaf-0.9.8

- old
+ new

@@ -35,26 +35,31 @@ return nil end def call(env) + require 'uri' + site = Siteleaf::Site.new({:id => self.site_id}) - url = env['PATH_INFO'] + url = URI.unescape(env['PATH_INFO']) path = url.gsub(/\/\z|\A\//, '') #strip beginning and trailing slashes if !['sitemap.xml','feed.xml'].include?(path) and !File.directory?(path) and File.exist?(path) Rack::File.new(Dir.pwd).call(env) else template_data = nil is_asset = /^(?!(sitemap|feed)\.xml)(assets|.*\.)/.match(path) if is_asset - if asset = site.resolve(url) and asset_url = asset['file']['url'] + output = site.resolve(url) + if output.code == 200 require 'open-uri' - output = open(asset_url) - [200, {'Content-Type' => output.content_type}, [output.read]] + asset = open(output['file']['url']) + [output.code, {'Content-Type' => asset.content_type}, [asset.read]] + else + [output.code, {'Content-Type' => 'text/html'}, [output.to_s]] end else if template_data = resolve_template(url) # compile liquid includes into a single page include_tags = /\{\%\s+include\s+['"]([A-Za-z0-9_\-\/]+)['"]\s+\%\}/ @@ -62,13 +67,13 @@ template_data = template_data.gsub(include_tags) { |i| File.read("_#{$1}.html") } end end output = site.preview(url, template_data) - if output.respond_to?('headers') - [200, {'Content-Type' => output.headers[:content_type]}, [output]] + if output.code == 200 + [output.code, {'Content-Type' => output.headers[:content_type]}, [output]] else - [200, {'Content-Type' => 'text/html'}, [output]] + [output.code, {'Content-Type' => 'text/html'}, [output]] end end end end end \ No newline at end of file