in reply to Re^2: IE specific conditional comments in header of CGI.pm
in thread IE specific conditional comments in header of CGI.pm
well, you're saying that there is no way, right?
I think he's saying you have to write it, but its better to switch to templates as early as possible, because the alternative is this
monkeypatching one of CGI.pm's very complicated html generation subroutines, no test written for test suite
#!/usr/bin/perl -- use strict; use warnings; use CGI; print CGI->new->start_html( -title => 'searc http://invertor.ru', -author => '@pashanoid', -base => 'true', -meta => { 'keywords' => 'invertor ups search solar wind alternative ene +rgy', 'copyright' => 'MicroART' }, -style => [ { 'src' => '/styles/invertor.css' }, { 'src' => '/styles/ie1.css', 'endif' => 'if lte IE 6' } ], -lang => 'ru-RU', -encoding => 'windows-1251', ); ### Method: _style # internal method for generating a CSS style section #### #~ '_style' => <<'END_OF_FUNC', ## MONKEYPATCHING sub CGI::_style { package CGI; use vars '$XHTML'; my ( $self, $style ) = @_; use DDS; Dump($style); my (@result); my $type = 'text/css'; my $rel = 'stylesheet'; my $cdata_start = $XHTML ? "\n<!--/* <![CDATA[ */" : "\n<!-- "; my $cdata_end = $XHTML ? "\n/* ]]> */-->\n" : " -->\n"; my @s = ref($style) eq 'ARRAY' ? @$style : $style; my $other = ''; for my $s (@s) { if ( ref($s) ) { use DDS; Dump({"WTF", $s, }); my $endif = delete $s->{endif}; my ( $src, $code, $verbatim, $stype, $alternate, $foo, @ot +her ) = rearrange( [qw(SRC CODE VERBATIM TYPE ALTERNATE FOO)], ( '-foo' => 'bar', ref($s) eq 'ARRAY' ? @$s : %$s ) ); use DDS; Dump({ qw{$src} => $src, qw{$code} => $code, qw{$verbatim} => $verbatim, qw{$stype} => $stype, qw{$alternate} => $alternate, qw{$foo} => $foo, qw{@other} => \@other, }); my $type = defined $stype ? $stype : 'text/css'; my $rel = $alternate ? 'alternate stylesheet' : 'styleshee +t'; $other = "@other" if @other; if ( ref($src) eq "ARRAY" ) # Check to see if the $src variable is an array ref +erence { # If it is, push a LINK tag for each one for $src (@$src) { push( @result, $XHTML ? qq(<link rel="$rel" type="$type" href="$src" + $other/>) : qq(<link rel="$rel" type="$type" href="$src" +$other>) ) if $src; $src and $endif and $result[-1] = sprintf "<!--[%s +]>\n%s\n<![endif]-->", $endif, $result[-1]; } } else { # Otherwise, push the single -src, if it exists. push( @result, $XHTML ? qq(<link rel="$rel" type="$type" href="$src" $ot +her/>) : qq(<link rel="$rel" type="$type" href="$src"$oth +er>) ) if $src; $src and $endif and $result[-1] = sprintf "<!--[%s]>\n +%s\n<![endif]-->", $endif, $result[-1]; } if ($verbatim) { my @v = ref($verbatim) eq 'ARRAY' ? @$verbatim : $verb +atim; push( @result, "<style type=\"text/css\">\n$_\n</style +>" ) for @v; } my @c = ref($code) eq 'ARRAY' ? @$code : $code if $code; push( @result, style( { 'type' => $type }, "$cdata_start\n$_\n$cdata_ +end" ) ) for @c; } else { my $src = $s; push( @result, $XHTML ? qq(<link rel="$rel" type="$type" href="$src" $other/ +>) : qq(<link rel="$rel" type="$type" href="$src"$other>) + ); } } @result; } __END__ $ARRAY1 = [ { src => '/styles/invertor.css' }, { endif => 'if lte IE 6', src => '/styles/ie1.css' } ]; $HASH1 = { WTF => { src => '/styles/invertor.css' } }; $HASH1 = { "\$alternate" => undef, "\$code" => undef, "\$foo" => 'bar', "\@other" => [], "\$src" => '/styles/invertor.css', "\$stype" => undef, "\$verbatim" => undef }; $HASH1 = { WTF => { endif => 'if lte IE 6', src => '/styles/ie1.css' } }; $HASH1 = { "\$alternate" => undef, "\$code" => undef, "\$foo" => 'bar', "\@other" => [], "\$src" => '/styles/ie1.css', "\$stype" => undef, "\$verbatim" => undef }; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="ru-RU" xml:lang="ru-R +U"> <head> <title>searc http://invertor.ru</title> <link rev="made" href="mailto:%40pashanoid" /> <base href="http://localhost" /> <meta name="keywords" content="invertor ups search solar wind alternat +ive energy" /> <meta name="copyright" content="MicroART" /> <link rel="stylesheet" type="text/css" href="/styles/invertor.css" /> <!--[if lte IE 6]> <link rel="stylesheet" type="text/css" href="/styles/ie1.css" /> <![endif]--> <meta http-equiv="Content-Type" content="text/html; charset=windows-12 +51" /> </head> <body>
I suppose it might be more genetic to accept
but whatever :){ 'src' => '/styles/ie1.css', -wrapp => [ '<!--[if lte IE 6]>', '<![endif]-->' ], },
|
|---|