lib/gumdrop/server.rb in gumdrop-0.8.0 vs lib/gumdrop/server.rb in gumdrop-1.0.0

- old
+ new

@@ -1,69 +1,78 @@ -# Rework this to be nicer.. Extend Sintra::Base? +# Maybe use Gserver? + require 'sinatra/base' -require 'logger' module Gumdrop STATIC_ASSETS= %w(.jpg .jpe .jpeg .gif .ico .png .swf) class Server < Sinatra::Base - site= Gumdrop.fetch_site + include Util::Loggable + site= Gumdrop.site + unless site.nil? - site.rescan() + site.scan true set :port, site.config.server_port if site.config.server_port if site.config.proxy_enabled - require 'gumdrop/support/proxy_handler' + require 'gumdrop/server/proxy_handler' get '/-proxy/*' do handle_proxy(params, env) end post '/-proxy/*' do handle_proxy(params, env) end put '/-proxy/*' do handle_proxy(params, env) end delete '/-proxy/*' do handle_proxy(params, env) end patch '/-proxy/*' do handle_proxy(params, env) end options '/-proxy/*' do handle_proxy(params, env) end - site.report 'Enabled proxy at /-proxy/*', :info + log.info 'Enabled proxy at /-proxy/*' end get '/*' do - site.report "- - - - - - - - - - - - - - - - - - - - - - - - - - - - -" + # log.info "- - - - - - - - - - - - - - - - - - - - - - - - - - - - -" file_path= get_content_path params[:splat].join('/'), site - site.report "[#{$$}] GET /#{params[:splat].join('/')} -> #{file_path}" + log.info "\n\n[#{$$}] GET /#{params[:splat].join('/')} -> #{file_path}" unless static_asset file_path since_last_build= Time.now.to_i - site.last_run.to_i # site.report "!>!>>>>> since_last_build: #{since_last_build}" if since_last_build > site.config.server_timeout - site.report "[#{$$}] Rebuilding from Source (#{since_last_build} > #{site.config.server_timeout})" - site.rescan() + log.info "[#{$$}] Rebuilding from Source (#{since_last_build} > #{site.config.server_timeout})" + site.scan true end end - if site.content_hash.has_key? file_path - content= site.content_hash[file_path] - if content.useLayout? - site.report "[#{$$}] *Dynamic: #{file_path} (#{content.ext})" - content_type :css if content.ext == '.css' # Meh? - content_type :js if content.ext == '.js' # Meh? - content_type :xml if content.ext == '.xml' # Meh? - output= content.render - site.content_filters.each {|f| output= f.call(output, content) } - output + if site.contents.has_key? file_path + renderer= Renderer.new + content= site.contents[file_path] + content_type :css if content.ext == '.css' # Meh? + content_type :js if content.ext == '.js' # Meh? + content_type :xml if content.ext == '.xml' # Meh? + unless content.binary? + log.info "[#{$$}] *Dynamic: #{file_path} (#{content.ext})" + begin + content= renderer.draw content + rescue => ex + log.error "ERROR!" + log.error ex + $stderr.puts "\n\n --------- \n Error! (#{content.uri}) #{ex}\n --------- \n\n" + raise ex + end + content else - site.report "[#{$$}] *Static: #{file_path}" - send_file File.join( site.src_path, file_path) + log.info "[#{$$}] *Static: #{file_path} (binary)" + send_file site.source_path / file_path end - elsif File.exists? File.join(site.config.output_dir, file_path) - site.report "[#{$$}] *Static (from OUTPUT): #{file_path}" - send_file File.join(site.config.output_dir, file_path) + elsif File.exists? site.output_path / file_path + log.info "[#{$$}] *Static (from OUTPUT): #{file_path}" + send_file site.output_path / file_path else - site.report "[#{$$}] *Missing: #{file_path}", :error + log.warn "[#{$$}] *Missing: #{file_path}" "#{file_path} Not Found" end end def get_content_path(file_path, site) @@ -73,10 +82,10 @@ "#{file_path}/index.html" ] if file_path == "" "index.html" else - keys.detect {|k| site.content_hash.has_key?(k) } or file_path + keys.detect {|k| site.contents.has_key?(k) } or file_path end end def handle_proxy(params, env) proxy_to= params[:splat][0] \ No newline at end of file