have no rows marker work as expected with columns
Robert 'phaylon' Sedlacek [Wed, 20 Jun 2012 22:39:01 +0000 (22:39 +0000)]
br.pl

diff --git a/br.pl b/br.pl
index efdc3af..08fe3b6 100644 (file)
--- a/br.pl
+++ b/br.pl
@@ -219,21 +219,25 @@ sub render_table {
     $data->{show_columns} ? { map +($_ => $_), @{$data->{columns}} } : (),
     @{$data->{data}}
   );
+  my $column_count = scalar @{$data->{columns}};
   [ 200, [ 'Content-type' => 'text/html' ], [
     HTML::Tags::to_html_string(
       <html>, <body>, "\n",
       ($data->{wrapper}||sub{@_})->(
         '', <table>, "\n",
-          @rows
-          ? (map { my $el = $_;
-              '  ', ($el->{key} eq '__error__') ? <tr class="error"> : <tr>,
-                (map {
-                  <td>, $self->render_el($el, $_, $el->{$_}), </td>
-                } @{$data->{columns}}),
-              </tr>, "\n"
-            } @rows)
+          (map { my $el = $_;
+            '  ', ($el->{key} eq '__error__') ? <tr class="error"> : <tr>,
+              (map {
+                <td>, $self->render_el($el, $_, $el->{$_}), </td>
+              } @{$data->{columns}}),
+            </tr>, "\n"
+          } @rows),
+          @{$data->{data}}
+          ? ()
           : (<tr class="no-rows">,
-              <td>, 'No entries in this data structure', </td>,
+              <td colspan="$column_count">,
+                'No entries in this data structure',
+              </td>,
             </tr>),
         '', </table>, "\n",
       ),