Rack::BodyClasses
Decorate your <body>
with CSS Classes indicating platform, browser, browser version, and more.
Project Status
Installation
Add this line to your application's Gemfile:
gem 'rack-body_classes'
And then execute:
$ bundle
Usage
First, add the middlware to your application...
Rack/Sinatra
use Rack::BodyClasses
Rails
config.middleware.use Rack::BodyClasses
Then, in your layout, output env['rack.body_classes']
in your <body>
tag's class
attribute.
Here's a trivial layout file, formatted with the slim
templating engine, to give you an example:
html
head
body class="#{env['rack.body_classes']}"
== yield
When rendered, the body tag will look something like this:
<body class="desktop chrome modern mac webkit">
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Shout Outs
This middleware is made possible by Browser
gem and MobileESP (converted)
gem and borrows a bit of code from Mobvious
gem. Mad props and many thank yous to these gem authors.