Synopsis - Synopsis/Formatters/HTML/Views/ModuleIndex.py

File: Synopsis/Formatters/HTML/Views/ModuleIndex.py

      1#
      2# Copyright (C) 2000 Stephen Davies
      3# Copyright (C) 2000 Stefan Seefeld
      4# All rights reserved.
      5# Licensed to the public under the terms of the GNU LGPL (>= 2),
      6# see the file COPYING for details.
      7#
      8
      9from Synopsis.Processor import Parameter
     10from Synopsis import ASG
     11from Synopsis.Formatters.HTML.View import View
     12from Synopsis.Formatters.HTML.Tags import *
     13
     14class ModuleIndex(View):
     15   """A module for indexing ASG.Modules. Each module gets its own view with a
     16   list of nested scope declarations with documentation. It is intended to go in
     17   the left frame..."""
     18
     19   def register(self, frame):
     20
     21      super(ModuleIndex, self).register(frame)
     22      self.__filename = self.directory_layout.module_index(self.processor.root.name)
     23      self.__title = 'Global %s Index'%self.processor.root.type.capitalize()
     24
     25   def filename(self):
     26
     27      return self.__filename
     28
     29   def title(self):
     30
     31      return self.__title
     32
     33   def process(self):
     34
     35      self.module_queue = [self.processor.root]
     36      while self.module_queue:
     37         m = self.module_queue.pop(0)
     38         self.process_module_index(m)
     39
     40   def make_view_heading(self, module):
     41      """Creates a HTML fragment which becomes the name at the top of the
     42      index view. This may be overridden, but the default is (now) to make a
     43      linked fully scoped name, where each scope has a link to the relevant
     44      index."""
     45
     46      name = module.name
     47      if not name: return 'Global Index'
     48      links = []
     49      for depth in range(0, len(name)):
     50         url = self.directory_layout.module_index(name[:depth+1])
     51         label = escape(name[depth])
     52         links.append(href(rel(self.__filename, url), label))
     53      return element('b', name.sep.join(links) + ' Index')
     54
     55   def process_module_index(self, module):
     56      "Index one module"
     57
     58      sorter = self.processor.sorter.clone(module.declarations)
     59
     60      self.__filename = self.directory_layout.module_index(module.name)
     61      self.__title = str(module.name) or 'Global Module'
     62      self.__title = self.__title + ' Index'
     63      # Create file
     64      self.start_file()
     65      #target = rel(self.__filename, self.directory_layout.scope(module.name))
     66      #link = href(target, self.__title, target='content')
     67      self.write(self.make_view_heading(module))
     68
     69      toc = self.processor.toc
     70
     71      # Make script to switch main frame upon load
     72      load_script = '<!--\n'
     73      if toc[module.name]:
     74         target = rel(self.__filename, toc[module.name].link)
     75         load_script = load_script + 'window.parent.frames["content"].location="%s";\n'%target
     76      load_script = load_script + 'function go(index,detail) {\n''window.parent.frames["index"].location=index;\n''window.parent.frames["detail"].location=detail;\n''return false;}\n-->'
     77      self.write(element('script', load_script, type='text/javascript'))
     78
     79      # Loop throught all the types of children
     80      for section in sorter:
     81         heading = '<br/>\n'+element('i', escape(section))+'<br/>\n'
     82         # Get a list of children of this type
     83         for child in sorter[section]:
     84            # Print out summary for the child
     85            if not isinstance(child, ASG.Scope):
     86               continue
     87            if heading:
     88               self.write(heading)
     89               heading = None
     90            label = str(module.name.prune(child.name))
     91            label = escape(label)
     92            label = replace_spaces(label)
     93            if isinstance(child, ASG.Module):
     94               index_url = rel(self.__filename,
     95                               self.directory_layout.module_index(child.name))
     96               self.write(href(index_url, label, target='detail'))
     97            else:
     98               entry = toc[child.name]
     99               if entry:
    100                  url = rel(self.__filename, entry.link)
    101                  self.write(href(url, label, target='content'))
    102               else:
    103                  self.write(label)
    104            self.write('<br/>\n')
    105      self.end_file()
    106
    107      children = [c for c in module.declarations if isinstance(c, ASG.Module)]
    108      self.module_queue.extend(children)
    109

Generated on Thu Apr 16 16:27:13 2009 by
synopsis (version devel)