lib/esvg/symbol.rb
# 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
#
Scans  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
Scans 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
def prep_defs(svg)
      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 svg.match(/url\(##{id}\)/)
            new_id = "def-#{@id}-#{index}"                 
            @defs.gsub!(/id="#{id}"/, %Q{id="#{new_id}"})  
            svg.gsub!(/url\(##{id}\)/, "url(##{new_id})")  
          end
        end
      end
      svg
    end
def prep_defs ( svg ) 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 svg . match ( / url \( # #{ id } \) / ) new_id = "def-#{@id}-#{index}" @defs . gsub! ( / id=" #{ id } " / , %Q{id="#{new_id}"} ) svg . gsub! ( / url \( # #{ id } \) / , "url(##{new_id})" ) 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
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
# <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 there are urls matching def ids # Generate a unique id # Replace the def ids # Replace url references to these old def ids
svg
<not_specific>