A plugin based on the css_browser_selector to add the browser type and os to either the body and/or html elements within a document. The full usage on how to use these css selectors can be understood at:
Major Props to Rafael Lima (from above link) who implemented this JS and has helped me with the plugin.
To add css_browser_selectors to your body tag in your layout (make sure you don't output the content with +<%= %>+ or you may end up with double content). Do the following:
<% body do %> <%= yield %> <% end %> This will render, depending on your user agent string: <body class="gecko mac"> <div>This is a test</div> </body>
You may pass any html_options as you would expect:
<% body :onload => "alert('yo')" do %> <%= yield %> <% end %>
<body class="gecko mac" onload="alert('yo')"> <div>This is a test</div> </body>
<% html do %> <head> <title>Example</title> </head> <body> <%= yield %> </body> <% end %>
Renders, by default, with the following attributes (which may be overriden by passing options):
<html class="gecko mac" xmlns="http://www.w3.org/1999/xhtml" xml:lang=>"en" lang=>"en"> <head> <title>Example</title> </head> <body> <div>This is a test</div> </body> </html>
Renders, as you would expect:
You can pass the css_browser_selector a string or symbol of the tag in which to place the selectors ('html' is the default):
Changes this line in the script:
If you enjoy the Window.addLoadEvent function and wish to use it alone, as a convenience you can:
For those who wish to use the html and body content tags but wish to turn off the css_browser_selectors you can turn them off. For example, if you are using both helpers:
<% html :exclude_browser_and_os => true do %> <head> <title>Example</title> </head> <% body do %> <%= yield %> <% end %> <% end %>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang=>"en" lang=>"en"> <head> <title>Example</title> </head> <body class="gecko mac"> <div>This is a test</div> </body> </html>
CssBrowserSelector keeps track of all the actions that each controller lists in caches_page in a class attribute called page_cached_actions. Each controller instance will have a method called page_cached? to determine if the action was listed in caches_page and honors the perform_caching configuration.
Currently, it does not keep track of actions cached directly through cache_page, but could be extended in the future to handle this need. Additionally, it does not track action_caching which could also be added at a later time.
Both the page_cached_action class variable and page_cached? instance method are added by the +ActionController::CachingTracker+ module and can be accessed from anywhere you can get a reference to a controller:
CustomController.page_cached_actions #=> ["new", "show"] controller.page_cached_actions #=> ["new", "show"] controller.page_cached? #=> true if perform_caching is true and is action_name in page_cached_actions
Copyright © 2008 Los Angeles Times (www.latimes.com) released under the MIT license