class DragonflySvg::Processors::ExtendIds
Public Instance Methods
call(content, append_str = SecureRandom.urlsafe_base64(8), options = {})
click to toggle source
# File lib/dragonfly_svg/processors/extend_ids.rb, line 7 def call(content, append_str = SecureRandom.urlsafe_base64(8), options = {}) raise UnsupportedFormat unless content.ext raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext.downcase) doc = Nokogiri::XML(content.data) # nodes with id attributes doc.xpath('//*[@id]').each do |node| node_id = node.get_attribute 'id' node.set_attribute 'id', [node_id, append_str].join('-') end # nodes with id references doc.xpath('//*[@href]').each do |node| node_href = node.get_attribute 'href' node.set_attribute 'href', [node_href, append_str].join('-') end content.update(doc.to_xml, 'name' => 'temp.svg') end