Forum: Ruby on Rails Beatify html?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
92219cfdc7be3f0b854b05f76f3d34e3?d=identicon&s=25 alex (Guest)
on 2007-04-26 01:46
(Received via mailing list)
Is there any way to beatify the html that is emitted?  Some of the
html that I generate dynamically is poorly formatted, and it would be
somewhat difficult to make it pretty (particularly in the context of
the static html that surrounds it).  It there a mechanism by which I
can (for debugging purposes at least) beatify the final html?

For example, is there a hook that allows one to intercept the
generated html and apply final processing before emitting it?

Or perhaps there is an option in the Webrick server to beatify the
output?

Or perhaps something else?

Thanks,
Alex
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2007-04-26 05:50
(Received via mailing list)
alex wrote:

> Is there any way to beatify the html that is emitted?

Get Tidy, and run this assertion from your functional tests:

  def assert_tidy(messy = @response.body, verbosity = :noisy)
    scratch_html = RAILS_ROOT + '/../scratch.html'  #  TODO  tune me!
    File.open(scratch_html, 'w'){|f|  f.write(messy)  }
    gripes = `tidy -eq #{scratch_html} 2>&1`
    gripes.split("\n")
    exclude, inclued = gripes.partition do |g|
      g =~ / - Info\: / or
      g =~ /Warning\: missing \<\!DOCTYPE\> declaration/ or
      g =~ /proprietary attribute/ or
      g =~ /lacks "(summary|alt)" attribute/
    end
    puts inclued if verbosity == :noisy
    # inclued.map{|i| puts Regexp.escape(i) }
    assert_xml `tidy -wrap 1001 -asxhtml #{scratch_html} 2>/dev/null`
      #  CONSIDER  that should report serious HTML deformities
  end

You can take out the assert_xml if you don't have yar_wiki (whence that
comes).

The system will push a scratch.html file into your parent folder, and if
the
errors Tidy reports are not utterly trivial, it will barf them out when
your
tests run.

When upgrading old websites to Rails I always run things through
Tidy -i -asxhtml, before inserting the <%%> tags. The difference in
development speed is astounding, when I don't need to count the freakin'
tags just to nest everything correctly.

My Short Cut with O'Reilly has lots more tips on keeping the HTML clean.

    http://www.oreilly.com/catalog/9780596510657

--
  Phlip
  http://flea.sourceforge.net/PiglegToo_1.html
8bc543795b502900b5333aea73ad5533?d=identicon&s=25 Eden Li (edenli)
on 2007-04-26 05:51
(Received via mailing list)
You could switch to markaby which makes you write everything in Ruby
(akin to XmlBuilder) and emits pretty HTML (I'm pretty sure).

 http://redhanded.hobix.com/inspect/markabyForRails.html

Having "beautiful" HTML code means very little for a user of your site
though...
C851541a809039c068400a97ddbf5a64?d=identicon&s=25 Dustin Tinney (tinney)
on 2007-04-27 00:08
(Received via mailing list)
haml will give you perfect html output.

http://haml.hamptoncatlin.com/

/Dustin
92219cfdc7be3f0b854b05f76f3d34e3?d=identicon&s=25 alex (Guest)
on 2007-04-27 00:50
(Received via mailing list)
Thanks to everybody for the helpful responses.

> Having "beautiful" HTML code means very little for a user of your site
> though...

It is useful to me when I examine my output.
This topic is locked and can not be replied to.