jammit 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/jammit.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jammit'
3
- s.version = '0.4.1' # Keep version in sync with jammit.rb
4
- s.date = '2009-1-5'
3
+ s.version = '0.4.2' # Keep version in sync with jammit.rb
4
+ s.date = '2009-1-27'
5
5
 
6
6
  s.homepage = "http://documentcloud.github.com/jammit/"
7
7
  s.summary = "Industrial Strength Asset Packaging for Rails"
data/lib/jammit.rb CHANGED
@@ -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.4.1"
7
+ VERSION = "0.4.2"
8
8
 
9
9
  ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
10
10
 
@@ -39,8 +39,9 @@ module Jammit
39
39
  class OutputNotWritable < StandardError; end
40
40
 
41
41
  class << self
42
- attr_reader :configuration, :template_function, :template_namespace, :embed_assets, :package_path,
43
- :package_assets, :compress_assets, :mhtml_enabled, :include_jst_script,
42
+ attr_reader :configuration, :template_function, :template_namespace,
43
+ :embed_assets, :package_assets, :compress_assets, :gzip_assets,
44
+ :package_path, :mhtml_enabled, :include_jst_script,
44
45
  :javascript_compressor, :compressor_options, :css_compressor_options
45
46
  end
46
47
 
@@ -58,6 +59,7 @@ module Jammit
58
59
  @package_path = conf[:package_path] || DEFAULT_PACKAGE_PATH
59
60
  @embed_assets = conf[:embed_assets] || conf[:embed_images]
60
61
  @compress_assets = !(conf[:compress_assets] == false)
62
+ @gzip_assets = !(conf[:gzip_assets] == false)
61
63
  @mhtml_enabled = @embed_assets && @embed_assets != "datauri"
62
64
  @compressor_options = (conf[:compressor_options] || {}).symbolize_keys
63
65
  @css_compressor_options = (conf[:css_compressor_options] || {}).symbolize_keys
@@ -136,8 +138,14 @@ module Jammit
136
138
  # complain loudly.
137
139
  def self.disable_compression
138
140
  @compress_assets = false
139
- complaint = "Warning: Jammit asset compression disabled -- Java unavailable."
140
- defined?(Rails) ? Rails.logger.warn(complaint) : STDERR.puts(complaint)
141
+ warn("Asset compression disabled -- Java unavailable.")
142
+ end
143
+
144
+ def self.warn(message)
145
+ message = "Jammit Warning: #{message}"
146
+ @logger ||= (defined?(Rails) && Rails.logger ? Rails.logger :
147
+ defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : nil)
148
+ @logger ? @logger.warn(message) : STDERR.puts(message)
141
149
  end
142
150
 
143
151
  end
@@ -59,11 +59,14 @@ module Jammit
59
59
  def cache(package, extension, contents, output_dir, suffix=nil, mtime=Time.now)
60
60
  FileUtils.mkdir_p(output_dir) unless File.exists?(output_dir)
61
61
  raise OutputNotWritable, "Jammit doesn't have permission to write to \"#{output_dir}\"" unless File.writable?(output_dir)
62
- filename = File.join(output_dir, Jammit.filename(package, extension, suffix))
63
- zip_name = "#{filename}.gz"
64
- File.open(filename, 'wb+') {|f| f.write(contents) }
65
- Zlib::GzipWriter.open(zip_name, Zlib::BEST_COMPRESSION) {|f| f.write(contents) }
66
- File.utime(mtime, mtime, filename, zip_name)
62
+ files = []
63
+ files << file_name = File.join(output_dir, Jammit.filename(package, extension, suffix))
64
+ File.open(file_name, 'wb+') {|f| f.write(contents) }
65
+ if Jammit.gzip_assets
66
+ files << zip_name = "#{file_name}.gz"
67
+ Zlib::GzipWriter.open(zip_name, Zlib::BEST_COMPRESSION) {|f| f.write(contents) }
68
+ end
69
+ File.utime(mtime, mtime, *files)
67
70
  end
68
71
 
69
72
  # Get the list of individual assets for a package.
@@ -97,9 +100,12 @@ module Jammit
97
100
  end
98
101
 
99
102
  # Absolute globs are absolute -- relative globs are relative to ASSET_ROOT.
103
+ # Print a warning if no files were found that match the glob.
100
104
  def glob_files(glob)
101
105
  absolute = Pathname.new(glob).absolute?
102
- Dir[absolute ? glob : File.join(ASSET_ROOT, glob)].sort
106
+ paths = Dir[absolute ? glob : File.join(ASSET_ROOT, glob)].sort
107
+ Jammit.warn("No assets match '#{glob}'") if paths.empty?
108
+ paths
103
109
  end
104
110
 
105
111
  # 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.4.1
4
+ version: 0.4.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-01-05 00:00:00 -05:00
12
+ date: 2009-01-27 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency