sprockets-assistant/lib/sprockets/assistant/app_builder.rb

64 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

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')
attr_reader :paths
def initialize
@paths = []
2012-08-10 20:09:51 +00:00
instance_eval(ASSISTANT_CONFIG_FILE.read)
end
def append_path(path)
@paths << path
end
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
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
Compiler.new(@compile).compile(@paths)
end
end
end
end
end