#require 'plist' #require 'ox' #require 'rexml/document' require 'nokogiri' class RewritePlistFile # def self.with_prefix(prefix, original) # v = Plist::parse_xml(original) # files = v['files'] # v['files'] = files.map{|i|File.join(prefix, i)} # v.to_plist() # end # def self.with_prefix(prefix, original) # doc = REXML::Document.new(original) # array_element = REXML::XPath.first(doc, "//key[text()='files']/following-sibling::array") # if array_element # array_element.elements.each do |s| # s.text = File.join(prefix, s.text) # end # res = StringIO.new # formatter = REXML::Formatters::Pretty.new(2) # formatter.compact = true # formatter.write(doc, res) # return res.string # end # return original # end def self.with_prefix(prefix, original) doc = Nokogiri::XML(original) array_element = doc.xpath("//key[text()='files']/following-sibling::array/string") array_element.each do |e| e.content = File.join(prefix, e.content) end return doc.to_xml() end end