Skip to content

Instantly share code, notes, and snippets.

@jacqui
Created July 22, 2010 17:26
Show Gist options
  • Save jacqui/486285 to your computer and use it in GitHub Desktop.
Save jacqui/486285 to your computer and use it in GitHub Desktop.
convert haml templates into erb using the w2tags gem
require 'rubygems'
require 'w2tags'
require File.join(File.dirname(__FILE__), '..', 'config', 'environment')
W2 = W2Tags::Parser.new('rails')
templates = Dir.glob("#{RAILS_ROOT}/app/views/**/*.haml")
puts "converting #{templates.size} to erb :("
templates.each do |template|
haml_data = File.read(template)
erb = W2.parse_line("%initialize\n"<<haml_data).join
erb_template = File.new(template.gsub('haml', 'erb'), "w+")
erb_template.puts(erb)
erb_template.close
end
@jacqui
Copy link
Author

jacqui commented Jul 22, 2010

Note that w2tags doesn't seem to add an "<% end %>" tag at the close of blocks, so you'll have to go through and find where those are missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment