Skip to content

Commit

Permalink
Item13436: Add class= option to TABLE macro
Browse files Browse the repository at this point in the history
Fix provided by MarcKloter.
  • Loading branch information
gac410 committed Dec 30, 2015
1 parent 1298518 commit 21e4dbb
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
3 changes: 2 additions & 1 deletion TablePlugin/data/System/TablePlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1449764954" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1451454504" format="1.1" version="1"}%
%META:TOPICPARENT{name="Plugins"}%
---+ Table Plugin

Expand Down Expand Up @@ -193,6 +193,7 @@ Sort icons in the header are read from %SYSTEMWEB%.DocumentGraphics.

%TABLE{columnwidths="10%,90%"}%
| Change History: | <!-- specify latest version first -->&nbsp; |
| 30 Dec 2015 | 1.153: Foswikitask:Item13436 - Add class parameter to the TABLE macro to permit custom class specifications. |
| 10 Dec 2015 | 1.152: Foswikitask:Item12569 - Improve sorting of UNICODE data by NFKD normalizing the comparisons. |
| 10 Sep 2015 | 1.151: Foswikitask:Item13688 - fixed css precedence for table css emitted by !TablePlugin; removed hard-coded vertical alignment; Foswikitask:Item13695 - add support for common css units |
| 28 May 2013 | 1.142: Foswikitask:Item12480 - memory leak amasses css styles from all visited pages |
Expand Down
3 changes: 2 additions & 1 deletion TablePlugin/data/System/VarTABLE.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1434650530" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1451454504" format="1.1" version="1"}%
%META:TOPICPARENT{name="Macros"}%
---+ TABLE -- control attributes of tables and sorting of table columns
The =%<nop>TABLE{}%= macro is handled by the TablePlugin
Expand All @@ -17,6 +17,7 @@ The =%<nop>TABLE{}%= macro is handled by the TablePlugin
| =summary= | Table summary used by screen readers: A summary of what the table presents. It should provide an orientation for someone who listens to the table. | <span class="foswikiGrayText">unspecified</span> | =summary="List of subscribed users"= |
| =caption= | Table caption: A title that will be displayed just above the table.| <span class="foswikiGrayText">unspecified</span> | =caption="Users"= |
| =inlinemarkup= | Set to "on" to generate inline markup HTML (in addition to the CSS markup); useful if you need to copy the table, for instance to paste the table into an email). | <span class="foswikiGrayText">unspecified</span> | =inlinemarkup="on"= |
| =class= | Add specified class to the default =foswikiTable= class. | <span class="foswikiGrayText">unspecified</span> | =class="mytable"= |

---++++ Attributes for table sorting
%TABLE{tablewidth="100%" columnwidths="10%,45%,20%,25%" sort="off" headerbg="#f5f5f5" databg="#ffffff" headercolor="#333333"}%
Expand Down
4 changes: 2 additions & 2 deletions TablePlugin/lib/Foswiki/Plugins/TablePlugin.pm
Expand Up @@ -19,8 +19,8 @@ BEGIN {
}

# Simple decimal version, use parse method, no leading "v"
our $VERSION = '1.152';
our $RELEASE = '10 Dec 2015';
our $VERSION = '1.153';
our $RELEASE = '30 Dec 2015';
our $SHORTDESCRIPTION =
'Control attributes of tables and sorting of table columns';
our $NO_PREFS_IN_TOPIC = 1;
Expand Down
9 changes: 8 additions & 1 deletion TablePlugin/lib/Foswiki/Plugins/TablePlugin/Core.pm
Expand Up @@ -331,7 +331,14 @@ sub _parseAttributes {
: 'table'
. $Foswiki::Plugins::TablePlugin::topic
. ( $tableCount + 1 );
_storeAttribute( 'id', $id, $inCollection );
_storeAttribute( 'id', $id, $inCollection );

my $class =
defined $inParams->{class}
? $defaultAttrs->{class} . ' ' . $inParams->{class}
: $defaultAttrs->{class};
_storeAttribute( 'class', $class, $inCollection );

_storeAttribute( 'headerrows', $inParams->{headerrows}, $inCollection );
_storeAttribute( 'footerrows', $inParams->{footerrows}, $inCollection );
}
Expand Down
56 changes: 56 additions & 0 deletions TablePlugin/test/unit/TablePlugin/TablePluginTests.pm
Expand Up @@ -1651,6 +1651,62 @@ ACTUAL
$this->assert_html_equals( $expected, $actual1 . $actual2 );
}

=pod
Test user specified class for table.
=cut

sub test_tableClassAttr {
my $this = shift;

my $cgi = $this->{request};
my $url = $cgi->url( -absolute => 1 );
my $expected = <<EXPECTED;
<nop>
<nop>
<nop>
<table id="table$this->{test_topic}1" class="foswikiTable foo" rules="none" border="1">
<tbody>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<td class="foswikiTableCol0 foswikiFirstCol"> a </td>
<td class="foswikiTableCol1 foswikiLastCol"> b </td>
</tr>
<tr class="foswikiTableEven foswikiTableRowdataBgSorted1 foswikiTableRowdataBg1">
<td class="foswikiTableCol0 foswikiFirstCol foswikiLast"> 2 </td>
<td class="foswikiTableCol1 foswikiLastCol foswikiLast"> 3 </td>
</tr>
</tbody>
</table>
<p></p>
<nop>
<nop>
<nop>
<table id="table$this->{test_topic}2" class="foswikiTable bar" rules="none" border="1">
<tbody>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<td class="foswikiTableCol0 foswikiFirstCol"> a </td>
<td class="foswikiTableCol1 foswikiLastCol"> b </td>
</tr>
<tr class="foswikiTableEven foswikiTableRowdataBgSorted1 foswikiTableRowdataBg1">
<td class="foswikiTableCol0 foswikiFirstCol foswikiLast"> 2 </td>
<td class="foswikiTableCol1 foswikiLastCol foswikiLast"> 3 </td>
</tr>
</tbody>
</table>
EXPECTED
my $actual = <<ACTUAL;
%TABLE{headerrows="0" footerrows="0" class="foo"}%
| a | b |
| 2 | 3 |
%TABLE{headerrows="0" footerrows="0" class="bar"}%
| a | b |
| 2 | 3 |
ACTUAL
$this->do_test( $expected, $actual );
}

# DEVELOPMENT TESTS

sub dev_test_convertStringToNumber_empty_string {
Expand Down

0 comments on commit 21e4dbb

Please sign in to comment.