No commit activity in last 3 years
No release in over 3 years
Simple and effective asset compilation, supporting Coffeescript and SASS. A lean alternative to larger, slower asset management gems.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

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