File: Synopsis/Formatters/HTML/Views/FileListing.py 1
2
3
4
5
6
7
8
9from Synopsis.Processor import Parameter
10from Synopsis import FileTree
11from Synopsis.Formatters.HTML.View import View
12from Synopsis.Formatters.HTML.Tags import *
13
14import os
15
16class FileListing(View):
17 """A view that creates an index of files, and an index for each file.
18 First the index of files is created, intended for the top-left frame.
19 Second a view is created for each file, listing the major declarations for
20 that file, eg: classes, global functions, namespaces, etc."""
21
22 def filename(self):
23
24 if self.main:
25 return self.directory_layout.index()
26 else:
27 return self.directory_layout.special('FileListing')
28
29 def title(self):
30
31 return 'Files'
32
33 def root(self):
34
35 return self.filename(), self.title()
36
37 def register_filenames(self):
38 """Registers a view for each file indexed."""
39
40 self.processor.register_filename(self.filename(), self, None)
41
42 def process(self):
43 """Creates the listing using the recursive process_file_tree_node method"""
44
45
46 self.start_file()
47 self.write_navigation_bar()
48 self.write('<ul class="tree">')
49
50 self.process_file_tree_node(self.processor.file_tree.root())
51 self.write('</ul>')
52 self.end_file()
53
54 def _node_sorter(self, a, b):
55 """Compares file nodes a and b depending on whether they are leaves
56 or not"""
57
58 a_leaf = isinstance(a, FileTree.File)
59 b_leaf = isinstance(b, FileTree.File)
60 if a_leaf != b_leaf:
61 return cmp(b_leaf, a_leaf)
62 return cmp(a.path.upper(), b.path.upper())
63
64 def process_file_tree_node(self, node):
65 """Creates a portion of the tree for the given file node. This method
66 assumes that the file is already in progress, and just appends to
67 it. This method is recursive, calling itself for each child of node
68 (file or directory)."""
69
70 if isinstance(node, FileTree.File):
71
72 ref = rel(self.filename(), self.directory_layout.file_index(node.path))
73 text = href(ref, node.filename, target='detail')
74 self.write('<li>%s</li>'%text)
75 return
76
77 children = node.children
78 children.sort(self._node_sorter)
79 if len(node.path):
80 self.write('<li>%s<ul class="tree">'%node.filename+os.sep)
81 if len(children):
82 for child in children:
83 self.process_file_tree_node(child)
84 if len(node.path):
85 self.write('</ul></li>')
86
Generated on Thu Apr 16 16:27:12 2009 by
synopsis (version devel)