Skip to content

Commit

Permalink
removing the active_support (and therefore rails) dependency from Jam…
Browse files Browse the repository at this point in the history
…mit altogether
  • Loading branch information
jashkenas committed Jul 8, 2010
1 parent 40b94f2 commit 2200aa9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
1 change: 0 additions & 1 deletion jammit.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Gem::Specification.new do |s|
'--main' << 'README' <<
'--all'

s.add_dependency 'rails', ['>= 2.0.0']
s.add_dependency 'yui-compressor', ['>= 0.9.1']
s.add_dependency 'closure-compiler', ['>= 0.1.0']

Expand Down
17 changes: 14 additions & 3 deletions lib/jammit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,20 @@ def self.load_configuration(config_path)
raise ConfigurationNotFound, "could not find the \"#{config_path}\" configuration file" unless exists
conf = YAML.load(ERB.new(File.read(config_path)).result)
@config_path = config_path
@configuration = conf = conf.symbolize_keys
@configuration = symbolize_keys(conf)
@package_path = conf[:package_path] || DEFAULT_PACKAGE_PATH
@embed_assets = conf[:embed_assets] || conf[:embed_images]
@compress_assets = !(conf[:compress_assets] == false)
@gzip_assets = !(conf[:gzip_assets] == false)
@mhtml_enabled = @embed_assets && @embed_assets != "datauri"
@compressor_options = (conf[:compressor_options] || {}).symbolize_keys
@css_compressor_options = (conf[:css_compressor_options] || {}).symbolize_keys
@compressor_options = symbolize_keys(conf[:compressor_options] || {})
@css_compressor_options = symbolize_keys(conf[:css_compressor_options] || {})
set_javascript_compressor(conf[:javascript_compressor])
set_package_assets(conf[:package_assets])
set_template_function(conf[:template_function])
set_template_namespace(conf[:template_namespace])
symbolize_keys(conf[:stylesheets]) if conf[:stylesheets]
symbolize_keys(conf[:javascripts]) if conf[:javascripts]
check_java_version
check_for_deprecations
self
Expand Down Expand Up @@ -163,6 +165,15 @@ def self.warn(message)
@logger ? @logger.warn(message) : STDERR.puts(message)
end

# Clone of active_support's symbolize_keys, so that we don't have to depend
# on active_support in any fashion. Converts a hash's keys to all symbols.
def self.symbolize_keys(hash)
hash.keys.each do |key|
hash[(key.to_sym rescue key) || key] = hash.delete(key)
end
hash
end

end

require 'jammit/dependencies'
2 changes: 1 addition & 1 deletion lib/jammit/compressor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def relative_path(absolute_path)
# append the RAILS_ASSET_ID cache-buster to URLs, if it's defined.
def rewrite_asset_path(path, file_path)
asset_id = rails_asset_id(file_path)
asset_id.blank? ? path : "#{path}?#{asset_id}"
(!asset_id || asset_id == '') ? path : "#{path}?#{asset_id}"
end

# Similar to the AssetTagHelper's method of the same name, this will
Expand Down
4 changes: 1 addition & 3 deletions lib/jammit/dependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
require 'uri'
require 'erb'
require 'zlib'
require 'yaml'
require 'base64'
require 'pathname'
require 'fileutils'

require 'yaml'

# Gem Dependencies:
require 'yui/compressor'
require 'closure-compiler'
require 'active_support/core_ext'

# Load initial configuration before the rest of Jammit.
Jammit.load_configuration(Jammit::DEFAULT_CONFIG_PATH) if defined?(Rails)
Expand Down
4 changes: 2 additions & 2 deletions lib/jammit/packager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def initialize
@compressor = Compressor.new
@force = false
@config = {
:css => (Jammit.configuration[:stylesheets] || {}).symbolize_keys,
:js => (Jammit.configuration[:javascripts] || {}).symbolize_keys
:css => (Jammit.configuration[:stylesheets] || {}),
:js => (Jammit.configuration[:javascripts] || {})
}
@packages = {
:css => create_packages(@config[:css]),
Expand Down

1 comment on commit 2200aa9

@ku1ik
Copy link

@ku1ik ku1ik commented on 2200aa9 Jul 8, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good commit.

Please sign in to comment.