Skip to content

Commit 364e01f

Browse files
author
Julien Guimont
committed
Remove hard dependencies on anything else than YUI. Closure and Uglifier can be used if loaded in the gem path.
1 parent 9156b6a commit 364e01f

4 files changed

Lines changed: 27 additions & 8 deletions

File tree

jammit.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Gem::Specification.new do |s|
2828
'--all'
2929

3030
s.add_dependency 'yui-compressor', ['>= 0.9.3']
31-
s.add_dependency 'closure-compiler', ['>= 0.1.0']
32-
s.add_dependency 'uglifier', ['>= 0.4.0']
31+
#s.add_dependency 'closure-compiler', ['>= 0.1.0']
32+
#s.add_dependency 'uglifier', ['>= 0.4.0']
3333

3434
s.files = Dir['lib/**/*', 'bin/*', 'rails/*', 'jammit.gemspec', 'LICENSE', 'README']
3535
end

lib/jammit.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ class << self
5151
:package_path, :mhtml_enabled, :include_jst_script, :config_path,
5252
:javascript_compressor, :compressor_options, :css_compressor_options,
5353
:template_extension, :template_extension_matcher, :allow_debugging
54+
attr_accessor :loaded_compressors
5455
end
5556

5657
# The minimal required configuration.
5758
@configuration = {}
5859
@package_path = DEFAULT_PACKAGE_PATH
60+
@loaded_compressors = AVAILABLE_COMPRESSORS
5961

6062
# Load the complete asset configuration from the specified @config_path@.
6163
# If we're loading softly, don't let missing configuration error out.
@@ -134,7 +136,7 @@ def self.package!(options={})
134136
# Ensure that the JavaScript compressor is a valid choice.
135137
def self.set_javascript_compressor(value)
136138
value = value && value.to_sym
137-
@javascript_compressor = AVAILABLE_COMPRESSORS.include?(value) ? value : DEFAULT_COMPRESSOR
139+
@javascript_compressor = loaded_compressors.include?(value) ? value : DEFAULT_COMPRESSOR
138140
end
139141

140142
# Turn asset packaging on or off, depending on configuration and environment.

lib/jammit/compressor.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ class Compressor
4343

4444
COMPRESSORS = {
4545
:yui => YUI::JavaScriptCompressor,
46-
:closure => Closure::Compiler,
47-
:uglifier => Jammit::Uglifier
4846
}
47+
48+
COMPRESSORS[:closure] = Closure::Compiler if Jammit.loaded_compressors.include? :closure
49+
COMPRESSORS[:uglifier] = Jammit::Uglifier if Jammit.loaded_compressors.include? :uglifier
4950

5051
DEFAULT_OPTIONS = {
5152
:yui => {:munge => true},

lib/jammit/dependencies.rb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,31 @@
88
require 'fileutils'
99

1010
# Gem Dependencies:
11+
available_dependencies = []
12+
13+
# Include YUI as the default
1114
require 'yui/compressor'
12-
require 'closure-compiler'
13-
require 'uglifier'
15+
16+
begin
17+
require 'closure-compiler'
18+
available_dependencies << :closure
19+
rescue LoadError
20+
Jammit.loaded_compressors.delete :closure
21+
puts "Closure is unavailable."
22+
end
23+
begin
24+
require 'uglifier'
25+
available_dependencies << :uglifier
26+
rescue LoadError
27+
Jammit.loaded_compressors.delete :uglifier
28+
puts "Uglifier is unavailable."
29+
end
1430

1531
# Load initial configuration before the rest of Jammit.
1632
Jammit.load_configuration(Jammit::DEFAULT_CONFIG_PATH, true) if defined?(Rails)
1733

1834
# Jammit Core:
19-
require 'jammit/uglifier'
35+
require 'jammit/uglifier' if Jammit.loaded_compressors.include?( :uglifier )
2036
require 'jammit/compressor'
2137
require 'jammit/packager'
2238

0 commit comments

Comments
 (0)