Skip to content

Instantly share code, notes, and snippets.

@n3bulous
Forked from kamali/gist:550231
Created June 27, 2011 16:12
Show Gist options
  • Save n3bulous/1049177 to your computer and use it in GitHub Desktop.
Save n3bulous/1049177 to your computer and use it in GitHub Desktop.
switch haml to erb
## based on the example at:
## http://gist.github.com/17371
##
## put me in lib/un_haml.rb (in the haml-based project)
##
## call me on the command line thus:
## $ script/runner UnHaml app/views/layouts/application.html.haml
## $ script/runner UnHaml */*/*/*.haml
##
class UnHaml < Haml::Engine
def push_script(text, preserve_script = false, in_tag = false, preserve_tag = false,
escape_html = false, nuke_inner_whitespace = false)
push_text "<%= #{text.strip} %>"
end
def push_silent(text, can_suppress = false)
push_text "<% #{text.strip} %>"
end
ARGV.each do |haml_file|
template = File.read(haml_file)
outfile = haml_file.sub(/.haml$/, '') + '.erb'
if File.exists?(outfile)
puts " !!!! Skipping #{haml_file} because #{outfile} already exists"
else
puts " IN: #{haml_file} OUT: #{outfile}"
unhaml = UnHaml.new(template)
File.open(outfile, 'w') {|f| f.write(unhaml.render) }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment