Are there any (local) HTML validators for Ruby on Rails?

I looked around all day yesterday for a working HTML validator that I could use to validate the code generated by my rails application. So far, I have tried several different strategies, such as RailsTidy, which no longer work with Rails 1.9, tidy_ffi, which I had to “require” when running rails in the console and Total Validator FireFox Total Validator, which always gives me the same error, regardless from what I'm checking.

My goal is to check my code without downloading anything to the Internet. It would be very useful to be able to run tests from the terminal (I use RedHat Linux) or run tests on a running localhost server.

To save myself another day (or maybe more) from disappointment, I asked this question here, and I would like to know if anyone else worked successfully with the Ruby on Rails validator.

+7
source share
2 answers

Try my gem, html_acceptance . It uses HTML Tidy to perform validation under the hood. I did this a long time ago, but so far it has gone unnoticed. It was useful to me, and if you report problems / receive feature requests, I will be happy to look at them.

In the samples, I have a custom RSpec mapping, so if you add this custom matches, in your integration tests in specifications / queries you can:

page.should have_valid_html 

The idea is that you can use it in integration tests, and even if you get minor warnings / crashes that you don't need (for example, TIDY complains about some IE hacks), you can log in, accept them, and for now the result verification will be constant, the test will then pass.

In addition, you need to be careful on the way. So, OS X: install the htmltidy port or Ubuntu sudo apt-get install tidy port.

+4
source

I am working on a universal HTML / CSS validation stone for Ruby On Rails applications. This is the name Headhunter .

From the docs:

Headhunter is an HTML and CSS validation tool that embeds itself in Rails tags and automatically validates all your generated HTML and CSS.

In addition, it also searches for unused (and therefore redundant) CSS selectors.

All you have to do is add the gem 'headhunter' to your gemfile in a test environment:

 group :test do gem 'headhunter' end 

Everything else is done automatically for you, and you will get statistics for your application at the end of your tests, for example:

 Validated 42 HTML pages. 41 pages are valid. 1 page is invalid. Open .validation/results.html to view full results. Validated 1 stylesheets. 1 stylesheet is invalid. application.css: - Invalid css: line 1: Property bla doesn't exist Found 23 CSS selectors. 20 selectors are in use. 3 selectors are not in use: a img, #flash.failure, input[type='file'] 
+2
source

All Articles