Skip to content

Instantly share code, notes, and snippets.

@dpaluy
Created July 4, 2012 20:55
Show Gist options
  • Select an option

  • Save dpaluy/3049495 to your computer and use it in GitHub Desktop.

Select an option

Save dpaluy/3049495 to your computer and use it in GitHub Desktop.
Convert Erb to Haml
class ToHaml
def initialize(path)
@path = path
end
def convert!
Dir["#{@path}/**/*.erb"].each do |file|
`html2haml -rx #{file} #{file.gsub(/\.erb$/, '.haml')}`
end
end
end
path = File.join(File.dirname(__FILE__), 'app', 'views')
ToHaml.new(path).convert!
namespace :erb do
namespace :to do
desc "Converts all .html.erb files to .html.haml"
task :haml do
puts "looking for erb views..."
files = `find ./app/views -name *.html.erb`
files.each_line do |file|
file.strip!
puts "parsing file: #{file}"
`bundle exec html2haml #{file} | cat > #{file.gsub(/\.erb$/, ".haml")}`
`rm #{file}`
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment