lib/htmlcompressor/compressor.rb in htmlcompressor-0.3.1 vs lib/htmlcompressor/compressor.rb in htmlcompressor-0.4.0
- old
+ new
@@ -383,10 +383,20 @@
html
end
def return_blocks(html, preBlocks, taBlocks, scriptBlocks, styleBlocks, eventBlocks, condCommentBlocks, skipBlocks, lineBreakBlocks, userBlocks)
+ # put skip blocks back
+ html = html.gsub(TEMP_SKIP_PATTERN) do |match|
+ i = $1.to_i
+ if skipBlocks.size > i
+ skipBlocks[i]
+ else
+ ''
+ end
+ end
+
# put line breaks back
if @options[:preserve_line_breaks]
html = html.gsub(TEMP_LINE_BREAK_PATTERN) do |match|
i = $1.to_i
if lineBreakBlocks.size > i
@@ -453,19 +463,10 @@
else
''
end
end
- # put skip blocks back
- html = html.gsub(TEMP_SKIP_PATTERN) do |match|
- i = $1.to_i
- if skipBlocks.size > i
- skipBlocks[i]
- else
- ''
- end
- end
# put user blocks back
unless @options[:preserve_patterns].nil?
@options[:preserve_patterns].each_with_index do |preservePattern, p|
tempUserPattern = Regexp.new("%%%~COMPRESS~USER#{p}~(\\d+?)~%%%")
@@ -526,11 +527,15 @@
if javascript_compressor.is_a?(Symbol)
javascript_compressor = get_javascript_compressor(javascript_compressor)
end
if javascript_compressor.nil?
- raise MissingCompressorError, "No JavaScript Compressor. Please set the :javascript_compressor option"
+ if @options[:javascript_compressor].is_a?(Symbol)
+ raise NotFoundCompressorError, "JavaScript Compressor \"#{@options[:javascript_compressor]}\" not found, please check :javascript_compressor option"
+ else
+ raise MissingCompressorError, "No JavaScript Compressor. Please set the :javascript_compressor option"
+ end
end
# detect CDATA wrapper
cdataWrapper = false
if source =~ CDATA_PATTERN
@@ -554,10 +559,14 @@
if css_compressor.is_a?(Symbol)
css_compressor = get_css_compressor(css_compressor)
end
if css_compressor.nil?
- raise MissingCompressorError, "No CSS Compressor. Please set the :css_compressor option"
+ if @options[:css_compressor].is_a?(Symbol)
+ raise NotFoundCompressorError, "CSS Compressor \"#{@options[:css_compressor]}\" not found, please check :css_compressor option"
+ else
+ raise MissingCompressorError, "No CSS Compressor. Please set the :css_compressor option"
+ end
end
# detect CDATA wrapper
cdataWrapper = false
if source =~ CDATA_PATTERN