middleware support
This commit is contained in:
parent
0b863b3ddb
commit
a3f155b594
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -1,4 +1,8 @@
|
||||
Attentive.configure do |c|
|
||||
c.title = "My presentation"
|
||||
|
||||
# add rack middleware here
|
||||
# require 'rack-livereload'
|
||||
# c.middleware << Rack::LiveReload
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user