[Commits] python.it commit r152 - www/branches/python/scripts/ht2html

commit a svn.python.it commit a svn.python.it
Gio 18 Maggio 2006 22:01:10 CEST


Author: manlio
Date: Thu May 18 22:01:09 2006
New Revision: 152

Modified:
   www/branches/python/scripts/ht2html/PDONewGenerator.py
Log:
correzioni da parte di Stefano

Modified: www/branches/python/scripts/ht2html/PDONewGenerator.py
==============================================================================
--- www/branches/python/scripts/ht2html/PDONewGenerator.py	(original)
+++ www/branches/python/scripts/ht2html/PDONewGenerator.py	Thu May 18 22:01:09 2006
@@ -1,6 +1,9 @@
-"""Generates the www.python.it website style
-    Realizzata da Stefano Giraldi <e.tino a email.it>
-    sulla base di PDOGenerator.py per ht2html
+"""
+ht2html Style class per creare python.it.
+
+Stefano Giraldi <e.tino a email.it>
+
+$Id$
 """
 
 import os
@@ -14,11 +17,15 @@
 from LinkFixer import LinkFixer
 #~ per SkeletonCSS
 from ht2html import __version__
+from types import StringType
 
 from cStringIO import StringIO
 import sys
 import time
 
+
+classversion = '0.0.2'
+
 sitelinks = [
     ('%(rootdir)s',  'Home'),
     ('%(rootdir)sdownload/',  'Download'),
@@ -27,124 +34,22 @@
     ('%(rootdir)shelp/',  'Aiutaci!!!'),
     ]
 
-
 class SkeletonCSS(Skeleton):
 
-    def get_banner(self):
-        """Returns HTML for the top banner, or None if no banner.
-        """
-        return None
-
-    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_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.
-
-        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).
-        """
-        return '90'
-
-    def get_corner(self):
-        """Returns HTML for the upper-left corner or None.
-
-        Note that if get_banner() and get_sidebar() both return None, then
-        get_corner() is ignored.  Also if both get_banner() and get_sidebar()
-        return a string, but get_corner() returns None, the smallest blank
-        corner possible is emitted.
-        """
-        return None
-
-    def get_body(self):
-        """Returns HTML for the internal document body.
-
-        Note that using this method causes the get_sidebar() -- if there is
-        one -- to run the full height of the page.  If you don't want this,
-        then make sure get_cont() returns a string.
-        """
-        return '<b>Intentionally left blank</b>'
-
-    def get_cont(self):
-        """Returns HTML for the continuation of the body.
-
-        When this method returns a string, and there is a get_sidebar(), the
-        continuation text appears below the get_sidebar() and get_body() at
-        the full width of the screen.  If there is no get_sidebar(), then
-        having a get_cont() is pointless.
-        """
-        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">' \
                % __version__
-
-    def get_headers(self):
-        """Return extra header information.  Must be a string."""
-        return ''
-
-    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"'
+        return None
 
     def get_banner_attributes(self):
         """Return extra attributes for the TABLE in the banner."""
-        return 'cellspacing="0" cellpadding="2"'
+        return None
 
     def get_charset(self):
         """Return charset of pages"""
@@ -219,10 +124,8 @@
             # space.  Watch out though because we don't want to close the
             # table twice
             if sidebar is None:
-#ste                print '</table><!-- end of page table -->'
                 closed = 1
             else:
-#ste                print '<tr><!-- start of sidebar/body row -->'
                 print '<div id="sidebar"><!-- start of sidebar -->'
                 self.__do_sidebar(sidebar)
                 print '</div><!-- end sidebar -->'
@@ -233,10 +136,6 @@
                 else:
                     self.__do_body(body)
                 print '</div><!-- end of body -->'
-#            if not closed:
-# ste               print '</tr><!-- end of sidebar/body row -->'
-# ste               print '</table><!-- end of page table -->'
-#                print '</div><!-- end of page-->'
             if cont is not None:
                 print '<div id="cont"><!-- start of cont-->'
                 self.__do_cont(cont)
@@ -247,50 +146,19 @@
         return html.getvalue()
 
     def __do_corner(self, corner):
-#ste        print '<!-- start of corner cells -->'
-#ste        print '<td width="150" valign="middle" bgcolor="%s" class="corner">' \
-#ste              % 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 '&nbsp;',
         else:
             print corner,
-#ste        print '</td>'
-#ste        print '<td width="15" bgcolor="%s">&nbsp;&nbsp;</td><!--spacer-->' % (
-#ste            self.get_lightshade())
-#ste        print '<!-- end of corner cells -->'
 
     def __do_sidebar(self, sidebar):
-#ste        print '<!-- start of sidebar cells -->'
-#ste        print '<td width="150" valign="top" bgcolor="%s" class="sidebar">' % (
-#ste            self.get_lightshade())
         print sidebar
-#ste        print '</td>'
-#ste        print '<td width="15">&nbsp;&nbsp;</td><!--spacer-->'
-#ste        print '<!-- end of sidebar cell -->'
 
     def __do_body(self, body):
-#ste        print '<!-- start of body cell -->'
-#ste        print '<td valign="top" width="%s%%" class="body"><br>' % (
-#ste            self.get_banner_width())
-#ste        print '<!-- start of side/content -->'
-#ste        print '<div id="sidecontent">'
-
         print body
-#ste        print '</td><!-- end of body cell -->'
-#ste        print '</div><!-- end of side/content -->'
 
     def __do_cont(self, cont):
-#ste       print '<div class="body">'
-#ste        print '<div class="continuation">'
-#ste        print '<!-- start of continued wide-body text -->'
-#ste        print '<div id="body">'
-#ste        print '<!-- start of continued wide-body text -->'
         print cont
-#ste        print '<!-- end of continued wide-body text -->'
-#ste        print '</div>'
-#ste        print '</div>'
 
     def __do_head(self):
         """Return the HTML <head> stuff."""
@@ -318,7 +186,7 @@
               'version' : __version__,
               'charset' : self.get_charset(),
               'style'   : self.__do_styles(),
-              'xmlstyle': self.get_stylesheet_pi(),
+              'xmlstyle': self.get_stylesheet_pi()
               }
 
     def __do_styles(self):
@@ -342,22 +210,9 @@
         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(),
-            #~ }
         print "<body>"
 
     def __finish_all(self):
-#ste        print '</body></html>'
         print '</div></body></html>'
 
 
@@ -417,8 +272,93 @@
             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):
+#ste        print '<!-- start of sidebar table -->'
+#ste        print '<table width="100%" border="0" cellspacing="0" cellpadding="3"'
+#ste        print '       bgcolor="%s">' % self.get_bgcolor()
+        print '<!-- start of sidebar -->'
+        print '<ul>'
+
+    def __finish(self):
+#ste        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
+#ste                if done_one:
+#ste                    # get some separation between header and last item
+#ste                    print '<tr><td bgcolor="%s">&nbsp;' % (
+#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, Sidebar, BannerCSS):
+class PDONewGenerator(SkeletonCSS, SidebarCSS, BannerCSS):
     AUTHOR = 'webmaster a python.it'
 
     def __init__(self, file, rootdir, relthis):
@@ -439,14 +379,14 @@
          src="%(rootdir)s/pics/PythonPoweredSmall.gif">
 ''' % self.__d))
         self.__linkfixer.massage(p.sidebar, self.__d)
-        Sidebar.__init__(self, p.sidebar)
+        SidebarCSS.__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)
-        Banner.__init__(self, sitelinks)
+        BannerCSS.__init__(self, sitelinks)
         # calculate the random corner
         # XXX Should really do a list of the pics directory...
         i = 0
@@ -484,10 +424,10 @@
     def get_sidebar(self):
         if self.__parser.get('wide-page', 'no').lower() == 'yes':
             return None
-        return Sidebar.get_sidebar(self)
+        return SidebarCSS.get_sidebar(self)
 
     def get_banner(self):
-        return Banner.get_banner(self)
+        return BannerCSS.get_banner(self)
 
     def get_banner_attributes(self):
         return 'cellspacing="0" cellpadding="0"'


More information about the Commits mailing list