Class: SvgOptimizer::Plugins::RemoveUnusedNamespace
- Inherits:
-
Base
- Object
- Base
- SvgOptimizer::Plugins::RemoveUnusedNamespace
show all
- Defined in:
- lib/svg_optimizer/plugins/remove_unused_namespace.rb
Instance Attribute Summary
Attributes inherited from Base
#xml
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#process ⇒ Object
6
7
8
9
10
11
12
|
# File 'lib/svg_optimizer/plugins/remove_unused_namespace.rb', line 6
def process
xml
.root
.namespace_definitions
.select(&:prefix)
.each(&method(:remove_unused_ns))
end
|
#remove_unused_ns(ns) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/svg_optimizer/plugins/remove_unused_namespace.rb', line 14
def remove_unused_ns(ns)
return if xml.xpath("//#{ns.prefix}:*").any?
return if xml.xpath("//@*[namespace-uri()='#{ns.href}']").any?
source = xml.root.to_s.gsub(/ *xmlns:#{ns.prefix}=".*?"/, "")
xml.root = Nokogiri::XML(source).root
end
|