Sha256: dc3c84acfdbae483e79b257d6a3d46195850971bd829c86d5e95e226865ace1d

Contents?: true

Size: 643 Bytes

Versions: 1

Compression:

Stored size: 643 Bytes

Contents

require 'nokogiri'

module DragonflySvg
  module Processors
    class SetNamespace
      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dragonfly_svg-1.0.1 lib/dragonfly_svg/processors/set_namespace.rb