[interchange-cvs] interchange - heins modified code/UserTag/table_organize.tag
interchange-core@icdevgroup.org
interchange-core@icdevgroup.org
Sun Dec 8 01:45:01 2002
User: heins
Date: 2002-12-08 06:44:22 GMT
Modified: code/UserTag table_organize.tag
Log:
* Add min-rows=$rows parameter to [table-organize]. Allows building small
result sets in one column (or however many columns needed to reach
min-rows).
[table-organize cols=3 min-rows=5 columnize=1]
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
[/table-organize]
becomes
<tr>
<td>1</td> <td>6</td>
</tr>
<tr>
<td>2</td> <td>7</td>
</tr>
<tr>
<td>3</td> <td>8</td>
</tr>
<tr>
<td>4</td> <td>9</td>
</tr>
<tr>
<td>5</td> <td> </td>
</tr>
while [table-organize min-rows=3 cols=3] performs normally
and [table-organize min-rows=10 cols=3] has only one
column.
Revision Changes Path
1.4 +15 -1 interchange/code/UserTag/table_organize.tag
rev 1.4, prev_rev 1.3
Index: table_organize.tag
===================================================================
RCS file: /var/cvs/interchange/code/UserTag/table_organize.tag,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- table_organize.tag 30 Oct 2002 20:43:05 -0000 1.3
+++ table_organize.tag 8 Dec 2002 06:44:22 -0000 1.4
@@ -59,6 +59,12 @@
Contents to place in empty cells put on as filler. Defaults to C< >.
+=item min_rows
+
+On small result sets, can be ugly to build more than necessary columns.
+This will guarantee a minimum number of rows -- columns will change
+as numbers change. Formula: $num_cells % $opt->{min_rows}.
+
=item limit
Maximum number of cells to use. Truncates extra cells silently.
@@ -171,7 +177,10 @@
my $postamble = $2;
my @cells;
- if($opt->{embed}) {
+ if($opt->{cells} and ref($opt->{cells}) eq 'ARRAY') {
+ @cells = @{$opt->{cells}};
+ }
+ elsif($opt->{embed}) {
if($opt->{embed} eq 'lc') {
push @cells, $1 while $body =~ s:(<td\b.*?</td>)::s;
}
@@ -181,6 +190,11 @@
}
else {
push @cells, $1 while $body =~ s:(<td\b.*?</td>)::is;
+ }
+
+ while ($opt->{min_rows} and ($opt->{min_rows} * $cols) > scalar(@cells) ) {
+ $cols--;
+ last if $cols == 1;
}
if(int($opt->{limit}) and $opt->{limit} < scalar(@cells) ) {