Skip to content

Instantly share code, notes, and snippets.

@geirarne
Created November 13, 2012 14:22
Show Gist options
  • Save geirarne/4065995 to your computer and use it in GitHub Desktop.
Save geirarne/4065995 to your computer and use it in GitHub Desktop.
use this as a helper method.
def conditional_html(options={}, &blk)
attrs = options.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) & !(IEMobile 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
@geirarne
Copy link
Author

call it like this in the layout:
!= conditional_html(:lang => I18n.locale) do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment