[interchange-cvs] interchange - jon modified code/UserTag/table_organize.tag
interchange-core@icdevgroup.org
interchange-core@icdevgroup.org
Tue Aug 6 19:11:00 2002
User: jon
Date: 2002-08-06 23:10:44 GMT
Modified: code/UserTag table_organize.tag
Log:
Add joiner option to table_organize that allows placement of arbitrary
text between table cells.
Rework columnize option for non-square tables. Previously the columnize
option resulted in fewer columns than specified, with empty cells in last
column, whereas normal row-formatted tables left empty cells at end of
last row. Now columnize figures out where to put the empty cells so
behavior is same as without columnize.
Without columnize:
A B C D
E F G H
I
With columnize:
Before:
A D G x
B E H x
C F I x
Now:
A D F H
B E G I
C
Revision Changes Path
1.2 +22 -18 interchange/code/UserTag/table_organize.tag
rev 1.2, prev_rev 1.1
Index: table_organize.tag
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /var/cvs/interchange/code/UserTag/table_organize.tag,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -u -r1.1 -r1.2
--- table_organize.tag 29 Jan 2002 05:52:42 -0000 1.1
+++ table_organize.tag 6 Aug 2002 23:10:44 -0000 1.2
@@ -243,27 +243,31 @@
$opt->{table} =3D ' ' if ! $opt->{table};
}
=20
- my $joiner =3D $pretty ? "\n\t\t" : "";
+ my $joiner =3D $opt->{joiner} || ($pretty ? "\n\t\t" : "");
while(@cells) {
- while (scalar(@cells) % $cols) {
- push @cells, "<td>$opt->{filler}</td>";
+ if ($opt->{columnize}) {
+ my $cell_count =3D scalar @cells;
+ my $row_count_ceil =3D POSIX::ceil($cell_count / $cols);
+ my $row_count_floor =3D int($cell_count / $cols);
+ my $remainder =3D $cell_count % $cols;
+ my @tmp =3D splice(@cells, 0);
+ my $index;
+ for (my $r =3D 0; $r < $row_count_ceil; $r++) {
+ for (my $c =3D 0; $c < $cols; $c++) {
+ if ($c >=3D $remainder + 1) {
+ $index =3D $r + $row_count_floor * $c + $remainder;
+ }
+ else {
+ $index =3D $r + $row_count_ceil * $c;
+ }
+ push @cells, $tmp[$index];
+ last if $r + 1 =3D=3D $row_count_ceil and $c + 1 =3D=3D $remainder;
+ }
+ }
}
=20
- if( $opt->{columnize}) {
- my $nr_of_rows =3D scalar(@cells) / $cols;
- my @tmp =3D splice(@cells,0);
- my $index;
- my $r =3D 0;
-
- while ($r < $nr_of_rows) {
- my $c =3D 0;
- while ($c < $cols) {
- $index =3D $r + $nr_of_rows * $c;
- push @cells, $tmp[$index];
- $c++;
- }
- $r++;
- }
+ while (scalar(@cells) % $cols) {
+ push @cells, "<td>$opt->{filler}</td>";
}
=20
#$out .=3D "<!-- starting table tmod=3D$tmod -->";