ClassyAssets

Sprockets-powered asset pipeline for classy Sinatra and/or Rack apps.

Installation

Add this line to your application's Gemfile:

gem 'classy_assets', require: 'false'

And then execute:

$ bundle

Usage

ClassyAssets consists of a Rack Middleware, which integrates your app with Sprockets to serve your assets, and a Sintra Extension, which provides helper methods for generating asset paths.

Configure your environment:

require 'classy_assets'
ClassyAssets.config do |config|
  config.asset_root = File.expand_path('../../', __FILE__)
  # asset_root is required and must be set.
  # See below for complete list of options.
end

Install the Rack Middleware (usually in config.ru):

require 'rack/classy_assets'
use Rack::ClassyAssets

Install the Sinatra Extension:

require 'sinatra/classy_assets'
class ClassyApp < Sinatra::Base
  register Sinatra::ClassyAssets
end

Available Configuration Options:

  :asset_root             # => (String)  path to root of the application (required, must be set before configuring other options)
  :asset_cache            # => (Boolean) enable/disable Sprockets environment caching (default: true in production, false in all other environments)
  :asset_compress         # => (Boolean) enable/disable asset compression (default: nil)
  :asset_debug            # => (Boolean) enable/disable asset debugging (default: true in development, false in all other environments)
  :asset_digest           # => (Boolean) enable/disable asset digests (default: nil)
  :asset_host             # => (String)  CDN hostname to use when building asset urls (default: nil)
  :asset_manifest_path    # => (String)  path to output Sprockets manifest file (default:  asset_precompile_path + "manifest.json")
  :asset_paths            # => (Array)   array of paths to add to the Sprockets environment (default: all paths under File.join(asset_root, asset_prefix))
  :asset_precompile       # => (Array)   array of files to precompile. Globs and Regular Expressions are allowed. (default: [/\w+\.(?!js|css).+/, /application.(css|js)$/])
  :asset_precompile_keep  # => (Integer) number of precompiled asset versions to keep (default: 2)
  :asset_precompile_path  # => (String)  path to output precompiled assets to (default: File.join(asset_public_path, asset_prefix))
  :asset_prefix           # => (String)  name of the directory assets should be stored/served under (default: 'assets')
  :asset_public_path      # => (String)  path to your app's public folder (default: File.join(asset_root, 'public'))
  :asset_version          # => (String)  arbitrary asset version, used by Sprockets (default: the version of ClassyAssets in use)
  :css_compressor         # => (Symbol)  name of a css compressor registered with Sprockets (default: :yui)
  :js_compressor          # => (Symbol)  name of a javascript compressor registered with Sprockets (default: :uglifier)

Project Status

  • Build: Build Status
  • Code Quality: Code Climate
  • Dependencies: Dependency Status

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request