Skip to content

Instantly share code, notes, and snippets.

@edolopez
Created December 18, 2012 19:07
Show Gist options
  • Save edolopez/4330934 to your computer and use it in GitHub Desktop.
Save edolopez/4330934 to your computer and use it in GitHub Desktop.
Script that converts 'haml' to 'erb'. It also accepts utf-8 encoding.
Encoding.default_external = 'UTF-8'
Encoding.default_internal = 'UTF-8'
require 'haml'
class ErbEngine < Haml::Engine
def push_script(text, preserve_script, 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
end
def haml_to_erb(haml)
ErbEngine.new(haml, :attr_wrapper => '"').render
end
puts haml_to_erb(File.read('app/views/object/x.html.haml'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment