[ic] using Usertag table-organize example displays nothing
Curt Hauge
interchange-users@interchange.redhat.com
Tue Oct 23 22:56:01 2001
This is a multi-part message in MIME format.
------=_NextPart_000_0004_01C15C0D.22D68960
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Thanks for your response, Jonathan! (kinda long) I'm going bald here...
Quoting Jonathan Clark:
> Firstly, what do you see in the page? If you see [table-organize] on the
> page, interchange is not treating it as a valid usertag.
This basic code:
[include templates/regions/top]
[include templates/regions/left]
[search-region]
<!-- this is where the table should be -->
<table>
[search-list]
[table-organize
interpolate=1
cols=3
pretty=1
tr.0='bgcolor="#EEEEEE"'
tr.1='bgcolor="#FFFFFF"'
td.0='align=right'
td.1='align=center'
td.2='align=left'
]
[loop list="1 2 3 1a 2a 3a 1b"] <td> [loop-code] </td> [/loop]
[/table-organize]
[/search-list]
</table>
[/search-region]
[include templates/regions/bottom]
Produces this (no ouput to page):
<html>
<head>
<title>The Interchange Test Catalog</title>
</head>
<body>
<div align=center>
<table width="80%" border cellpadding=15>
<tr><td colspan=2 align=center><h1>The Interchange Test
Catalog</h1></td></tr>
<tr>
<td align=center>(left)</td>
<td align=center>
<!-- this is where the table should be -->
<table>
</table>
</td>
</tr>
<tr><td colspan=2 align=center>(bottom)</td></tr>
</table>
</div>
</body>
</html>
This is basicly the example in the documentation, shown below. It does not
show the [table-organize] code or even <table> code, just blank space where
the table should be. It seems to parse the code, but outputs nothing. The
rest of the page output is fine.
> If you have a valid usertag file in the correct location, and restart ic,
> you don't need a reference in the interchange.cfg as well.
OK, I removed all table_organize references in interchange.cfg and I put the
usertag table_organize in /usr/lib/interchange/usertag, and restarted IC.
> Lets make sure ic is has the usertag compiled in before continuing... then
> pls provide the complete code for the use of the tag
Usage is below, I also attached the full tag routine:
UserTag table-organize Documentation <<EOD
=head2 table-organize
usage: [table-organize <options>]
[loop ....] <td> [loop-tags] </td> [/loop]
[/table-organize]
Takes an unorganized set of table cells and organizes them into
rows based on the number of columns; it will also break them into
separate tables.
If the number of cells are not on an even modulus of the number of columns,
then "filler" cells are pushed on.
Parameters:
=over 4
=item cols (or columns)
Number of columns. This argument defaults to 2 if not present.
=item rows
Optional number of rows. Implies "table" parameter.
=item table
If present, will cause a surrounding <TABLE > </TABLE> pair with the
attributes
specified in this option.
=item caption
Table <CAPTION> container text, if any. Can be an array.
=item td
Attributes for table cells. Can be an array.
=item tr
Attributes for table rows. Can be an array.
=item pretty
Adds newline and tab characters to provide some reasonable indenting.
=item filler
Contents to place in empty cells put on as filler. Defaults to C< >.
=item limit
Maximum number of cells to use. Truncates extra cells silently.
=back
The C<tr>, C<td>, and C<caption> attributes can be specified with indexes;
if they are, then they will alternate according to the modulus.
The C<td> option array size should probably always equal the number of
columns;
if it is bigger, then trailing elements are ignored. If it is smaller, no
attribute
is used.
For example, to produce a table that 1) alternates rows with background
colors C<#EEEEEE> and C<#FFFFFF>, and 2) aligns the columns RIGHT CENTER
LEFT, do:
[table-organize
cols=3
pretty=1
tr.0='bgcolor="#EEEEEE"'
tr.1='bgcolor="#FFFFFF"'
td.0='align=right'
td.1='align=center'
td.2='align=left'
]
[loop list="1 2 3 1a 2a 3a 1b"] <td> [loop-code] </td> [/loop]
[/table-organize]
which will produce:
<tr bgcolor="#EEEEEE">
<td align=right>1</td>
<td align=center>2</td>
<td align=left>3</td>
</tr>
<tr bgcolor="#FFFFFF">
<td align=right>1a</td>
<td align=center>2a</td>
<td align=left>3a</td>
</tr>
<tr bgcolor="#EEEEEE">
<td align=right>1b</td>
<td align=center> </td>
<td align=left> </td>
</tr>
See the source for more ideas on how to extend this tag.
EOD
------=_NextPart_000_0004_01C15C0D.22D68960
Content-Type: application/octet-stream;
name="table_organize"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="table_organize"
UserTag table-organize Documentation <<EOD
=3Dhead2 table-organize
usage: [table-organize <options>]
[loop ....] <td> [loop-tags] </td> [/loop]
[/table-organize]
Takes an unorganized set of table cells and organizes them into
rows based on the number of columns; it will also break them into
separate tables.
If the number of cells are not on an even modulus of the number of =
columns,
then "filler" cells are pushed on.
Parameters:
=3Dover 4
=3Ditem cols (or columns)
Number of columns. This argument defaults to 2 if not present.
=3Ditem rows
Optional number of rows. Implies "table" parameter.
=3Ditem table
If present, will cause a surrounding <TABLE > </TABLE> pair with the =
attributes
specified in this option.
=3Ditem caption
Table <CAPTION> container text, if any. Can be an array.
=3Ditem td
Attributes for table cells. Can be an array.
=3Ditem tr
Attributes for table rows. Can be an array.
=3Ditem pretty
Adds newline and tab characters to provide some reasonable indenting.
=3Ditem filler
Contents to place in empty cells put on as filler. Defaults to =
C< >.
=3Ditem limit
Maximum number of cells to use. Truncates extra cells silently.
=3Dback
The C<tr>, C<td>, and C<caption> attributes can be specified with =
indexes;
if they are, then they will alternate according to the modulus.
The C<td> option array size should probably always equal the number of =
columns;
if it is bigger, then trailing elements are ignored. If it is smaller, =
no attribute
is used.
For example, to produce a table that 1) alternates rows with background
colors C<#EEEEEE> and C<#FFFFFF>, and 2) aligns the columns RIGHT CENTER
LEFT, do:
[table-organize
cols=3D3
pretty=3D1
tr.0=3D'bgcolor=3D"#EEEEEE"'
tr.1=3D'bgcolor=3D"#FFFFFF"'
td.0=3D'align=3Dright'
td.1=3D'align=3Dcenter'
td.2=3D'align=3Dleft'
]
[loop list=3D"1 2 3 1a 2a 3a 1b"] <td> [loop-code] </td> =
[/loop]
[/table-organize]
which will produce:
<tr bgcolor=3D"#EEEEEE">
<td align=3Dright>1</td>
<td align=3Dcenter>2</td>
<td align=3Dleft>3</td>
</tr>
<tr bgcolor=3D"#FFFFFF">
<td align=3Dright>1a</td>
<td align=3Dcenter>2a</td>
<td align=3Dleft>3a</td>
</tr>
<tr bgcolor=3D"#EEEEEE">
<td align=3Dright>1b</td>
<td align=3Dcenter> </td>
<td align=3Dleft> </td>
</tr>
See the source for more ideas on how to extend this tag.
EOD
UserTag table-organize Order cols
UserTag table-organize attrAlias columns cols
UserTag table-organize Interpolate
UserTag table-organize addAttr
UserTag table-organize hasEndTag
UserTag table-organize Routine <<EOR
sub {
my ($cols, $opt, $body) =3D @_;
$cols =3D int($cols) || 2;
$body =3D~ s/(.*?)(<td)\b/$2/is;
my $out =3D $1;
$body =3D~ s:(</td>)(?!.*</td>)(.*):$1:is;
my $postamble =3D $2;
my @cells;
push @cells, $1 while $body =3D~ s:(<td\b.*?</td>)::is;
if(int($opt->{limit}) and $opt->{limit} < scalar(@cells) ) {
splice(@cells, $opt->{limit});
}
for(qw/ table/) {
$opt->{$_} =3D defined $opt->{$_} ? " $opt->{$_}" : '';
}
my @td;
if(! $opt->{td}) {
@td =3D '' x $cols;
}
elsif (ref $opt->{td} ) {
@td =3D @{$opt->{td}};
push @td, '' while scalar(@td) < $cols;
}
else {
@td =3D " $opt->{td}" x $cols;
}
my %attr;
for(qw/caption tr/) {
if( ! $opt->{$_} ) {
#do nothing
}
elsif (ref $opt->{$_}) {
$attr{$_} =3D $opt->{$_};
}
else {
$attr{$_} =3D [$opt->{$_}];
}
}
my $pretty =3D $opt->{pretty};
$opt->{td} =3D~ s/^(\S)/ $1/;
$opt->{tr} =3D~ s/^(\S)/ $1/;
my @rest;
my $rows;
my $rmod;
my $tmod =3D 0;
my $total_mod;
$opt->{filler} =3D ' ' if ! defined $opt->{filler};
if($rows =3D int($opt->{rows}) ) {
$total_mod =3D $rows * $cols;
@rest =3D splice(@cells, $total_mod)
if $total_mod < @cells;
$opt->{table} =3D ' ' if ! $opt->{table};
}
my $joiner =3D $pretty ? "\n\t\t" : "";
while(@cells) {
while (scalar(@cells) % $cols) {
push @cells, "<td>$opt->{filler}</td>";
}
#$out .=3D "<!-- starting table tmod=3D$tmod -->";
if($opt->{table}) {
$out .=3D "<table$opt->{table}>";
$out .=3D "\n" if $pretty;
if($opt->{caption}) {
my $idx =3D $tmod % scalar(@{$attr{caption}});
#$out .=3D "<!-- caption index $idx -->";
$out .=3D "\n" if $pretty;
$out .=3D "<CAPTION>" . $attr{caption}[$idx] . "</CAPTION>";
$out .=3D "\n" if $pretty;
}
}
$rmod =3D 0;
while(@cells) {
$out .=3D "\t" if $pretty;
$out .=3D "<tr";
if($opt->{tr}) {
my $idx =3D $rmod % scalar(@{$attr{tr}});
$out .=3D " " . $attr{tr}[$idx];
}
$out .=3D ">";
$out .=3D "\n\t\t" if $pretty;
my @op =3D splice (@cells, 0, $cols);
if($opt->{td}) {
for ( my $i =3D 0; $i < $cols; $i++) {
$op[$i] =3D~ s/(<td)/$1 $td[$i]/i;
}
}
$out .=3D join($joiner, @op);
$out .=3D "\n\t" if $pretty;
$out .=3D "</tr>";
$out .=3D "\n" if $pretty;
$rmod++;
}
if($opt->{table}) {
$out .=3D "</table>";
$out .=3D "\n" if $pretty;
}
if(@rest) {
my $num =3D $total_mod < scalar(@rest) ? $total_mod : scalar(@rest);
@cells =3D splice(@rest, 0, $num);
}
$tmod++;
}
return $out . $postamble;
}
EOR
------=_NextPart_000_0004_01C15C0D.22D68960--