attilagyorffy.com

Local HTML validation using Docker

Introduction

Attila Györffy

Attila Györffy

I'm a Ruby/JS dev/trainer with a focus on quality. An ex-Londoner, @terracycle, @ubxd, @lastfm. Follow me at http://twitter.com/attilagyorffy


html5 validation w3c docker

Local HTML validation using Docker

Posted by Attila Györffy on .
Featured

html5 validation w3c docker

Local HTML validation using Docker

Posted by Attila Györffy on .

I’m not going to lie, I’m a purist. Even though browsers are very capable of handling our mistakes when it comes down to markup, I always thought that if my markup is wrong then there must be some deeper underlying problem.

When you work with Rails applications the be_valid_asset gem is there to help. It connects to the official W3C validator service to check your markup.

But what happens when you are on the road or have a flakey Internet connection? Surely when the network is down for some reason you don’t want your specs to fail.

It’s not quite obvious but the Validator Service can be installed locally. There are ways to install it on Mac OS X but it’s a bit fiddly and not immediately obvious how to do it. Enter Docker.

Docker W3C/HTML5 validator instance

Luckily someone has already done the bulk of the work and packaged this service up in the form of a html5validator docker container. I have Kitematic installed on my machine so I just pulled down a container instance:

Kitematic running the html5validator container
Kitematic

Visual Docker Container Management on Mac

This will pull down a container, start it and forward a port to the validator service running in the container. All we need to do is to find out what port is used. You can take a look at ‘Ports’ under the ‘Settings’ tab:

Checking port allocations in Kitematic
Validator running in a container

Find the host and port number to the container running the validator instance.

In my example above, docker is configured to use the default machine with IP 192.168.99.100. The container runs within this virtual machine and the Apache2 service inside it is exposed to us on port 32770.

You can open 192.168.99.100:32770 from your browser to see it running. The Validator Service API is running at the /check path which means we can configure our validators to connect to the following URL:

http://192.168.99.100:32770/check

Configure BeValidAsset to use our local container

We’ve built the be_valid_asset gem to be configurable and therefore you can specify the URL that the RSpec matcher will connect to:

For further configuration, please see the README.


Disclaimer:

Attila Györffy

Attila Györffy

https://attilagyorffy.com

I'm a Ruby/JS dev/trainer with a focus on quality. An ex-Londoner, @terracycle, @ubxd, @lastfm. Follow me at http://twitter.com/attilagyorffy

View Comments...