Created
November 27, 2012 21:59
-
-
Save jhafner/4157425 to your computer and use it in GitHub Desktop.
Conditional HTML Classes in Haml Helper
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 conditional_html( lang = "en", &block ) | |
haml_concat Haml::Util::html_safe <<-"HTML".gsub( /^\s+/, '' ) | |
<!--[if lt IE 7 ]> <html lang="#{lang}" class="no-js ie6"> <![endif]--> | |
<!--[if IE 7 ]> <html lang="#{lang}" class="no-js ie7"> <![endif]--> | |
<!--[if IE 8 ]> <html lang="#{lang}" class="no-js ie8"> <![endif]--> | |
<!--[if IE 9 ]> <html lang="#{lang}" class="no-js ie9"> <![endif]--> | |
<!--[if (gte IE 9)|!(IE)]><!--> <html lang="#{lang}" class="no-js"> <!--<![endif]--> | |
HTML | |
haml_concat capture( &block ) << Haml::Util::html_safe( "\n</html>" ) if block_given? | |
end | |
# Usage in your layout file: | |
# - conditional_html | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment