-
-
Save tbuehlmann/5414360 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
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 | |
configure :development do | |
require "sinatra/reloader" | |
register Sinatra::Reloader | |
end | |
get '/' do | |
@title = "My App!" | |
slim :index | |
end | |
use SprocketsMiddleware, %r{/assets} do |env| | |
env.append_path "assets/stylesheets" | |
env.append_path "assets/templates" | |
env.append_path "assets/javascripts" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment