{"thread":{"id":"4589","subject":"[PATCH] gitweb: style done with stylesheet","startedAt":"2006-06-20T14:58:12Z","lastAt":"2006-06-20T14:58:12Z","messageCount":1,"participants":["Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"22142","messageId":"11508154583352-git-send-email-jnareb@gmail.com","threadId":"4589","inReplyTo":null,"subject":"[PATCH] gitweb: style done with stylesheet","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-06-20T14:58:12Z","receivedAt":"2006-06-20T14:58:12Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Replace (almost) all 'style' attributes with 'class' attribute\nand adding rule to CSS file. Some tables use CSS for styling\ninstead of legacy styling attributes.\n\n---\nThis patch needs readable CSS style file gitweb/gitweb.css\nintroduced in previous patch.\n\nIt applies on top of next.\n\n gitweb/gitweb.cgi |   80 ++++++++++++++++++++++--------------------\n gitweb/gitweb.css |  101 ++++++++++++++++++++++++++++++++++++++++++++++++++---\n 2 files changed, 136 insertions(+), 45 deletions(-)\n\neaa8afc21044fcce134777b35bdcfb3e97f8ab8f\ndiff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi\nindex 1b254df..89224e6 100755\n--- a/gitweb/gitweb.cgi\n+++ b/gitweb/gitweb.cgi\n@@ -252,6 +252,19 @@ sub unquote {\n \treturn $str;\n }\n \n+# CSS class for given age value (in seconds)\n+sub age_class {\n+\tmy $age = shift;\n+\n+\tif ($age < 60*60*2) {\n+\t\treturn \"age0\";\n+\t} elsif ($age < 60*60*24*2) {\n+\t\treturn \"age1\";\n+\t} else {\n+\t\treturn \"age2\";\n+\t}\n+}\n+\n sub git_header_html {\n \tmy $status = shift || \"200 OK\";\n \tmy $expires = shift;\n@@ -600,13 +613,13 @@ sub git_diff_print {\n \t\twhile (my $line = <$fd>) {\n \t\t\tchomp($line);\n \t\t\tmy $char = substr($line, 0, 1);\n-\t\t\tmy $color = \"\";\n+\t\t\tmy $diff_class = \"\";\n \t\t\tif ($char eq '+') {\n-\t\t\t\t$color = \" style=\\\"color:#008800;\\\"\";\n+\t\t\t\t$diff_class = \" add\";\n \t\t\t} elsif ($char eq \"-\") {\n-\t\t\t\t$color = \" style=\\\"color:#cc0000;\\\"\";\n+\t\t\t\t$diff_class = \" rem\";\n \t\t\t} elsif ($char eq \"@\") {\n-\t\t\t\t$color = \" style=\\\"color:#990099;\\\"\";\n+\t\t\t\t$diff_class = \" chunk_header\";\n \t\t\t} elsif ($char eq \"\\\\\") {\n \t\t\t\t# skip errors\n \t\t\t\tnext;\n@@ -617,7 +630,7 @@ sub git_diff_print {\n \t\t\t\t\t$line =~ s/\\t/$spaces/;\n \t\t\t\t}\n \t\t\t}\n-\t\t\tprint \"<div class=\\\"pre\\\"$color>\" . esc_html($line) . \"</div>\\n\";\n+\t\t\tprint \"<div class=\\\"diff$diff_class\\\">\" . esc_html($line) . \"</div>\\n\";\n \t\t}\n \t}\n \tclose $fd;\n@@ -849,7 +862,7 @@ sub git_project_list {\n \t\tclose $fd;\n \t\tprint \"</div>\\n\";\n \t}\n-\tprint \"<table cellspacing=\\\"0\\\">\\n\" .\n+\tprint \"<table class=\\\"project_list\\\">\\n\" .\n \t      \"<tr>\\n\";\n \tif (!defined($order) || (defined($order) && ($order eq \"project\"))) {\n \t\t@projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;\n@@ -888,15 +901,7 @@ sub git_project_list {\n \t\tprint \"<td>\" . $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$pr->{'path'};a=summary\"), -class => \"list\"}, esc_html($pr->{'path'})) . \"</td>\\n\" .\n \t\t      \"<td>$pr->{'descr'}</td>\\n\" .\n \t\t      \"<td><i>\" . chop_str($pr->{'owner'}, 15) . \"</i></td>\\n\";\n-\t\tmy $colored_age;\n-\t\tif ($pr->{'commit'}{'age'} < 60*60*2) {\n-\t\t\t$colored_age = \"<span style =\\\"color: #009900;\\\"><b><i>$pr->{'commit'}{'age_string'}</i></b></span>\";\n-\t\t} elsif ($pr->{'commit'}{'age'} < 60*60*24*2) {\n-\t\t\t$colored_age = \"<span style =\\\"color: #009900;\\\"><i>$pr->{'commit'}{'age_string'}</i></span>\";\n-\t\t} else {\n-\t\t\t$colored_age = \"<i>$pr->{'commit'}{'age_string'}</i>\";\n-\t\t}\n-\t\tprint \"<td>$colored_age</td>\\n\" .\n+\t\tprint \"<td class=\\\"\". age_class($pr->{'commit'}{'age'}) . \"\\\">\" . $pr->{'commit'}{'age_string'} . \"</td>\\n\" .\n \t\t      \"<td class=\\\"link\\\">\" .\n \t\t      $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$pr->{'path'};a=summary\")}, \"summary\") .\n \t\t      \" | \" . $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$pr->{'path'};a=shortlog\")}, \"shortlog\") .\n@@ -1240,7 +1245,7 @@ sub git_blame {\n \tprint \"<div class=\\\"page_path\\\"><b>\" . esc_html($file_name) . \"</b></div>\\n\";\n \tprint \"<div class=\\\"page_body\\\">\\n\";\n \tprint <<HTML;\n-<table style=\"border-collapse: collapse;\">\n+<table class=\"blame\">\n   <tr>\n     <th>Commit</th>\n     <th>Age</th>\n@@ -1261,7 +1266,7 @@ HTML\n \t\tmy $data;\n \t\tmy $age;\n \t\tmy $age_str;\n-\t\tmy $age_style;\n+\t\tmy $age_class;\n \n \t\tchomp $line;\n \t\t$line_class_num = ($line_class_num + 1) % $line_class_len;\n@@ -1273,16 +1278,14 @@ HTML\n \t\t\t$lineno   = $4;\n \t\t\t$data     = $5;\n \t\t} else {\n-\t\t\tprint qq(  <tr><td colspan=\"5\" style=\"color: red; background-color: yellow;\">Unable to parse: $line</td></tr>\\n);\n+\t\t\tprint qq(  <tr><td colspan=\"5\" class=\"error\">Unable to parse: $line</td></tr>\\n);\n \t\t\tnext;\n \t\t}\n \t\t$short_rev  = substr ($long_rev, 0, 8);\n \t\t$age        = time () - $time;\n \t\t$age_str    = age_string ($age);\n \t\t$age_str    =~ s/ /&nbsp;/g;\n-\t\t$age_style  = 'font-style: italic;';\n-\t\t$age_style .= ' color: #009900; background: transparent;' if ($age < 60*60*24*2);\n-\t\t$age_style .= ' font-weight: bold;' if ($age < 60*60*2);\n+\t\t$age_class  = age_class($age);\n \t\t$author     = esc_html ($author);\n \t\t$author     =~ s/ /&nbsp;/g;\n \t\t# escape tabs\n@@ -1293,15 +1296,14 @@ HTML\n \t\t\t}\n \t\t}\n \t\t$data = esc_html ($data);\n-\t\t$data =~ s/ /&nbsp;/g;\n \n \t\tprint <<HTML;\n   <tr class=\"$line_class[$line_class_num]\">\n-    <td style=\"font-family: monospace;\"><a href=\"$my_uri?${\\esc_param (\"p=$project;a=commit;h=$long_rev\")}\" class=\"text\">$short_rev..</a></td>\n-    <td style=\"$age_style\">$age_str</td>\n+    <td class=\"sha1\"><a href=\"$my_uri?${\\esc_param (\"p=$project;a=commit;h=$long_rev\")}\" class=\"text\">$short_rev..</a></td>\n+    <td class=\"$age_class\">$age_str</td>\n     <td>$author</td>\n-    <td style=\"text-align: right;\"><a id=\"$lineno\" href=\"#$lineno\" class=\"linenr\">$lineno</a></td>\n-    <td style=\"font-family: monospace;\">$data</td>\n+    <td class=\"linenr\"><a id=\"$lineno\" href=\"#$lineno\" class=\"linenr\">$lineno</a></td>\n+    <td class=\"pre\">$data</td>\n   </tr>\n HTML\n \t} # while (my $line = <$fd>)\n@@ -1646,7 +1648,7 @@ sub git_tree {\n \t\t\tprint \"<tr class=\\\"light\\\">\\n\";\n \t\t}\n \t\t$alternate ^= 1;\n-\t\tprint \"<td style=\\\"font-family:monospace\\\">\" . mode_str($t_mode) . \"</td>\\n\";\n+\t\tprint \"<td class=\\\"mode\\\">\" . mode_str($t_mode) . \"</td>\\n\";\n \t\tif ($t_type eq \"blob\") {\n \t\t\tprint \"<td class=\\\"list\\\">\" .\n \t\t\t      $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name\"), -class => \"list\"}, esc_html($t_name)) .\n@@ -1912,7 +1914,7 @@ sub git_commit {\n \t      \"<tr>\" .\n \t      \"<td></td><td> $ad{'rfc2822'}\";\n \tif ($ad{'hour_local'} < 6) {\n-\t\tprintf(\" (<span style=\\\"color: #cc0000;\\\">%02d:%02d</span> %s)\", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});\n+\t\tprintf(\" (<span class=\\\"atnight\\\">%02d:%02d</span> %s)\", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});\n \t} else {\n \t\tprintf(\" (%02d:%02d %s)\", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});\n \t}\n@@ -1920,10 +1922,10 @@ sub git_commit {\n \t      \"</tr>\\n\";\n \tprint \"<tr><td>committer</td><td>\" . esc_html($co{'committer'}) . \"</td></tr>\\n\";\n \tprint \"<tr><td></td><td> $cd{'rfc2822'}\" . sprintf(\" (%02d:%02d %s)\", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . \"</td></tr>\\n\";\n-\tprint \"<tr><td>commit</td><td style=\\\"font-family:monospace\\\">$co{'id'}</td></tr>\\n\";\n+\tprint \"<tr><td>commit</td><td class=\\\"sha1\\\">$co{'id'}</td></tr>\\n\";\n \tprint \"<tr>\" .\n \t      \"<td>tree</td>\" .\n-\t      \"<td style=\\\"font-family:monospace\\\">\" .\n+\t      \"<td class=\\\"sha1\\\">\" .\n \t      $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=tree;h=$co{'tree'};hb=$hash\"), class => \"list\"}, $co{'tree'}) .\n \t      \"</td>\" .\n \t      \"<td class=\\\"link\\\">\" . $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=tree;h=$co{'tree'};hb=$hash\")}, \"tree\") .\n@@ -1933,7 +1935,7 @@ sub git_commit {\n \tforeach my $par (@$parents) {\n \t\tprint \"<tr>\" .\n \t\t      \"<td>parent</td>\" .\n-\t\t      \"<td style=\\\"font-family:monospace\\\">\" . $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=commit;h=$par\"), class => \"list\"}, $par) . \"</td>\" .\n+\t\t      \"<td class=\\\"sha1\\\">\" . $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=commit;h=$par\"), class => \"list\"}, $par) . \"</td>\" .\n \t\t      \"<td class=\\\"link\\\">\" .\n \t\t      $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=commit;h=$par\")}, \"commit\") .\n \t\t      \" | \" . $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=commitdiff;h=$hash;hp=$par\")}, \"commitdiff\") .\n@@ -1958,7 +1960,7 @@ sub git_commit {\n \t\t}\n \t\tif ($line =~ m/^ *(signed[ \\-]off[ \\-]by[ :]|acked[ \\-]by[ :]|cc[ :])/i) {\n \t\t\t$signed = 1;\n-\t\t\tprint \"<span style=\\\"color: #888888\\\">\" . esc_html($line) . \"</span><br/>\\n\";\n+\t\t\tprint \"<span class=\\\"signoff\\\">\" . esc_html($line) . \"</span><br/>\\n\";\n \t\t} else {\n \t\t\t$signed = 0;\n \t\t\tprint format_log_line_html($line) . \"<br/>\\n\";\n@@ -1970,7 +1972,7 @@ sub git_commit {\n \t\tprint(($#difftree + 1) . \" files changed:\\n\");\n \t}\n \tprint \"</div>\\n\";\n-\tprint \"<table cellspacing=\\\"0\\\">\\n\";\n+\tprint \"<table class=\\\"diff_tree\\\">\\n\";\n \tmy $alternate = 0;\n \tforeach my $line (@difftree) {\n \t\t# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M      ls-files.c'\n@@ -1998,12 +2000,12 @@ sub git_commit {\n \t\t\t}\n \t\t\tprint \"<td>\" .\n \t\t\t      $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=blob;h=$to_id;hb=$hash;f=$file\"), -class => \"list\"}, esc_html($file)) . \"</td>\\n\" .\n-\t\t\t      \"<td><span style=\\\"color: #008000;\\\">[new \" . file_type($to_mode) . \"$mode_chng]</span></td>\\n\" .\n+\t\t\t      \"<td><span class=\\\"file_status new\\\">[new \" . file_type($to_mode) . \"$mode_chng]</span></td>\\n\" .\n \t\t\t      \"<td class=\\\"link\\\">\" . $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=blob;h=$to_id;hb=$hash;f=$file\")}, \"blob\") . \"</td>\\n\";\n \t\t} elsif ($status eq \"D\") {\n \t\t\tprint \"<td>\" .\n \t\t\t      $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=blob;h=$from_id;hb=$hash;f=$file\"), -class => \"list\"}, esc_html($file)) . \"</td>\\n\" .\n-\t\t\t      \"<td><span style=\\\"color: #c00000;\\\">[deleted \" . file_type($from_mode). \"]</span></td>\\n\" .\n+\t\t\t      \"<td><span class=\\\"file_status deleted\\\">[deleted \" . file_type($from_mode). \"]</span></td>\\n\" .\n \t\t\t      \"<td class=\\\"link\\\">\" .\n \t\t\t      $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=blob;h=$from_id;hb=$hash;f=$file\")}, \"blob\") .\n \t\t\t      \" | \" . $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=history;h=$hash;f=$file\")}, \"history\") .\n@@ -2011,7 +2013,7 @@ sub git_commit {\n \t\t} elsif ($status eq \"M\" || $status eq \"T\") {\n \t\t\tmy $mode_chnge = \"\";\n \t\t\tif ($from_mode != $to_mode) {\n-\t\t\t\t$mode_chnge = \" <span style=\\\"color: #777777;\\\">[changed\";\n+\t\t\t\t$mode_chnge = \" <span class=\\\"file_status mode_chnge\\\">[changed\";\n \t\t\t\tif (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {\n \t\t\t\t\t$mode_chnge .= \" from \" . file_type($from_mode) . \" to \" . file_type($to_mode);\n \t\t\t\t}\n@@ -2047,7 +2049,7 @@ sub git_commit {\n \t\t\t}\n \t\t\tprint \"<td>\" .\n \t\t\t      $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file\"), -class => \"list\"}, esc_html($to_file)) . \"</td>\\n\" .\n-\t\t\t      \"<td><span style=\\\"color: #777777;\\\">[moved from \" .\n+\t\t\t      \"<td><span class=\\\"file_status moved\\\">[moved from \" .\n \t\t\t      $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=blob;h=$from_id;hb=$hash;f=$from_file\"), -class => \"list\"}, esc_html($from_file)) .\n \t\t\t      \" with \" . (int $similarity) . \"% similarity$mode_chng]</span></td>\\n\" .\n \t\t\t      \"<td class=\\\"link\\\">\" .\n@@ -2407,7 +2409,7 @@ sub git_search {\n \t\t\t\t\tmy $match = esc_html($2) || \"\";\n \t\t\t\t\tmy $trail = esc_html($3) || \"\";\n \t\t\t\t\t$trail = chop_str($trail, 30, 10);\n-\t\t\t\t\tmy $text = \"$lead<span style=\\\"color:#e00000\\\">$match</span>$trail\";\n+\t\t\t\t\tmy $text = \"$lead<span class=\\\"match\\\">$match</span>$trail\";\n \t\t\t\t\tprint chop_str($text, 80, 5) . \"<br/>\\n\";\n \t\t\t\t}\n \t\t\t}\n@@ -2456,7 +2458,7 @@ sub git_search {\n \t\t\t\t\twhile (my $setref = shift @files) {\n \t\t\t\t\t\tmy %set = %$setref;\n \t\t\t\t\t\tprint $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}\"), class => \"list\"},\n-\t\t\t\t\t\t      \"<span style=\\\"color:#e00000\\\">\" . esc_html($set{'file'}) . \"</span>\") .\n+\t\t\t\t\t\t      \"<span class=\\\"match\\\">\" . esc_html($set{'file'}) . \"</span>\") .\n \t\t\t\t\t\t      \"<br/>\\n\";\n \t\t\t\t\t}\n \t\t\t\t\tprint \"</td>\\n\" .\ndiff --git a/gitweb/gitweb.css b/gitweb/gitweb.css\nindex da53eb4..98410f5 100644\n--- a/gitweb/gitweb.css\n+++ b/gitweb/gitweb.css\n@@ -89,14 +89,18 @@ span.age {\n \tposition: relative;\n \tfloat: left;\n \twidth: 142px;\n-\tfont-style:italic;\n+\tfont-style: italic;\n+}\n+\n+div.page_body span.signoff {\n+\tcolor: #888888;\n }\n \n div.log_link {\n \tpadding: 0px 8px;\n \tfont-size: 10px;\n \tfont-family: sans-serif;\n-\tfont-style:normal;\n+\tfont-style: normal;\n \tposition: relative;\n \tfloat: left;\n \twidth: 136px;\n@@ -138,6 +142,14 @@ table {\n \tpadding: 8px 4px;\n }\n \n+table.project_list, table.diff_tree {\n+\tborder-spacing: 0;\n+}\n+\n+table.blame {\n+\tborder-collapse: collapse;\n+}\n+\n th {\n \tpadding: 2px 5px;\n \tfont-size: 12px;\n@@ -156,11 +168,10 @@ tr.dark:hover {\n \tbackground-color: #edece6;\n }\n \n-\n td {\n \tpadding: 2px 5px;\n \tfont-size: 12px;\n-\tvertical-align:top;\n+\tvertical-align: top;\n }\n \n td.link {\n@@ -169,10 +180,77 @@ td.link {\n \tfont-size: 10px;\n }\n \n-div.pre {\n+td.sha1 {\n+\tfont-family: monospace;\n+}\n+\n+td.error {\n+\tcolor: red;\n+\tbackground-color: yellow;\n+}\n+\n+table.diff_tree span.file_status.new {\n+\tcolor: #008000;\n+}\n+\n+table.diff_tree span.file_status.deleted {\n+\tcolor: #c00000;\n+}\n+\n+table.diff_tree span.file_status.moved,\n+table.diff_tree span.file_status.mode_chnge {\n+\tcolor: #777777;\n+}\n+\n+/* age2: 60*60*24*2 <= age */\n+table.project_list td.age2, table.blame td.age2 {\n+\tfont-style: italic;\n+}\n+\n+/* age1: 60*60*2 <= age < 60*60*24*2 */\n+table.project_list td.age1 {\n+\tcolor: #009900;\n+\tfont-style: italic;\n+}\n+\n+table.blame td.age1 {\n+\tcolor: #009900;\n+\tbackground: transparent;\n+}\n+\n+/* age0: age < 60*60*2 */\n+table.project_list td.age0 {\n+\tcolor: #009900;\n+\tfont-style: italic;\n+\tfont-weight: bold;\n+}\n+\n+table.blame td.age0 {\n+\tcolor: #009900;\n+\tbackground: transparent;\n+\tfont-weight: bold;\n+}\n+\n+td.pre, div.pre, div.diff {\n \tfont-family: monospace;\n \tfont-size: 12px;\n \twhite-space: pre;\n+}\n+\n+td.mode {\n+\tfont-family: monospace;\n+}\n+\n+div.diff.add {\n+\tcolor: #008800;\n+}\n+\n+div.diff.rem {\n+\tcolor: #cc0000;\n+}\n+\n+div.diff.chunk_header {\n+\tcolor: #990099;\n }\n \n div.diff_info {\n@@ -196,6 +273,10 @@ div.search {\n \tright: 12px\n }\n \n+td.linenr {\n+\ttext-align: right;\n+}\n+\n a.linenr {\n \tcolor: #999999;\n \ttext-decoration: none\n@@ -229,3 +310,11 @@ span.tag {\n \tborder: 1px solid;\n \tborder-color: #ffffcc #ffee00 #ffee00 #ffffcc;\n }\n+\n+span.atnight {\n+\tcolor: #cc0000;\n+}\n+\n+span.match {\n+\tcolor: #e00000;\n+}\n-- \n1.3.0\n"}]}