Navigation Menu

Skip to content

Commit

Permalink
Use minor version dependencies now, and making the README pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
petebrowne committed Aug 30, 2011
1 parent a3b82c9 commit 4a2ca6d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 63 deletions.
127 changes: 78 additions & 49 deletions README.md 100755 → 100644
@@ -1,89 +1,118 @@
# Rack::Pack
Rack::Pack
==========

Rack::Pack is a piece of Rack Middleware that packages and optionally compresses assets such as javascripts and stylesheets into single files. In a development environment, assets will be packaged on each request if there have been changes to the source files. In a production environment, assets will only be packaged one time, and only if there have been changes.

### Why?

I've tried a dozen different asset packaging solutions including AssetPackager, BundleFu, Jammit, Sprockets, etc...none of which were quite what I wanted. I didn't need any helpers, controllers, embedded images, rake tasks, or Yaml config files. I just wanted something to take my assets and package them into one file, and you're looking at it.

## Installation
Installation
------------

gem install rack-pack
``` bash
$ gem install rack-pack
```

## Basic Usage

require 'rack-pack'
use Rack::Pack
Basic Usage
-----------

or in Rails:
``` ruby
require 'rack-pack'
use Rack::Pack
```

# Gemfile
gem 'rack-pack'
or in Rails:

# config/application.rb
config.middleware.use Rack::Pack
``` ruby
# Gemfile
gem 'rack-pack'

# config/application.rb
config.middleware.use Rack::Pack
```

### Packages
Packages
--------

Two files will be packaged out of the box: `javascripts/application.js` & `stylesheets/application.css`. Rack::Pack will look in `vendor/javascripts`, `app/javascripts`, & `./javascripts` for any .js files and `vendor/stylesheets`, `app/stylesheets`, & `./stylesheets` for any .css files. These files will be packaged in the order they're found.

To create your own packages, pass in the name of the output file and the source files as options:

use Rack::Pack, 'js/main.js' => [
'vendor/javascripts/jquery.js',
'vendor/javascripts/swfobject.js,
'app/javascripts/misc.js',
'app/javascripts/main.js'
]
# Creates a 'public/js/main.js' file

``` ruby
use Rack::Pack, 'js/main.js' => [
'vendor/javascripts/jquery.js',
'vendor/javascripts/swfobject.js,
'app/javascripts/misc.js',
'app/javascripts/main.js'
]
# Creates a 'public/js/main.js' file
```
Notice how the output file is relative to the public dir. By default this is just `'public'`, but this can be changed using the `:public_dir` option:

use Rack::Pack, :public_dir => 'html', 'js/main.js' => %w(js/plugins.js js/main.js)
# Creates a 'html/js/main.js' file
``` ruby
use Rack::Pack, :public_dir => 'html', 'js/main.js' => %w(js/plugins.js js/main.js)
# Creates a 'html/js/main.js' file
```
You can also pass a glob string for the source files. This string will be used to search for new files on each request. The downside is the source files will be concatenated in the order they're found.

use Rack::Pack, 'assets/scripts.js' => 'app/js/**/*.js'

``` ruby
use Rack::Pack, 'assets/scripts.js' => 'app/js/**/*.js'
```

In fact, this is how the default packages are declared:

use Rack::Pack,
'javascripts/application.js' => '{vendor,app,.}/javascripts/*.js',
'stylesheets/application.css' => '{vendor,app,.}/stylesheets/*.css'

``` ruby
use Rack::Pack,
'javascripts/application.js' => '{vendor,app,.}/javascripts/*.js',
'stylesheets/application.css' => '{vendor,app,.}/stylesheets/*.css'
```

Beautiful, isn't it? I don't think you can get simpler than that. No Yaml config files or rake tasks. You'll set it up once then forget about it completely. Well unless you have to add a new source file and you were explicity setting your source files for a package, but whatever.
### Compression
Compression
-----------
What good would an asset packager be without compression? Rack::Pack determines which javascript compressor you want to use based on which one has been required.

require 'packr'
use Rack::Pack
# would use Packr
``` ruby
require 'packr'
use Rack::Pack
# would use Packr
```
or in Rails:

# Gemfile
gem 'jsmin'
# config/application.rb
config.middleware.use Rack::Pack
# would use JSMin
``` ruby
# Gemfile
gem 'jsmin'
To pass options to the javascript compressor just use the `:js_compressor` option:
# config/application.rb
config.middleware.use Rack::Pack
# would use JSMin
```
require 'packr'
use Rack::Pack, :js_compression => { :shrink_vars => true }
To pass options to the javascript compressor just use the `:js_compressor` option:
``` ruby
require 'packr'
use Rack::Pack, :js_compression => { :shrink_vars => true }
```
By default, packages are only compressed in a production environment. If for some reason you want them to always be compressed, pass the `:always_compress` option:
``` ruby
use Rack::Pack, :always_compress => true
```
use Rack::Pack, :always_compress => true

## Heroku and other read-only filesystems
Heroku and other read-only filesystems
--------------------------------------
Because Rack::Pack relies on writing the packaged files, it won't package anything on Heroku. But, you could just check in your packaged files and push them to Heroku. I'll look into other options for future versions.
## Copyright
Copyright
---------
Copyright (c) 2010 [Peter Browne](http://petebrowne.com). See LICENSE for details.
Copyright (c) 2011 [Peter Browne](http://petebrowne.com). See LICENSE for details.
2 changes: 1 addition & 1 deletion lib/rack/pack/version.rb
@@ -1,5 +1,5 @@
module Rack
class Pack
VERSION = '0.3.1'
VERSION = '0.3.2'
end
end
26 changes: 13 additions & 13 deletions rack-pack.gemspec
Expand Up @@ -6,26 +6,26 @@ Gem::Specification.new do |s|
s.name = 'rack-pack'
s.version = Rack::Pack::VERSION
s.platform = Gem::Platform::RUBY
s.authors = 'Pete Browne'
s.email = 'me@petebrowne.com'
s.authors = ['Pete Browne']
s.email = ['me@petebrowne.com']
s.homepage = 'http://github.com/petebrowne/rack-pack'
s.summary = 'Rack Middleware for packaging assets such as javascripts and stylesheets.'
s.description = 'Rack::Pack is a piece of Rack Middleware that packages and optionally compresses assets such as javascripts and stylesheets into single files. In a development environment, assets will be packaged on each request if there have been changes to the source files. In a production environment, assets will only be packaged one time, and only if there have been changes.'

s.required_rubygems_version = '>= 1.3.6'
s.rubyforge_project = 'rack-pack'

s.add_dependency 'rack', '~> 1.2.1'
s.add_development_dependency 'rspec', '~> 2.6.0'
s.add_development_dependency 'activesupport', '~> 3.0.7'
s.add_development_dependency 'i18n', '~> 0.5.0'
s.add_development_dependency 'test-construct', '~> 1.2.0'
s.add_development_dependency 'jsmin', '~> 1.0.1'
s.add_development_dependency 'packr', '~> 3.1.0'
s.add_development_dependency 'yui-compressor', '~> 0.9.1'
s.add_development_dependency 'closure-compiler', '~> 0.3.2'
s.add_development_dependency 'uglifier', '~> 0.5.3'
s.add_development_dependency 'rainpress', '~> 1.0.0'
s.add_dependency 'rack', '~> 1.2'
s.add_development_dependency 'rspec', '~> 2.6'
s.add_development_dependency 'activesupport', '~> 3.0'
s.add_development_dependency 'i18n', '~> 0.5'
s.add_development_dependency 'test-construct', '~> 1.2'
s.add_development_dependency 'jsmin', '~> 1.0'
s.add_development_dependency 'packr', '~> 3.1'
s.add_development_dependency 'yui-compressor', '~> 0.9'
s.add_development_dependency 'closure-compiler', '~> 0.3'
s.add_development_dependency 'uglifier', '~> 0.5'
s.add_development_dependency 'rainpress', '~> 1.0'

s.files = `git ls-files`.split("\n")
s.executables = `git ls-files`.split("\n").map{ |f| f =~ /^bin\/(.*)/ ? $1 : nil }.compact
Expand Down

0 comments on commit 4a2ca6d

Please sign in to comment.