Skip to content

Instantly share code, notes, and snippets.

@grantmichaels
Forked from ericallam/Gemfile
Created September 5, 2011 05:44
Show Gist options
  • Save grantmichaels/1194180 to your computer and use it in GitHub Desktop.
Save grantmichaels/1194180 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
@kristianmandrup
Copy link

Hey, this is really sweet. I've been starting to use Sencha Touch for my frontend with Rails 3 as the backend exposing a REST API. I'm looking to use the Asset pipeline for my frontend app. But now sure I understand the '/path/to/standalone-pipeline' in your example. In a Rails app, would this translate to the Rails app directory? could is simply be "." if I have the assets dir directly in my application root ? Please advice. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment