Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9edb7fd
adding google closure compiler jar
Feb 8, 2010
923644e
use google closure compiler web service instead of compiler.jar
lannon Feb 10, 2010
2a1137f
Updating JS Min to work as a module and not a command line app, match…
Apr 30, 2010
b3df18e
Moving JSMin require for support with rake tasks.
May 6, 2010
08c1758
Rails 3 XSS fixes (using html_safe)
sentientmonkey Apr 18, 2010
d1b5959
Packaged files should take their modification times from the most rec…
Jun 6, 2010
94ae0f1
General cleanup.
Jun 6, 2010
ba9d717
Merge remote branch 'lannon/master'
Jun 11, 2010
6696bc6
add ?xxxxx timestamp suffixes to images referenced in css, when compr…
marcroberts Oct 28, 2010
92bd55d
Rails 3 XSS fixes (using html_safe)
bloomper Oct 21, 2010
1fab677
make readme readable on github
grosser Aug 18, 2010
cd1e12d
make test/asset_packager_test.rb run standalone
grosser Aug 18, 2010
d1fb124
remove jsmin from top-level namespace
grosser Aug 18, 2010
a83b511
add bundler to the mix, make test/asset_package_helper_development_te…
grosser Aug 18, 2010
4ec5f37
make test/asset_package_helper_production_test.rb run without rails e…
grosser Aug 18, 2010
fd28ef3
Merge branch 'master' of http://github.com/neutroncreations/asset_pac…
Nov 3, 2010
d164c53
Rails 3.0.3 support now
galetahub Dec 7, 2010
d13a455
Generate gemspec and update readme
galetahub Dec 7, 2010
55cc7c7
Use Google's Closure Compiler by default.
Dec 9, 2010
87423ab
Updated README.
Dec 9, 2010
2d05d8c
Replace call to obsolete `Object#to_a` with `Array(str)`.
jasoncodes Mar 9, 2011
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 0 additions & 122 deletions CHANGELOG

This file was deleted.

75 changes: 45 additions & 30 deletions README → README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,39 @@ JavaScript and CSS Asset Compression for Production Rails Apps

== Description

When it comes time to deploy your new web application, instead of
sending down a dozen JavaScript and CSS files full of formatting
and comments, this Rails plugin makes it simple to merge and
compress JavaScript and CSS down into one or more files, increasing
When it comes time to deploy your new web application, instead of
sending down a dozen JavaScript and CSS files full of formatting
and comments, this Rails plugin makes it simple to merge and
compress JavaScript and CSS down into one or more files, increasing
speed and saving bandwidth.

When in development, it allows you to use your original versions
When in development, it allows you to use your original versions
and retain formatting and comments for readability and debugging.

This code is released under the MIT license (like Ruby). You're free
to rip it up, enhance it, etc. And if you make any enhancements,
This code is released under the MIT license (like Ruby). You're free
to rip it up, enhance it, etc. And if you make any enhancements,
I'd like to know so I can add them back in. Thanks!

* Formerly known as MergeJS.

== Credit

This Rails Plugin was inspired by Cal Henderson's article
This Rails Plugin was inspired by Cal Henderson's article
"Serving JavaScript Fast" on Vitamin:
http://www.thinkvitamin.com/features/webapps/serving-javascript-fast

It also uses the Ruby JavaScript Minifier created by
It also uses the Ruby JavaScript Minifier created by
Douglas Crockford.
http://www.crockford.com/javascript/jsmin.html

...and Google's Closure Compiler, which is now the default as it often leads to better compression than Crockford's JS Minifier.
http://closure-compiler.appspot.com/

== Key Features

* Merges and compresses JavaScript and CSS when running in production.
* Merges and compresses JavaScript and CSS when running in production, using Google's Closure Compiler by default and falling back to Crockford's JS Minifier on failure (the Closure Compiler runs remotely on Google's servers).
* Uses uncompressed originals when running in development.
* Generates packages on demand in production
* Generates packages on demand in production.

== Components

Expand All @@ -44,7 +47,14 @@ http://www.crockford.com/javascript/jsmin.html

== Updates

November '08:
December 2010:
* Rails 3.0.3 support.

June 2010:
* Works fine with Rails 3 beta 3.
* Sets the built packages' modification times to the latest mtime of the source files, or order to be more compatible with Rails asset ID caching.

November 2008:
* Rails 2.2 compatibility fixes
* No more mucking with internal Rails functions, which means:
* Return to use of query-string timestamps. Greatly simplifies things.
Expand All @@ -56,30 +66,33 @@ November '08:
== How to Use:

1. Download and install the plugin:
./script/plugin install git://github.com/sbecker/asset_packager.git

rails plugin install git://github.com/brady8/asset_packager.git

2. Run the rake task "asset:packager:create_yml" to generate the /config/asset_packages.yml
file the first time. You will need to reorder files under 'base' so dependencies are loaded
file the first time. You will need to reorder files under 'base' so dependencies are loaded
in correct order. Feel free to rename or create new file packages.

rake asset:packager:create_yml

IMPORTANT: JavaScript files can break once compressed if each statement doesn't end with a semi-colon.
The minifier puts multiple statements on one line, so if the semi-colon is missing, the statement may no
The minifier puts multiple statements on one line, so if the semi-colon is missing, the statement may no
longer makes sense and cause a syntax error.

== Examples of config/asset_packages.yml

Example from a fresh rails app after running the rake task. (Stylesheets is blank because a
Example from a fresh rails app after running the rake task. (The 'stylesheets' listing is blank because a
default rails app has no stylesheets yet.):

---
javascripts:
- base:
---
javascripts:
- base:
- prototype
- effects
- dragdrop
- controls
- application
stylesheets:
stylesheets:
- base: []

Multiple packages:
Expand All @@ -104,33 +117,35 @@ stylesheets:
- bar

3. Run the rake task "asset:packager:build_all" to generate the compressed, merged versions
for each package. Whenever you rearrange the yaml file, you'll need to run this task again.
for each package. Whenever you rearrange the yaml file, you'll need to run this task again.

rake asset:packager:build_all

Merging and compressing is expensive, so this is something we want to do once, not every time
your app starts. Thats why its a rake task. You can run this task via Capistrano when deploying
to avoid an initially slow request the first time a page is generated.
to avoid an initially slow request the first time a page is generated.

Note: The package will be generated on the fly if it doesn't yet exist, so you don't *need*
Note: The package will be generated on the fly if it doesn't yet exist, so you don't *need*
to run the rake task when deploying, its just recommended for speeding up initial requests.

4. Use the helper functions whenever including these files in your application. See below for examples.

5. Potential warning: css compressor function currently removes CSS comments. This might blow
away some CSS hackery. To disable comment removal, comment out /lib/synthesis/asset_package.rb line 176.
away some CSS hackery. To disable comment removal, comment out /lib/synthesis/asset_package.rb line 206.

== JavaScript Examples

Example call (based on above /config/asset_packages.yml):
<%= javascript_include_merged :base %>

In development, this generates:
In development, this generates:
<script type="text/javascript" src="/javascripts/prototype.js?1228027240"></script>
<script type="text/javascript" src="/javascripts/effects.js?1228027240"></script>
<script type="text/javascript" src="/javascripts/controls.js?1228027240"></script>
<script type="text/javascript" src="/javascripts/dragdrop.js?1228027240"></script>
<script type="text/javascript" src="/javascripts/application.js?1228027240"></script>

In production, this generates:
In production, this generates:
<script type="text/javascript" src="/javascripts/base_packaged.js?123456789"></script>

== Stylesheet Examples
Expand All @@ -139,11 +154,11 @@ Example call:
<%= stylesheet_link_merged :base %>

In development, this generates:
<link href="/stylesheets/screen.css?1228027240" media="screen" rel="Stylesheet" type="text/css" />
<link href="/stylesheets/header.css?1228027240" media="screen" rel="Stylesheet" type="text/css" />
<link href="/stylesheets/screen.css?1228027240" media="screen" rel="stylesheet" type="text/css" />
<link href="/stylesheets/header.css?1228027240" media="screen" rel="stylesheet" type="text/css" />

In production this generates:
<link href="/stylesheets/base_packaged.css?1228027240" media="screen" rel="Stylesheet" type="text/css" />
<link href="/stylesheets/base_packaged.css?1228027240" media="screen" rel="stylesheet" type="text/css" />

== Different CSS Media

Expand Down Expand Up @@ -175,4 +190,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 changes: 21 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require File.join(File.dirname(__FILE__), 'lib', 'synthesis', 'version')

desc 'Default: run unit tests.'
task :default => :test
Expand All @@ -17,6 +18,25 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'AssetPackager'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('Readme.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end

begin
require 'jeweler'
Jeweler::Tasks.new do |gemspec|
gemspec.name = "asset_packager"
gemspec.version = Synthesis::Version.dup
gemspec.summary = "JavaScript and CSS Asset Compression for Production Rails Apps"
gemspec.description = "This Rails plugin makes it simple to merge and compress JavaScript and CSS down into one or more files, increasing speed and saving bandwidth"
gemspec.email = "brady@ldawn.com"
gemspec.homepage = "http://synthesis.sbecker.net/pages/asset_packager"
gemspec.authors = ["Scott Becker", "Brady Bouchard", "Igor Galeta"]
gemspec.files = FileList["[A-Z]*", "lib/**/*"]
gemspec.rubyforge_project = "asset_packager"
end

Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler not available. Install it with: gem install jeweler"
end
8 changes: 0 additions & 8 deletions about.yml

This file was deleted.

52 changes: 52 additions & 0 deletions asset_packager.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{asset_packager}
s.version = "0.3.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Scott Becker", "Brady Bouchard", "Igor Galeta"]
s.date = %q{2010-12-07}
s.description = %q{This Rails plugin makes it simple to merge and compress JavaScript and CSS down into one or more files, increasing speed and saving bandwidth}
s.email = %q{brady@ldawn.com}
s.extra_rdoc_files = [
"README.rdoc"
]
s.files = [
"README.rdoc",
"Rakefile",
"lib/synthesis.rb",
"lib/synthesis/asset_package.rb",
"lib/synthesis/asset_package_helper.rb",
"lib/synthesis/jsmin.rb",
"lib/synthesis/railtie.rb",
"lib/synthesis/version.rb",
"lib/tasks/asset_packager_tasks.rake"
]
s.homepage = %q{http://synthesis.sbecker.net/pages/asset_packager}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{asset_packager}
s.rubygems_version = %q{1.3.7}
s.summary = %q{JavaScript and CSS Asset Compression for Production Rails Apps}
s.test_files = [
"test/asset_package_helper_development_test.rb",
"test/asset_packager_test.rb",
"test/asset_package_helper_production_test.rb",
"test/test_helper.rb"
]

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
else
end
else
end
end

4 changes: 1 addition & 3 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
require 'synthesis/asset_package'
require 'synthesis/asset_package_helper'
ActionView::Base.send :include, Synthesis::AssetPackageHelper
require File.join(File.dirname(__FILE__), 'lib', 'synthesis')
Loading