Changeset 10907


Ignore:
Timestamp:
03/05/11 15:02:47 (15 months ago)
Author:
ArthurClemens
Message:

Item10441: Foswikitask:Item8302: init sorting is broken if no header row.
Foswikitask:Item10016: No rowspan in header rows possible.
Foswikitask:Item5864: documentation needs better coverage of spans from header row.
Foswikitask:Item8991: header-only table violates XHTML DTD.

Location:
trunk/TablePlugin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/TablePlugin/data/System/TablePlugin.txt

    r10903 r10907  
    108108| Three One | ^ | Three Three | 
    109109 
     110*Note:* Row spans do not work across the header and body boundaries of a table. So it you have a header row, the row cells beneath (in the body section) cannot be merged with the header row cells. Row spans within header cells are possible. 
     111 
     112<verbatim class="tml"> 
     113%TABLE{headerrows="2" sort="off"}% 
     114| *One One* | *One Two* | *One Three* | 
     115| ^ | *Two Two* | *Two Three* | 
     116| Two One | Two Two | Two Three | 
     117| Three One | ^ | Three Three | 
     118</verbatim> 
     119 
     120Results in: 
     121%TABLE{headerrows="2" sort="off"}% 
     122| *One One* | *One Two* | *One Three* |  
     123| ^ | *Two Two* | *Two Three* |  
     124| Two One | Two Two | Two Three |  
     125| Three One | ^ | Three Three | 
     126 
    110127---+++ Col spans 
    111128Col spans can be achieved by writing table cell separators without contents or spacing: 
     
    179196|  Release: | %$RELEASE% | 
    180197|  Change History: | <!-- specify latest version first -->&nbsp; | 
     198|  05 Mar 2011 | 1.129: Arthur Clemens: Foswikitask:Item8302: init sorting is broken if no header row. \ 
     199Foswikitask:Item10016: No rowspan in header rows possible. \ 
     200Foswikitask:Item5864: documentation needs better coverage of spans from header row. \ 
     201Foswikitask:Item8991: header-only table violates XHTML DTD. | 
    181202|  04 Mar 2011 | 1.128: Arthur Clemens: disable sorting if =sort="off"= is set in =TABLEPLUGIN_TABLEATTRIBUTES=. | 
    182203|  16 Feb 2011 | 1.127: Michael Daum: Foswikitask:Item10357: only emit inline css when there's a foswikiTable on the current page | 
  • trunk/TablePlugin/lib/Foswiki/Plugins/TablePlugin.pm

    r10903 r10907  
    1010 
    1111our $VERSION = '$Rev$'; 
    12 our $RELEASE = '1.128'; 
     12our $RELEASE = '1.129'; 
    1313our $SHORTDESCRIPTION = 
    1414  'Control attributes of tables and sorting of table columns'; 
     
    4242 
    4343    $initialised = 0; 
     44 
     45    debug( 'TablePlugin', "inited" ); 
    4446 
    4547    return 1; 
  • trunk/TablePlugin/lib/Foswiki/Plugins/TablePlugin/Core.pm

    r10903 r10907  
    135135    _debug('_initDefaults'); 
    136136    $defaultAttrs = { 
    137         headerrows    => 1, 
     137        headerrows    => 0, 
    138138        footerrows    => 0, 
    139139        class         => 'foswikiTable', 
     
    543543              _getCurrentSortDirection( $combinedTableAttrs->{initDirection} ); 
    544544        } 
    545  
    546545    } 
    547546 
     
    722721} 
    723722 
    724 # Determine whether to generate sorting headers for this table. The header 
    725 # indicates the context of the table (body or file attachment) 
    726 sub _shouldISortThisTable { 
    727     my ($header) = @_; 
    728  
    729     return 0 unless $combinedTableAttrs->{sortAllTables}; 
    730  
     723sub _headerRowCount { 
     724    my ($table) = @_; 
     725 
     726    my $count = 0; 
    731727    # All cells in header are headings? 
    732     #foreach my $cell (@$header) { 
    733     #return 0 if ( $cell->{type} ne 'th' ); 
    734     #} 
    735  
    736     return 1; 
     728    foreach my $row (@$table) { 
     729        my $isHeader = 1; 
     730        foreach my $cell (@$row) { 
     731                 $isHeader = 0 if ( $cell->{type} ne 'th' ); 
     732        } 
     733        $count++ if $isHeader; 
     734    } 
     735 
     736    return $count; 
    737737} 
    738738 
     
    13091309    } 
    13101310 
    1311     my $sortThisTable = _shouldISortThisTable( 
    1312         $curTable[ $combinedTableAttrs->{headerrows} - 1 ] ); 
    1313  
     1311    my $sortThisTable = $combinedTableAttrs->{sortAllTables} == 0 ? 0 : 1;  
     1312    if ( $combinedTableAttrs->{headerrows} == 0) { 
     1313                my $headerRowCount = _headerRowCount( \@curTable ); 
     1314                $headerRowCount -= $combinedTableAttrs->{footerrows}; 
     1315                # override default setting with calculated header count 
     1316                $combinedTableAttrs->{headerrows} = $headerRowCount; 
     1317        } 
     1318         
    13141319    my $tableTagAttributes = {}; 
    13151320    $tableTagAttributes->{class}       = $combinedTableAttrs->{class}; 
     
    16831688          $doubleIndent . CGI::Tr( { class => $trClassName }, $rowtext ); 
    16841689 
    1685         my $isHeaderRow = ( $headerCellCount == $colCount ); 
     1690        my $isHeaderRow = $rowCount < $combinedTableAttrs->{headerrows}; #( $headerCellCount == $colCount ); 
    16861691        my $isFooterRow = 
    16871692          ( ( $numberOfRows - $rowCount ) <= 
     
    17271732    $text .= $currTablePre . $tfoot if scalar @footerRowList; 
    17281733 
    1729     my $tbody = 
    1730         "$singleIndent<tbody>" 
    1731       . join( "", @bodyRowList ) 
    1732       . "$singleIndent</tbody>"; 
    1733     $text .= $currTablePre . $tbody if scalar @bodyRowList; 
     1734    my $tbody; 
     1735    if (scalar @bodyRowList) { 
     1736      $tbody = 
     1737          "$singleIndent<tbody>" 
     1738        . join( "", @bodyRowList ) 
     1739        . "$singleIndent</tbody>"; 
     1740    } 
     1741    else { 
     1742      # A HTML table requires a body, which cannot be empty (Item8991). 
     1743      # So we provide one, but prevent it from being displayed. 
     1744      $tbody = 
     1745          "$singleIndent<tbody>$doubleIndent<tr style=\"display:none;\">$tripleIndent<td></td>$doubleIndent</tr>$singleIndent</tbody>\n"; 
     1746    } 
     1747    $text .= $currTablePre . $tbody ; 
    17341748 
    17351749    $text .= $currTablePre . CGI::end_table() . "\n"; 
  • trunk/TablePlugin/test/unit/TablePlugin/TablePluginTests.pm

    r8446 r10907  
    4949=cut 
    5050 
    51 sub test_simpleTableusing { 
     51sub test_simpleTable { 
    5252    my $this = shift; 
    5353 
     
    126126=cut 
    127127 
    128 sub test_simpleTfootTableusingTablePlugin { 
     128sub test_simpleTfootTableUsingTablePlugin { 
    129129    my $this = shift; 
    130130 
     
    182182        <thead> 
    183183                <tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0"> 
    184                         <th class="foswikiTableCol0 foswikiFirstCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=$tableCount;up=0#sorted_table" title="Sort by this column">a</a> </th> 
    185                         <th class="foswikiTableCol1 foswikiLastCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=$tableCount;up=0#sorted_table" title="Sort by this column">b</a> </th> 
    186                 </tr> 
    187                 <tr class="foswikiTableEven foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0"> 
    188                         <th class="foswikiTableCol0 foswikiFirstCol"> c </th> 
    189                         <th class="foswikiTableCol1 foswikiLastCol"> c </th> 
     184                        <th class="foswikiTableCol0 foswikiFirstCol"> a </th> 
     185                        <th class="foswikiTableCol1 foswikiLastCol"> b </th> 
     186                </tr> 
     187                <tr class="foswikiTableEven foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0"> 
     188                        <th class="foswikiTableCol0 foswikiFirstCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=1;up=0#sorted_table" title="Sort by this column">c</a> </th> 
     189                        <th class="foswikiTableCol1 foswikiLastCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=1;up=0#sorted_table" title="Sort by this column">c</a> </th> 
    190190                </tr> 
    191191        </thead> 
     
    199199                        <td class="foswikiTableCol1 foswikiLastCol foswikiLast"> bad </td> 
    200200                </tr> 
    201         </tbody> 
    202 </table> 
     201        </tbody></table> 
    203202EXPECTED 
    204203    my $actual = <<ACTUAL; 
     
    215214=cut 
    216215 
    217 sub test_doubleTheadandTfootTableusingTablePlugin { 
     216sub test_doubleTheadandTfootTableUsingTablePlugin { 
    218217    my $this = shift; 
    219218 
     
    258257| 2 | 3 | 
    259258| *ok* | *bad* | 
     259ACTUAL 
     260    $this->do_test( $expected, $actual ); 
     261} 
     262 
     263=pod 
     264 
     265=cut 
     266 
     267sub test_onlyHeaderRow { 
     268    my $this = shift; 
     269 
     270    my $cgi = $this->{request}; 
     271    my $url = $cgi->url( -absolute => 1 ); 
     272 
     273    my $expected = <<EXPECTED; 
     274<nop> 
     275<table class="foswikiTable" rules="none" border="1"> 
     276        <thead> 
     277                <tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0"> 
     278                        <th class="foswikiTableCol0 foswikiFirstCol foswikiLast"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=1;up=0#sorted_table" title="Sort by this column">a</a> </th> 
     279                        <th class="foswikiTableCol1 foswikiLastCol foswikiLast"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=1;up=0#sorted_table" title="Sort by this column">b</a> </th> 
     280                </tr> 
     281        </thead> 
     282        <tbody> 
     283                <tr style="display:none;"> 
     284                        <td></td> 
     285                </tr> 
     286        </tbody> 
     287</table> 
     288EXPECTED 
     289    my $actual = <<ACTUAL; 
     290| *a* | *b* | 
    260291ACTUAL 
    261292    $this->do_test( $expected, $actual ); 
     
    763794} 
    764795 
    765  
    766796=pod 
    767797 
     
    12661296Foswiki - The Free and Open Source Wiki, http://foswiki.org/ 
    12671297 
    1268 Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors 
     1298Copyright (C) 2008-2011 Foswiki Contributors. Foswiki Contributors 
    12691299are listed in the AUTHORS file in the root of this distribution. 
    12701300NOTE: Please extend that file, not this notice. 
Note: See TracChangeset for help on using the changeset viewer.