moseley     02/05/23 15:42:02

  Modified:    src/search .swishcgi.conf
  Added:       src/search make.pl
  Removed:     src/search search_options
  Log:
  Here's the unified version of the search options that Stas requested.
  
  make.pl must be run befor generating any pages.
  I'm not clear how (or if) Docset can do that automatically.
  
  The code see ok, Stas?
  
  Revision  Changes    Path
  1.11      +6 -102    modperl-docs/src/search/.swishcgi.conf
  
  Index: .swishcgi.conf
  ===================================================================
  RCS file: /home/cvs/modperl-docs/src/search/.swishcgi.conf,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- .swishcgi.conf    15 May 2002 04:22:13 -0000      1.10
  +++ .swishcgi.conf    23 May 2002 22:42:02 -0000      1.11
  @@ -1,88 +1,11 @@
   
  -
  -# Display swish times in GMT
  -
  -$ENV{TZ} = 'UTC';
  +use Storable;
  +my $CHECKBOX_DATA = 'checkboxes.storable';
   
   
  -# Stas added tree display - Apr 15, 2002
  -# syntax (amount of spaces doesn't matter):
  -# indent path title
  -#
  -
  -
  -my $items = <<ITEMS;
  -    0 outstanding Technologie Extraordinaire
  -    0 download    Download
  -    0 docs        Documentation
  -    1   docs/1.0 mod_perl 1.0 Docs
  -    2     docs/1.0/guide Guide
  -    2     docs/1.0/win32 Win32
  -    2     docs/1.0/api   API
  -    1   docs/2.0 mod_perl 2.0 Docs
  -    2     docs/2.0/user  User
  -    2     docs/2.0/devel Developer
  -    2     docs/2.0/api   API
  -    1   docs/general      General Docs
  -    1   docs/tutorials    Tutorials
  -    1   docs/offsite      OffSite Docs
  -    0 help       Getting Help
  -    0 products   Products
  -    0 contribute Contribute
  -ITEMS
  -
  -my @items_flat = split /\n/, $items, ;
  -
  -my @items = ();
  -my $parent;
  -my $cur_indent = 0;
  -for my $item (@items_flat) {
  -    $item = '' unless defined $item;
  -    my ($indent, $path, $title);
  -    if ($item =~ m|^\s*(\d+)\s+(\S+)\s+(.*)$|) {
  -        ($indent, $path, $title) = ($1, $2, $3)
  -    }
  -    else {
  -        warn "couldn't parse '$item'";
  -        next;
  -    }
  -
  -    my $node = {
  -        label  => $title,
  -        value  => $path,
  -        parent => $parent,
  -    };
  -
  -    my $diff = $indent - $cur_indent;
  -    #print "$indent, $cur_indent, $path, $title\n";
  -    if ($diff < 1 ) {
  -        for (0..abs($diff)) {
  -            $parent = $parent->{parent};
  -            $cur_indent--;
  -        }
  -    }
  -
  -    if ($indent == 0) {
  -        push @items, $node;
  -        $parent = $items[-1];
  -        $cur_indent = 0;
  -        next;
  -    }
  -
  -    if ($diff > 1) {
  -        $cur_indent++;
  -        $parent = @{ $parent->{subs} }[-1];
  -        push @{ $parent->{subs} }, $node;
  -    }
  -    else { # $indent - $cur_indent = 1
  -        push @{ $parent->{subs} }, $node;
  -    }
  -
  -}
  -
  -#use Data::Dumper;
  -#print Dumper [EMAIL PROTECTED];
   
  +# Display swish times in GMT
  +$ENV{TZ} = 'UTC';
   
   return {
       title           => 'Search mod_perl Site',
  @@ -108,30 +31,11 @@
           columns     => 6,
           metaname    => 'section',     # Can't be a metaname used elsewhere!
   
  -        # These are the words (phrases) used for limiting searches to areas 
of the document tree
  -        values      => [qw(
  -            docs
  -            docs/1.0/guide
  -            docs/2.0
  -            maillist
  -            stories
  -            support
  -        )],
  -
  -        labels  => {
  -            docs        => 'mod_perl Documentation',
  -            'docs/1.0/guide'    => 'The Guide',
  -            'docs/2.0'  => '2.0 Docs',
  -            maillist    => 'Mailing Lists',
  -            products    => 'mod_perl Based Software',
  -            stories     => 'Sucess Stories',
  -            support     => 'Support Options',
  -        },
   
           description => 'Limit search to these areas: ',
   
  -        # This is the tree structure of selects
  -        items       => [EMAIL PROTECTED],
  +        # This is the tree structure of selects, saved with Storable
  +        items       => retrieve( $CHECKBOX_DATA ),
       },
       
   };
  
  
  
  1.1                  modperl-docs/src/search/make.pl
  
  Index: make.pl
  ===================================================================
  #!/usr/local/bin/perl -w
  use strict;
  use Storable;
  
  # This must match up with .swishcgi.conf setting
  my $CHECKBOX_DATA = 'checkboxes.storable';
  
  # This is used for all pages -- it's the array and has for the sidebar search
  my $SEARCH_OPTIONS = 'search_options';
  
  
  # Stas added tree display - Apr 15, 2002
  # Rewritten May 23, 2000 at Stas' request to centralize the input data in one 
place
  # syntax (amount of spaces doesn't matter):
  # indent, path, title, optional short title (for drop down list)
  #
  
  
  my $items = <<ITEMS;
      0, outstanding, Technologie Extraordinaire, Stories
      0, download,    Download, Download
      0, docs,        Documentation, All Docs
      1,   docs/1.0, mod_perl 1.0 Docs, 1.0 Docs
      2,     docs/1.0/guide, Guide,
      2,     docs/1.0/win32, Win32
      2,     docs/1.0/api,   API
      1,   docs/2.0, mod_perl 2.0 Docs, 2.0 Docs
      2,     docs/2.0/user,  User
      2,     docs/2.0/devel, Developer
      2,     docs/2.0/api,   API
      1,   docs/general,      General Docs
      1,   docs/tutorials,    Tutorials
      1,   docs/offsite,      OffSite Docs
      0, help,       Getting Help
      0, maillist,  Mailing Lists
      0, products,   Products
      0, contribute, Contribute
  ITEMS
  
  
  
      my @items_flat = map {
               s/^\s+//;
               s/\s+$//;
               my %h;
               @h{qw/indent value label short/} = split m!\s*,\s*!;
  
               $h{short} ||= ( $h{label} || 'missing description' );
  
               \%h
          } split /\n/, $items;
  
  
      my $array_values = join "\n", map { ' ' x (( $_->{indent}+2 ) * 4) . 
qq["$_->{value}"] }  @items_flat;
      my $hash_values  = join "\n", map {
          my $dots = '..' x  $_->{indent};
          my $spaces = ' ' x (( $_->{indent}+2 ) * 4);
          qq[$spaces"$_->{value}" => "$dots$_->{short}" ]
      } @items_flat;
          
      my $check_box_array = build_array( [EMAIL PROTECTED] );
  
  #use Data::Dumper;                
  #print Dumper $check_box_array;
  
      store( $check_box_array, $CHECKBOX_DATA );  # store for swish.cgi
  
      # Now write out the search_options
      open FH, ">$SEARCH_OPTIONS" or die "Failed to open '$SEARCH_OPTIONS': $!";
  
      my $now = scalar localtime;
      
      print FH <<EOF;
  [%-
  
#--------------------------------------------------------------------------------------
  # *** Automatically generated file.  Do not edit.  Modify $0 instead! ***
  #    File: '$SEARCH_OPTIONS'
  #     Use: generating the sidebar select options for searching
  # Created: $now
  
#--------------------------------------------------------------------------------------
  
      search_areas = [
          ""
  $array_values
      ]
  
      search_labels = {
          ""          => 'Whole Site'
  $hash_values        
      }
  -%]
  EOF
  
      close FH || warn "Failed to close '$SEARCH_OPTIONS': $!";
  
      warn "Built search data structures\n";
      
  
  
  
#==============================================================================
  # Subroutine that builds the data structure expected by template toolkit
  # TT uses values .value, .label, and .subs.  See search.tt for example
  #
  #
  #
  sub build_array {
      my ( $items ) = @_;
  
      my $indent = $items->[0]{indent};
  
      my @array;
  
      while ( @$items ) {  # more left in array?
  
          if ( $items->[0]{indent} == $indent ) {      # this is the level we 
are processing
              push @array, shift @$items;
  
          } elsif ( $items->[0]{indent} < $indent ) {  # all done with this 
level, so just return
              return [EMAIL PROTECTED];
  
          } else {                                        # found an indented 
section
              $array[-1]{subs} = build_array( $items );
          }
      }
  
      return [EMAIL PROTECTED];
  }
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to