Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use sprockets CSS and JavaScript compressors

  • Loading branch information...
commit 823d43e06e99ee509c8c23135a4a032f6ea31f54 1 parent 4dc5c80
@kalasjocke authored
View
34 README.md
@@ -62,8 +62,11 @@ However, if your application doesn't follow the defaults you can customize it as
# Serve assets using this protocol
set :assets_protocol, :http
- # Compress CSS using SASS
- set :assets_sass_style, :compress
+ # CSS minification
+ set :assets_css_compressor, :sass
+
+ # JavaScript minification
+ set :assets_js_minification, :uglifier
register Sinatra::AssetPipeline
@@ -78,6 +81,33 @@ Now when everything is in place you can use all helpers provided by [sprockets-h
background-image: image-url('cat.png');
}
+# CSS and JavaScript minification
+
+If you would like to use CSS and/or JavaScript minification make sure to require the gems needed in your `Gemfile`.
+
+<table>
+ <tr>
+ <th>Minifier</th>
+ <th>Gem</th>
+ </tr>
+ <tr>
+ <td>:sass</td>
+ <td>sass</td>
+ </tr>
+ <tr>
+ <td>:closure</td>
+ <td>closure-compiler</td>
+ </tr>
+ <tr>
+ <td>:uglifier</td>
+ <td>uglifier</td>
+ </tr>
+ <tr>
+ <td>:yui</td>
+ <td>yui-compressor</td>
+ </tr>
+</table>
+
# Compass integration
Given that we're using [sprockets-sass](https://github.com/petebrowne/sprockets-sass) 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.
View
7 lib/sinatra/asset_pipeline.rb
@@ -10,7 +10,8 @@ def self.registered(app)
app.set_default :assets_prefix, 'assets'
app.set_default :assets_path, -> { File.join(public_folder, assets_prefix) }
app.set_default :assets_protocol, :http
- app.set_default :assets_sass_style, :compressed
+ app.set_default :assets_css_compressor, :none
+ app.set_default :assets_js_compressor, :none
app.set :static, true
app.set :assets_digest, true
@@ -32,7 +33,9 @@ def self.registered(app)
end
app.configure :production do
- Sprockets::Sass.options[:style] = :compressed
+ app.sprockets.css_compressor = app.assets_css_compressor unless app.assets_css_compressor == :none
+ app.sprockets.js_compressor = app.assets_js_compressor unless app.assets_js_compressor == :none
+
Sprockets::Helpers.configure do |config|
config.protocol = app.assets_protocol
config.asset_host = app.assets_host if app.respond_to? :assets_host
View
2  lib/sinatra/asset_pipeline/version.rb
@@ -1,5 +1,5 @@
module Sinatra
module AssetPipeline
- VERSION = '0.1.3'
+ VERSION = '0.2.0'
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.