Cleaning Rails' ugly HTML output

is there a way of cleaning rails’ html output? by default, it looks
real ugly (in terms of indentation), and i don’t know how people can
live with that. there is rails-tidy, and although it makes html really
pretty, setting it up involves some tricky workarounds, and the author
also commented:

“THIS IS CERTAINLY A RESOURCE HOG. I’m not interrested in this feature
so I didn’t benchmarked it but at first sight rendering is at least 2
times slower with the filter enabled.”?

is there anything better out there?

If it renders fine in a browser, who cares what it looks like under the hood?

That being said, haml as a replacement for erb, produces some nicely
formatted html if you’re into viewing page source. It may have been a
goal of the author, but I just like the cleaner forms I have to produce.

On 17 Apr 2008, at 13:44, Mister Blood R. wrote:

is there anything better out there?

From my fuzzy memories of when I saw a session about haml a year or 2
ago it was one of its goals.

Fred

shudder

XHTML:
Hello, World!

Haml:
%small{:class => “code”, :id => “message”} Hello, World!

Seems less gorgeous to me… >_> I like my rhtml. Although I dunno how
your output doesn’t look nice, mine does. Perhaps you’re using tags
I’m not.

Yeah HAML is gorgeous, however, it’s whitespace sensitive making it
impossible for me to join things that should be joined.

On Apr 17, 8:52 pm, Frederick C. [email protected]

I just think good design should flow through every aspect of an app…

In all seriousness, I’ve been doing web programming for a long time. If
I’m
generating HTML from a web application, I just don’t care what the
rendered
HTML code looks like, and I can’t figure out why people do. This isn’t
the
first time I’ve seen this question, so am I missing something? If it
validates, and it renders, then does it matter?

How about (HAML):

%small#message.code Hello, World! === Hello, World!

Now that’s gorgeous. I know which I’d rather type.
You only need to use the hash braces if you’re doing something more
conditional, and then you can just put it in a helper and call the
method

e.g.

%small{choose_class(somevar)} Hello, World!

def choose_class(somevar)
{:class => somevar ||= ‘default’, :id => ‘message’}
##approximately, untested!
end

I agree the 2-space indenting can be a pain, well it was till i
discovered my text editor did multi-line select.

HAML rules, and SASS makes CSS like it should be :wink:

Each to their own though…

I just look at it in firebug to see the layout. Much easier that
dealing with the raw source and links the css nicely as well.

Fundamentally in Rails, it is how clean the ERB is to look at rather
than the HTML. You don’t take a C program and then complain that the
assembler output from the compiler is not very pretty.

Wildtangent wrote:

Each to their own though…

Agreed… my standard indentation in Rails (controllers, models,
helpers, etc) is 2 spaces, so doing that for the views is just second
nature (be it erb or haml)… but I’m a lazy bastidge at heart, so if
indentation can imply all those closing tags and the view code is less
for my poor brain to process, I’m all for it.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs