Skip to content

Instantly share code, notes, and snippets.

@ericallam
Created August 28, 2011 14:55
Show Gist options
  • Save ericallam/1176760 to your computer and use it in GitHub Desktop.
Save ericallam/1176760 to your computer and use it in GitHub Desktop.
Using the Asset Pipeline outside of Rails - Serving CoffeeScript and SASS
h2 {
font-size: 10em;
a {
height: 64px;
width: 50px;
display: block;
}
}
$(document).ready ->
$('#foo').html("<p>bar</p>")
$(document).ready ->
$('img').attr('src', "<%= asset_path('lolwut.png') %>")
source "http://rubygems.org"
gem 'sprockets', :git => 'git://github.com/sstephenson/sprockets.git'
gem 'coffee-script'
gem 'sass'
gem 'rack-test'
gem 'sinatra'
require 'bundler/setup'
Bundler.require
assets = Sprockets::Environment.new('/path/to/standalone-pipeline') do |env|
env.logger = Logger.new(STDOUT)
end
assets.append_path('/path/to/standalone-pipeline/assets')
module AssetHelpers
def asset_path(name)
"/assets/#{name}"
end
end
assets.context_class.instance_eval do
include AssetHelpers
end
get '/assets/*' do
new_env = env.clone
new_env["PATH_INFO"].gsub!("/assets", "")
assets.call(new_env)
end
session = Rack::Test::Session.new(Rack::MockSession.new(assets))
session.get('application.css')
puts session.last_response.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment