Rails Edge: Getting your view extensions ready for edge
Posted by jamie Wed, 16 May 2007 13:07:00 GMT
Following my previous post, below is a modified version of John Nunemaker’s ‘Renaming RHTML to ERB’ to take into account the format in the extension, and handle the RJS issues I was having.
namespace 'views' do
desc 'Renames all .rhtml views to .html.erb, .rjs to .js.rjs, .rxml to .xml.builder and .haml to .html.haml'
task 'rename' do
Dir.glob('app/views/**/[^_]*.rhtml').each do |file|
puts `svn mv #{file} #{file.gsub(/\.rhtml$/, '.html.erb')}`
end
Dir.glob('app/views/**/[^_]*.rjs').each do |file|
puts `svn mv #{file} #{file.gsub(/\.rjs$/, '.js.rjs')}`
end
Dir.glob('app/views/**/[^_]*.rxml').each do |file|
puts `svn mv #{file} #{file.gsub(/\.rxml$/, '.xml.builder')}`
end
Dir.glob('app/views/**/[^_]*.haml').each do |file|
puts `svn mv #{file} #{file.gsub(/\.haml$/, '.html.haml')}`
end
end
endUpdate
Added haml conversion.

Remember, we found that .html.erb, etc doesn’t seem to work with partials, so you should probably add in:
after each puts line so it doesn’t effect partials
Good, point. Changed the Dir.glob’s so that they don’t get anything that starts with an underscore.
as of REV 7136, the issue Andy raised has been resolved. .html.erb works fine for partials as well
mattc: Thanks for the heads up on that one.
Nice converting script. It’s just a shame you’re not converting to HAML ;)
Sam: I can’t say as I’m keen on HAML, all those opening tags but no closing tags feels weird.
Perhaps I should give it more of a chance.
Here is a sake script created from your rake task that includes all of the original plus the .haml => .html.haml conversion.
sake -i http://pastie.caboo.se/84585.txt
Brett: A sake script makes sense, I’ve not installed it yet. I have amended the post to include .haml conversion.