0

There are a few of us working on a Ruby on Rails project. We have ~10K lines of code. One of the main issues we are having right now is that in some places, the code looks very messy. At times, some of us used Emacs without tabs being set to 2 spaces. At other times, we have code from interns, etc that is just not properly indented.

Basically, I have some very ugly looking code - in .rb files and in .html.erb files. I would like to autoindent these as easily as possible.

I know there are some tools that facilitate this for C++, but I can't seem to find one that would do the job for RoR.

In case I'm not being totally clear, all I want to cleanup is the formatting/indentation of my code:

<% if @test %>
<div class = "test">hello</div>
<% else %>
<div class = "boo">foo</div>
<% end %>

becomes

<% if @test %>
  <div class = "test">hello</div>
<% else %>
  <div class = "boo">foo</div>
<% end %>

Any ideas on how I can do this?

user229044
  • 232,980
  • 40
  • 330
  • 338
Ringo Blancke
  • 2,444
  • 6
  • 30
  • 54
  • Possible duplicate of http://stackoverflow.com/questions/9103874/coding-style-checker-or-code-formatter-for-ruby-rails – LanguagesNamedAfterCofee Jul 11 '12 at 17:39
  • yeah but sadly none of those have any definitive answers and are from a while back. I'm not sure what the stackoverflow policy is on such things, but please see my own answer below: the two tools I suggested seem to be the best for what I'm trying to do, but none of the older posts on this topic suggested them. Want to make sure people who seek out this info aren't just shoved to posts without relevant answers! – Ringo Blancke Jul 11 '12 at 18:55
  • True, sorry for the misunderstanding – LanguagesNamedAfterCofee Jul 11 '12 at 19:55
  • Do you know regular expressions? You could write a very quick script in any language that supports them to indent lines beginning with `
    – KChaloux Jul 11 '12 at 21:05
  • If you're looking for an example, this would indent your non-indented
    lines by 2 spaces. http://pastie.org/4240122
    – KChaloux Jul 11 '12 at 21:18

2 Answers2

0

If you only care about indentation then emacs does it very well

C-x h C-M-\
kn330
  • 542
  • 3
  • 18
0

I have found some potentially relevant tools - if someone has used these, please let me know!

for ERB cleanup: http://coderack.org/users/webficient/middlewares/38-racktidy

for ruby cleanup: http://www.arachnoid.com/ruby/rubyBeautifier.html

Ringo Blancke
  • 2,444
  • 6
  • 30
  • 54