lib/scavenger/compressor.rb in scavenger-0.2.1 vs lib/scavenger/compressor.rb in scavenger-0.3.0
- old
+ new
@@ -21,22 +21,24 @@
rect script set solidcolor stop style svg switch symbol text
textPath tref tspan unknown use video view vkern)
end
def compress_dir
- sheet = Dir.entries(@path)
+ sheet = Dir.glob(File.join(@path, "**/*.svg"))
.select { |f| should_compress? f }
.sort
- .map { |f| compress_file(File.join(@path, f), f) }
+ .map { |f| f.sub(%r{^#{@path}/?}, "") }
+ .map { |f| compress_file(f) }
.join("")
File.write(Scavenger::Config.sprite_path, "<svg>#{sheet}</svg>") unless Scavenger::Config.sprite_path.nil?
sheet
end
- def compress_file(filename, id)
- doc = Nokogiri::XML(File.open(filename), &:noblanks)
+ def compress_file(filename)
+ id = filename.gsub(%r{/}, "--")
+ doc = Nokogiri::XML(File.open(File.join(@path, filename)), &:noblanks)
doc = doc.remove_namespaces!.root
remove_comments(doc)
remove_tags(doc)
remove_ids(doc)
symbolize(doc, id)
@@ -45,10 +47,10 @@
private
def should_compress?(filename)
!File.directory?(filename) &&
- !File.basename(filename).start_with?('.')
+ !File.basename(filename).start_with?(".")
end
def remove_comments(doc)
doc.xpath("//comment()").remove
end