/[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

Diff of /lib/PXElator/html.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 64 by dpavlin, Thu Jul 30 16:26:54 2009 UTC revision 187 by dpavlin, Sun Aug 9 21:59:17 2009 UTC
# Line 1  Line 1 
1  package html;  package html;
2    
3    use Data::Dump qw/dump/;
4    
5  sub table {  sub table {
6          my $cols = shift;          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>" } @_;          my @td = map { "<td>$_</td>" } @_;
16          my $html = qq{<table>\n<tr>};          my $html = qq{<table>\n<tr>$th};
17          foreach ( 0 .. $#td ) {          foreach ( 0 .. $#td ) {
18                          $html .= $td[$_];                          $html .= $td[$_];
19                          $html .= qq{</tr>\n<tr>} if $_ % $cols == 1;                          $html .= qq{</tr>\n<tr>} if ( $_ + 1 ) % $cols == 0;
20          }          }
21          $html .= qq{</tr>\n</table>};          $html .= qq{</tr>\n</table>};
22  }  }
23    
24    sub tabs {
25            return unless @_;
26            my $html = qq{<table border=1>\n<tr>};
27            foreach my $row ( @_ ) {
28                    $row =~ s{\t}{</td><td>}g;
29                    $html .= qq|<tr><td>$row</td><tr>\n|;
30            }
31            $html .= qq|</table>|;
32            return $html;
33    }
34            
35    
36  sub tt {  sub tt {
37          qq|<tt>| . join(' ', @_) . qq|</tt>|;          qq|<tt>| . join(' ', @_) . qq|</tt>|;
38  }  }
39    
40    sub select {
41            my $name = shift;
42            my $selected_option = shift;
43            return join("\n"        
44                    , qq|<select type=select name=$name>|
45                    , join("\n", map { my $selected = $_ eq $selected_option ? 'selected' : ''; qq|<option name=$_ $selected>$_</option>| } @_ )
46                    , qq|</select>|
47                    , qq|</form>|
48            );
49    }
50    
51    sub pre_dump {
52            my $data = shift;
53            my $dump = dump( $data );
54            $dump =~ s{"([^"]+)"(\s*=>)}{$1  $2}gs;
55            $dump =~ s{"([^"]*)"}{"<b>$1</b>"}gs;
56            qq|<pre>$dump</pre>|;
57    }
58    
59  warn "loaded";  warn "loaded";
60    
61  1;  1;

Legend:
Removed from v.64  
changed lines
  Added in v.187

  ViewVC Help
Powered by ViewVC 1.1.26