/[pxelator]/lib/PXElator/html.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/PXElator/html.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 307 - (show annotations)
Thu Aug 27 14:31:49 2009 UTC (14 years, 7 months ago) by dpavlin
File size: 1337 byte(s)
added zebra stripes
1 package html;
2
3 use Data::Dump qw/dump/;
4
5 sub table {
6 my $cols = shift;
7 my $th;
8
9 if ( $cols < 0 ) {
10 $cols = abs($cols);
11 $th .= qq|<th>| . shift(@_) . qq|</td>| foreach ( 1 .. $cols );
12 $th .= qq|</tr>\n<tr>|;
13 }
14
15 my @td = map { "<td>$_</td>" } @_;
16 my $html = qq{<table>\n<tr>$th};
17 my $row = 0;
18
19 foreach ( 0 .. $#td ) {
20 $html .= $td[$_];
21 if ( ( $_ + 1 ) % $cols == 0 ) {
22 $zebra = $row++ % 2 == 0 ? qq{ style="background: #eee"} : '';
23 $html .= qq{</tr>\n<tr$zebra>};
24 };
25 }
26 $html .= qq{</tr>\n</table>};
27 }
28
29 sub tabs {
30 return unless @_;
31 my $html = qq{<table border=1>\n<tr>};
32 foreach my $row ( @_ ) {
33 $row =~ s{\t}{</td><td>}g;
34 $html .= qq|<tr><td>$row</td><tr>\n|;
35 }
36 $html .= qq|</table>|;
37 return $html;
38 }
39
40
41 sub tt {
42 qq|<tt>| . join(' ', @_) . qq|</tt>| if @_;
43 }
44
45 sub select {
46 my $name = shift;
47 my $selected_option = shift;
48 return join("\n"
49 , qq|<select type=select name=$name>|
50 , join("\n", map { my $selected = $_ eq $selected_option ? 'selected' : ''; qq|<option name=$_ $selected>$_</option>| } @_ )
51 , qq|</select>|
52 , qq|</form>|
53 );
54 }
55
56 sub pre {
57 qq|<pre>| . join(' ', @_) . qq|</pre>| if @_;
58 }
59
60 sub pre_dump {
61 my $data = shift;
62 my $dump = dump( $data );
63 $dump =~ s{"([^"]+)"(\s*=>)}{$1 $2}gs;
64 $dump =~ s{"([^"]*)"}{"<b>$1</b>"}gs;
65 qq|<pre>$dump</pre>|;
66 }
67
68 warn "loaded";
69
70 1;

  ViewVC Help
Powered by ViewVC 1.1.26