Created
February 26, 2012 00:49
-
-
Save frank-who/1911952 to your computer and use it in GitHub Desktop.
Adding IE version specific class names to the <html> tag without using conditional comments.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# initializers/app_configuration.rb | |
# Browser object used for UserAgent comparison | |
Browser = Struct.new(:browser, :version) | |
# Render indented HTML in development mode | |
if Rails.env.development? | |
Slim::Engine.set_default_options pretty: true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doctype 5 | |
= html_tag do | |
head | |
meta charset="utf-8" | |
meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" | |
title Cool App | |
meta name="viewport" content="width=device-width" | |
= stylesheet_link_tag "application", media: "all" | |
= javascript_include_tag "modernizr" | |
= csrf_meta_tags | |
body | |
= javascript_include_tag "application" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
def html_tag(options={}, &block) | |
css = ["no-js"] | |
browser = UserAgent.parse(request.user_agent) | |
ie7 = Browser.new("Internet Explorer", "7.0") | |
ie8 = Browser.new("Internet Explorer", "8.0") | |
if browser < ie7 | |
css << ["oldie", "lt-ie7"] | |
elsif browser == ie7 | |
css << ["oldie", "ie7"] | |
elsif browser == ie8 | |
css << ["oldie", "ie8"] | |
end | |
output = ActiveSupport::SafeBuffer.new | |
output.safe_concat(tag(:html, {class: css, lang: I18n.default_locale}, true)) | |
output << capture(&block) | |
output.safe_concat("</html>") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem "slim" | |
gem "useragent" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment