def prep_defs(svg)

      # <defs> should be moved to the beginning of the SVG file for braod browser support. Ahem, Firefox ಠ_ಠ
      # When symbols are reassembled, @defs will be added back

      if @defs = svg.scan(/<defs>(.+)<\/defs>/m).flatten[0]
        svg.sub!("<defs>#{@defs}</defs>", '')
        @defs.gsub!(/(\n|\s{2,})/,'')

        @defs.scan(/id="(.+?)"/).flatten.uniq.each_with_index do |id, index|

          # If there are urls matching def ids
          if svg.match(/url\(##{id}\)/)

            new_id = "def-#{@id}-#{index}"                 # Generate a unique id
            @defs.gsub!(/id="#{id}"/, %Q{id="#{new_id}"})  # Replace the def ids
            svg.gsub!(/url\(##{id}\)/, "url(##{new_id})")  # Replace url references to these old def ids
          end
        end
      end

      svg
    end
def prep_defs(svg)

      # <defs> should be moved to the beginning of the SVG file for braod browser support. Ahem, Firefox ಠ_ಠ
      # When symbols are reassembled, @defs will be added back

      if @defs = svg.scan(/<defs>(.+)<\/defs>/m).flatten[0]
        svg.sub!("<defs>#{@defs}</defs>", '')
        @defs.gsub!(/(\n|\s{2,})/,'')

        @defs.scan(/id="(.+?)"/).flatten.uniq.each_with_index do |id, index|

          # If there are urls matching def ids
          if svg.match(/url\(##{id}\)/)

            new_id = "def-#{@id}-#{index}"                 # Generate a unique id
            @defs.gsub!(/id="#{id}"/, %Q{id="#{new_id}"})  # Replace the def ids
            svg.gsub!(/url\(##{id}\)/, "url(##{new_id})")  # Replace url references to these old def ids
          end
        end
      end

      svg
    end
Scans <def> blocks for IDs
 If urls(#id) are used, ensure these IDs are unique to this file
 Only replace IDs if urls exist to avoid replacing defs
 used in other svg files