Skip to content

Commit 24508fe

Browse files
committed
Merged from documentcloud master.
2 parents 80ec16f + 3dedc9d commit 24508fe

15 files changed

Lines changed: 86 additions & 56 deletions

index.html

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@
8787
<a href="http://github.com/documentcloud/jammit/">Jammit</a> is an
8888
industrial strength asset packaging library for <b>Rails</b>, providing
8989
both the CSS and JavaScript concatenation and compression
90-
that you'd expect, as well as <b>YUI Compressor</b> and <b>Closure Compiler</b>
90+
that you'd expect, as well as <b>YUI Compressor</b>, <b>Closure Compiler</b>, and <b>UglifyJS</b>
9191
compatibility, ahead-of-time gzipping, built-in JavaScript template
9292
support, and optional <b>Data-URI / MHTML image and font embedding</b>.
9393
</p>
9494

9595
<p>
96-
<b>Current Version:</b> <a href="http://rubygems.org/gems/jammit/">0.6.0</a>
96+
<b>Current Version:</b> <a href="http://rubygems.org/gems/jammit/">0.6.3</a>
9797
</p>
9898

9999
<p>
@@ -109,11 +109,11 @@
109109

110110
<h2>Table of Contents</h2>
111111

112-
<p style="line-height: 30px;">
112+
<p style="line-height: 30px; width: 650px;">
113113
<a href="#installation">Installation</a> |
114114
<a href="#configuration">Configuration</a> |
115115
<a href="#usage">Usage</a> |
116-
<a href="#compressors">YUI &amp; Closure</a> |
116+
<a href="#compressors">YUI, Closure &amp; UglifyJS</a> |
117117
<a href="#precaching">Precaching Assets</a> <br />
118118
<a href="#expires">Expires Headers</a> |
119119
<a href="#embedding">Embedding Assets</a> |
@@ -161,8 +161,9 @@ <h2 id="installation">Installation</h2>
161161

162162
<p>
163163
<i>Note: If you don't already have the
164-
<a href="http://github.com/sstephenson/ruby-yui-compressor">ruby-yui-compressor</a> or
165-
<a href="http://github.com/documentcloud/closure-compiler">closure-compiler</a>
164+
<a href="http://github.com/sstephenson/ruby-yui-compressor">ruby-yui-compressor</a>,
165+
<a href="http://github.com/documentcloud/closure-compiler">closure-compiler</a> or
166+
<a href="https://github.com/lautis/uglifier">uglifier</a>
166167
gems installed, downloading make take a minute &mdash; the jar files together
167168
weigh in at 5 megabytes.</i>
168169
</p>
@@ -231,7 +232,7 @@ <h2 id="configuration">Configuration</h2>
231232
<td><tt>on&nbsp;|&nbsp;off</tt></td>
232233
<td class="definition">
233234
Defaults to <b>on</b>. When <b>off</b>, JavaScript and CSS packages
234-
will be left uncompressed (by YUI or Closure). Disabling compression is only recommended
235+
will be left uncompressed (by YUI, Closure, or UglifyJS). Disabling compression is only recommended
235236
if you're packaging assets in development.
236237
</td>
237238
</tr>
@@ -254,12 +255,12 @@ <h2 id="configuration">Configuration</h2>
254255
</tr>
255256
<tr>
256257
<td><b>javascript_compressor</b></td>
257-
<td><tt>yui&nbsp;|&nbsp;closure</tt></td>
258+
<td><tt>yui&nbsp;|&nbsp;closure&nbsp;|&nbsp;uglifier</tt></td>
258259
<td class="definition">
259-
Defaults to <b>yui</b>. As of <b>0.2.0</b>, the Jammit gem can use either the
260-
<a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a>
261-
or the
262-
<a href="http://code.google.com/closure/compiler/">Google Closure Compiler</a>
260+
Defaults to <b>yui</b>. The Jammit gem can use either the
261+
<a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a>, the
262+
<a href="http://code.google.com/closure/compiler/">Google Closure Compiler</a>, or
263+
<a href="https://github.com/mishoo/UglifyJS/">UglifyJS</a>
263264
to compress your JavaScript.
264265
</td>
265266
</tr>
@@ -321,8 +322,9 @@ <h2 id="configuration">Configuration</h2>
321322
<td class="definition">
322323
Pass an options hash directly to the underlying JavaScript compressor
323324
to configure it. See the
324-
<a href="http://github.com/sstephenson/ruby-yui-compressor">ruby-yui-compressor</a> or
325-
<a href="http://github.com/documentcloud/closure-compiler">closure-compiler</a>
325+
<a href="http://github.com/sstephenson/ruby-yui-compressor">ruby-yui-compressor</a>,
326+
<a href="http://github.com/documentcloud/closure-compiler">closure-compiler</a>, or
327+
<a href="https://github.com/lautis/uglifier">uglifier</a>
326328
gem documentation for the full list of available options.
327329
</td>
328330
</tr>
@@ -384,23 +386,25 @@ <h2 id="usage">Usage</h2>
384386
<pre>require 'jammit'
385387
Jammit.package!</pre>
386388

387-
<h2 id="compressors">YUI &amp; Closure</h2>
389+
<h2 id="compressors">YUI, Closure &amp; UglifyJS</h2>
388390

389391
<p>
390-
Jammit can be configured to use either the
391-
<a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a> or the
392-
<a href="http://code.google.com/closure/compiler/">Google Closure Compiler</a>
392+
Jammit can be configured to use the
393+
<a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a>, the
394+
<a href="http://code.google.com/closure/compiler/">Google Closure Compiler</a>, or
395+
<a href="https://github.com/mishoo/UglifyJS/">UglifyJS</a>
393396
to compress and optimize your JavaScript. (CSS is always run through the
394-
YUI Compressor.) Specify the <b>javascript_compressor</b> to choose either <b>yui</b>
395-
or <b>closure</b> backends. If left blank, Jammit defaults to <b>yui</b>.
397+
YUI Compressor.) Specify the <b>javascript_compressor</b> to choose either <b>yui</b>,
398+
<b>closure</b>, or <b>uglifier</b> backends. If left blank, Jammit defaults to <b>yui</b>.
396399
</p>
397400

398401
<p>
399402
You can configure the JavaScript compilation by adding <b>compressor_options</b>
400403
to your <b>assets.yml</b>. The <b>compressor_options</b>
401404
will be passed directly to the Gem backend of your chosen compressor. See the
402-
<a href="http://github.com/sstephenson/ruby-yui-compressor">ruby-yui-compressor</a> or
403-
<a href="http://github.com/documentcloud/closure-compiler">closure-compiler</a>
405+
<a href="http://github.com/sstephenson/ruby-yui-compressor">ruby-yui-compressor</a>,
406+
<a href="http://github.com/documentcloud/closure-compiler">closure-compiler</a>, or
407+
<a href="https://github.com/lautis/uglifier">uglifier</a>
404408
gem documentation for all the available options. For example, to configure
405409
the Closure Compiler to use its
406410
<a href="http://code.google.com/closure/compiler/docs/compilation_levels.html">advanced optimizations</a>,
@@ -463,8 +467,6 @@ <h2 id="precaching">Precaching Assets</h2>
463467
<a href="http://rubyhitsquad.com/Vlad_the_Deployer.html">Vlad</a>,
464468
or just good 'ol <a href="http://rake.rubyforge.org/">Rake</a>,
465469
it shouldn't be too hard to add a step that calls the <tt>jammit</tt> command.
466-
For an example Jammit setup under Capistrano and Apache, see
467-
<a href="http://afreshcup.com/home/2010/1/18/notes-on-using-jammit-with-rails.html">Mike Gunderloy's blog post</a>.
468470
</p>
469471

470472
<h2 id="expires">Expires Headers</h2>
@@ -697,6 +699,24 @@ <h2 id="jst">JavaScript Templates</h2>
697699

698700
<h2 id="changes">Change Log</h2>
699701

702+
<p>
703+
<b class="header">0.6.3</b> &mdash; <small><i>May 26, 2011</i></small><br />
704+
Quick bugfix release for Rails 3.1 compatibility, which changes the method
705+
signatures of <tt>javascript_include_tag</tt> and <tt>stylesheet_link_tag</tt>
706+
in a backwards-incompatible fashion.
707+
</p>
708+
709+
<p>
710+
<b class="header">0.6.1</b> &mdash; <small><i>May 25, 2011</i></small><br />
711+
Jammit now supports <b>UglifyJS</b> as a Java-free alternative to YUI and Closure,
712+
for JavaScript compression.
713+
You can now pass <tt>--packages core,embed,ui</tt> to the <tt>jammit</tt>
714+
command, in order to only build a subset of your asset packages.
715+
The built-in JS templating function has been upgraded to the equivalent of
716+
the latest <tt>_.template</tt>.
717+
Environment-specific settings are now supported in your <tt>assets.yml</tt> file.
718+
</p>
719+
700720
<p>
701721
<b class="header">0.6.0</b><br />
702722
You can now pass <tt>debug_assets=true</tt> as a query parameter to debug

jammit.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'jammit'
3-
s.version = '0.6.0' # Keep version in sync with jammit.rb
3+
s.version = '0.6.3' # Keep version in sync with jammit.rb
44
s.date = Time.now.strftime('%Y-%m-%d')
55

66
s.homepage = "http://documentcloud.github.com/jammit/"

lib/jammit.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# to all of the configuration options.
55
module Jammit
66

7-
VERSION = "0.6.0"
7+
VERSION = "0.6.3"
88

99
ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
1010

@@ -36,9 +36,10 @@ module Jammit
3636
# requested by a browser -- rendering a 404.
3737
class PackageNotFound < NameError; end
3838

39-
# Jammit raises a ConfigurationNotFound exception when you try to load the
40-
# configuration of an assets.yml file that doesn't exist.
41-
class ConfigurationNotFound < NameError; end
39+
# Jammit raises a MissingConfiguration exception when you try to load the
40+
# configuration of an assets.yml file that doesn't exist, or are missing
41+
# a piece of required configuration.
42+
class MissingConfiguration < NameError; end
4243

4344
# Jammit raises an OutputNotWritable exception if the output directory for
4445
# cached packages is locked.
@@ -67,11 +68,12 @@ class << self
6768
def self.load_configuration(config_path, soft=false)
6869
exists = config_path && File.exists?(config_path)
6970
return false if soft && !exists
70-
raise ConfigurationNotFound, "could not find the \"#{config_path}\" configuration file" unless exists
71+
raise MissingConfiguration, "could not find the \"#{config_path}\" configuration file" unless exists
7172
conf = YAML.load(ERB.new(File.read(config_path)).result)
7273

7374
# Optionally overwrite configuration based on the environment.
74-
conf.merge! conf.delete RAILS_ENV if conf.has_key? RAILS_ENV
75+
rails_env = defined?(Rails) ? Rails.env : ENV['RAILS_ENV']
76+
conf.merge! conf.delete rails_env if conf.has_key? rails_env
7577

7678
@config_path = config_path
7779
@configuration = symbolize_keys(conf)

lib/jammit/command_line.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def parse_options
6363
opts.on('-f', '--force', 'force a rebuild of all assets') do |force|
6464
@options[:force] = force
6565
end
66-
opts.on('-p', '--packages PACKAGE_NAMES', 'comma-separated list of packages (ex: "core,embed", default: all packages)') do |package_names|
66+
opts.on('-p', '--packages LIST', 'list of packages to build (ex: "core,ui", default: all)') do |package_names|
6767
@options[:package_names] = package_names.split(/,\s*/).map {|n| n.to_sym }
6868
end
6969
opts.on_tail('-v', '--version', 'display Jammit version') do

lib/jammit/helper.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module Helper
1616
# compressed CSS, and in development the stylesheet URLs are passed verbatim.
1717
def include_stylesheets(*packages)
1818
options = packages.extract_options!
19-
return individual_stylesheets(packages, options) unless should_package?
19+
return html_safe(individual_stylesheets(packages, options)) unless should_package?
2020
disabled = (options.delete(:embed_assets) == false) || (options.delete(:embed_images) == false)
2121
return html_safe(packaged_stylesheets(packages, options)) if disabled || !Jammit.embed_assets
2222
return html_safe(embedded_image_stylesheets(packages, options))
@@ -25,10 +25,11 @@ def include_stylesheets(*packages)
2525
# Writes out the URL to the bundled and compressed javascript package,
2626
# except in development, where it references the individual scripts.
2727
def include_javascripts(*packages)
28-
tags = packages.map do |pack|
28+
html_safe packages.map {|pack|
2929
should_package? ? Jammit.asset_url(pack, :js) : Jammit.packager.individual_urls(pack.to_sym, :js)
30-
end
31-
html_safe(javascript_include_tag(tags.flatten))
30+
}.flatten.map {|pack|
31+
javascript_include_tag pack
32+
}.join("\n")
3233
end
3334

3435
# Writes out the URL to the concatenated and compiled JST file -- we always
@@ -71,10 +72,11 @@ def embedded_image_stylesheets(packages, options)
7172
# Generate the stylesheet tags for a batch of packages, with options, by
7273
# yielding each package to a block.
7374
def tags_with_options(packages, options)
74-
packages = packages.dup
75-
packages.map! {|package| yield package }.flatten!
76-
packages.push(options) unless options.empty?
77-
stylesheet_link_tag(*packages)
75+
packages.dup.map {|package|
76+
yield package
77+
}.flatten.map {|package|
78+
stylesheet_link_tag package, options
79+
}.join("\n")
7880
end
7981

8082
end

lib/jammit/jst.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/jammit/packager.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ def precache_all(output_dir=nil, base_url=nil)
4343
cache(p, 'css', pack_stylesheets(p), output_dir)
4444
if Jammit.embed_assets
4545
cache(p, 'css', pack_stylesheets(p, :datauri), output_dir, :datauri)
46-
if Jammit.mhtml_enabled && base_url
47-
mtime = Time.now
46+
if Jammit.mhtml_enabled
47+
raise MissingConfiguration, "A --base-url option is required in order to generate MHTML." unless base_url
48+
mtime = latest_mtime package_for(p, :css)[:paths]
4849
asset_url = "#{base_url}#{Jammit.asset_url(p, :css, :mhtml, mtime)}"
4950
cache(p, 'css', pack_stylesheets(p, :mhtml, asset_url), output_dir, :mhtml, mtime)
5051
end
@@ -55,9 +56,10 @@ def precache_all(output_dir=nil, base_url=nil)
5556
# Caches a single prebuilt asset package and gzips it at the highest
5657
# compression level. Ensures that the modification time of both both
5758
# variants is identical, for web server caching modules, as well as MHTML.
58-
def cache(package, extension, contents, output_dir, suffix=nil, mtime=Time.now)
59+
def cache(package, extension, contents, output_dir, suffix=nil, mtime=nil)
5960
FileUtils.mkdir_p(output_dir) unless File.exists?(output_dir)
6061
raise OutputNotWritable, "Jammit doesn't have permission to write to \"#{output_dir}\"" unless File.writable?(output_dir)
62+
mtime ||= latest_mtime package_for(package, extension.to_sym)[:paths]
6163
files = []
6264
files << file_name = File.join(output_dir, Jammit.filename(package, extension, suffix))
6365
File.open(file_name, 'wb+') {|f| f.write(contents) }
@@ -105,6 +107,12 @@ def glob_files(glob)
105107
Jammit.warn("No assets match '#{glob}'") if paths.empty?
106108
paths
107109
end
110+
111+
# Get the latest mtime of a list of files (plus the config path).
112+
def latest_mtime(paths)
113+
paths += [Jammit.config_path]
114+
paths.map {|p| File.mtime(p) }.max || Time.now
115+
end
108116

109117
# Return a list of all of the packages that should be cached. If "force" is
110118
# true, this is all of them -- otherwise only the packages that are missing

test/fixtures/jammed/js_test_with_templates.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/jammed/jst_test-custom-namespace.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/jammed/jst_test.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)