Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
User-Agent to CSS parser for ruby
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.gitignore
.travis.yml
Gemfile
MIT-LICENSE
README.md
Rakefile
useragent2css.gemspec

README.md

User-Agent to CSS Build Status Dependency Status

Parse an HTTP User-Agent header string and get a bunch of CSS classes back identifying the browser and OS of the client. That's it. Nothing more.

Why determine this on the server instead of on the client using javascript?

Because the javascript code will run after the browser has already started rendering the HTML code. By having the appropriate CSS classes injected in the HTML source as early as possible, the browser will render faster and slow browsers will not 'flicker'.

Installation and Usage

If you use Rails, add this to your Gemfile:

gem 'useragent2css'

In your view code, e.g.:

<body class="<%= useragent2css %>">

Example result:

<body class="webkit chrome chrome16 mac">

Or:

gem install useragent2css

And in your view code, e.g.:

<body class="<%= UserAgent.css(request["HTTP_USER_AGENT"]) %>">

Thanks

Rafael Lima - for the original javascript implementation.

LATimes - for the original ruby implementation.

Author

Lawrence Pit, lawrence.pit@gmail.com, lawrencepit.com, @lawrencepit

Copyright

Copyright (c) 2012 Lawrence Pit. See MIT-LICENSE for details.

Something went wrong with that request. Please try again.