Skip to content

Instantly share code, notes, and snippets.

@geirarne
Created November 3, 2011 17:58
Show Gist options
  • Save geirarne/1337213 to your computer and use it in GitHub Desktop.
Save geirarne/1337213 to your computer and use it in GitHub Desktop.
Helper for HTML5 Boilerplate-style IE conditionals in Middleman with HAML. Thanks to http://ricostacruz.com/2010/haml_and_ie_compatibility.html
helpers do
def conditional_html(opts={}, &blk)
attrs = opts.map { |(k, v)| " #{h k}='#{h v}'" }.join('')
[ "<!--[if lt IE 7 ]> <html#{attrs} class='ie6 no-js oldie'> <![endif]-->",
"<!--[if IEMobile 7 ]> <html#{attrs} class='iemob7 no-js oldie'> <![endif]-->",
"<!--[if IE 7 ]> <html#{attrs} class='ie7 no-js oldie'> <![endif]-->",
"<!--[if IE 8 ]> <html#{attrs} class='ie8 no-js oldie'> <![endif]-->",
"<!--[if IE 9 ]> <html#{attrs} class='ie9 no-js oldie'> <![endif]-->",
"<!--[if (gt IE 9)|!(IE)]><!--> <html#{attrs} class='no-js'> <!--<![endif]-->",
capture_haml(&blk).strip,
"</html>"
].join("\n")
end
end
!!! 5
!= conditional_html(:lang => 'no-NB') do
%head
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment