Python Source Code: common.py
#!/usr/bin/env python
import cgi
import textwrap
import os
import re
#----------------------------------------------------------
# The Web Language Project
# Mark Brautigam
# May-June 2015
# http://www.mixed-up.com/markb/
#----------------------------------------------------------
#----------------------------------------------------
def is_number (s) :
#----------------------------------------------------
try:
float(s)
return True
except ValueError:
return False
#----------------------------------------------
def headers1 () :
#----------------------------------------------
print textwrap.dedent("""\
Content-Type: text/html;charset=utf-8
<!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";
""")
#----------------------------------------------
def headers2 () :
#----------------------------------------------
print textwrap.dedent("""\
</style>
</head>
<body>
<h1 class='brown'>Web Programming Languages</h1>
<div id="container">
""")
#----------------------------------------------
def sidebar () :
#----------------------------------------------
f = open ('sidebar.html', 'r')
sidebar = f.read()
print sidebar
f.close()
#----------------------------------------------
def footers () :
#----------------------------------------------
print textwrap.dedent("""\
</div>
<div id="footer" class='brown'>
© 2015 · Mark Brautigam
</div>
<script type='text/javascript' src='../scripts/icons.js'></script>
<script type='text/javascript' src='../scripts/whereami.js'></script>
<!-- !3 -->
</body>
</html>
""")
#---------------------------------------------
def sidebarX (language, activity, ext) :
#---------------------------------------------
#
# replace placeholders with actual content
#
f = open ('../sidebar/sidebar.html', 'r')
sidebar = f.read()
f.close()
# put a star by the language (Python)
hash = "{#" + language + "}";
sidebar = sidebar.replace (hash, " <b>★</b>");
# put a star by the activity
hash = "{#" + activity + "}";
sidebar = sidebar.replace (hash, " <b>★</b>");
# fill in the file extensions (py)
sidebar = sidebar.replace ("{ext}", ext);
# get rid of all other placeholders
sidebar = re.sub(r'{.*}', "", sidebar);
return sidebar;