Skip to content

Instantly share code, notes, and snippets.

@hron84
Forked from jzajpt/haml2erb
Created March 6, 2011 23:42
Show Gist options
  • Save hron84/857877 to your computer and use it in GitHub Desktop.
Save hron84/857877 to your computer and use it in GitHub Desktop.
haml2erb
#!/usr/bin/ruby
require 'rubygems'
require 'haml'
class ErbEngine < Haml::Engine
def push_script(text, opts = {} )
push_text "<%= #{text.strip} %>"
end
def push_silent(text, can_suppress = false)
push_text "<% #{text.strip} %>"
end
end
if ARGV.size == 0
puts "usage: haml2erb [files]"
exit
end
ARGV.each do |filename|
content = File.open(filename).read
erb_engine = ErbEngine.new(content)
erbized = erb_engine.render
new_filename = filename.gsub('haml', 'html.erb').gsub('html.html', 'html')
puts "writing to file #{new_filename}"
File.open(new_filename, "w").write(erbized)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment