-
-
Save n3bulous/1049177 to your computer and use it in GitHub Desktop.
switch haml to erb
This file contains hidden or 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
## 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