/[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 161 by dpavlin, Thu Aug 6 18:09:30 2009 UTC revision 362 by dpavlin, Sun Aug 30 10:38:13 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            my $row = 0;
18    
19          foreach ( 0 .. $#td ) {          foreach ( 0 .. $#td ) {
20                          $html .= $td[$_];                          $html .= $td[$_];
21                          $html .= qq{</tr>\n<tr>} if $_ % $cols == 1;                          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>};          $html .= qq{</tr>\n</table>};
27  }  }
# Line 24  sub tabs { Line 39  sub tabs {
39                    
40    
41  sub tt {  sub tt {
42          qq|<tt>| . join(' ', @_) . qq|</tt>|;          qq|<tt>| . join(' ', @_) . qq|</tt>| if @_;
43  }  }
44    
45  sub select {  sub select {
46          my $name = shift;          my $name = shift;
47          my $selected_option = shift;          my $selected_option = shift;
48            unshift @_, '' unless $selected_option;
49          return join("\n"                  return join("\n"        
50                  , qq|<select type=select name=$name>|                  , qq|<select type=select name=$name>|
51                  , join("\n", map { my $selected = $_ eq $selected_option ? 'selected' : ''; qq|<option name=$_ $selected>$_</option>| } @_ )                  , join("\n", map { my $selected = $_ eq $selected_option ? 'selected' : ''; qq|<option name=$_ $selected>$_</option>| } @_ )
# Line 38  sub select { Line 54  sub select {
54          );          );
55  }  }
56    
57    sub pre {
58            qq|<pre>| . join(' ', @_) . qq|</pre>| if @_;
59    }
60    
61    sub pre_dump {
62            my $data = shift;
63            my $dump = dump( $data );
64            $dump =~ s{"([^"]+)"(\s*=>)}{$1  $2}gs;
65            $dump =~ s{"([^"]*)"}{"<b>$1</b>"}gs;
66            qq|<pre>$dump</pre>|;
67    }
68    
69    sub conf {
70            my ($ip,$conf,$format) = @_;
71            my @editable = splice(@_,3);
72    
73            warn "# conf ",dump( $ip, $conf, $format, [ @editable ] );
74    
75            $format ||= 'inline';
76    
77            my @opts = map {
78                    my $name = $_;
79                    my $html = $conf->{$name};
80    
81                    if ( $format eq 'edit' && grep { m/^$name$/ } @editable ) {
82                            $size = length($html);
83                            ( $name, qq|<input name=$name value="$html" size=$size>| )
84                    } else {
85                            if ( $name eq 'amt' ) {
86                                    $html = qq|<a title="$html" href=http://$ip:16992/logon.htm>logon</a>|;
87                            } elsif ( $name eq 'ssh' ) {
88                                    $html =~ s{\s(\S{16}).+(\S{16})\s}{ $1..$2 };
89                                    chomp($html);
90                            }
91                            $html = qq|<pre style="display: inline">$html</pre>|
92                            unless
93                            $html =~ s{\b(\S+)\t(\S+)\t(\S+)\b}{<b title="$1/$2">$3</b> }gs;
94                    
95                            if ( $format =~ /edit|table/ ) {
96                                    ( $name, $html );
97                            } else {
98                                    qq|<em>$name</em> $html<br>|
99                            }
100                    }
101            } sort keys %$conf;
102    
103            $format eq 'inline' ? join("\n", @opts) : @opts;
104    }
105    
106  warn "loaded";  warn "loaded";
107    
108  1;  1;

Legend:
Removed from v.161  
changed lines
  Added in v.362

  ViewVC Help
Powered by ViewVC 1.1.26