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_title.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_description.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,
lib/svg_optimizer/plugins/remove_useless_stroke_and_fill.rb
Defined Under Namespace
Modules: Plugins
Constant Summary collapse
- DEFAULT_PLUGINS =
%w[ RemoveTitle RemoveDescription RemoveUnusedNamespace CleanupAttribute CleanupId RemoveComment RemoveMetadata RemoveEditorNamespace RemoveHiddenElement RemoveRasterImage RemoveEmptyAttribute RemoveUselessStrokeAndFill RemoveEmptyTextNode RemoveEmptyContainer ].map {|name| Plugins.const_get(name) }
- VERSION =
"0.3.0"
Class Method Summary collapse
- .optimize(contents, plugins = DEFAULT_PLUGINS, trusted: false) ⇒ Object
- .optimize_file(path, target = path, plugins = DEFAULT_PLUGINS, trusted: false) ⇒ Object
Class Method Details
.optimize(contents, plugins = DEFAULT_PLUGINS, trusted: false) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/svg_optimizer.rb', line 40 def self.optimize(contents, plugins = DEFAULT_PLUGINS, trusted: false) xml = Nokogiri::XML(contents) do |config| config.recover.noent if trusted end plugins.each {|plugin| plugin.new(xml).process } xml.root.to_xml end |
.optimize_file(path, target = path, plugins = DEFAULT_PLUGINS, trusted: false) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/svg_optimizer.rb', line 50 def self.optimize_file( path, target = path, plugins = DEFAULT_PLUGINS, trusted: false ) contents = optimize(File.read(path), plugins, trusted: trusted) File.open(target, "w") {|file| file << contents } true end |