Skip to content

Instantly share code, notes, and snippets.

@brentkirby
Created August 13, 2011 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brentkirby/1143362 to your computer and use it in GitHub Desktop.
Save brentkirby/1143362 to your computer and use it in GitHub Desktop.
sprockets circular dependency demo
class AssetHandler < Sprockets::Environment
def initialize
Sprockets.register_engine '.scss', Tipsy::Sass::Template
super(Tipsy.root) do |env|
env.static_root = Tipsy.options.asset_path
end
Tipsy.sprockets = self
configure_paths!
configure_compass!
self
end
end
# Function that initializes the server. Tipsy::Static subclasses Rack::Static but allows it to continue down the
# app chain if theres a 404.
# I'm subclassing Sprockets::Environment with an internal class so I can do the setup at the same time.
def init!
Rack::Builder.new {
use Rack::CommonLogger
use Rack::ShowStatus
use Rack::ShowExceptions
use Tipsy::StaticFile, :root => Tipsy.options.public_path, :urls => %w[/]
run Rack::Cascade.new([
Rack::URLMap.new({ "/#{File.basename(Tipsy.options.asset_path)}" => Tipsy::AssetHandler.new }),
Tipsy::Server.new
])
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment