middleware support

This commit is contained in:
John Bintz 2012-02-13 12:10:05 -05:00
parent 0b863b3ddb
commit a3f155b594
4 changed files with 28 additions and 11 deletions

View File

@ -26,17 +26,7 @@ class Attentive::CLI < Thor
method_options [ :port, '-p' ] => 9393
def start
if Attentive.has_presentation?
require 'rack'
require 'pygments'
require 'coffee_script'
require 'sass'
# make sure pygments is ready
Pygments.highlight("attentive")
Rack::Handler::WEBrick.run(Attentive::Server, :Port => options[:port]) do |server|
trap(:INT) { server.shutdown }
end
Attentive::Server.start!
else
raise Attentive::NoPresentationError
end

View File

@ -9,6 +9,10 @@ module Attentive
def has_presentation?
@has_presentation == true
end
def middleware
@middleware ||= []
end
end
def self.configure
@ -23,3 +27,4 @@ module Attentive
class NoPresentationError < StandardError ; end
end

View File

@ -14,6 +14,20 @@ require 'forwardable'
module Attentive
class Server < Rack::Builder
def start!
require 'rack'
require 'pygments'
require 'coffee_script'
require 'sass'
# make sure pygments is ready
Pygments.highlight("attentive")
Rack::Handler::WEBrick.run(Attentive::Server, :Port => options[:port]) do |server|
trap(:INT) { server.shutdown }
end
end
def self.call(env)
@app ||= Rack::Builder.new do
map '/assets' do
@ -28,6 +42,10 @@ module Attentive
end
map '/' do
Attentive.middleware.each do |opts|
use(*opts)
end
run Attentive::Sinatra
end
end

View File

@ -1,4 +1,8 @@
Attentive.configure do |c|
c.title = "My presentation"
# add rack middleware here
# require 'rack-livereload'
# c.middleware << Rack::LiveReload
end