Print CSS for Rails and a print link helper
Posted on January 29, 2014
A while back How About We for Couples launched gift memberships and we needed a way to allow the buyer to print something for the person they were giving it to.
“No problem,” I thought – we’ll use a print stylesheet!
Turns out there was a bit more to it than that.
Basically, there is really no good semantic way to create print-only or no-print-only styles. Compass has built-in print styles or you can easily roll your own.
In addition, browsers automatically convert links to TEXT(url) when printing a web page. This is awesome … unless the text is the url. Then it looks terrible. Note: there was a lot of misdirection when googling this. Apparently, browsers didn’t always convert links in this way and most searches come up with CSS to create this. Ignore those.
An application helper
Cuz really who wants to do this every time.
And what kind of devs would we be without tests?
With Compass
Without Compass
Happy printing
The full gist is here.
Got something to say?