-
-
Save grantmichaels/1194180 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
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!