Rails Edge: Getting your view extensions ready for edge

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
end

Update

Added haml conversion.

Tags: , , , ,

8 comments ↓

#1 Andy on 05.16.07 at 6:00 pm

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

#2 Jamie on 05.16.07 at 6:29 pm

Good, point. Changed the Dir.glob’s so that they don’t get anything that starts with an underscore.

#3 mattc on 06.27.07 at 9:00 am

as of REV 7136, the issue Andy raised has been resolved. .html.erb works fine for partials as well

#4 Jamie on 07.02.07 at 2:33 am

mattc: Thanks for the heads up on that one.

#5 Sam on 07.06.07 at 1:00 am

Nice converting script. It’s just a shame you’re not converting to HAML ;)

#6 Jamie Hill on 07.25.07 at 12:31 am

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.

#7 Brett on 08.03.07 at 6:44 am

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

#8 Jamie Hill on 08.03.07 at 12:50 pm

Brett: A sake script makes sense, I’ve not installed it yet. I have amended the post to include .haml conversion.

Leave a Comment