--- burst.pl 2001/04/17 09:47:30 1.2 +++ burst.pl 2001/05/11 14:17:27 1.16 @@ -1,6 +1,6 @@ -#!/usr/local/bin/perl +#!/usr/bin/perl # -# SLies Copyright 2001 Dobrica Pavlinusic +# PLies Copyright 2001 Dobrica Pavlinusic # # this tool is based on SlideMaker and XLSies tool # split a all.htm into slide*.htm @@ -42,13 +42,19 @@ # # Sami Lempinen - lempinen@iki.fi # http://www.snowman.sgic.fi/ssl/xslies/ +# +# Text::FastTemplate: +# Robert Lehr - bozzio@the-lehrs.com -make_dotgif("pero.gif"); +use Text::FastTemplate; ############################################################################## ## default values of variables ## +## show debug output +my $debug=0; + ## default DOCTYPE added on the slides $doctype = ''; @@ -101,6 +107,9 @@ ## standard style sheets $cssStandard = '../PLies/css/default.css'; +## template name +$template = '../PLies/default'; + ## default charset use in meta tag http-equiv (undef to skip) #$charset = 'ISO-8859-1'; @@ -120,9 +129,12 @@ ############################################################################## ## globals -my $logo_html; -my $date_html; my $last_toc_title; +my %page_data; +my %overview_data; + +my $pack = 0; +my @pack_additional; # additional files to pack (pictures, logos...) ############################################################################## ## reading user input from $infos @@ -131,35 +143,46 @@ # of the slidemaker tool #when the parameters were in Makefile or make.bat +my @file; + +############################################################################## +sub parse_infos { + my @file=@_; + do { + if ($file[0] && $file[0] =~ /^[^#\n\r]/) { + $file[0] =~ s/\n//; # remove UNIX \n + $file[0] =~ s/\r//; # remove WINDOWS \r + my ($var,$value) = split(/ *= */,$file[0],2); + $value=~s/'/\\'/g; + $cmd="\$$var = \'$value\';"; + if (defined($value)) { + eval($cmd) || warn "problem with eval of: $cmd"; + } else { + die "no value defined for $var"; + } + print STDERR "$file[0]\n"; + } + } while (shift(@file)); +} +############################################################################## + # read parameters from infos.txt and put them in @PARAM if (open(INFOS, $infos)) { - print STDOUT "--- Reading parameters file $infos ---\n"; - local(@file,$counter); - $counter = 0; - @file = ; - @PARAM = (); - do { - if ($file[0] && $file[0] =~ /^[^#\n\r]/) { - $file[0] =~ s/\n//; # remove UNIX \n - $file[0] =~ s/\r//; # remove WINDOWS \r - $file[0] =~ s/ *= */=/; - $PARAM[$counter++] = $file[0]; - print "$file[0]\n"; - } - } while (shift(@file)); + print STDERR "--- Reading parameters file $infos ---\n"; + @file = ; + parse_infos(@file); } -## @PARAM is now a table with the user preferences for his presentation -## process arguments -## each preset variable is now re-attributed using the user preferences -foreach (@PARAM) { - @_ = split(/ *= */,$_,2); - $cmd="\$$_[0] = \'$_[1]\';"; - if (length $_[1] != 0) { - eval($cmd); - } +# try to read local infos.txt for template +if (-f "$template/$infos" && open(INFOS,"$template/$infos")) { + print STDERR "--- Reading template parameters file $template/$infos ---\n"; + @file = ; + parse_infos(@file); + close(INFOS); } +## @PARAM is now a table with the user preferences for his presentation + ## use charset if ($charset) { @@ -169,20 +192,6 @@ } -## build an html string for the author variable -## containing the presentation author name linked to -## a location of his choice -if ($authorUrl) { - $author = "$author"; -} - -## same string is built if there is a second author for the presentation -if ($author2Url) { - $author2 = "
$author2"; -} elsif ($author2) { - $author2 = "
$author2"; -} - ############################################################################## ## read the raw html presentation ## @@ -190,11 +199,9 @@ ## copy file in memory my $sep = $/; $/ = undef; -if (!open(ALL, $all)) { - print "Error: Cannot open file: $all\n"; - exit 0; -} +open(ALL, $all) || die "Error: Cannot open file: $all"; my $buf = ; +$buf =~ s/\r//g; # remove WINDOWS \r close(ALL); $/ = $sep; @@ -202,6 +209,14 @@ ## they do not need to show up on the slides $buf =~ s///sgo; +## if $pack is set, output name of css (for inclusion in archive), but +## reset $cssStandard only to filename (without path) + +if ($pack) { + push @pack_additional,$cssStandard; + $cssStandard =~ s/^.*\/([^\/]+)$/$1/g; +} + ## the slidemaker tool assumes that each slide is self contained between 2 sets of h1 tags ## if not it will generate a rather weird output ## split using and as separator (ignores attributes!) @@ -221,7 +236,7 @@ ############################################################################## ## processing the slides -print STDOUT "\n--- Processing $total slides ---\n"; +print STDERR "\n--- Processing $total slides ---\n"; ## generate the header table of content of the presentation ## which is also the first page of the talk @@ -230,12 +245,46 @@ ## start the slide count so we can number them $slideCount = 1; +## pre-load template slides using $template dir +Text::FastTemplate->defaults( + path => [ $template ] + ); + +Text::FastTemplate->preload( [ + { file => 'slide.html', key => 'slide' }, + { file => 'overview.html', key => 'overview' }, + { file => 'title.html', key => 'title' }, + ]); + +## unroll relative anchors (#something) into links with slides + +my %anchor_on_slide; + +## step 1: record anchors +for($i=0; $i<$total; $i++) { + my $tmp = $table[($i*2)].$table[($i*2)+1]; + while ($tmp =~ s,,,i) { + $anchor_on_slide{$1}=($i+1); + print STDERR "\tslide ",($i+1)," anchor: $1\n" if ($debug); + } +} + +## step 2: fix links +for($i=0; $i<$total; $i++) { + foreach (keys %anchor_on_slide) { + $table[($i*2)] =~ s,href="*#$_"*>,href="slide$anchor_on_slide{$_}\.html#$_">,gi; + } +} ## @table is the array containing each slide with its title ## for each slide to be generated ## we delete each slide and its title when generated ## so that the current slide and its title are always at $table[0] (for the title) ## and $table[1] (for the slide content) + +undef $prev_title; +undef $next_title; + do { ## get rid of the first element contained by the raw presentation array @@ -251,14 +300,14 @@ ## need to check if the title contains any anchor ## if so it needs to be removed ## because the title is being used in the table of content to link to the corresponding slide - $table[0] =~ s/(.*)]*>(.*)<\/A>(.*)/$1$2$3/i; + $table[0] = remove_anchor($table[0]); ## grab next slide title $table[2] (if there's a next slide) ## to be able to use in the 'next' navigation button ## keep in mind that $table[1] contains the slide corresponding to the title $table[0] - $next_slide_title = $table[2] if $table[2]; - ## remove any anchor from the next slide title - $next_slide_title =~ s/(.*)]*>(.*)<\/A>(.*)/$1$2$3/i; + if ($table[2]) { + $next_title= remove_anchor($table[2]); + } ## the current slide content is stored $table[1] ## there is an attempt to make sure it's clean HTML @@ -268,8 +317,8 @@ ## extract slide Sub Title

undef $slideSubTitle; - if ($slideContent =~ s/<[hH]2[^>]*>([^<]+)<\/[hH]2[^>]*>//) { - $slideSubTitle=$1; + if ($slideContent =~ s/<[hH]2[^>]*>(.+)<\/[hH]2[^>]*>//sm) { + $slideSubTitle=remove_anchor($1); } ## add the title of the current slide to the table of content @@ -278,10 +327,10 @@ ## generate the current slide ## parameters are: ## title of the slide, its content, the slide number, the title of the previous slide and the title of the next slide - &createSlide($slideTitle,$slideSubTitle,$slideContent ,$slideCount++,$previous_slide_title,$next_slide_title); + &createSlide($slideTitle,$slideSubTitle,$slideContent ,$slideCount++,$prev_title,$next_title); ## save the title of the previous slide to be displayed in the 'previous' navigation button - $previous_slide_title="$table[0]"; + $prev_title=remove_anchor($table[0]); } ## process the next slide while (shift(@table)); @@ -295,8 +344,10 @@ ## and would not work on all platforms (ie would fail on Joe's laptop) &generateTOC; +## print additional files to pack +print STDOUT join("\n",@pack_additional) if ($pack); -print STDOUT "--- Finished ---\n"; +print STDERR "--- Finished ---\n"; exit 0; ## ## end of the slidemaker main program @@ -310,54 +361,42 @@ { ## open the file to write to open(FOO, ">$_[0].html") || die "can't open $_[0].html: $!"; + push @pack_additional,"$_[0].html" if ($pack); ## the style sheet used in the table of content is $stylelink = ""; ## here is the standard style sheet $stylelink .= ""; - if ($logoFile) { - $logo_html="\"$logoAlt\""; - } - - if ($logoFile2) { - $logo_html.="\"$logoAlt2\""; - } - - $title_html="

$talkTitle

"; - if (length $talkSubTitle != 0) { - $title_html.="

$talkSubTitle

"; - } - - if (length $date != 0) { - $date_html="($date)"; - } - - print FOO < - $talkTitle - $loc_toc - $http_equiv - $stylelink - - $body - - - - - - - - - - -
- - - - - -
$title_html
-
-
-

$loc_toc

-
    -END + %overview_data = ( + doctype => $doctype, + title => $title, + http_equiv => $http_equiv, + stylelink => $stylelink, + body => $body, + + logoLink => $logoLink, + logoFile => $logoFile, + logoAlt => $logoAlt, + logoLink2 => $logoLink2, + logoFile2 => $logoFile2, + logoAlt2 => $logoAlt2, + + talkTitle => $talkTitle, + talkSubTitle => $talkSubTitle, + + content_hight => $content_hight, + + author => $author, + authorUrl => $authorUrl, + author2 => $author2, + authorUrl2 => $authorUrl2, + + date => $date, + + toc_title => $loc_toc, + template => $template, + ); } ## @@ -369,40 +408,11 @@ sub closeOverview { - my $slide_html=make_progress_bar(0,$total); - print FOO < -
-
- - -END + $overview_data{slide_html} = make_progress_bar(0,$total); + $overview_data{toc_entries} = [ @toc_entries ]; + + my $page= new Text::FastTemplate key => 'overview'; + print FOO $page->output( \%overview_data ); close(FOO); } @@ -428,19 +438,27 @@ if ($nr % $toc_on_page == 0) { my $toc_nr=int($nr/$toc_on_page); - print FOO <...
-END + $item = { + pre_html => $pre_ul, + accesskey => " ", # space + href => "index-toc$toc_nr.html", + title => "...", + post_html => $post_ul, + more => 1, # use style for more pages link (...) + }; + push @toc_entries, $item; + &closeOverview; + undef @toc_entries; &openOverview("$overview-toc$toc_nr"); $last_toc_title=''; } - $ul1=$ul2=''; - if ($last_toc_title eq $title) { + $pre_ul=$post_ul=''; + if ($last_toc_title eq $title && $subtitle) { $title = $subtitle; - $ul1='
    '; - $ul2='
'; + $pre_ul='
    '; + $post_ul='
'; } else { $last_toc_title=$title; } @@ -448,13 +466,25 @@ # add accesskey for first 9 slides (`1' - `9') or just for first # TOC page, and tabindex for all slides if ($nr < 10 && $nr < $toc_on_page) { - print FOO <$title$ul2 -END + $item = { + pre_html => $pre_ul, + accesskey => "$nr", + tabindex => "$nr", + href => "slide$nr.html", + title => $title, + post_html => $post_ul, + more => 0, + }; + push @toc_entries,$item; } else { - print FOO <$title$ul2 -END + $item = { + pre_html => $pre_ul, + tabindex => "$nr", + href => "slide$nr.html", + title => $title, + post_html => $post_ul, + }; + push @toc_entries,$item; } } ## @@ -469,7 +499,7 @@ # parameters are respectively the slide title, its content, # its number, the next slide title and the previous slide title - my ($title,$subtitle,$content,$nr,$next_title,$prev_title) = @_; + my ($title,$subtitle,$content,$nr,$prev_title,$next_title) = @_; if (! $title) { return 1; @@ -497,98 +527,90 @@ $status = sprintf "Slide %2d: %s %s\n", $nr, $title, $subtitle; $status =~ s/<[^>]+>//g; - print STDOUT $status; + print STDERR $status; &verify_html($content); # check the html ## write to the slide open(SLIDE, ">slide$nr.html") || die "can't save slide$nr.html: $!"; + push @pack_additional,"slide$nr.html" if ($pack); - my $toclink = "[ Contents ]"; + my $toc_link = "$overview\.html"; ## initialization of the navigation links - my $nextlink = ""; - my $prevlink = ""; + my $next_link = ""; + my $prev_link = ""; if ($nr>1) { - $prevlink = "<<"; + $prev_link = "slide".($nr-1).".html"; # } else { # ## add a link back to the toc for the first slide --CMN 19991102 -# $prevlink = "<<"; +# $prev_link = "$overview\.html"; } if ($nr != $total) { - $nextlink = ">>"; + $next_link = "slide".($nr+1).".html"; } $stylelink = ""; # here is the standard style sheet $stylelink .= ""; - $title_html="

$title

"; - if ($subtitle) { - $title_html.="

$subtitle

"; - } - my $slide_html=make_progress_bar($nr,$total); - print SLIDE < - $talkTitle - $title - $http_equiv - $stylelink - - $body - - - - - - - - - - -
- - - - - -
$title_html
-
-
-$content -
-
- - -END - + # undefine body if no content is found (so that template can show + # only title and sub-title + if ($content !~ m/\S/g) { + undef $content; + } + + %page_data = ( + doctype => $doctype, + talkTitle => $talkTitle, + title => $title, + subtitle => $subtitle, + http_equiv => $http_equiv, + stylelink => $stylelink, + body => $body, + + logoLink => $logoLink, + logoFile => $logoFile, + logoAlt => $logoAlt, + logoLink2 => $logoLink2, + logoFile2 => $logoFile2, + logoAlt2 => $logoAlt2, + + + content_hight => $content_hight, + content => $content, + + prev_link => $prev_link, + toc_link => $toc_link, + next_link => $next_link, + prev_title => $prev_title, + toc_title => $loc_toc, + next_title => $next_title, + + author => $author, + authorUrl => $authorUrl, + author2 => $author2, + authorUrl2 => $authorUrl2, + + date => $date, + + slide_html => $slide_html, + + template => $template, + ); + + my $page; + if ($content) { + $page= new Text::FastTemplate key => 'slide'; + } else { + $page= new Text::FastTemplate key => 'title'; + } + print SLIDE $page->output( \%page_data ); + extract_files($page->output( \%page_data )) if ($pack); close(SLIDE); return 0; } @@ -636,8 +658,8 @@ if ($_[0] =~ /]*)>/im) { if (!($1 =~ /ALT=/im)) { - print STDOUT "WARNING: without ALT\n"; - print STDOUT " \n" ; + print STDERR "WARNING: without ALT\n"; + print STDERR " \n" ; } } } @@ -646,8 +668,10 @@ # clean the html of the slide # remove all
blabla
sub clean_html { - $_[0] =~ s/]|\"comment\").*?<\/div>//igs; - return $_[0]; + my $tmp=$_[0]; + $tmp =~ s/]|\"comment\").*?<\/div>//igs; + $tmp =~ s,]+>,,ig; + return $tmp; } ############################################################################## @@ -672,7 +696,7 @@ my $pcnt_done=int($nr*100/$total); my $pcnt_left=100-$pcnt_done; - if ($progress_bar) { + if ($progress_bar && uc($progress_bar) ne "NO") { my $l=$r=" "; my $t="$nr of $total"; if ($pcnt_done > 50) { @@ -680,7 +704,14 @@ } else { $r=$t; } - $html='
'.$l.''.$r.'
'; + $html=''; + if ($pcnt_done != 0) { + $html.=''; + } + if ($pcnt_left != 0) { + $html.=''; + } + $html.='
'.$l.''.$r.'
'; } else { $html="$loc_slide $nr $loc_of $total"; } @@ -688,3 +719,23 @@ return $html; } +############################################################################## +# remove anchors from html (for titles) +sub remove_anchor { + my $tmp = $_[0]; + $tmp =~ s/(.*)]*>(.*)<\/A>(.*)/$1$2$3/ig; + return $tmp; +} + +############################################################################## +# extract files referenced in presentation + +sub extract_files { + my $tmp = $_[0]; + while ($tmp =~ s/