Skip to content

Instantly share code, notes, and snippets.

@scruffyfox
Created September 12, 2013 09:04
Show Gist options
  • Select an option

  • Save scruffyfox/6534765 to your computer and use it in GitHub Desktop.

Select an option

Save scruffyfox/6534765 to your computer and use it in GitHub Desktop.
Remove whitespace and replace 4 spaces with tabs in xml resource files
#!/usr/bin/ruby
# Based on the script from http://www.splinter.com.au/ruby-script-to-increment-a-build-number/
@path = File.dirname(__FILE__)
res = "/res/"
def strip(filename)
# Read it
file_str = ''
if File.exists?(filename)
file_str = File.open(filename, 'r') {|file| file.read }
end
file_str = file_str.gsub(/ /, "\t")
file_str = file_str.gsub(/\"^[ \t]+|[ \t]+$/, "")
# Write
File.open(filename, 'w') {|file| file.write(file_str) }
puts "Removing trailing whitespace and converting spaces to tabs in #{filename}"
end
Dir.entries(@path + res).each {|entry|
if (!File.basename(@path + res + entry).start_with?("."))
Dir.entries(@path + res + entry).each {|file|
if (!File.basename(@path + res + entry + "/" + file).start_with?(".") and File.basename(@path + res + entry + "/" + file).end_with?("xml"))
strip(@path + res + entry + "/" + file)
end
}
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment