Coder Social home page Coder Social logo

kuadrosx / sinatra-asset-pipeline Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kalasjocke/sinatra-asset-pipeline

0.0 1.0 0.0 300 KB

An asset pipeline implementation for Sinatra based on Sprockets packaged up in a gem.

License: MIT License

Ruby 98.71% CoffeeScript 0.03% JavaScript 0.38% CSS 0.87%

sinatra-asset-pipeline's Introduction

Sinatra Asset Pipeline Build Status

An asset pipeline implementation for Sinatra based on Sprockets with support for CoffeeScript, SASS, SCSS, LESS, ERB as well as CSS (SASS, YUI) and JavaScript (uglifier, YUI, Closure) minification.

sinatra-asset-pipeline supports both compiling assets on the fly for development as well as precompiling assets for production.

Installation

Include sinatra-asset-pipeline in your project's Gemfile:

gem 'sinatra-asset-pipeline'

Make sure to add the sinatra-asset-pipeline Rake task in your applications Rakefile:

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

Sinatra::AssetPipeline::Task.define! App

Now, when everything is in place you can precompile assets located in assets/<asset-type> with:

$ RACK_ENV=production rake assets:precompile

And remove old compiled assets with:

$ RACK_ENV=production rake assets:clean

Example

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

Bundler.require

require 'sinatra/asset_pipeline'

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

  get '/' do
    haml :index
  end
end

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

Bundler.require

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)

  # Logical paths to your assets
  set :assets_prefix, %w(assets vendor/assets)

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

  # Serve assets using this protocol
  set :assets_protocol, :http

  # CSS minification
  set :assets_css_compressor, :sass

  # JavaScript minification
  set :assets_js_compressor, :uglifier

  # Register the AssetPipeline extention, make sure this goes after all customization
  register Sinatra::AssetPipeline

  get '/' do
    haml :index
  end
end

Now when everything is in place you can use all helpers provided by sprockets-helpers, an example:

body {
  background-image: image-url('cat.png');
}

Note that you don't need to require sprockets-helpers inside your code to leverage the functionallity given to you by the integration, sinatra-asset-pipeline handles that for you.

CSS and JavaScript minification

If you would like to use CSS and/or JavaScript minification make sure to require the needed gems in your Gemfile:

Minifier Gem
:sass sass
:closure closure-compiler
:uglifier uglifier
:yui yui-compressor

Compass integration

Given that we're using sprockets-sass under the hood we have out of the box support for compass. Just include the compass gem in your Gemfile and include the compass mixins in your app.css.scss file.

sinatra-asset-pipeline's People

Contributors

awea avatar bajamircea avatar benmanns avatar danielspaniel avatar georges avatar jamiees2 avatar kalasjocke avatar kuadrosx avatar kwbock avatar lepfhty avatar madwork avatar olemchls avatar pbevin avatar plukevdh avatar rubycut avatar sobering avatar

Watchers

 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.