Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Update: I am done mostly with writing the indexes. There are a few parts of the code that I am still mulling over. The following is a basic index script.

#!/usr/bin/perl # This is the index for <dir>. use strict; use warnings FATAL => qw( all ); use CGI::Carp qw(fatalsToBrowser); use CGI::Minimal; use HTML::Entities qw(encode_entities); use lib '../files/lib'; use Base::Page qw(page story); use HTML::Elements qw(list anchor); use Util::Convert qw(searchify); use Util::Data qw(file_directory file_list); use Util::Menu qw(file_menu); use Util::Sort qw(article_sort); my $cgi = CGI::Minimal->new; my $page = $cgi->param('page') ? encode_entities($cgi->param('pa +ge'),'/<>"') : undef; my $pages_dir = file_directory(<dir>, 'text'); my @pages_list = file_list($pages_dir); my @pages = sort { article_sort($a, $b) } map { $_ =~ s/\.txt//; $_ =~ s/_/ /g; $_ } grep { -f "$pages_dir/$_" && /^\p{uppercase}/ } @pages_list; my $heading = q(<the heading for the index>); my $page_file = "$pages_dir/index.txt"; if ( $page && grep { $_ eq $page } @pages ) { $heading = $page; $page_file = "$pages_dir/$page.txt"; $page_file =~ s/ /_/g; } open(my $page_fh, '<', $page_file) || die "Can't open $page_file. $!"; my $magic; $magic->{'pages'} = sub { my $file_menu = file_menu('page', \@pages, $page); list(4, 'u', $file_menu); }; page( 'heading' => $heading, 'selected' => $page, 'code' => sub { story($page_fh, { 'doc magic' => $magic, 'line magic' => $magic }) +; } );

I have 5 page-scripts that do not use story, so they are still independent scripts for now until I can figure out how to get them into the menu automatically if I put their code into their indexes. I mentioned in the OP that I had to rewrite my base_menu subroutine. Lines 16-28 took me several hours over a couple of days to get right.

sub base_menu { my %opt = @_; my $directory = $opt{'directory'}; my $root_path = $opt{'root path'}; my $curr_cwd = cwd; my @contents = file_list($directory); @contents = grep {/^\p{uppercase}/} @contents if (!$opt{'full'} || $ +opt{'full'} !~ /^[yt1]/); # Thank you [tye]! # Thank you [davido]! my $sub = $directory =~ /(Other_poets|Player_characters|Spellbooks)$ +/ ? \&name_sort : \&article_sort; @contents = sort { $sub->($a, $b, { 'misc' => $opt{'misc'} }) } @con +tents; my (@files, @directories); if (!$opt{'full'} || $opt{'full'} !~ /^[yt1]/) { my $text_dir = $directory; $text_dir =~ s|(\Q$root_path\E)|$1/files/text|; my @text_files = sort { $sub->($a, $b, { 'misc' => $opt{'misc'} }) + } file_list($text_dir, { 'uppercase' => 1 }) if -e $text_dir; for my $text_file (@text_files) { my $text = textify($text_file); my $select = searchify($text_file); my $link = File::Spec->abs2rel("$directory/index.pl?page=$sele +ct"); my $class = $opt{'selected'} && $opt{'selected'} eq $text ? 'ac +tive' : 'inactive'; my $anchor = anchor($text, { 'href' => $link, 'title' => $text}) +; push @files, [$anchor, { 'class' => $class }] if -f "$text_dir/$ +text_file"; } } for my $content (@contents) { my $long_content = "$directory/$content"; my $link = File::Spec->abs2rel($long_content); my $text = $content !~ /^\./ ? textify($content) : $content; if (-f $long_content) { my $active = realpath($0) eq $long_content ? 'active' : 'inactiv +e'; my $color = $opt{'color'} == 1 ? link_color($content,1) : undef +; my $inlist = $active eq 'active' && $opt{'file menu'} ? ['u', $o +pt{'file menu'}, { 'class' => 'sub_menu' }] : undef; $active .= $active eq 'active' && $opt{'file menu'} ? ' open' +: ''; if (-M $long_content < 3) { $active .= ' updated'; } my $anchor = anchor($text, { 'href' => $link, 'title' => $text, +'style' => $color }); push @files, [$anchor, { 'class' => $active, 'inlist' => $inlist + }]; } if (-d $long_content) { my $active = $curr_cwd =~ /$long_content/ ? 'open active' : 'clo +sed inactive'; my $index = "$long_content/index.pl"; my $file_list; my $anchor; if (-e $index && (!$opt{'full'} || $opt{'full'} !~ /^[yt1]/)) { $link .= "/index.pl"; my $color = $opt{'color'} == 1 ? link_color($link,1) : undef; $anchor = anchor($text, { 'href' => $link, 'title' => $text, ' +style' => $color }); $file_list = "$curr_cwd/$0" =~ /$index/ && $active =~ / active +$/ && $opt{'file menu'} ? $opt{'file menu'} : undef; } my $next_list = base_menu( 'directory' => $long_content, 'color' => $opt{'color'}, 'full' => $opt{'full'}, 'misc' => $opt{'misc'}, 'selected' => $opt{'selected'}, 'file menu' => $opt{'file menu'}, 'root path' => $opt{'root path'} ); push @$next_list, @$file_list if $file_list; my $inlist = $next_list ? ['u', $next_list] : undef; $active =~ s/^(?:open|closed) // if !$inlist; push @directories, [$anchor ? $anchor : $text, { 'class' => $act +ive, 'inlist' => $inlist}]; } } my @file_lines = (@files, @directories); return @file_lines > 0 ? \@file_lines : undef; }

My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.8.8 on web host.

Version control is a non-issue, I do not use it.

No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena

In reply to Re: Collapsing smaller scripts into a larger one, request for comment by Lady_Aleena
in thread Collapsing smaller scripts into a larger one, request for comment by Lady_Aleena

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (3)
    As of 2021-04-23 02:01 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?