Skip to content

Instantly share code, notes, and snippets.

@mdigital
Forked from johnnyicon/to_haml.rb
Created June 7, 2012 22:41
Show Gist options
  • Save mdigital/2892143 to your computer and use it in GitHub Desktop.
Save mdigital/2892143 to your computer and use it in GitHub Desktop.
Convert all html.erb files to html.haml while preserving git history
# Adapted the script listed in the following link to maintain git history
# Original Script: http://snippets.dzone.com/posts/show/5449
# Usage:
# 1) Copy the file to the root of your Rails app
# 2) Run the script (i.e., ruby to_haml.rb app/views)
class ToHaml
def initialize(path)
@path = path
end
def convert!
Dir["#{@path}/**/*.erb"].each do |file|
`html2haml -r #{file} #{file.gsub(/\.erb$/, '.haml')}`
`rm #{file}`
`mv #{file.gsub(/\.erb$/, '.haml')} #{file}`
`git mv #{file} #{file.gsub(/\.erb$/, '.haml')}`
end
end
end
path = File.join(File.dirname(__FILE__), 'app', 'views')
ToHaml.new(path).convert!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment