Git Product home page Git Product logo

sinatra-asset-pipeline's Introduction

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:

gem install sinatra-asset-pipeline

Or, include it in your project's Gemfile:

gem 'sinatra-asset-pipeline', '~> 2.2.0'

Usage

Add the provided Rake tasks to your applications Rakefile:

require 'sinatra/asset_pipeline/task'
require './app'

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

RACK_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:

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

Customization

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

require 'sinatra/asset_pipeline'

class App < Sinatra::Base
  register Sinatra::AssetPipeline

  get '/' do
    'hi'
  end
end

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

require 'sinatra/asset_pipeline'

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

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

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

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

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

  # CSS minification
  set :assets_css_compressor, :sass

  # JavaScript minification
  set :assets_js_compressor, :uglifier

  # Register the AssetPipeline extension, make sure this goes after all customization
  register Sinatra::AssetPipeline
  
  # If you need more environments
  set :precompiled_environments, %i(staging uat production)

  get '/' do
    'hi'
  end
end

sinatra-asset-pipeline's People

Contributors

allenan avatar alotofnoodles avatar awea avatar bajamircea avatar benmanns avatar bogdanrada avatar buonomo avatar danielspaniel avatar georges avatar jamiees2 avatar kalasjocke avatar khelll avatar kwbock avatar lepfhty avatar madwork avatar michaelfairley avatar msalzburg avatar olemchls avatar pbevin avatar plukevdh avatar rubycut avatar sobering avatar tomgi avatar toroidal-code avatar westonganger avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.