2012-08-10 15:35:06 +00:00
|
|
|
require 'sprockets-vendor_gems/extend_all'
|
|
|
|
require 'sinatra/base'
|
|
|
|
require 'sinatra/sprockets'
|
|
|
|
require 'sprockets/assistant/compiler'
|
|
|
|
|
|
|
|
module Sprockets
|
|
|
|
module Assistant
|
|
|
|
class AppBuilder
|
2012-08-10 20:09:51 +00:00
|
|
|
ASSISTANT_CONFIG_FILE = Pathname('assistant_config.rb')
|
|
|
|
|
2012-08-13 18:25:18 +00:00
|
|
|
attr_reader :paths
|
|
|
|
|
2012-08-10 15:35:06 +00:00
|
|
|
def initialize
|
2012-08-13 18:25:18 +00:00
|
|
|
@paths = []
|
|
|
|
|
2012-08-10 20:09:51 +00:00
|
|
|
instance_eval(ASSISTANT_CONFIG_FILE.read)
|
2012-08-10 15:35:06 +00:00
|
|
|
end
|
|
|
|
|
2012-08-13 18:25:18 +00:00
|
|
|
def append_path(path)
|
|
|
|
@paths << path
|
|
|
|
end
|
|
|
|
|
2012-08-10 15:35:06 +00:00
|
|
|
def app(&block)
|
|
|
|
if block
|
|
|
|
@app = block
|
|
|
|
else
|
|
|
|
_app = @app
|
|
|
|
|
|
|
|
Class.new(Sinatra::Base) do
|
|
|
|
set :root, Dir.pwd
|
|
|
|
|
|
|
|
register Sinatra::Sprockets
|
|
|
|
|
2012-08-15 18:45:22 +00:00
|
|
|
Sinatra::Sprockets.configure do |c|
|
|
|
|
c.compile = true
|
|
|
|
end
|
|
|
|
|
2012-08-10 15:35:06 +00:00
|
|
|
set :views, 'views'
|
|
|
|
|
|
|
|
class_eval(&_app)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def middleware(&block)
|
|
|
|
if block
|
|
|
|
@middleware = block
|
|
|
|
else
|
|
|
|
@middleware
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def compile(&block)
|
|
|
|
if block
|
|
|
|
@compile = block
|
|
|
|
else
|
2012-08-13 18:25:18 +00:00
|
|
|
Compiler.new(@compile).compile(@paths)
|
2012-08-10 15:35:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|