Skip to content

Instantly share code, notes, and snippets.

@jhafner
Created November 27, 2012 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhafner/4157425 to your computer and use it in GitHub Desktop.
Save jhafner/4157425 to your computer and use it in GitHub Desktop.
Conditional HTML Classes in Haml Helper
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