lib/jammit/compressor.rb in jammit-0.6.5 vs lib/jammit/compressor.rb in jammit-0.6.6
- old
+ new
@@ -13,13 +13,13 @@
'.jpg' => 'image/jpeg',
'.jpeg' => 'image/jpeg',
'.gif' => 'image/gif',
'.tif' => 'image/tiff',
'.tiff' => 'image/tiff',
- '.ttf' => 'font/truetype',
+ '.ttf' => 'application/x-font-ttf',
'.otf' => 'font/opentype',
- '.woff' => 'font/woff'
+ '.woff' => 'application/x-font-woff'
}
# Font extensions for which we allow embedding:
EMBED_EXTS = EMBED_MIME_TYPES.keys
EMBED_FONTS = ['.ttf', '.otf', '.woff']
@@ -39,30 +39,43 @@
# JST file constants.
JST_START = "(function(){"
JST_END = "})();"
- COMPRESSORS = {
- :yui => YUI::JavaScriptCompressor,
- :closure => Jammit.compressors.include?(:closure) ? Closure::Compiler : nil,
- :uglifier => Jammit.compressors.include?(:uglifier) ? Jammit::Uglifier : nil
+ JAVASCRIPT_COMPRESSORS = {
+ :jsmin => Jammit.javascript_compressors.include?(:jsmin) ? Jammit::JsminCompressor : nil,
+ :yui => Jammit.javascript_compressors.include?(:yui) ? YUI::JavaScriptCompressor : nil,
+ :closure => Jammit.javascript_compressors.include?(:closure) ? Closure::Compiler : nil,
+ :uglifier => Jammit.javascript_compressors.include?(:uglifier) ? Jammit::Uglifier : nil
}
- DEFAULT_OPTIONS = {
+ CSS_COMPRESSORS = {
+ :cssmin => Jammit.css_compressors.include?(:cssmin) ? Jammit::CssminCompressor : nil,
+ :yui => Jammit.css_compressors.include?(:yui) ? YUI::CssCompressor : nil,
+ :sass => Jammit.css_compressors.include?(:sass) ? Jammit::SassCompressor : nil
+ }
+
+ JAVASCRIPT_DEFAULT_OPTIONS = {
+ :jsmin => {},
:yui => {:munge => true},
:closure => {},
:uglifier => {:copyright => false}
}
- # The css compressor is always the YUI Compressor. JS compression can be
- # provided with YUI Compressor, Google Closure Compiler or UglifyJS.
+ # CSS compression can be provided with YUI Compressor or sass. JS
+ # compression can be provided with YUI Compressor, Google Closure
+ # Compiler or UglifyJS.
def initialize
- Jammit.check_java_version
- @css_compressor = YUI::CssCompressor.new(Jammit.css_compressor_options || {})
- flavor = Jammit.javascript_compressor || Jammit::DEFAULT_COMPRESSOR
- @options = DEFAULT_OPTIONS[flavor].merge(Jammit.compressor_options || {})
- @js_compressor = COMPRESSORS[flavor].new(@options)
+ if Jammit.javascript_compressors.include?(:yui) || Jammit.javascript_compressors.include?(:closure) || Jammit.css_compressors.include?(:yui)
+ Jammit.check_java_version
+ end
+
+ css_flavor = Jammit.css_compressor || Jammit::DEFAULT_CSS_COMPRESSOR
+ @css_compressor = CSS_COMPRESSORS[css_flavor].new(Jammit.css_compressor_options || {})
+ js_flavor = Jammit.javascript_compressor || Jammit::DEFAULT_JAVASCRIPT_COMPRESSOR
+ @options = JAVASCRIPT_DEFAULT_OPTIONS[js_flavor].merge(Jammit.compressor_options || {})
+ @js_compressor = JAVASCRIPT_COMPRESSORS[js_flavor].new(@options)
end
# Concatenate together a list of JavaScript paths, and pass them through the
# YUI Compressor (with munging enabled). JST can optionally be included.
def compress_js(paths)
@@ -177,10 +190,10 @@
# be tagged for embedding if embeddable, and referenced at the correct level
# if relative.
def construct_asset_path(asset_path, css_path, variant)
public_path = absolute_path(asset_path, css_path)
return "__EMBED__#{public_path}" if embeddable?(public_path, variant)
- source = asset_path.absolute? ? asset_path.to_s : relative_path(public_path)
+ source = asset_path.absolute? || ! Jammit.rewrite_relative_paths ? asset_path.to_s : relative_path(public_path)
rewrite_asset_path(source, public_path)
end
# Get the site-absolute public path for an asset file path that may or may
# not be relative, given the path of the stylesheet that contains it.