lib/juicer/merger/stylesheet_merger.rb in psyho_juicer-1.0.0 vs lib/juicer/merger/stylesheet_merger.rb in psyho_juicer-1.0.7
- old
+ new
@@ -51,17 +51,17 @@
#
# If options[:hosts] is set to an array of hosts, then they will be cycled
# for all absolute URLs regardless of absolute/relative URL strategy.
#
def merge(file)
- content = super.gsub(/^\s*@import(?:\surl\(|\s)(['"]?)([^\?'"\)\s]+)(\?(?:[^'"\)]+)?)?\1\)?(?:[^?;]+)?;?/i, "")
+ content = super.gsub(/^\s*@import(?:\surl\(|\s)(['"]?)([^\?'"\)\s]+)(\?(?:[^'"\)]*))?\1\)?(?:[^?;]*);?/i, "")
dir = File.expand_path(File.dirname(file))
content.scan(/url\([\s"']*([^\)"'\s]*)[\s"']*\)/m).uniq.collect do |url|
url = url.first
path = resolve_path(url, dir)
- content.gsub!(/\(#{url}\)/m, "(#{path})") unless path == url
+ content.gsub!(/\([\s"']*#{url}[\s"']*\)/m, "(#{path})") unless path == url
end
content
end
@@ -77,20 +77,20 @@
path = Pathname.new(File.join(@document_root, url)).relative_path_from(@root).to_s
end
# All URLs that don't start with a protocol
if url !~ %r{^/} && url !~ %r{^[a-z]+://}
- if @use_absolute
+ if @use_absolute || @hosts.length > 0
raise ArgumentError.new("Unable to handle absolute URLs without :document_root option") if !@document_root
path = File.expand_path(File.join(dir, url)).sub(@document_root, "") # Make absolute
else
path = Pathname.new(File.join(dir, url)).relative_path_from(@root).to_s # ...or redefine relative ref
end
end
# Cycle hosts, if any
- if url =~ %r{^/} && @hosts.length > 0
- path = File.join(@hosts[@host_num % @hosts.length], url)
+ if path =~ %r{^/} && @hosts.length > 0
+ path = File.join(@hosts[@host_num % @hosts.length], path)
@host_num += 1
end
path
end