Sha256: 57ec7456a18f35137e680b405dab3f593734b356ba76d7d4eb6b5279c9b1f209

Contents?: true

Size: 431 Bytes

Versions: 3

Compression:

Stored size: 431 Bytes

Contents

require 'nokogiri'

module DragonflySvg
  module Processors
    class SetViewBox

      def call content, min_x, min_y, width, height
        doc = Nokogiri::XML(content.data)

        value = [min_x, min_y, width, height].map(&:to_s).join(' ')

        if svg_node = doc.xpath("//*[name()='svg']").first
          svg_node.set_attribute 'viewBox', value
        end

        content.update(doc.to_xml)
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dragonfly_svg-0.0.3 lib/dragonfly_svg/processors/set_view_box.rb
dragonfly_svg-0.0.2 lib/dragonfly_svg/processors/set_view_box.rb
dragonfly_svg-0.0.1 lib/dragonfly_svg/processors/set_view_box.rb