Changeset 10907
- Timestamp:
- 03/05/11 15:02:47 (15 months ago)
- Location:
- trunk/TablePlugin
- Files:
-
- 4 edited
-
data/System/TablePlugin.txt (modified) (2 diffs)
-
lib/Foswiki/Plugins/TablePlugin.pm (modified) (2 diffs)
-
lib/Foswiki/Plugins/TablePlugin/Core.pm (modified) (6 diffs)
-
test/unit/TablePlugin/TablePluginTests.pm (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/TablePlugin/data/System/TablePlugin.txt
r10903 r10907 108 108 | Three One | ^ | Three Three | 109 109 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 120 Results 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 110 127 ---+++ Col spans 111 128 Col spans can be achieved by writing table cell separators without contents or spacing: … … 179 196 | Release: | %$RELEASE% | 180 197 | Change History: | <!-- specify latest version first --> | 198 | 05 Mar 2011 | 1.129: Arthur Clemens: Foswikitask:Item8302: init sorting is broken if no header row. \ 199 Foswikitask:Item10016: No rowspan in header rows possible. \ 200 Foswikitask:Item5864: documentation needs better coverage of spans from header row. \ 201 Foswikitask:Item8991: header-only table violates XHTML DTD. | 181 202 | 04 Mar 2011 | 1.128: Arthur Clemens: disable sorting if =sort="off"= is set in =TABLEPLUGIN_TABLEATTRIBUTES=. | 182 203 | 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 10 10 11 11 our $VERSION = '$Rev$'; 12 our $RELEASE = '1.12 8';12 our $RELEASE = '1.129'; 13 13 our $SHORTDESCRIPTION = 14 14 'Control attributes of tables and sorting of table columns'; … … 42 42 43 43 $initialised = 0; 44 45 debug( 'TablePlugin', "inited" ); 44 46 45 47 return 1; -
trunk/TablePlugin/lib/Foswiki/Plugins/TablePlugin/Core.pm
r10903 r10907 135 135 _debug('_initDefaults'); 136 136 $defaultAttrs = { 137 headerrows => 1,137 headerrows => 0, 138 138 footerrows => 0, 139 139 class => 'foswikiTable', … … 543 543 _getCurrentSortDirection( $combinedTableAttrs->{initDirection} ); 544 544 } 545 546 545 } 547 546 … … 722 721 } 723 722 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 723 sub _headerRowCount { 724 my ($table) = @_; 725 726 my $count = 0; 731 727 # 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; 737 737 } 738 738 … … 1309 1309 } 1310 1310 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 1314 1319 my $tableTagAttributes = {}; 1315 1320 $tableTagAttributes->{class} = $combinedTableAttrs->{class}; … … 1683 1688 $doubleIndent . CGI::Tr( { class => $trClassName }, $rowtext ); 1684 1689 1685 my $isHeaderRow = ( $headerCellCount == $colCount );1690 my $isHeaderRow = $rowCount < $combinedTableAttrs->{headerrows}; #( $headerCellCount == $colCount ); 1686 1691 my $isFooterRow = 1687 1692 ( ( $numberOfRows - $rowCount ) <= … … 1727 1732 $text .= $currTablePre . $tfoot if scalar @footerRowList; 1728 1733 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 ; 1734 1748 1735 1749 $text .= $currTablePre . CGI::end_table() . "\n"; -
trunk/TablePlugin/test/unit/TablePlugin/TablePluginTests.pm
r8446 r10907 49 49 =cut 50 50 51 sub test_simpleTable using{51 sub test_simpleTable { 52 52 my $this = shift; 53 53 … … 126 126 =cut 127 127 128 sub test_simpleTfootTable usingTablePlugin {128 sub test_simpleTfootTableUsingTablePlugin { 129 129 my $this = shift; 130 130 … … 182 182 <thead> 183 183 <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> 190 190 </tr> 191 191 </thead> … … 199 199 <td class="foswikiTableCol1 foswikiLastCol foswikiLast"> bad </td> 200 200 </tr> 201 </tbody> 202 </table> 201 </tbody></table> 203 202 EXPECTED 204 203 my $actual = <<ACTUAL; … … 215 214 =cut 216 215 217 sub test_doubleTheadandTfootTable usingTablePlugin {216 sub test_doubleTheadandTfootTableUsingTablePlugin { 218 217 my $this = shift; 219 218 … … 258 257 | 2 | 3 | 259 258 | *ok* | *bad* | 259 ACTUAL 260 $this->do_test( $expected, $actual ); 261 } 262 263 =pod 264 265 =cut 266 267 sub 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> 288 EXPECTED 289 my $actual = <<ACTUAL; 290 | *a* | *b* | 260 291 ACTUAL 261 292 $this->do_test( $expected, $actual ); … … 763 794 } 764 795 765 766 796 =pod 767 797 … … 1266 1296 Foswiki - The Free and Open Source Wiki, http://foswiki.org/ 1267 1297 1268 Copyright (C) 2008-201 0Foswiki Contributors. Foswiki Contributors1298 Copyright (C) 2008-2011 Foswiki Contributors. Foswiki Contributors 1269 1299 are listed in the AUTHORS file in the root of this distribution. 1270 1300 NOTE: Please extend that file, not this notice.
Note: See TracChangeset
for help on using the changeset viewer.
