File: Synopsis/Formatters/HTML/Views/FileTree.py 1
2
3
4
5
6
7
8
9from Synopsis.Processor import Parameter
10from Tree import Tree
11from Synopsis.Formatters.HTML.Tags import *
12
13import os
14
15class FileTree(Tree):
16 """Create a javascript-enabled file tree."""
17
18 link_to_views = Parameter(False, 'some docs...')
19
20 def filename(self):
21
22 if self.main:
23 return self.directory_layout.index()
24 else:
25 return self.directory_layout.special('FileTree')
26
27 def title(self):
28
29 return 'File Tree'
30
31 def root(self):
32
33 return self.filename(), self.title()
34
35 def process(self):
36
37
38 self.start_file()
39 self.write_navigation_bar()
40
41 self.process_node(self.processor.file_tree)
42 self.end_tree()
43 self.end_file()
44
45 def process_node(self, node):
46
47 def node_cmp(a, b):
48 a_leaf = hasattr(a, 'declarations')
49 b_leaf = hasattr(b, 'declarations')
50 if a_leaf != b_leaf:
51 return cmp(b_leaf, a_leaf)
52 return cmp(a.path[-1].upper(), b.path[-1].upper())
53
54 dirname, filename = os.path.split(node.path)
55 if hasattr(node, 'declarations'):
56
57 text = href(self.directory_layout.file_index(node.path),
58 filename, target='detail')
59 self.write_leaf(text)
60 return
61
62 children = node.children[:]
63 children.sort(node_cmp)
64 if node.path:
65 self.write_node_start(filename + os.sep)
66 if len(children):
67 for child in children:
68
69 self.process_node(child)
70
71 if node.path:
72 self.write_node_end()
73
Generated on Thu Apr 16 16:27:15 2009 by
synopsis (version devel)