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
end

Update

Added haml conversion.

Posted in , , ,  | Tags , , , ,  | 8 comments

Comments

  1. Avatar Andy said about 4 hours later:

    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. Avatar Jamie said about 4 hours later:

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

  3. Avatar mattc said about 1 month later:

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

  4. Avatar Jamie said about 1 month later:

    mattc: Thanks for the heads up on that one.

  5. Avatar Sam said about 1 month later:

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

  6. Avatar Jamie Hill said 2 months later:

    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. Avatar Brett said 3 months later:

    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. Avatar Jamie Hill said 3 months later:

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

(leave url/email »)

   Comment Markup Help Preview comment