SprockAssets is a Rack middleware that makes compiling your assets easy and fast.
Here is how to use it.
gem 'sprock-assets', require: 'sprock_assets'
Add a use to your config.ru
use SprockAssets
You can use assets just like in Rails.
require 'sinatra/base'
require 'sprock_assets'
class MyApp < Sinatra::Base
use SprockAssets
end
Source Path | Compiled Path |
---|---|
app/assets/stylesheets/application.css | public/assets/stylesheets/application.css |
app/assets/javascripts/application.js | public/assets/javascripts/application.js |
ruby config.ru
curl http://localhost/assets/stylesheets/application.css
curl http://localhost/assets/javascripts/application.js
Your compiled assets will now be served at their corresponding URIs. When your application is run in production your assets will automatically be compiled and saved to disk.
Make sure you require the compressors if you use SprockAssets in production.
gem 'yui-compressor', require: 'yui/compressor'
gem 'uglifier', require: 'uglifier'
WTFPL © 2012 Nick Barth