--- burst.pl 2001/04/20 08:01:02 1.4 +++ burst.pl 2001/05/05 19:20:27 1.7 @@ -1,4 +1,4 @@ -#!/usr/local/bin/perl +#!/usr/bin/perl # # SLies Copyright 2001 Dobrica Pavlinusic # @@ -42,11 +42,19 @@ # # Sami Lempinen - lempinen@iki.fi # http://www.snowman.sgic.fi/ssl/xslies/ +# +# Text::FastTemplate: +# Robert Lehr - bozzio@the-lehrs.com + +use Text::FastTemplate; ############################################################################## ## default values of variables ## +## show debug output +my $debug=1; + ## default DOCTYPE added on the slides $doctype = ''; @@ -99,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'; @@ -118,9 +129,9 @@ ############################################################################## ## globals -my $logo_html; -my $date_html; my $last_toc_title; +my %page_data; +my %overview_data; ############################################################################## ## reading user input from $infos @@ -131,31 +142,34 @@ # 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 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)); } ## @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); - } + my ($var,$value) = split(/ *= */,$_,2); + $value=~s/'/\\'/g; + $cmd="\$$var = \'$value\';"; + if ($value) { + eval($cmd) || die "problem with eval of: $cmd"; + } else { + die "no value defined for $var"; + } } ## use charset @@ -166,22 +180,6 @@ $http_equiv=''; } - -## 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"; -} -if ($author2) { - $author2 = "
$author2"; -} - ############################################################################## ## read the raw html presentation ## @@ -189,10 +187,7 @@ ## 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 = ; close(ALL); $/ = $sep; @@ -229,12 +224,45 @@ ## 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' }, + ]); + +## 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)]; + while ($tmp =~ s,,,i) { + $anchor_on_slide{$1}=($i+1); + print "\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 @@ -255,9 +283,11 @@ ## 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= $table[2]; + ## remove any anchor from the next slide title + $next_title =~ s/(.*)]*>(.*)<\/A>(.*)/$1$2$3/i; + } ## the current slide content is stored $table[1] ## there is an attempt to make sure it's clean HTML @@ -277,10 +307,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="$table[0]"; } ## process the next slide while (shift(@table)); @@ -315,48 +345,34 @@ ## here is the standard style sheet $stylelink .= ""; - if ($logoFile) { - $logo_html="\"$logoAlt\""; - } + %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, - if ($logoFile2) { - $logo_html.="\"$logoAlt2\""; - } + date => $date, - $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 + toc => $loc_toc, + ); } ## @@ -368,40 +384,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); } @@ -427,19 +414,26 @@ 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; &openOverview("$overview-toc$toc_nr"); $last_toc_title=''; } - $ul1=$ul2=''; + $pre_ul=$post_ul=''; if ($last_toc_title eq $title) { $title = $subtitle; - $ul1='
    '; - $ul2='
'; + $pre_ul='
    '; + $post_ul='
'; } else { $last_toc_title=$title; } @@ -447,13 +441,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; } } ## @@ -468,7 +474,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; @@ -503,90 +509,68 @@ ## write to the slide open(SLIDE, ">slide$nr.html") || die "can't save slide$nr.html: $!"; - 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 + %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, + next_title => $next_title, + + author => $author, + authorUrl => $authorUrl, + author2 => $author2, + authorUrl2 => $authorUrl2, + + date => $date, + + slide_html => $slide_html, + + ); + + my $page= new Text::FastTemplate key => 'slide'; + print SLIDE $page->output( \%page_data ); close(SLIDE); return 0;