Created
January 17, 2013 13:35
-
-
Save bnadlerjr/4555945 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "sprockets" | |
| require "sinatra/base" | |
| class SprocketsMiddleware | |
| attr_reader :app, :prefix, :sprockets | |
| def initialize(app, prefix) | |
| @app = app | |
| @prefix = prefix | |
| @sprockets = Sprockets::Environment.new | |
| yield sprockets if block_given? | |
| end | |
| def call(env) | |
| path_info = env["PATH_INFO"] | |
| if path_info =~ prefix | |
| env["PATH_INFO"].sub!(prefix, "") | |
| sprockets.call(env) | |
| else | |
| app.call(env) | |
| end | |
| ensure | |
| env["PATH_INFO"] = path_info | |
| end | |
| end | |
| class App < Sinatra::Base | |
| use SprocketsMiddleware, %r{/assets} do |env| | |
| env.append_path "assets/css" | |
| env.append_path "assets/js" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment