File: Synopsis/Formatters/HTML/Parts/Body.py
 1#
 2# Copyright (C) 2009 Stefan Seefeld
 3# All rights reserved.
 4# Licensed to the public under the terms of the GNU LGPL (>= 2),
 5# see the file COPYING for details.
 6#
 7
 8from Synopsis import ASG
 9from Synopsis.Processor import Parameter
10from Synopsis.Formatters.HTML.Part import Part
11from Synopsis.Formatters.HTML.Fragments import *
12from Synopsis.Formatters.HTML.Tags import *
13
14class Body(Part):
15
16    fragments = Parameter([DeclarationDetailFormatter(),
17                           DeclarationCommenter()],
18                         '')
19
20    def write_section_start(self, heading):
21        """Start a 'detail' section and write an appropriate heading."""
22
23        c = self.view().generate_id()
24        toggle = span('-', class_='toggle', id="toggle_s%d"%c,
25                      onclick='return body_section_toggle(\'s%d\');'%c)
26        self.write(div(toggle + heading, class_='heading') + '\n')
27        self.write('<div class="body expanded" id="s%d">\n'%c)
28
29    def write_section_end(self, heading):
30        """Close the section."""
31
32        self.write('</div><!-- body -->\n')
33
34    def write_section_item(self, text):
35        """Add an item."""
36
37        self.write(div(text, class_='item') + '\n')
38
39    def process(self, decl):
40        "Print out the details for the children of the given decl"
41
42        if type(decl) == ASG.Forward:
43            return
44
45        doc = self.processor.documentation
46        sorter = self.processor.sorter.clone(decl.declarations)
47
48        # Iterate through the sections with details
49        self.write_start()
50        for section in sorter:
51            started = 0 # Lazy section start incase no details for this section
52            # Iterate through the children in this section
53            for child in sorter[section]:
54                # Check section heading
55                if not started:
56                    started = 1
57                    self.write_section_start(section)
58                child.accept(self)
59            # Finish the section
60            if started: self.write_section_end(section)
61        self.write_end()
62