Created
February 25, 2012 12:36
-
-
Save frank-who/1908327 to your computer and use it in GitHub Desktop.
View helper for adding IE conditional classes to the <html> tag.
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 | |
= ie_conditional_classes 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 ie_conditional_classes(options={}, &block) | |
content = capture(&block) | |
output = ActiveSupport::SafeBuffer.new | |
versions = ["lt IE 7", "IE 7", "IE 8", "gt IE 8"] | |
versions.each do |version| | |
default = version == versions.last | |
css_class = default ? nil : version.gsub(/IE /,"ie").gsub(/ /,"-") | |
html_tag = tag(:html, {class: ["no-js", css_class].compact, lang: "en"}, true) | |
output.safe_concat("<!--[if #{version}]>#{default ? "<!-->" : nil} #{html_tag} #{default ? "<!--" : nil}<![endif]-->\n") | |
end | |
output << content | |
output.safe_concat("\n</html>") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment