Created
November 24, 2011 14:34
-
-
Save fxposter/1391475 to your computer and use it in GitHub Desktop.
Haml to ERB converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
👍
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
Thank you! Very helpful!