Created
July 8, 2011 19:37
-
-
Save noelrappin/1072630 to your computer and use it in GitHub Desktop.
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
# from the erb2haml gem by David Leung | |
# copied to a gist for easier integration into our Rails 2 training | |
require 'find' | |
RED_FG ="\033[31m" | |
GREEN_FG = "\033[32m" | |
END_TEXT_STYLE = "\033[0m" | |
# Helper method to inject ASCII escape sequences for colorized output | |
def color(text, begin_text_style) | |
begin_text_style + text + END_TEXT_STYLE | |
end | |
namespace :haml do | |
desc "Perform bulk conversion of all html.erb files to Haml in views folder." | |
task :convert_erbs do | |
if `which html2haml`.empty? | |
puts "#{color "ERROR: ", RED_FG} Could not find " + | |
"#{color "html2haml", GREEN_FG} in your PATH. Aborting." | |
exit(false) | |
end | |
puts "Looking for #{color "ERB", GREEN_FG} files to convert to " + | |
"#{color("Haml", RED_FG)}..." | |
Find.find("app/views/") do |path| | |
if FileTest.file?(path) and path.downcase.match(/\.html\.erb$/i) | |
haml_path = path.slice(0...-3)+"haml" | |
unless FileTest.exists?(haml_path) | |
print "Converting: #{path}... " | |
if system("html2haml", path, haml_path) | |
puts color("Done!", GREEN_FG) | |
File.delete(path) | |
else | |
puts color("Failed!", RED_FG) | |
end | |
end | |
end | |
end | |
end #End rake task | |
end # End of :haml namespace | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment