I implemented this through the use of a CGI script and a patched Template Toolkit installation. This patch to the Template Toolkit was to add support for bitwise AND and XOR operations into templates - This patch can be found here and has been submitted to Andy Wardley for consideration for incorporation into the Template Toolkit distribution. This code made the development of this Folder Tree functionality quite easy and can be demonstrated temporarily here.
The CGI script employed is quite simple:
#!/usr/bin/perl -Tw use CGI; use CGI::Carp qw/ fatalsToBrowser /; use Template; use strict; my $cgi = CGI->new; my $index = 0; if ( defined $cgi->path_info ) { my $path = substr( $cgi->path_info, 1 ); $index = $1 if $path =~ /^(\d+)$/; } my $template = Template->new({ 'INCLUDE_PATH' => '/http/development.co +wsnet.com.au/templates' }); my $html = ''; $template->process( 'navigation.tt2', { 'index' => $index }, \$html ) || croak( 'main:: - Cannot process output template - ', $template->e +rror ); print STDOUT $cgi->header, $html; exit 0;
The corresponding template file can be found here - The integer value passed to this CGI script as additional path information is employed through the use of bitwise operations in the template in the following fashion:
<tr> <td bgcolor="#eeeeee" style="padding:2px 4px 2px 4px;" onMouse +Out="this.style.backgroundColor='#eeeeee';" onMous eOver="this.style.backgroundColor='#cbcbe8';"> <font face="Arial" style="font-size:8pt;"><b><a href="/cgi-b +in/navigation.cgi/[% index ^ 1 %]" style="text-dec oration:none;">Access Control</a></b></font><br> </td> </tr> [% IF index & 1 %] <tr> <td bgcolor="#aaaaaa"><img src="/images/spacer.gif" border="0" + height="1" width="1" alt="" /></td> </tr> . . [% END %]
The bitwise AND and XOR operations are used to test the expansion/collapse state of the folder tree and the switching of integer bits respectively.
perl -e 'print+unpack("N",pack("B32","00000000000000000000000111101110")),"\n"'
In reply to Re: Folder Tree functionality in perl. Does it exist?
by rob_au
in thread Folder Tree functionality in perl. Does it exist?
by tachyon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |