/[sysadmin-cookbook-html]/bin/html.pl
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 /bin/html.pl

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

revision 1 by dpavlin, Wed May 13 19:51:26 2009 UTC revision 2 by dpavlin, Wed May 13 20:16:30 2009 UTC
# Line 7  my $recepies = '/srv/sysadmin-cookbook/r Line 7  my $recepies = '/srv/sysadmin-cookbook/r
7    
8  use File::Find;  use File::Find;
9  use File::Slurp;  use File::Slurp;
10    use Data::Dump qw/dump/;
 my $in_ul = 0;  
11    
12  my @html;  my @html;
13  sub html { push @html, @_ }  sub html { push @html, @_ }
# Line 21  sub file { Line 20  sub file {
20          my $content = read_file $path;          my $content = read_file $path;
21          $content =~ s{[\n\r\s]+$}{}s;          $content =~ s{[\n\r\s]+$}{}s;
22          $content =~ s/($escape_re)/$escape{$1}/gs;          $content =~ s/($escape_re)/$escape{$1}/gs;
23          return $content;          return ''
24                    . "<pre class=changes>" . `svn log $path` . "</pre>"
25                    . "<pre class=content>$content</pre>"
26                    ;
27  }  }
28    
29  my @names;  my @names;
# Line 29  find({ follow => 0, no_chdir => 1, wante Line 31  find({ follow => 0, no_chdir => 1, wante
31          push @names, $_ unless m{/\.};          push @names, $_ unless m{/\.};
32  }}, $recepies );  }}, $recepies );
33    
34    my $last_level = 0;
35    my $toc_html = '';
36    sub header {
37            my ($level, $content) = @_;
38            html qq|<a name=$content></a>|;
39            html qq|<h$level>$content</h$level>|;
40    
41            if ( $last_level > $level ) {
42                    $toc_html .= "</ul>";
43            } elsif ( $last_level < $level ) {
44                    $toc_html .= "<ul>";
45            }
46            $toc_html .= qq|<li><a href="#$content">$content</li>|;
47            $last_level = $level;
48    }
49    
50  foreach my $path ( sort @names ) {  foreach my $path ( sort @names ) {
51    
52          my $name = $path;          my $name = $path;
53          $name =~ s{^$recepies/*}{};          $name =~ s{^$recepies.*?([^/]+)$}{$1};
54            next unless $name;
55    
56          if ( -d $path ) {          if ( -d $path ) {
57                  html "</ul>" if $in_ul++;                  header 1,$name;
                 html "<h1>$name</h1><ul>";  
58          } elsif ( -l $path ) {          } elsif ( -l $path ) {
59                  my $to = readlink $path;                  my $to = readlink $path;
60                  html "<li>$name</li>";                  header 2,$name;
61                    html $to;
62          } else {          } else {
63                  html "<li>$name<pre>", file( $path ), "</pre></li>";                  header 2, $name;
64                    html file( $path );
65          }          }
66    
67  };  };
68    
69  html "</ul>" if $in_ul;  $toc_html .= "</ul>" foreach ( 1 .. $last_level );
70    
71  print qq|  print qq|
72  <html><head>  <html><head>
# Line 55  print qq| Line 75  print qq|
75  <link type=text/css rel=stylesheet href="style.css">  <link type=text/css rel=stylesheet href="style.css">
76  -->  -->
77  <style type=text/css>  <style type=text/css>
78  pre {  pre.changes {
79            color: #444;
80    }
81    pre.content {
82            padding: 1em;
83          background: #eee;          background: #eee;
84  }  }
85  </style>  </style>
86  </head><body>  </head><body>
87          |          |
88            . "<div class=toc>$toc_html</div>"
89          , join("\n", @html)          , join("\n", @html)
90          , "</body></html>"          , "</body></html>"
91          ;          ;

Legend:
Removed from v.1  
changed lines
  Added in v.2

  ViewVC Help
Powered by ViewVC 1.1.26