Web Programming Languages

Perl Source Code: common.pm

#!/usr/bin/perl
#use CGI qw(:standard);

#----------------------------------------------------------
#   The Web Language Project
#   Mark Brautigam
#   May-June 2015
#   http://www.mixed-up.com/markb/
#----------------------------------------------------------

package myUtils;

#---------------------------------------------
sub headers1
#---------------------------------------------
{
print <<head1;
Content-Type: text/html;

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<link rel="icon" href="../images/puzzle2.png" />
<link href='http://fonts.googleapis.com/css?family=Share+Tech+Mono' rel='stylesheet' type='text/css'>
<title>Web Programming Languages</title>

<style type='text/css'>
@import "../common.css";
head1
}

#---------------------------------------------
sub headers2
#---------------------------------------------
{
print <<head2;
</style>

</head>

<body>
<h1 class='brown'>Web Programming Languages</h1>

<div id="container">
head2
}

#---------------------------------------------
sub footers 
#---------------------------------------------
{
print <<foot;

</div>

<div id="footer" class='brown'>
&copy; 2015 &middot; Mark Brautigam
</div>

<script type='text/javascript' src='../scripts/icons.js'></script>
<script type='text/javascript' src='../scripts/whereami.js'></script>
<!-- !3 -->
</body>
</html>
foot
}

#---------------------------------------------
sub print_file 
#---------------------------------------------
{
  open (my $fh, $_[0]);
  @src = <$fh>;
  foreach $src (@src) {
    print $src;
  }
}

#---------------------------------------------
sub trim
#---------------------------------------------
{
  # trim white space from beginning and end of string
  # http://perlmaven.com/trim
  my $str = $_[0];
  $str =~ s/^\s+|\s+$//g;
  return $str;
}


#---------------------------------------------
sub sidebar
#---------------------------------------------
{
  # replace the placeholders {#foo} with the real strings
  #
  local $/;
  open (FILE, "../sidebar/sidebar.html");
  $document = <FILE>;
  close (FILE);

  # put a star by this language (Perl)
  $hash = "{#" . $_[0] . "}";
  $document =~ s/$hash/ &nbsp; <b>&#9733;<\/b>/g;

  # put a star by this activity, whatever it is
  $hash = "{#" . $_[1] . "}";
  $document =~ s/$hash/ &nbsp; <b>&#9733;<\/b>/g;

  # put in the correct file extensions (pl)
  $ext = $_[2];
  $document =~ s/{ext}/$ext/g;

  # get rid of all the other placeholders
  $document =~ s/{.*}//g;

  return $document;
}



1;