jammit 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jammit'
3
- s.version = '0.3.1' # Keep version in sync with jammit.rb
4
- s.date = '2009-11-29'
3
+ s.version = '0.3.2' # Keep version in sync with jammit.rb
4
+ s.date = '2009-12-03'
5
5
 
6
6
  s.homepage = "http://documentcloud.github.com/jammit/"
7
7
  s.summary = "Industrial Strength Asset Packaging for Rails"
@@ -4,7 +4,7 @@ $LOAD_PATH.push File.expand_path(File.dirname(__FILE__))
4
4
  # to all of the configuration options.
5
5
  module Jammit
6
6
 
7
- VERSION = "0.3.1"
7
+ VERSION = "0.3.2"
8
8
 
9
9
  ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
10
10
 
@@ -32,10 +32,6 @@ module Jammit
32
32
  # configuration of an assets.yml file that doesn't exist.
33
33
  class ConfigurationNotFound < NameError; end
34
34
 
35
- # Jammit raises a JavaNotFound exception if Java is not installed, or it's
36
- # not a recent enough version to run the JavaScript compressor.
37
- class JavaNotFound < StandardError; end
38
-
39
35
  # Jammit raises an OutputNotWritable exception if the output directory for
40
36
  # cached packages is locked.
41
37
  class OutputNotWritable < StandardError; end
@@ -118,10 +114,18 @@ module Jammit
118
114
  # The YUI Compressor requires Java > 1.4, and Closure requires Java > 1.6.
119
115
  def self.check_java_version
120
116
  java = @compressor_options[:java] || 'java'
121
- version = (`#{java} -version 2>&1`).match(/\d+\.\d+/)[0] rescue false
122
- raise JavaNotFound, "the \"#{java}\" command could not be found" unless version
123
- raise JavaNotFound, "the closure compiler requires Java 6 (1.6) or greater" if @javascript_compressor == :closure && version < '1.6'
124
- raise JavaNotFound, "the YUI compressor requires Java 1.4 or greater" if @javascript_compressor == :yui && version < '1.4'
117
+ version = (`#{java} -version 2>&1`)[/\d+\.\d+/]
118
+ disable_compression if !version ||
119
+ (@javascript_compressor == :closure && version < '1.6') ||
120
+ (@javascript_compressor == :yui && version < '1.4')
121
+ end
122
+
123
+ # If we don't have a working Java VM, then disable asset compression and
124
+ # complain loudly.
125
+ def self.disable_compression
126
+ @compressor_options[:disabled] = true
127
+ complaint = "Warning: Jammit asset compression disabled -- Java unavailable."
128
+ defined?(Rails) ? Rails.logger.warn(complaint) : STDERR.puts(complaint)
125
129
  end
126
130
 
127
131
  end
@@ -31,6 +31,11 @@ module Jammit
31
31
  JST_START = "(function(){window.JST = window.JST || {};"
32
32
  JST_END = "})();"
33
33
 
34
+ COMPRESSORS = {
35
+ :yui => YUI::JavaScriptCompressor,
36
+ :closure => Closure::Compiler
37
+ }
38
+
34
39
  DEFAULT_OPTIONS = {
35
40
  :yui => {:munge => true},
36
41
  :closure => {}
@@ -41,28 +46,28 @@ module Jammit
41
46
  # "closure-compiler" gem.
42
47
  def initialize
43
48
  @css_compressor = YUI::CssCompressor.new
44
- flavor = Jammit.javascript_compressor
45
- js_options = DEFAULT_OPTIONS[flavor].merge(Jammit.compressor_options)
46
- @js_compressor = flavor == :closure ?
47
- Closure::Compiler.new(js_options) :
48
- YUI::JavaScriptCompressor.new(js_options)
49
+ flavor = Jammit.javascript_compressor
50
+ @options = DEFAULT_OPTIONS[flavor].merge(Jammit.compressor_options)
51
+ @js_compressor = COMPRESSORS[flavor].new(@options)
49
52
  end
50
53
 
51
54
  # Concatenate together a list of JavaScript paths, and pass them through the
52
55
  # YUI Compressor (with munging enabled).
53
56
  def compress_js(paths)
54
- @js_compressor.compress(concatenate(paths))
57
+ js = concatenate(paths)
58
+ @options[:disabled] ? js : @js_compressor.compress(js)
55
59
  end
56
60
 
57
61
  # Concatenate and compress a list of CSS stylesheets. When compressing a
58
62
  # :datauri or :mhtml variant, post-processes the result to embed
59
63
  # referenced images.
60
64
  def compress_css(paths, variant=nil, asset_url=nil)
61
- compressed_css = @css_compressor.compress(concatenate_and_tag_images(paths, variant))
65
+ css = concatenate_and_tag_images(paths, variant)
66
+ css = @css_compressor.compress(css) unless @options[:disabled]
62
67
  case variant
63
- when nil then return compressed_css
64
- when :datauri then return with_data_uris(compressed_css)
65
- when :mhtml then return with_mhtml(compressed_css, asset_url)
68
+ when nil then return css
69
+ when :datauri then return with_data_uris(css)
70
+ when :mhtml then return with_mhtml(css, asset_url)
66
71
  else raise PackageNotFound, "\"#{variant}\" is not a valid stylesheet variant"
67
72
  end
68
73
  end
@@ -15,9 +15,10 @@ module Jammit
15
15
  # versions of the stylesheet package, otherwise the package is regular
16
16
  # compressed CSS, and in development the stylesheet URLs are passed verbatim.
17
17
  def include_stylesheets(*packages)
18
- return individual_stylesheets(packages) unless Jammit.package_assets
19
- return embedded_image_stylesheets(packages) if Jammit.embed_images
20
- return packaged_stylesheets(packages)
18
+ options = packages.extract_options!
19
+ return individual_stylesheets(packages, options) unless Jammit.package_assets
20
+ return packaged_stylesheets(packages, options) if options.delete(:embed_images) == false || !Jammit.embed_images
21
+ return embedded_image_stylesheets(packages, options)
21
22
  end
22
23
 
23
24
  # Writes out the URL to the bundled and compressed javascript package,
@@ -39,30 +40,29 @@ module Jammit
39
40
  private
40
41
 
41
42
  # HTML tags, in order, for all of the individual stylesheets.
42
- def individual_stylesheets(packages)
43
- tags_with_options(packages) {|p| Jammit.packager.individual_urls(p.to_sym, :css) }
43
+ def individual_stylesheets(packages, options)
44
+ tags_with_options(packages, options) {|p| Jammit.packager.individual_urls(p.to_sym, :css) }
44
45
  end
45
46
 
46
47
  # HTML tags for the stylesheet packages.
47
- def packaged_stylesheets(packages)
48
- tags_with_options(packages) {|p| Jammit.asset_url(p, :css) }
48
+ def packaged_stylesheets(packages, options)
49
+ tags_with_options(packages, options) {|p| Jammit.asset_url(p, :css) }
49
50
  end
50
51
 
51
52
  # HTML tags for the 'datauri', and 'mhtml' versions of the packaged
52
53
  # stylesheets, using conditional comments to load the correct variant.
53
- def embedded_image_stylesheets(packages)
54
- datauri_tags = tags_with_options(packages) {|p| Jammit.asset_url(p, :css, :datauri) }
54
+ def embedded_image_stylesheets(packages, options)
55
+ datauri_tags = tags_with_options(packages, options) {|p| Jammit.asset_url(p, :css, :datauri) }
55
56
  ie_tags = Jammit.mhtml_enabled ?
56
- tags_with_options(packages) {|p| Jammit.asset_url(p, :css, :mhtml) } :
57
- packaged_stylesheets(packages)
57
+ tags_with_options(packages, options) {|p| Jammit.asset_url(p, :css, :mhtml) } :
58
+ packaged_stylesheets(packages, options)
58
59
  [DATA_URI_START, datauri_tags, DATA_URI_END, MHTML_START, ie_tags, MHTML_END].join("\n")
59
60
  end
60
61
 
61
62
  # Generate the stylesheet tags for a batch of packages, with options, by
62
63
  # yielding each package to a block.
63
- def tags_with_options(packages)
64
+ def tags_with_options(packages, options)
64
65
  packages = packages.dup
65
- options = packages.extract_options!
66
66
  packages.map! {|package| yield package }.flatten!
67
67
  packages.push(options) unless options.empty?
68
68
  stylesheet_link_tag(*packages)
@@ -99,7 +99,7 @@ module Jammit
99
99
  # Absolute globs are absolute -- relative globs are relative to ASSET_ROOT.
100
100
  def glob_files(glob)
101
101
  absolute = Pathname.new(glob).absolute?
102
- Dir[absolute ? glob : File.join(ASSET_ROOT, glob)]
102
+ Dir[absolute ? glob : File.join(ASSET_ROOT, glob)].sort
103
103
  end
104
104
 
105
105
  # Return a list of all of the packages that should be cached. If "force" is
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jammit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Ashkenas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-29 00:00:00 -05:00
12
+ date: 2009-12-03 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency