Following my previous post, below is a modified version of “John Nunemaker’s ‘Renaming RHTML to ERB’”:http://railstips.org/2007/3/4/renaming-rhtml-to-erb to take into account the format in the extension, and handle “the RJS issues I was having”:http://www.thelucid.com/articles/2007/05/16/rails-edge-view-file-extention-functionality-has-changed.
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 end
h4. Update
Added haml conversion.
8 comments ↓
Remember, we found that .html.erb, etc doesn’t seem to work with partials, so you should probably add in:
unless File.basename(file)[0].chr == ‘_’
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”:http://haml.hamptoncatlin.com
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.
Leave a Comment