ClassyAssets
Classy Assets (powered by Sprockets) for Sinatra and Rack apps
Installation
Add this line to your application's Gemfile:
gem 'classy_assets', require: 'false'
And then execute:
$ bundle
Usage
ClassyAssets is available as Rack Middleware or a Sintra Extension. The Sinatra Extension version integrates the sprockets-helpers to provide helper methods for generating asset paths.
Use the Rack Middleware directly:
require 'rack/classy_assets'
class ClassyApp < Sinatra::Base
use Rack::ClassyAssets, root: 'path/to/your/app/root/directory'
end
Use the Sinatra Extension:
require 'sinatra/classy_assets'
class ClassyApp < Sinatra::Base
register Sinatra::ClassyAssets
end
Both the middleware and extension assume your assets are stored in the root
directory, in the following layout:
/assets
|_ images
|_ stylesheets
|_ javascripts
Sass and CoffeeScript are fully supported.
Available Options:
Pass these in via the options hash if you're using the rack middleware.
If you're using the sinatra extension, then configure your app's settings
after the register Sintra::ClassyAssets
statement to override the defaults
:root # => path to root of the application. set by default in Sinatra apps, but must be explictly passed to the rack middleware, if used directly
:public_folder # => path to public folder for the application. (default: File.join(root, 'public') )
:assets_prefix # => currently does nothing useful (default: 'assets')
:asset_host # => used by Sprockets::Helpers to return asset path prefixed by asset_host uri (default: nil)
:digest_assets # => enable digest version of assets? true or false (default: false)
:css_compressor # => instance of a sprokets compatible css compressor class (default: ::YUI::CssCompressor.new)
:js_compressor # => instance of a sprokets compatible js compressor class (default: ::Uglifier.new)
:sprockets # => instance of Sprockets::Environment. Should almost never need to be set manually. (default: Sprockets::Environment.new(root) )
Project Status
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request