Because Assetpack can sometimes be really slow in development.... and everyone loves snacks
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib/sinatra
test
.gitignore
.travis.yml
Gemfile
Gemfile.lock
LICENSE.txt
README.md
Rakefile
sinatra-asset-snack.gemspec

README.md

AssetSnack for Sinatra

Build Status Gem Version endorse

A lean asset compiler for Sinatra developed specifically for Coffeescript and SASS. It stitches all assets for a route into a single file, no uglification, no minification (configure your server to use Gzip), just lean, fast compilation.

Installation

Bundler users

If you use Bundler, add it to your Gemfile.

gem install sinatra-asset-snack

Setup

Require and register the gem then configure your routes.

require 'sinatra/asset_snack'

class App < Sinatra::Base
  register Sinatra::AssetSnack
  asset_map '/javascript/application.js', ['assets/js/**/*.js', 'assets/js/**/*.coffee']
  asset_map '/stylesheets/application.css', ['assets/stylesheets/**/*.css', 'assets/stylesheets/**/*.scss']
end

In your view / layout reference your assets using the relevant tag

<link rel="stylesheet" href="/stylesheets/application.css" type="text/css" />
<script src="/javascript/application.js" type="text/javascript"></script>

If you want - use the helpers to add cache busting

<link rel="stylesheet" href="<%= nocache '/stylesheets/application.css' %>" type="text/css" />
<script src="<%= nocache '/javascript/application.js' %>" type="text/javascript"></script>

Configuring

Configuration options may be passed into each compiler. For example

Sinatra::AssetSnack.configuration.compilers[:coffee_script] = {bare: true}
Sinatra::AssetSnack.configuration.compilers[:sass] = {syntax: :scss}

See each compiler's repo for the list of configuration options

sinatra

coffee-script

sass

Precompile

To precompile your assets, you must set a constant APP_FILE to the source file which defines your Sinatra app.

Rakefile

APP_FILE = "lib/app/app.rb"
require 'sinatra/asset_snack/rake'

This defines the rake task assetsnack:build which will precompile your assets.

Bitdeli Badge