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 method_options [ :port, '-p' ] => 9393
def start def start
if Attentive.has_presentation? if Attentive.has_presentation?
require 'rack' Attentive::Server.start!
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
else else
raise Attentive::NoPresentationError raise Attentive::NoPresentationError
end end

View File

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

View File

@ -14,6 +14,20 @@ require 'forwardable'
module Attentive module Attentive
class Server < Rack::Builder 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) def self.call(env)
@app ||= Rack::Builder.new do @app ||= Rack::Builder.new do
map '/assets' do map '/assets' do
@ -28,6 +42,10 @@ module Attentive
end end
map '/' do map '/' do
Attentive.middleware.each do |opts|
use(*opts)
end
run Attentive::Sinatra run Attentive::Sinatra
end end
end end

View File

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