Created
October 19, 2010 23:28
-
-
Save rstacruz/635398 to your computer and use it in GitHub Desktop.
cc_html.rb
This file contains hidden or 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
# Implements the world-famous Paul Irish IE conditional comments HTML tag--in HAML. | |
# http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ | |
class Main | |
helpers do | |
def cc_html(options={}, &blk) | |
attrs = options.map { |(k, v)| " #{h k}='#{h v}'" }.join('') | |
[ "<!--[if lt IE 7 ]> <html#{attrs} class='ie6'> <![endif]-->", | |
"<!--[if IE 7 ]> <html#{attrs} class='ie7'> <![endif]-->", | |
"<!--[if IE 8 ]> <html#{attrs} class='ie8'> <![endif]-->", | |
"<!--[if IE 9 ]> <html#{attrs} class='ie9'> <![endif]-->", | |
"<!--[if (gt IE 9)|!(IE)]><!--> <html#{attrs}> <!--<![endif]-->", | |
capture_haml(&blk), | |
"</html>" | |
].join('') | |
end | |
def h(str) Rack::Utils.escape_html(str); end | |
end | |
end |
This file contains hidden or 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
!!! 5 | |
!= cc_html(:lang => 'en') do | |
%head | |
%meta(charset='UTF-8') | |
%title Hello! | |
%body | |
... |
This file contains hidden or 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 html> | |
<!--[if lt IE 7 ]> <html lang="en" class="ie6"> <![endif]--> | |
<!--[if IE 7 ]> <html lang="en" class="ie7"> <![endif]--> | |
<!--[if IE 8 ]> <html lang="en" class="ie8"> <![endif]--> | |
<!--[if IE 9 ]> <html lang="en" class="ie9"> <![endif]--> | |
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class=""> <!--<![endif]--> | |
<head> | |
<meta charset="utf-8"> | |
<title>Hello!</title> | |
</head> | |
<body> | |
... | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment