Skip to content

Instantly share code, notes, and snippets.

@tbuehlmann
Forked from banister/app.rb
Last active December 16, 2015 09:39
Show Gist options
  • Save tbuehlmann/5414360 to your computer and use it in GitHub Desktop.
Save tbuehlmann/5414360 to your computer and use it in GitHub Desktop.
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