Quartermaster
A collection of shortcuts and helpers for leveraging a request’s env in Rails, such as including a browser-specific stylesheet if one exists or putting a short version of the user agent in the CSS classes of the body tag.
This eliminates the need for most hacks or conditional comments since you can now get browser-specific with your CSS rules (ex. body.ie6 div { ... })
Features
- Short user agents for major browsers
- Detect and include browser-specific stylesheets
- Add short user agent to CSS classes which includes OS and browser info
Installation
sudo gem install quartermaster
Examples
Example 1: Including classes in the body tag of an HTML layout when making a request with IE6/Win:
Results in:
Example 2: Including browser-specific stylesheets, using Firefox 2 and a stylesheet at public/stylesheets/browsers/firefox2.css. Quartermaster only includes stylesheets if they actually exist. It will look for stylesheets for the base browser – ‘firefox’ – as well as version-specific – ‘firefox2’:
Results in:
Caveats
A major drawback of the current implementation of user_agent_for_css (which places the short user agent into the CSS classes of the body tag) is that it can’t be used (meaningfully) for cached pages. None of the sites it’s been used on do full-page caching so I haven’t had the need to change it. A future version will move this specific feature client-side with Javascript. Patches are welcome.
Another trade-off if you’re using stylesheet_link_tag_for_browser is that you have multiple stylesheet requests. If you want to consolidate your requests per page, don’t use stylesheet_link_tag_for_browser and instead use a combination of user_agent_for_css and body.<short user agent> in your rules