File: Synopsis/Formatters/HTML/Parts/Summary.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 import ASG
10from Synopsis.Processor import Parameter
11from Synopsis.Formatters.HTML.Part import Part
12from Synopsis.Formatters.HTML.Fragments import *
13from Synopsis.Formatters.HTML.Tags import *
14
15class Summary(Part):
16    """Formatting summary visitor. This formatter displays a summary for each
17    declaration, with links to the details if there is one. All of this is
18    controlled by the ASGFormatters."""
19
20    fragments = Parameter([DeclarationSummaryFormatter(), SummaryCommenter()],
21                         '')
22
23    def register(self, view):
24
25        Part.register(self, view)
26        self.__link_detail = False
27
28    def set_link_detail(self, flag):
29        """Sets link_detail flag to given value.
30        @see label()"""
31
32        self.__link_detail = flag
33
34    def label(self, ref, label=None):
35        """Override to check link_detail flag. If it's set, returns a reference
36        instead - which will be to the detailed info"""
37
38        if label is None: label = ref
39        if self.__link_detail:
40            # Insert a reference instead
41            return span('name',self.reference(ref, str(self.scope().prune(label))))
42        return Part.label(self, ref, label)
43
44    def write_section_start(self, heading):
45        """Start a 'summary' section and write an appropriate heading."""
46
47        self.write('<div class="summary">\n')
48        self.write(div('heading', heading) + '\n')
49
50    def write_section_end(self, heading):
51        """Close the section."""
52
53        self.write('</div><!-- summary -->\n')
54
55    def write_section_item(self, text):
56        """Add an item."""
57
58        self.write(div('item', text) + '\n')
59
60    def process(self, scope):
61        "Print out the summaries from the given scope"
62
63        if type(scope) == ASG.Forward:
64            return
65
66        doc = self.processor.documentation
67        sorter = self.processor.sorter.clone(scope.declarations)
68
69        self.write_start()
70        for section in sorter:
71            # Write a header for this section
72            heading = section+' Summary:'
73            self.write_section_start(heading)
74            # Iterate through the children in this section
75            for child in sorter[section]:
76                # Check if need to add to detail list
77                if doc.details(child, self.view()):
78                    # Setup the linking stuff
79                    self.set_link_detail(1)
80                    child.accept(self)
81                    self.set_link_detail(0)
82                else:
83                    # Just do it
84                    child.accept(self)
85            # Finish off this section
86            self.write_section_end(heading)
87        self.write_end()
88
89