lib/gumdrop/server.rb in gumdrop-0.2.3 vs lib/gumdrop/server.rb in gumdrop-0.2.4

- old
+ new

@@ -1,72 +1,51 @@ +# Rework this to be nicer.. Extend Sintra::Base + +require 'sinatra/base' + module Gumdrop - - module Server - - class << self - - def start(opts={}) - # Opts - opts.reverse_merge! :auto_run => true, :cache_data => false - Gumdrop.config.merge! opts - require 'sinatra' + class Server < Sinatra::Base - set :port, Gumdrop.config.port if Gumdrop.config.port + set :port, Gumdrop.config.port if Gumdrop.config.port + + get '/' do + redirect '/index.html' + end + + get '/*' do + file_path= params[:splat].join('/') + matches= Dir["source/#{file_path}*"] + if matches.length > 0 - get '/' do - redirect '/index.html' - end - - get '/*' do - file_path= params[:splat].join('/') - matches= Dir["source/#{file_path}*"] - if matches.length > 0 - - Gumdrop.site= Gumdrop.layouts= Gumdrop.generators= Hash.new do |hash, key| - templates= Dir["source/**/#{key}*"] - if templates.length > 0 - Content.new( templates[0] ) - else - puts "NOT FOUND: #{key}" - nil - end - end - - Gumdrop.partials= Hash.new do |hash, key| - templates= Dir["source/**/_#{key}*"] - if templates.length > 0 - Content.new( templates[0] ) - else - puts "NOT FOUND: #{key}" - nil - end - end - - content= Content.new matches[0] - if content.useLayout? - content_type :css if content.ext == '.css' # Meh? - content_type :js if content.ext == '.js' # Meh? - content_type :xml if content.ext == '.xml' # Meh? - content.render - else - send_file matches[0] - end - else - puts "NOT FOUND: #{file_path}" - "#{file_path} Not Found" - end - end - - if Gumdrop.config.auto_run - Sinatra::Application.run! + Gumdrop.site= Gumdrop.layouts= Gumdrop.generators= Utils.content_hash("source/**/") + Gumdrop.partials= Utils.content_hash("source/**/_") + + content= Content.new matches[0] + if content.useLayout? + content_type :css if content.ext == '.css' # Meh? + content_type :js if content.ext == '.js' # Meh? + content_type :xml if content.ext == '.xml' # Meh? + content.render else - Sinatra::Application + send_file matches[0] end + else + puts "NOT FOUND: #{file_path}" + "#{file_path} Not Found" end - end - + if Gumdrop.config.auto_run + run! + end + + def self.start(opts={}) + # Options + opts.reverse_merge! :auto_run => true, :cache_data => false + Gumdrop.config.merge! opts + ::Gumdrop::Server + end + end - + end \ No newline at end of file