Class: DragonflySvg::Processors::SetNamespace

Inherits:
Object
  • Object
show all
Defined in:
lib/dragonfly_svg/processors/set_namespace.rb

Instance Method Summary collapse

Instance Method Details

#call(content, namespace = 'http://www.w3.org/2000/svg') ⇒ Object

Raises:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dragonfly_svg/processors/set_namespace.rb', line 6

def call(content, namespace = 'http://www.w3.org/2000/svg')
  raise UnsupportedFormat unless content.ext
  raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext.downcase)

  doc = Nokogiri::XML(content.data)

  if svg_node = doc.xpath("//*[name()='svg']").first
    unless svg_node.namespace.href == namespace
      doc.remove_namespaces!
      svg_node.add_namespace(nil, namespace)
    end
  end

  content.update(doc.to_xml, 'name' => 'temp.svg')
end