Skip to content

Instantly share code, notes, and snippets.

@Andrew8xx8
Created November 5, 2012 15:47
Show Gist options
  • Select an option

  • Save Andrew8xx8/4017893 to your computer and use it in GitHub Desktop.

Select an option

Save Andrew8xx8/4017893 to your computer and use it in GitHub Desktop.
Convert indentation and line endings
#!/usr/bin/env ruby
require 'fileutils'
require 'tempfile'
if ARGV[0] == nil
path = '**'
else
path = File.join(ARGV[0], '**')
end
files = File.join(path, "*.{xml,js,css,tpl}")
Dir.glob(files).each do |file_name|
t_file = Tempfile.new(file_name + '.tmp')
File.open(file_name, 'r') do |f|
f.each_line{|line| t_file.puts line.gsub(/\t/, ' '*4).gsub(/\r\n/, '\n')}
end
FileUtils.mv(t_file.path, file_name)
puts 'Succesful converted: ' + file_name
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment