Created
August 28, 2011 14:55
-
-
Save ericallam/1176760 to your computer and use it in GitHub Desktop.
Using the Asset Pipeline outside of Rails - Serving CoffeeScript and SASS
This file contains 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
h2 { | |
font-size: 10em; | |
a { | |
height: 64px; | |
width: 50px; | |
display: block; | |
} | |
} |
This file contains 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
$(document).ready -> | |
$('#foo').html("<p>bar</p>") |
This file contains 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
$(document).ready -> | |
$('img').attr('src', "<%= asset_path('lolwut.png') %>") |
This file contains 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
source "http://rubygems.org" | |
gem 'sprockets', :git => 'git://github.com/sstephenson/sprockets.git' | |
gem 'coffee-script' | |
gem 'sass' | |
gem 'rack-test' | |
gem 'sinatra' |
This file contains 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 '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