Next / Previous / Contents / TCC Help System / NM Tech homepage

18. buildIndexPage(): Build the top-level page

homelist2
# - - -   b u i l d I n d e x P a g e

def buildIndexPage(dirPath, letterList):
    '''Build the top-level page pointing to the subpages.

      [ (dirPath is a path relative to http://www.nmt.edu/tcc/) and
        (letterList is a list of the initial letters of the
        subpages in ascending order) ->
          directory (dirPath) is writeable ->
            directory (dirPath)  +:=  an INDEX_NAME file linking
                to the subpages in (letterList) ]
    '''

For a discussion of the navigational elements, see Section 3.2, “Page format”. See also Section 19, “relToURL(): URL of a relative path” and Section 20, “relToAbs(): Absolute path from a relative path”.

homelist2
    #-- 1 --
    # [ indexURL  :=  URL of dirPath+INDEX_NAME
    #   indexPath  :=  absolute pathname to dirPath+INDEX_NAME ]
    #   page  :=  a new tp.TCCPage instance with standard
    #      TCC navigation ]
    indexURL = relToURL(dirPath, INDEX_NAME)
    indexPath = relToAbs(dirPath, INDEX_NAME)
    navList = [
        tp.NavLink("Next", ()),
        tp.NavLink("Previous", ()),
        tp.NavLink("TCC help system",
          [("", "http://www.nmt.edu/tcc/help/")]),
        tp.NavLink("TCC homepage",
          [("", "http://www.nmt.edu/tcc/")]),
        tp.NavLink("NM Tech homepage",
          [("", "http://www.nmt.edu/")]) ]
    page = tp.TCCPage(BASE_TITLE, navList, url=indexURL)

At this point, page.content is a div element under which we add the page's content. First to be added is the instructional paragraph, then a horizontal rule.

homelist2
    #-- 2 --
    # [ page.content  +:=  instructional paragraph ]
    page.content.append (
      E.p("To find a homepage, click on the first letter of their "
          "first or last name.") )
    page.content.append ( E.hr() )

Each subpage link is followed by three nonbreak spaces.

homelist2
    #-- 3 --
    # [ page.content  +:=  links to the subpages for elements of
    #                      letterList ]
    for letter in letterList:
        addSubpageLink(dirPath, page.content, letter)
        addText(page.content, SPACER)

    #-- 4 --
    # [ if indexPath is writeable ->
    #     file (indexPath)  :=  XHTML rendering of page
    #   else ->
    #     sys.stderr  +:=  error message(s) ]
    try:
        outFile = file(indexPath, 'w')
    except IOError, details:
        fatal("Can't write index page '%s': %s" %
              (indexPath, details))
    page.write(outFile)
    outFile.close()