Skip to content

Commit

Permalink
gitweb: provide a routine to display (sub)sections
Browse files Browse the repository at this point in the history
The routine puts the given contento into a DIV element, automatically
adding a header div. The content can be provided as a standard scalar
value (which is used as-is), as a scalar ref (which is HTML-escaped), as
a function reference to be executed, or as a file handle to be dumped.

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Acked-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Giuseppe Bilotta authored and Junio C Hamano committed Nov 17, 2010
1 parent 0e65699 commit b891d52
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions gitweb/gitweb.perl
Original file line number Diff line number Diff line change
Expand Up @@ -3802,6 +3802,44 @@ sub format_repo_url {
return "<tr class=\"metadata_url\"><td>$name</td><td>$url</td></tr>\n";
}

# Group output by placing it in a DIV element and adding a header.
# Options for start_div() can be provided by passing a hash reference as the
# first parameter to the function.
# Options to git_print_header_div() can be provided by passing an array
# reference. This must follow the options to start_div if they are present.
# The content can be a scalar, which is output as-is, a scalar reference, which
# is output after html escaping, an IO handle passed either as *handle or
# *handle{IO}, or a function reference. In the latter case all following
# parameters will be taken as argument to the content function call.
sub git_print_section {
my ($div_args, $header_args, $content);
my $arg = shift;
if (ref($arg) eq 'HASH') {
$div_args = $arg;
$arg = shift;
}
if (ref($arg) eq 'ARRAY') {
$header_args = $arg;
$arg = shift;
}
$content = $arg;

print $cgi->start_div($div_args);
git_print_header_div(@$header_args);

if (ref($content) eq 'CODE') {
$content->(@_);
} elsif (ref($content) eq 'SCALAR') {
print esc_html($$content);
} elsif (ref($content) eq 'GLOB' or ref($content) eq 'IO::Handle') {
print <$content>;
} elsif (!ref($content) && defined($content)) {
print $content;
}

print $cgi->end_div;
}

sub print_local_time {
print format_local_time(@_);
}
Expand Down

0 comments on commit b891d52

Please sign in to comment.