Skip to content

Commit

Permalink
Merging in the soft dependency branch ... no more closure/uglifier ge…
Browse files Browse the repository at this point in the history
…m deps.
  • Loading branch information
jashkenas committed Mar 31, 2011
1 parent 4c0c813 commit 50a85d0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
2 changes: 0 additions & 2 deletions jammit.gemspec
Expand Up @@ -28,8 +28,6 @@ Gem::Specification.new do |s|
'--all'

s.add_dependency 'yui-compressor', ['>= 0.9.3']
#s.add_dependency 'closure-compiler', ['>= 0.1.0']
#s.add_dependency 'uglifier', ['>= 0.4.0']

s.files = Dir['lib/**/*', 'bin/*', 'rails/*', 'jammit.gemspec', 'LICENSE', 'README']
end
22 changes: 11 additions & 11 deletions lib/jammit.rb
Expand Up @@ -22,7 +22,7 @@ module Jammit

DEFAULT_JST_NAMESPACE = "window.JST"

AVAILABLE_COMPRESSORS = [:yui, :closure, :uglifier]
COMPRESSORS = [:yui, :closure, :uglifier]

DEFAULT_COMPRESSOR = :yui

Expand All @@ -46,18 +46,18 @@ class OutputNotWritable < StandardError; end
class DeprecationError < StandardError; end

class << self
attr_reader :configuration, :template_function, :template_namespace,
:embed_assets, :package_assets, :compress_assets, :gzip_assets,
:package_path, :mhtml_enabled, :include_jst_script, :config_path,
:javascript_compressor, :compressor_options, :css_compressor_options,
:template_extension, :template_extension_matcher, :allow_debugging
attr_accessor :loaded_compressors
attr_reader :configuration, :template_function, :template_namespace,
:embed_assets, :package_assets, :compress_assets, :gzip_assets,
:package_path, :mhtml_enabled, :include_jst_script, :config_path,
:javascript_compressor, :compressor_options, :css_compressor_options,
:template_extension, :template_extension_matcher, :allow_debugging
attr_accessor :compressors
end

# The minimal required configuration.
@configuration = {}
@package_path = DEFAULT_PACKAGE_PATH
@loaded_compressors = AVAILABLE_COMPRESSORS
@configuration = {}
@package_path = DEFAULT_PACKAGE_PATH
@compressors = COMPRESSORS

# Load the complete asset configuration from the specified @config_path@.
# If we're loading softly, don't let missing configuration error out.
Expand Down Expand Up @@ -136,7 +136,7 @@ def self.package!(options={})
# Ensure that the JavaScript compressor is a valid choice.
def self.set_javascript_compressor(value)
value = value && value.to_sym
@javascript_compressor = loaded_compressors.include?(value) ? value : DEFAULT_COMPRESSOR
@javascript_compressor = compressors.include?(value) ? value : DEFAULT_COMPRESSOR
end

# Turn asset packaging on or off, depending on configuration and environment.
Expand Down
5 changes: 2 additions & 3 deletions lib/jammit/compressor.rb
Expand Up @@ -43,10 +43,9 @@ class Compressor

COMPRESSORS = {
:yui => YUI::JavaScriptCompressor,
:closure => Jammit.compressors.include?(:closure) ? Closure::Compiler : nil,
:uglifier => Jammit.compressors.include?(:uglifier) ? Jammit::Uglifier : nil
}

COMPRESSORS[:closure] = Closure::Compiler if Jammit.loaded_compressors.include? :closure
COMPRESSORS[:uglifier] = Jammit::Uglifier if Jammit.loaded_compressors.include? :uglifier

DEFAULT_OPTIONS = {
:yui => {:munge => true},
Expand Down
16 changes: 6 additions & 10 deletions lib/jammit/dependencies.rb
Expand Up @@ -7,32 +7,28 @@
require 'pathname'
require 'fileutils'

# Gem Dependencies:
available_dependencies = []

# Include YUI as the default
require 'yui/compressor'

# Try Closure.
begin
require 'closure-compiler'
available_dependencies << :closure
rescue LoadError
Jammit.loaded_compressors.delete :closure
puts "Closure is unavailable."
Jammit.compressors.delete :closure
end

# Try Uglifier.
begin
require 'uglifier'
available_dependencies << :uglifier
rescue LoadError
Jammit.loaded_compressors.delete :uglifier
puts "Uglifier is unavailable."
Jammit.compressors.delete :uglifier
end

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

# Jammit Core:
require 'jammit/uglifier' if Jammit.loaded_compressors.include?( :uglifier )
require 'jammit/uglifier' if Jammit.compressors.include? :uglifier
require 'jammit/compressor'
require 'jammit/packager'

Expand Down

0 comments on commit 50a85d0

Please sign in to comment.