Skip to content

Instantly share code, notes, and snippets.

@fxposter
Created November 24, 2011 14:34
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fxposter/1391475 to your computer and use it in GitHub Desktop.
Save fxposter/1391475 to your computer and use it in GitHub Desktop.
Haml to ERB converter
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/features/_feature.html.haml'))
@the-teacher
Copy link

Thank you! Very helpful!

@mntdamania
Copy link

👍

@quartzmo
Copy link

This didn't work for me.

> haml_to_erb('%a{href: edit_user_path(current_user)}')
NameError: undefined local variable or method `current_user' for #<Object:0x007fa655770350>

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