helium/sinatra-asset-pipeline

Name: sinatra-asset-pipeline

Owner: Helium

Description: An asset pipeline implementation for Sinatra based on Sprockets.

Forked from: kalasjocke/sinatra-asset-pipeline

Created: 2016-11-16 23:08:09.0

Updated: 2016-11-16 23:08:10.0

Pushed: 2016-11-16 23:21:07.0

Homepage:

Size: 208

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Sinatra Asset Pipeline Build Status

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.

Installation

Install Sinatra Asset Pipeline from RubyGems:

install sinatra-asset-pipeline

Or, include it in your project's Gemfile:

'sinatra-asset-pipeline', '~> 1.0'

Usage

Add the provided Rake tasks to your applications Rakefile:

ire 'sinatra/asset_pipeline/task'
ire './app'

tra::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.

_ENV=production rake assets:precompile

To leverage the Sprockets preprocessor pipeline inside your app you can use the assets_js_compressor and assets_css_compressor settings respectively. See the Using Processors section of the Sprockets readme for details.

Classic style

If your application runs Sinatra in classic style you can define your Rake tasks as follows:

tra::AssetPipeline::Task.define! Sinatra::Application

Customization

In its most simple form, you just register the Sinatra::AssetPipeline Sinatra extension within your application:

ire 'sinatra/asset_pipeline'

s App < Sinatra::Base
gister Sinatra::AssetPipeline

t '/' do
'hi'
d

However, if your application doesn't follow the defaults you can customize it as follows:

ire 'sinatra/asset_pipeline'

s App < Sinatra::Base
Include these files when precompiling assets
t :assets_precompile, %w(app.js app.css *.png *.jpg *.svg *.eot *.ttf *.woff *.woff2)

The path to your assets
t :assets_paths, %w(assets)

Use another host for serving assets
t :assets_host, '<id>.cloudfront.net'

Which prefix to serve the assets under
t :assets_prefix, 'custom-prefix'

Serve assets using this protocol (http, :https, :relative)
t :assets_protocol, :http

CSS minification
t :assets_css_compressor, :sass

JavaScript minification
t :assets_js_compressor, :uglifier

Register the AssetPipeline extension, make sure this goes after all customization
gister Sinatra::AssetPipeline

t '/' do
'hi'
d


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.