An asset pipeline implementation for Sinatra based on Sprockets. sinatra-asset-pipeline supports both compiling assets on the fly for development as well as precompiling assets for production. The design goal for sinatra-asset-pipeline is to provide good defaults for integrating your Sinatra application with Sprockets.
Install Sinatra Asset Pipeline from RubyGems:
gem install sinatra-asset-pipeline
Or, include it in your project's
gem 'sinatra-asset-pipeline', '~> 2.2.0'
Add the provided Rake tasks to your applications
require 'sinatra/asset_pipeline/task' require './app' Sinatra::AssetPipeline::Task.define! App
This makes your application serve assets inside
assets folder under the public
/assets path. You can use the helpers provided by sprocket-helpers inside your assets to ease locating your assets.
During deployment of your application you can use
precompile rake task to precompile your assets to serve them as static files from your applications public folder.
RACK_ENV=production rake assets:precompile
To leverage the Sprockets preprocessor pipeline inside your app you can use the
assets_css_compressor settings respectively. See the Using Processors section of the Sprockets readme for details.
If your application runs Sinatra in classic style you can define your Rake tasks as follows:
In its most simple form, you just register the
Sinatra::AssetPipeline Sinatra extension within your application:
require 'sinatra/asset_pipeline' class App < Sinatra::Base register Sinatra::AssetPipeline get '/' do 'hi' end end
However, if your application doesn't follow the defaults you can customize it as follows: