Module: SvgOptimizer
- Defined in:
- lib/svg_optimizer.rb,
lib/svg_optimizer/version.rb,
lib/svg_optimizer/plugins/base.rb,
lib/svg_optimizer/plugins/cleanup_id.rb,
lib/svg_optimizer/plugins/remove_comment.rb,
lib/svg_optimizer/plugins/remove_metadata.rb,
lib/svg_optimizer/plugins/cleanup_attribute.rb,
lib/svg_optimizer/plugins/remove_raster_image.rb,
lib/svg_optimizer/plugins/remove_hidden_element.rb,
lib/svg_optimizer/plugins/remove_empty_attribute.rb,
lib/svg_optimizer/plugins/remove_empty_container.rb,
lib/svg_optimizer/plugins/remove_empty_text_node.rb,
lib/svg_optimizer/plugins/remove_editor_namespace.rb,
lib/svg_optimizer/plugins/remove_unused_namespace.rb
Defined Under Namespace
Modules: Plugins
Constant Summary collapse
- PLUGINS =
%w[ CleanupAttribute CleanupId RemoveComment RemoveMetadata RemoveEditorNamespace RemoveHiddenElement RemoveUnusedNamespace RemoveRasterImage RemoveEmptyAttribute RemoveEmptyTextNode RemoveEmptyContainer ]
- VERSION =
"0.0.4"
Class Method Summary collapse
Class Method Details
.optimize(contents) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/svg_optimizer.rb', line 32 def self.optimize(contents) xml = Nokogiri::XML(contents) PLUGINS.each do |plugin_name| Plugins.const_get(plugin_name).new(xml).process end xml.root.to_xml end |
.optimize_file(path, target = path) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/svg_optimizer.rb', line 41 def self.optimize_file(path, target = path) contents = optimize(File.read(path)) File.open(target, "w") {|file| file << contents } true end |