/[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 172 by dpavlin, Thu Aug 6 22:27:34 2009 UTC revision 346 by dpavlin, Sat Aug 29 16:51:07 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;          my $th;
# Line 12  sub table { Line 14  sub table {
14    
15          my @td = map { "<td>$_</td>" } @_;          my @td = map { "<td>$_</td>" } @_;
16          my $html = qq{<table>\n<tr>$th};          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 ( $_ + 1 ) % $cols == 0;                          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 32  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 46  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                            }
88                            $html = qq|<pre style="display: inline">$html</pre>|
89                            unless
90                            $html =~ s{\b(\S+)\t(\S+)\t(\S+)\b}{<b title="$1/$2">$3</b> }gs;
91                    
92                            if ( $format =~ /edit|table/ ) {
93                                    ( $name, $html );
94                            } else {
95                                    qq|<em>$name</em> $html<br>|
96                            }
97                    }
98            } keys %$conf;
99    
100            $format eq 'inline' ? join("\n", @opts) : @opts;
101    }
102    
103  warn "loaded";  warn "loaded";
104    
105  1;  1;

Legend:
Removed from v.172  
changed lines
  Added in v.346

  ViewVC Help
Powered by ViewVC 1.1.26