A user agent parser, primarily designed to easily deliver browser-based css overrides.
Many limitations. No nice syntactic sugar. No seperation of browser names and
their versions. No support for browser forks (e.g. AOL, Iceweasel, etc.)
Also bear in mind that this approach will not be appropriate for everyone.
I like to use:
spec spec/**/* --format=nested
The —format=nested is entirely optional, but it gives you a good overview of the
supported browsers.
Currently, the usage is fairly basic, and reflects very basic requirements. It will be improved in time.
To install these facilities into a rails project, give the following command
from RAILS_ROOT (Git is required):
script/plugin install git://github.com/eshopworks/user_agent_stylesheets.git
In a helper:
def browser_stylesheet_tag parser = UserAgent::Parser.new(request.user_agent) stylesheet = "" stylesheet = "opera" if parser.browser == :opera stylesheet = "safariWin" if parser.browser == :safari && parser.operating_system == :windows stylesheet = "safari" if parser.browser == :safari && parser.operating_system == :mac stylesheet = "chrome" if parser.browser == :chrome stylesheet = "firefox" if parser.browser == :firefox stylesheet = "firefoxMac" if parser.browser == :firefox && parser.operating_system == :mac stylesheet = "ie6" if parser.browser == :ie6 stylesheet = "ie7" if parser.browser == :ie7 stylesheet = "ie8" if parser.browser == :ie8 stylesheet_link_tag(stylesheet) if(parser.browser != "") end
… then in your view:
stylesheet_link_tag :defaults, :cache => true
browser_stylesheet_tag
Matthew Bennett <matthew@eshopworks.co.uk>
(The MIT License)
Copyright© 2009 eShopworks LTD
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.