lib/jammit/compressor.rb in jammit-0.6.0 vs lib/jammit/compressor.rb in jammit-0.6.1

- old
+ new

@@ -40,23 +40,25 @@ # JST file constants. JST_START = "(function(){" JST_END = "})();" COMPRESSORS = { - :yui => YUI::JavaScriptCompressor, - :closure => Closure::Compiler + :yui => YUI::JavaScriptCompressor, + :closure => Jammit.compressors.include?(:closure) ? Closure::Compiler : nil, + :uglifier => Jammit.compressors.include?(:uglifier) ? Jammit::Uglifier : nil } DEFAULT_OPTIONS = { - :yui => {:munge => true}, - :closure => {} + :yui => {:munge => true}, + :closure => {}, + :uglifier => {:copyright => false} } - # Creating a compressor initializes the internal YUI Compressor from - # the "yui-compressor" gem, or the internal Closure Compiler from the - # "closure-compiler" gem. + # The css compressor is always the YUI Compressor. 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) end @@ -96,10 +98,10 @@ namespace = Jammit.template_namespace paths = paths.grep(Jammit.template_extension_matcher).sort base_path = find_base_path(paths) compiled = paths.map do |path| contents = read_binary_file(path) - contents = contents.gsub(/\n/, '').gsub("'", '\\\\\'') + contents = contents.gsub(/\r?\n/, "\\n").gsub("'", '\\\\\'') name = template_name(path, base_path) "#{namespace}['#{name}'] = #{Jammit.template_function}('#{contents}');" end compiler = Jammit.include_jst_script ? read_binary_file(DEFAULT_JST_SCRIPT) : ''; setup_namespace = "#{namespace} = #{namespace} || {};"