[Commits] python.it commit r209 - in www/trunk: python.it
python.it/styles scripts/ht2html
commit a svn.python.it
commit a svn.python.it
Gio 31 Ago 2006 18:37:58 CEST
Author: manlio
Date: Thu Aug 31 18:37:26 2006
New Revision: 209
Modified:
www/trunk/python.it/links.h
www/trunk/python.it/styles/style.css
www/trunk/scripts/ht2html/Banner.py
www/trunk/scripts/ht2html/PDONewGenerator.py
www/trunk/scripts/ht2html/Sidebar.py
www/trunk/scripts/ht2html/Skeleton.py
Log:
refactoring di ht2html.
XHTML 1.0 Strict
di Stefano
Modified: www/trunk/python.it/links.h
==============================================================================
--- www/trunk/python.it/links.h (original)
+++ www/trunk/python.it/links.h Thu Aug 31 18:37:26 2006
@@ -2,7 +2,7 @@
<li><a href="doc/intro.html">Che cos'è Python?</a>
<h3>Versioni Python
<img alt="[off-site link]" border="0" class="offsitelink"
- height="15" src="./pics/offsite.gif" width="17"></h3>
+ height="15" src="./pics/offsite.gif" width="17" /></h3>
<li><a href="http://www.python.org/2.4/">Python 2.4</a> <a href="http://www.python.org/dev/doc/devel/">(docs)</a>
<li><a href="http://www.python.org/2.3.4/">Python 2.3</a> <a href="http://www.python.org/doc/2.3.4/">(docs)</a>
<li><a href="http://www.python.org/download/download_mac.html">MacPython</a>
Modified: www/trunk/python.it/styles/style.css
==============================================================================
--- www/trunk/python.it/styles/style.css (original)
+++ www/trunk/python.it/styles/style.css Thu Aug 31 18:37:26 2006
@@ -27,6 +27,10 @@
padding: 0;
}
+a>img {
+ border: 0px;
+ }
+
#page {
width: 100%;
margin: 0;
@@ -199,15 +203,23 @@
/* This avoids the white border around the page in MSIE. */
-html { border: 0px;
- margin: 0px;
- padding: 0px; }
+html {
+ border: 0px;
+ margin: 0px;
+ padding: 0px;
+ }
-.continuation { margin-left: 1em;
- margin-right: 1em; }
+.continuation {
+ margin-left: 1em;
+ margin-right: 1em;
+}
/* additional rules */
-img.offsitelink { border: 0 }
+img.offsitelink {
+ border: 0
+}
-dt { font-weight: bolder }
+dt {
+ font-weight: bolder
+}
Modified: www/trunk/scripts/ht2html/Banner.py
==============================================================================
--- www/trunk/scripts/ht2html/Banner.py (original)
+++ www/trunk/scripts/ht2html/Banner.py Thu Aug 31 18:37:26 2006
@@ -1,4 +1,4 @@
-"""Generate a site links table for use in a banner.
+"""Generate a site links table for use in a banner.
"""
import sys
@@ -8,7 +8,8 @@
from StringIO import StringIO
class Banner:
- def __init__(self, links, cols=4):
+
+ def __init__(self, links):
"""Initialize the Banner instance.
This class is intended to be a mixin-class with Skeleton.
@@ -19,11 +20,6 @@
"""
self.__links = links
- self.__cols = cols
- rows, leftover = divmod(len(links), self.__cols)
- if leftover:
- rows = rows + 1
- self.__rows = rows
def get_banner(self):
stdout = sys.stdout
@@ -38,19 +34,12 @@
return html.getvalue()
def __start_table(self):
- print '<!-- start of site links table -->'
- print '<table width="100%" border="0"'
- print self.get_banner_attributes()
- print ' bgcolor="%s">' % (
- self.get_bgcolor())
- print '<tr>'
+ print '<ul>'
def __end_table(self):
- print '</tr>'
- print '</table><!-- end of site links table -->'
+ print '</ul>'
def __do_table(self):
- col = 0
for item in self.__links:
if len(item) == 3:
url, text, extra = item
@@ -61,21 +50,11 @@
s = text + extra
else:
s = '<a href="%s">%s</a>%s' % (url, text, extra)
- if col >= self.__cols:
- # break the row
- print '</tr><tr>'
- col = 0
- print ' <td bgcolor="%s">' % self.get_lightshade()
+ print '<li>'
print s
- print ' </td>'
- col = col + 1
- # fill rest of row with non-breaking spaces.
- while col and col < self.__cols:
- print ' <td bgcolor="%s">' % self.get_lightshade()
- print ' </td>'
- col = col + 1
+ print '</li>'
+
-
from Skeleton import _Skeleton
class _Banner(_Skeleton, Banner):
@@ -86,6 +65,7 @@
return Banner.get_banner(self)
if __name__ == '__main__':
+ from ht2html import __version__
t = _Banner([('page1.html', 'First Page'),
('page2.html', 'Second Page'),
('page3.html', 'Third Page'),
Modified: www/trunk/scripts/ht2html/PDONewGenerator.py
==============================================================================
--- www/trunk/scripts/ht2html/PDONewGenerator.py (original)
+++ www/trunk/scripts/ht2html/PDONewGenerator.py Thu Aug 31 18:37:26 2006
@@ -1,4 +1,4 @@
-"""
+"""
ht2html Style class per creare python.it.
Stefano Giraldi <e.tino a email.it>
@@ -19,9 +19,6 @@
from Banner import Banner
from HTParser import HTParser
from LinkFixer import LinkFixer
-#~ per SkeletonCSS
-from ht2html import __version__
-from types import StringType
from cStringIO import StringIO
import sys
@@ -41,340 +38,8 @@
('%(rootdir)s/help/', 'Aiutaci!!!'),
]
-class SkeletonCSS(Skeleton):
-
- def get_meta(self):
- """Return extra meta-data. Must be a string."""
- import __main__
- return '<meta name="generator" content="HT2HTML/%s">' \
- % __version__
- def get_body_attributes(self):
- """Return extra attributes for the body start tag."""
- # These are not supported in HTML, but are needed for
- # Netscape 4
- return None
-
- def get_banner_attributes(self):
- """Return extra attributes for the TABLE in the banner."""
- return None
-
- def get_charset(self):
- """Return charset of pages"""
- return 'us-ascii'
-
- # Style sheets
- def get_stylesheet(self):
- """Return filename of CSS stylesheet."""
- return ''
-
-
- def get_stylesheet_pi(self):
- s = self.get_stylesheet()
- if s:
- return '<?xml-stylesheet href="%s" type="%s"?>\n' \
- % (s, self.get_stylesheet_type(s))
- else:
- return ''
-
- def get_stylesheet_type(self, filename):
- ext = os.path.splitext(filename)[1]
- if ext == ".css":
- return "text/css"
- elif ext in (".xsl", ".xslt"):
- return "text/xslt"
- else:
- raise ValueError("unknown stylesheet language")
-
- def get_style(self):
- """Return the style sheet for this document"""
- s = self.body_style()
- if s:
- return 'body { %s }' % self.body_style()
- else:
- return ''
-
- def body_style(self):
- if self.get_stylesheet():
- # If there's an external stylesheet, rely on that for the body.
- return ''
- else:
- return 'margin: 0px;'
-
- # Call this method
- def makepage(self):
- banner = self.get_banner()
- sidebar = self.get_sidebar()
- corner = self.get_corner()
- body = self.get_body()
- cont = self.get_cont()
- html = StringIO()
- stdout = sys.stdout
- closed = 0
- try:
- sys.stdout = html
- self.__do_head()
- self.__start_body()
- print '<!-- start of page -->'
- print '<div id="page">'
-
- if banner is not None:
- print '<!-- start of banner -->'
- print '<div id="banner">'
- if corner is not None:
- self.__do_corner(corner)
- print banner
- print '</div><!-- end of banner -->'
- # if there is a body but no sidebar, then we'll just close the
- # table right here and put the body (and any cont) in the full
- # page. if there is a sidebar but no body, then we still create
- # the new row and just populate the body cell with a non-breaking
- # space. Watch out though because we don't want to close the
- # table twice
- if sidebar is None:
- closed = 1
- else:
- print '<div id="sidebar"><!-- start of sidebar -->'
- self.__do_sidebar(sidebar)
- print '</div><!-- end sidebar -->'
- if body is not None:
- print '<div id="body"><!-- start of body -->'
- if closed:
- print body
- else:
- self.__do_body(body)
- print '</div><!-- end of body -->'
- if cont is not None:
- print '<div id="cont"><!-- start of cont-->'
- self.__do_cont(cont)
- print '</div><!-- start of cont-->'
- self.__finish_all()
- finally:
- sys.stdout = stdout
- return html.getvalue()
-
- def __do_corner(self, corner):
- if corner is None:
- print ' ',
- else:
- print corner,
-
- def __do_sidebar(self, sidebar):
- print sidebar
-
- def __do_body(self, body):
- print body
-
- def __do_cont(self, cont):
- print cont
-
- def __do_head(self):
- # XXX TODO use XHTML instead?
- """Return the HTML <head> stuff."""
- print '''\
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-%(xmlstyle)s<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">
-<!-- THIS PAGE IS AUTOMATICALLY GENERATED. DO NOT EDIT. -->
-<!-- %(time)s -->
-<!-- USING HT2HTML %(version)s -->
-<!-- SEE http://ht2html.sf.net -->
-<!-- User-specified headers:
-Title: %(title)s
-%(headers)s
--->
-
-<head>
-<title>%(title)s</title>
-<meta http-equiv="Content-Type" content="text/html; charset=%(charset)s">
-%(meta)s
-%(style)s
-</head>''' % {'title' : self.get_title(),
- 'headers' : self.get_headers(),
- 'meta' : self.get_meta(),
- 'time' : time.ctime(time.time()),
- 'version' : __version__,
- 'charset' : self.get_charset(),
- 'style' : self.__do_styles(),
- 'xmlstyle': self.get_stylesheet_pi()
- }
-
- def __do_styles(self):
- # assemble all the style information we have to produce the
- # appropriate LINK and STYLE elements
- stylesheet = self.get_stylesheet()
- #~ added css reference for print media
- printsheet = self.get_printsheet()
- #~ added referce for favicon
- favicon = self.get_favicon()
- localstyle = self.get_style()
- s = ''
- if stylesheet and stylesheet.strip():
- stylesheet = stylesheet.strip()
- type = self.get_stylesheet_type(stylesheet)
- s = '<link rel="stylesheet" href="%s" type="%s" media="screen">\n' \
- % (stylesheet, type)
- #~ added css reference for print media
- if printsheet and printsheet.strip():
- printsheet = printsheet.strip()
- type = self.get_stylesheet_type(printsheet)
- s = s + '<link rel="stylesheet" href="%s" type="%s" media="print">\n' \
- %(printsheet, type)
- if favicon and favicon.strip():
- favicon = favicon.strip()
- s = s + '<link rel="shortcut icon" type="image/ico" href="%s" />\n'\
- %(favicon)
- if localstyle and localstyle.strip():
- localstyle = '<style type="text/css">\n%s\n</style>' \
- % localstyle.strip()
- if stylesheet or printsheet:
- s = s + "\n" + localstyle
- else:
- s = localstyle
- return s
-
- def __start_body(self):
- print "<body>"
-
- def __finish_all(self):
- print '</div></body></html>'
-
-
-
-
-class BannerCSS(Banner):
- def __init__(self, links, cols=4):
- """Initialize the Banner instance.
-
- This class is intended to be a mixin-class with Skeleton.
-
- links must be a list of 2-tuples of the form: (URL, text). If URL is
- None, then the text is not hyperlinked. These are arranged in a table
- in order, evenly in the specified number of columns.
-
- """
- self.__links = links
- self.__cols = cols
- rows, leftover = divmod(len(links), self.__cols)
- if leftover:
- rows = rows + 1
- self.__rows = rows
-
- def get_banner(self):
- stdout = sys.stdout
- html = StringIO()
- try:
- sys.stdout = html
- self.__start_table()
- self.__do_table()
- self.__end_table()
- finally:
- sys.stdout = stdout
- return html.getvalue()
-
- def __start_table(self):
- print '<ul>'
-
- def __end_table(self):
- print '</ul>'
-
- def __do_table(self):
- col = 0
- for item in self.__links:
- if len(item) == 3:
- url, text, extra = item
- else:
- url, text = item
- extra = ''
- if not url:
- s = text + extra
- else:
- s = '<a href="%s">%s</a>%s' % (url, text, extra)
- print '<li>'
- print s
- print '</li>'
-
-class SidebarCSS(Sidebar):
- def __init__(self, links):
- """Initialize the Sidebar instance.
-
- This class is indented to be a mixin-class with Skeleton.
-
- links must be a list of elements for the sidebar. Each entry in the
- list can either be a string, indicating that the entry is a category
- header, or a 2-tuple of the form: (URL, text) indicating it is taken
- as a link to include under the category.
-
- If the entry is a two tuple, the URL can be None to indicate that
- there is no link to that text.
-
- """
- self.links = links
-
- def get_sidebar(self):
- stdout = sys.stdout
- html = StringIO()
- try:
- sys.stdout = html
- self.__start_table()
- self.__do_link()
- self.__finish()
- finally:
- sys.stdout = stdout
- return html.getvalue()
-
- def get_validated(self):
- return """<tr><td bgcolor="%s">
- <center>
- <a href="http://validator.w3.org/check/referer"><img border="0"
- src="http://www.w3.org/Icons/valid-html401"
- alt="Valid HTML 4.01!" height="31" width="88"%s</a></center>
- </td></tr>
- """ % (self.get_lightshade(), self.empty_tag_end)
-
- def __start_table(self):
- print '<!-- start of sidebar -->'
- print '<ul>'
-
- def __finish(self):
- print '</ul><!-- end of sidebar -->'
-
- def __do_link(self):
- done_one = 0
- for item in self.links:
- if type(item) == StringType:
- # category header
-#ste if done_one:
-#ste # get some separation between header and last item
-#ste print '<tr><td bgcolor="%s"> ' % (
-#ste self.get_lightshade())
-#ste else:
-#ste done_one = 1
-#ste print '<tr><td bgcolor="%s"><b><font color="%s">' % (
-#ste self.get_darkshade(), self.get_bgcolor())
-#ste print item
-#ste print '</font></b></td></tr>'
- print '<li class="group">'
- print item
- print '</li>'
- else:
- if len(item) == 3:
- url, text, extra = item
- else:
- url, text = item
- extra = ''
- if url is None:
- s = text
- else:
- s = '<a href="%s">%s</a>' % (url, text)
-#ste print '<tr><td bgcolor="%s">' % self.get_lightshade()
-#ste print '%s%s' % (s, extra)
-#ste print '</td></tr>'
- print '<li class="items">'
- print '%s%s' % (s, extra)
- print '</li>'
-
-
-class PDONewGenerator(SkeletonCSS, SidebarCSS, BannerCSS):
+
+class PDONewGenerator(Skeleton, Sidebar, Banner):
AUTHOR = 'webmaster a python.it'
def __init__(self, file, rootdir, relthis):
@@ -387,29 +52,25 @@
# calculate the sidebar links, adding a few of our own
self.__d = {'rootdir': rootdir}
p.process_sidebar()
- p.sidebar.append(BLANKCELL)
- # it is important not to have newlines between the img tag and the end
- # end center tags, otherwise layout gets messed up
- p.sidebar.append(('%(rootdir)s', '''
- <img alt="" border="0"
- src="%(rootdir)s/pics/PythonPoweredSmall.gif">
-''' % self.__d))
+ #~ Sezione Crediti e link validatori XHTML e CSS
+ p.sidebar.append('Crediti')
+ p.sidebar.append(('http://www.python.org/',
+ 'Pyhton Powered'))
+ p.sidebar.append(('http://validator.w3.org/check?uri=referer',
+ 'Valid XHTML 1.0 Strict'))
+ p.sidebar.append(('http://jigsaw.w3.org/css-validator/',
+ 'Valid CSS W3C'))
self.__linkfixer.massage(p.sidebar, self.__d)
- SidebarCSS.__init__(self, p.sidebar)
+ Sidebar.__init__(self, p.sidebar)
#
# fix up our site links, no relthis because the site links are
# relative to the root of our web pages
#
sitelink_fixer = LinkFixer(f.myurl(), rootdir)
sitelink_fixer.massage(sitelinks, self.__d, aboves=1)
- BannerCSS.__init__(self, sitelinks)
- # calculate the random corner
- # XXX Should really do a list of the pics directory...
- i = 0
- #~ s = self.__d['rootdir']+"python-logo.gif"
+ Banner.__init__(self, sitelinks)
s = posixpath.join(self.__d['rootdir'], 'styles/images/python-logo.gif')
self.__d['banner'] = s
- self.__whichbanner = i
def get_meta(self):
s1 = Skeleton.get_meta(self)
@@ -430,6 +91,9 @@
else:
return s2
+ def get_title(self):
+ return self.__parser.get('title')
+
def get_stylesheet(self):
#~ return posixpath.join('/style.css')
return posixpath.join(self.__d['rootdir'], 'styles/style.css')
@@ -437,53 +101,28 @@
def get_printsheet(self):
#~ return stylesheet for print media called by SkeletronCSS.__do_style()
return posixpath.join(self.__d['rootdir'], 'styles/print.css')
+
def get_favicon(self):
#~ return favicon reference
return posixpath.join(self.__d['rootdir'], 'styles/favicon.ico')
- def get_title(self):
- return self.__parser.get('title')
-
def get_sidebar(self):
if self.__parser.get('wide-page', 'no').lower() == 'yes':
return None
- return SidebarCSS.get_sidebar(self)
+ return Sidebar.get_sidebar(self)
def get_banner(self):
- return BannerCSS.get_banner(self)
-
- def get_banner_attributes(self):
- return 'cellspacing="0" cellpadding="0"'
+ return Banner.get_banner(self)
def get_corner(self):
# it is important not to have newlines between the img tag and the end
# anchor and end center tags, otherwise layout gets messed up
return '''
<a href="%(rootdir)s/" id="logolink">
- <img alt="" border="0"
- src="%(rootdir)s/%(banner)s"></a>''' % \
+ <img alt=""
+ src="%(rootdir)s/%(banner)s" /></a>''' % \
self.__d
- def get_corner_bgcolor(self):
- # this may not be 100% correct. it uses PIL to get the RGB values at
- # the corners of the image and then takes a vote as to the most likely
- # value. Some images may be `bizarre'. See .../pics/backgrounds.py
- return [
- '#3399ff', '#6699cc', '#3399ff', '#0066cc', '#3399ff',
- '#0066cc', '#0066cc', '#3399ff', '#3399ff', '#3399ff',
- '#3399ff', '#6699cc', '#3399ff', '#3399ff', '#ffffff',
- '#6699cc', '#0066cc', '#3399ff', '#0066cc', '#3399ff',
- '#6699cc', '#0066cc', '#6699cc', '#3399ff', '#3399ff',
- '#6699cc', '#3399ff', '#3399ff', '#6699cc', '#6699cc',
- '#0066cc', '#6699cc', '#0066cc', '#6699cc', '#0066cc',
- '#0066cc', '#6699cc', '#3399ff', '#0066cc', '#bbd6f1',
- '#0066cc', '#6699cc', '#3399ff', '#3399ff', '#0066cc',
- '#0066cc', '#0066cc', '#6699cc', '#6699cc', '#3399ff',
- '#3399ff', '#6699cc', '#0066cc', '#0066cc', '#6699cc',
- '#0066cc', '#6699cc', '#3399ff', '#6699cc', '#3399ff',
- '#d6ebff', '#6699cc', '#3399ff', '#0066cc',
- ][self.__whichbanner]
-
def get_body(self):
self.__grokbody()
return self.__body
@@ -511,15 +150,5 @@
# there is no wide body
self.__body = text
- # python.org color scheme overrides
- def get_lightshade(self):
- return '#99ccff'
-
- def get_mediumshade(self):
- return '#3399ff'
-
- def get_darkshade(self):
- return '#003366'
-
def get_charset(self):
return 'iso-8859-1'
Modified: www/trunk/scripts/ht2html/Sidebar.py
==============================================================================
--- www/trunk/scripts/ht2html/Sidebar.py (original)
+++ www/trunk/scripts/ht2html/Sidebar.py Thu Aug 31 18:37:26 2006
@@ -1,4 +1,4 @@
-"""Sidebar generator.
+"""Sidebar generator.
"""
import sys
@@ -10,6 +10,7 @@
class Sidebar:
+
def __init__(self, links):
"""Initialize the Sidebar instance.
@@ -48,28 +49,20 @@
""" % (self.get_lightshade(), self.empty_tag_end)
def __start_table(self):
- print '<!-- start of sidebar table -->'
- print '<table width="100%" border="0" cellspacing="0" cellpadding="3"'
- print ' bgcolor="%s">' % self.get_bgcolor()
+ print '<!-- start of sidebar -->'
+ print '<ul>'
def __finish(self):
- print '</table><!-- end of sidebar table -->'
+ print '</ul><!-- end of sidebar -->'
+
def __do_link(self):
done_one = 0
for item in self.links:
if type(item) == StringType:
- # category header
- if done_one:
- # get some separation between header and last item
- print '<tr><td bgcolor="%s"> ' % (
- self.get_lightshade())
- else:
- done_one = 1
- print '<tr><td bgcolor="%s"><b><font color="%s">' % (
- self.get_darkshade(), self.get_bgcolor())
+ print '<li class="group">'
print item
- print '</font></b></td></tr>'
+ print '</li>'
else:
if len(item) == 3:
url, text, extra = item
@@ -80,9 +73,9 @@
s = text
else:
s = '<a href="%s">%s</a>' % (url, text)
- print '<tr><td bgcolor="%s">' % self.get_lightshade()
+ print '<li class="items">'
print '%s%s' % (s, extra)
- print '</td></tr>'
+ print '</li>'
from Skeleton import _Skeleton
@@ -101,6 +94,7 @@
if __name__ == '__main__':
+ from ht2html import __version__
t = _Sidebar(
# banner links
[('page1.html', 'First Page'),
@@ -132,7 +126,7 @@
('help.html', 'python-help a python.org'),
(None, 'For help with Website:'),
('web.html', 'webmaster a python.org'),
- (None, '<br>'),
+ (None, '<br/>'),
('pp.html', '[Python Powered]'),
])
Modified: www/trunk/scripts/ht2html/Skeleton.py
==============================================================================
--- www/trunk/scripts/ht2html/Skeleton.py (original)
+++ www/trunk/scripts/ht2html/Skeleton.py Thu Aug 31 18:37:26 2006
@@ -1,4 +1,4 @@
-"""Skeleton class.
+"""Skeleton class.
Should be sub-classed to provide basic generation of able-contained HTML
document.
@@ -16,32 +16,69 @@
#
# for sub-classes to override
#
+ def get_title(self):
+ """Return the title of the page. Required."""
+ return 'Intentionally left blank'
- def get_banner(self):
- """Returns HTML for the top banner, or None if no banner.
- """
- return None
+ def get_meta(self):
+ """Return extra meta-data. Must be a string."""
+ import __main__
+ return '<meta name="generator" content="HT2HTML/%s" />' \
+ % __main__.__version__
- def get_left_sidebar(self):
- """Returns HTML for the left sidebar or None.
- """
- return None
- # for backwards compatibility
- get_sidebar = get_left_sidebar
+ def get_headers(self):
+ """Return extra header information. Must be a string."""
+ return ''
+
+ def get_charset(self):
+ """Return charset of pages"""
+ return 'us-ascii'
+
+ # Style sheets
+ def get_stylesheet(self):
+ """Return filename of CSS stylesheet."""
+ return ''
+
+ def get_printsheet(self):
+ """Return filename of CSS stylesheet."""
+ return ''
+
+ def get_favicon(self):
+ """Return filename of CSS stylesheet."""
+ return ''
+
+ def get_link_type(self, filename):
+ ext = os.path.splitext(filename)[1]
+ if ext == ".css":
+ return "text/css"
+ elif ext in (".xsl", ".xslt"):
+ return "text/xslt"
+ elif ext == ".ico":
+ return "image/ico"
+
+ else:
+ raise ValueError("unknown stylesheet language")
+
+ def get_body_style(self):
+ if self.get_stylesheet():
+ # If there's an external stylesheet, rely on that for the body.
+ return ''
+ else:
+ return 'margin: 0px;'
- def get_right_sidebar(self):
- """Returns HTML for the right sidebar or None.
- """
- return None
- def get_banner_width(self):
- """HTML `width' of banner column as a percentage.
+ def get_style(self):
+ """Return the style sheet for this document"""
+ s = self.get_body_style()
+ if s:
+ return 'body { %s }' % self.body_style()
+ else:
+ return ''
- Should be a string that does not include the percent sign (e.g. "90").
- This affects the column containing both the banner and body text (if
- they exist).
+ def get_banner(self):
+ """Returns HTML for the top banner, or None if no banner.
"""
- return '90'
+ return None
def get_corner(self):
"""Returns HTML for the upper-left corner or None.
@@ -72,107 +109,92 @@
"""
return None
- def get_title(self):
- """Return the title of the page. Required."""
- return 'Intentionally left blank'
-
- def get_meta(self):
- """Return extra meta-data. Must be a string."""
- import __main__
- return '<meta name="generator" content="HT2HTML/%s">' \
- % __main__.__version__
-
- def get_headers(self):
- """Return extra header information. Must be a string."""
- return ''
+ def __do_corner(self, corner):
+ if corner is None:
+ print ' ',
+ else:
+ print corner,
- def get_bgcolor(self):
- """Return the background color"""
- return '#ffffff'
-
- def get_fgcolor(self):
- """Return foreground color"""
- return '#000000'
-
- def get_linkcolor(self):
- """Return link color"""
- return '#0000bb'
-
- def get_vlinkcolor(self):
- """Return vlink color"""
- return '#551a8b'
-
- def get_alinkcolor(self):
- """Return alink color"""
- return '#ff0000'
-
- def get_corner_bgcolor(self):
- """Return the background color for the corner"""
- return self.get_lightshade()
-
- # Barry's prefs
- def get_lightshade(self):
- """Return lightest of 3 color scheme shade."""
- return '#cdba96'
-
- def get_mediumshade(self):
- """Return middle of 3 color scheme shade."""
- return '#cc9966'
-
- def get_darkshade(self):
- """Return darkest of 3 color scheme shade."""
- return '#b78900'
-
- def get_body_attributes(self):
- """Return extra attributes for the body start tag."""
- # These are not supported in HTML, but are needed for
- # Netscape 4
- return 'marginwidth="0" marginheight="0"'
-
- def get_banner_attributes(self):
- """Return extra attributes for the TABLE in the banner."""
- return 'cellspacing="0" cellpadding="2"'
+ def __do_sidebar(self, sidebar):
+ print sidebar
- def get_charset(self):
- """Return charset of pages"""
- return 'us-ascii'
+ def __do_body(self, body):
+ print body
- # Style sheets
- def get_stylesheet(self):
- """Return filename of CSS stylesheet."""
- return ''
+ def __do_cont(self, cont):
+ print cont
- def get_stylesheet_pi(self):
- s = self.get_stylesheet()
- if s:
- return '<?xml-stylesheet href="%s" type="%s"?>\n' \
- % (s, self.get_stylesheet_type(s))
- else:
- return ''
+ def __do_styles(self):
+ # assemble all the style information we have to produce the
+ # appropriate LINK and STYLE elements
+ stylesheet = self.get_stylesheet()
+ #~ added css reference for print media
+ printsheet = self.get_printsheet()
+ #~ added referce for favicon
+ favicon = self.get_favicon()
+ #~ reference to localstyle
+ localstyle = self.get_style()
+ s = ''
+ if stylesheet and stylesheet.strip():
+ stylesheet = stylesheet.strip()
+ type = self.get_link_type(stylesheet)
+ s = '<link rel="stylesheet" href="%s" type="%s" media="screen" />\n' \
+ % (stylesheet, type)
+ #~ added css reference for print media
+ if printsheet and printsheet.strip():
+ printsheet = printsheet.strip()
+ type = self.get_link_type(printsheet)
+ s = s + '<link rel="stylesheet" href="%s" type="%s" media="print" />\n' \
+ %(printsheet, type)
+ if favicon and favicon.strip():
+ favicon = favicon.strip()
+ type = self.get_link_type(favicon)
+ s = s + '<link rel="shortcut icon" href="%s" type="%s" />\n'\
+ %(favicon, type)
+ if localstyle and localstyle.strip():
+ localstyle = '<style type="text/css">\n%s\n</style>' \
+ % localstyle.strip()
+ if stylesheet or printsheet:
+ s = s + "\n" + localstyle
+ else:
+ s = localstyle
+ return s
- def get_stylesheet_type(self, filename):
- ext = os.path.splitext(filename)[1]
- if ext == ".css":
- return "text/css"
- elif ext in (".xsl", ".xslt"):
- return "text/xslt"
- else:
- raise ValueError("unknown stylesheet language")
+ def __do_head(self):
+ # XXX TODO use XHTML instead?
+ """Return the HTML <head> stuff."""
+ print '''\
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<!-- THIS PAGE IS AUTOMATICALLY GENERATED. DO NOT EDIT. -->
+<!-- %(time)s -->
+<!-- USING HT2HTML %(version)s -->
+<!-- SEE http://ht2html.sf.net -->
+<!-- User-specified headers:
+Title: %(title)s
+%(headers)s
+-->
+<html>
+<head>
+<title>%(title)s</title>
+<meta http-equiv="Content-Type" content="text/html; charset=%(charset)s" />
+%(meta)s
+%(style)s
+</head>''' % {'title' : self.get_title(),
+ 'headers' : self.get_headers(),
+ 'meta' : self.get_meta(),
+ 'time' : time.ctime(time.time()),
+ 'version' : __version__,
+ 'charset' : self.get_charset(),
+ 'style' : self.__do_styles(),
+ }
+
+ def __start_body(self):
+ print "<body>"
- def get_style(self):
- """Return the style sheet for this document"""
- s = self.body_style()
- if s:
- return 'body { %s }' % self.body_style()
- else:
- return ''
+ def __finish_all(self):
+ print '</div></body></html>'
- def body_style(self):
- if self.get_stylesheet():
- # If there's an external stylesheet, rely on that for the body.
- return ''
- else:
- return 'margin: 0px;'
# Call this method
def makepage(self):
@@ -188,20 +210,16 @@
sys.stdout = html
self.__do_head()
self.__start_body()
- print '<!-- start of page table -->'
- print ('<table width="100%" border="0"'
- ' cellspacing="0" cellpadding="0">')
+ print '<!-- start of page -->'
+ print '<div id="page">'
+
if banner is not None:
- print '<!-- start of banner row -->'
- print '<tr>'
+ print '<!-- start of banner -->'
+ print '<div id="banner">'
if corner is not None:
self.__do_corner(corner)
- print '<!-- start of banner -->'
- print '<td width="%s%%" bgcolor="%s" class="banner">' % (
- self.get_banner_width(), self.get_lightshade())
print banner
- print '</td><!-- end of banner -->'
- print '</tr><!-- end of banner row -->'
+ print '</div><!-- end of banner -->'
# if there is a body but no sidebar, then we'll just close the
# table right here and put the body (and any cont) in the full
# page. if there is a sidebar but no body, then we still create
@@ -209,147 +227,56 @@
# space. Watch out though because we don't want to close the
# table twice
if sidebar is None:
- print '</table><!-- end of page table -->'
closed = 1
else:
- print '<tr><!-- start of sidebar/body row -->'
+ print '<div id="sidebar"><!-- start of sidebar -->'
self.__do_sidebar(sidebar)
+ print '</div><!-- end sidebar -->'
if body is not None:
+ print '<div id="body"><!-- start of body -->'
if closed:
print body
else:
self.__do_body(body)
- if not closed:
- print '</tr><!-- end of sidebar/body row -->'
- print '</table><!-- end of page table -->'
+ print '</div><!-- end of body -->'
if cont is not None:
+ print '<div id="cont"><!-- start of cont-->'
self.__do_cont(cont)
+ print '</div><!-- start of cont-->'
self.__finish_all()
finally:
sys.stdout = stdout
return html.getvalue()
- def __do_corner(self, corner):
- print '<!-- start of corner cells -->'
- print '<td width="150" valign="middle" bgcolor="%s" class="corner">' \
- % self.get_corner_bgcolor()
- # it is important not to have a newline between the corner text and
- # the table close tag, otherwise layout is messed up
- if corner is None:
- print ' ',
- else:
- print corner,
- print '</td>'
- print '<td width="15" bgcolor="%s"> </td><!--spacer-->' % (
- self.get_lightshade())
- print '<!-- end of corner cells -->'
-
- def __do_sidebar(self, sidebar):
- print '<!-- start of sidebar cells -->'
- print '<td width="150" valign="top" bgcolor="%s" class="sidebar">' % (
- self.get_lightshade())
- print sidebar
- print '</td>'
- print '<td width="15"> </td><!--spacer-->'
- print '<!-- end of sidebar cell -->'
-
- def __do_body(self, body):
- print '<!-- start of body cell -->'
- print '<td valign="top" width="%s%%" class="body"><br>' % (
- self.get_banner_width())
- print body
- print '</td><!-- end of body cell -->'
-
- def __do_cont(self, cont):
- print '<div class="body">'
- print '<div class="continuation">'
- print '<!-- start of continued wide-body text -->'
- print cont
- print '<!-- end of continued wide-body text -->'
- print '</div>'
- print '</div>'
-
- def __do_head(self):
- """Return the HTML <head> stuff."""
- print '''\
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-%(xmlstyle)s<html>
-<!-- THIS PAGE IS AUTOMATICALLY GENERATED. DO NOT EDIT. -->
-<!-- %(time)s -->
-<!-- USING HT2HTML %(version)s -->
-<!-- SEE http://ht2html.sf.net -->
-<!-- User-specified headers:
-Title: %(title)s
-%(headers)s
--->
-
-<head>
-<title>%(title)s</title>
-<meta http-equiv="Content-Type" content="text/html; charset=%(charset)s">
-%(meta)s
-%(style)s
-</head>''' % {'title' : self.get_title(),
- 'headers' : self.get_headers(),
- 'meta' : self.get_meta(),
- 'time' : time.ctime(time.time()),
- 'version' : __version__,
- 'charset' : self.get_charset(),
- 'style' : self.__do_styles(),
- 'xmlstyle': self.get_stylesheet_pi(),
- }
-
- def __do_styles(self):
- # assemble all the style information we have to produce the
- # appropriate LINK and STYLE elements
- stylesheet = self.get_stylesheet()
- localstyle = self.get_style()
- s = ''
- if stylesheet and stylesheet.strip():
- stylesheet = stylesheet.strip()
- type = self.get_stylesheet_type(stylesheet)
- s = '<link rel="STYLESHEET" href="%s" type="%s">' \
- % (stylesheet, type)
- if localstyle and localstyle.strip():
- localstyle = '<style type="text/css">\n%s\n</style>' \
- % localstyle.strip()
- if stylesheet:
- s = s + "\n" + localstyle
- else:
- s = localstyle
- return s
-
- def __start_body(self):
- print '''\
-<body bgcolor="%(bgcolor)s" text="%(fgcolor)s"
- %(extraattrs)s
- link="%(linkcolor)s" vlink="%(vlinkcolor)s"
- alink="%(alinkcolor)s">''' % {
- 'bgcolor' : self.get_bgcolor(),
- 'fgcolor' : self.get_fgcolor(),
- 'linkcolor' : self.get_linkcolor(),
- 'vlinkcolor': self.get_vlinkcolor(),
- 'alinkcolor': self.get_alinkcolor(),
- 'extraattrs': self.get_body_attributes(),
- }
-
- def __finish_all(self):
- print '</body></html>'
-
-
-
# test script
class _Skeleton(Skeleton):
+
+ def get_stylesheet(self):
+ import posixpath
+ #~ return posixpath.join('/style.css')
+ return posixpath.join('styles/style.css')
+
+ def get_printsheet(self):
+ import posixpath
+ #~ return stylesheet for print media called by SkeletronCSS.__do_style()
+ return posixpath.join('styles/print.css')
+
+ def get_favicon(self):
+ import posixpath
+ #~ return favicon reference
+ return posixpath.join('styles/favicon.ico')
+
def get_banner(self):
return '<b>The Banner</b>'
def get_sidebar(self):
- return '''<ul><li>Sidebar line 1
- <li>Sidebar line 2
- <li>Sidebar line 3
+ return '''<ul><li>Sidebar line 1</li>
+ <li>Sidebar line 2</li>
+ <li>Sidebar line 3</li>
</ul>'''
def get_corner(self):
- return '<center><em>CORNER</em></center>'
+ return None
def get_body(self):
return 'intentionally left blank ' * 110
@@ -357,12 +284,6 @@
def get_cont(self):
return 'wide stuff ' * 100
- def get_corner_bgcolor(self):
- return 'yellow'
-
- def get_banner_width(self):
- return "80"
-
if __name__ == '__main__':
t = _Skeleton()
Maggiori informazioni sulla lista
Commits