@matheusbsbs / matheus-bagliano / commits / b891d52a64
Fork 0

gitweb: provide a routine to display (sub)sections

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>

Giuseppe Bilotta committed Nov 11, 2010 at 13:26 UTC b891d52a644e58a830091463911cb859499ae504
1 file changed +38
gitweb/gitweb.perl
+38
@@ -3802,6 +3802,44 @@ sub format_repo_url {
3802 return "<tr class=\"metadata_url\"><td>$name</td><td>$url</td></tr>\n";
3803 }
3804
3805 +# Group output by placing it in a DIV element and adding a header.
3806 +# Options for start_div() can be provided by passing a hash reference as the
3807 +# first parameter to the function.
3808 +# Options to git_print_header_div() can be provided by passing an array
3809 +# reference. This must follow the options to start_div if they are present.
3810 +# The content can be a scalar, which is output as-is, a scalar reference, which
3811 +# is output after html escaping, an IO handle passed either as *handle or
3812 +# *handle{IO}, or a function reference. In the latter case all following
3813 +# parameters will be taken as argument to the content function call.
3814 +sub git_print_section {
3815 + my ($div_args, $header_args, $content);
3816 + my $arg = shift;
3817 + if (ref($arg) eq 'HASH') {
3818 + $div_args = $arg;
3819 + $arg = shift;
3820 + }
3821 + if (ref($arg) eq 'ARRAY') {
3822 + $header_args = $arg;
3823 + $arg = shift;
3824 + }
3825 + $content = $arg;
3826 +
3827 + print $cgi->start_div($div_args);
3828 + git_print_header_div(@$header_args);
3829 +
3830 + if (ref($content) eq 'CODE') {
3831 + $content->(@_);
3832 + } elsif (ref($content) eq 'SCALAR') {
3833 + print esc_html($$content);
3834 + } elsif (ref($content) eq 'GLOB' or ref($content) eq 'IO::Handle') {
3835 + print <$content>;
3836 + } elsif (!ref($content) && defined($content)) {
3837 + print $content;
3838 + }
3839 +
3840 + print $cgi->end_div;
3841 +}
3842 +
3843 sub print_local_time {
3844 print format_local_time(@_);
3845 }