File: Synopsis/Formatters/HTML/DirectoryLayout.py 1
2
3
4
5
6
7
8
9from Synopsis import config
10from Synopsis import ASG
11from Synopsis.Formatters import TOC
12from Synopsis.Formatters import quote_name, open_file, copy_file
13from Tags import *
14import os, sys
15
16
17class DirectoryLayout (TOC.Linker):
18 """DirectoryLayout defines how the generated html files are organized.
19 The default implementation uses a flat layout with all files being part
20 of a single directory."""
21
22 def init(self, processor):
23
24 self.processor = processor
25 self.base = self.processor.output
26 if not os.path.exists(self.base):
27 if processor.verbose: print "Warning: Output directory does not exist. Creating."
28 try:
29 os.makedirs(self.base, 0755)
30 except EnvironmentError, reason:
31 print "ERROR: Creating directory:",reason
32 sys.exit(2)
33 elif not os.path.isdir(self.base):
34 print "ERROR: Output must be a directory."
35 sys.exit(1)
36
37 js = os.path.join(config.datadir, 'html.js')
38 self.copy_file(js, 'synopsis.js')
39 if os.path.isfile(processor.stylesheet):
40 self.copy_file(processor.stylesheet, 'synopsis.css')
41 else:
42 print "ERROR: stylesheet %s doesn't exist"%processor.stylesheet
43 sys.exit(1)
44 self.copy_file(os.path.join(config.datadir, 'logo-small.png'),
45 'synopsis.png')
46
47
48 def copy_file(self, src, dest):
49 """Copy src to dest, if dest doesn't exist yet or is outdated."""
50
51 copy_file(src, os.path.join(self.base, dest))
52
53 def scope(self, scope = None):
54 """Return the filename of a scoped name (class or module).
55 The default implementation is to join the names with '-' and append
56 ".html". Additionally, special characters are quoted."""
57
58 if not scope: return self.special('global')
59 return quote_name('.'.join(scope)) + '.html'
60
61 def _strip(self, filename):
62
63 if filename.endswith('/'): filename = filename[:-1]
64 if filename.startswith('/'): filename = filename[1:]
65 return filename
66
67 def file_index(self, filename):
68 """Return the filename for the index of an input file.
69 Default implementation is to join the path with '.', prepend '_file.'
70 and append '.html' """
71
72 filename = self._strip(filename)
73 return '_file.%s.html'%filename.replace(os.sep, '.')
74
75 def file_source(self, filename):
76 """Return the filename for the source of an input file.
77 Default implementation is to join the path with '.', prepend '_source.'
78 and append '.html' """
79
80 file = self._strip(filename)
81 return '_source.'+file.replace(os.sep, '.')+'.html'
82
83 def file_details(self, filename):
84 """Return the filename for the details of an input file.
85 Default implementation is to join the path with '.', prepend
86 '_file_detail.' and append '.html' """
87
88 return '_file_detail.'+self._strip(filename).replace(os.sep, '.')+'.html'
89
90 def index(self):
91 """Return the name of the main index file. Default is index.html"""
92
93 return 'index.html'
94
95 def special(self, name):
96 """Return the name of a special file (tree, etc). Default is
97 _name.html"""
98
99 return '_%s.html'%name
100
101 def scoped_special(self, name, scope, ext='.html'):
102 """Return the name of a special type of scope file. Default is to join
103 the scope with '.' and prepend '.'+name"""
104
105 return "_%s%s%s"%(name, quote_name('.'.join(scope)), ext)
106
107 def xref(self, page):
108 """Return the name of the xref file for the given page"""
109
110 return '_xref%d.html'%page
111
112 def module_tree(self):
113 """Return the name of the module tree index. Default is
114 _modules.html"""
115
116 return '_modules.html'
117
118 def module_index(self, scope):
119 """Return the name of the index of the given module. Default is to
120 join the name with '.', prepend '_module' and append '.html' """
121
122 return quote_name('_module' + '.'.join(scope)) + '.html'
123
124 def link(self, decl):
125 """Create a link to the named declaration. This method may have to
126 deal with the directory layout."""
127
128 if (isinstance(decl, ASG.Scope) or
129
130
131 (isinstance(decl, ASG.Forward) and decl.specializations)):
132
133 return self.scope(decl.name)
134
135 filename = self.scope(decl.name[:-1])
136 fragment = quote_as_id(decl.name[-1])
137 return filename + '#' + fragment
138
139class NestedDirectoryLayout(DirectoryLayout):
140 """Organizes files in a directory tree."""
141
142 def scope(self, scope = None):
143
144 if not scope: return 'Scopes/global.html'
145 else: return quote_name('Scopes/' + '/'.join(scope)) + '.html'
146
147 def file_index(self, filename):
148
149 return 'File/%s.html'%self._strip(filename)
150
151 def file_source(self, filename):
152
153 return 'Source/%s.html'%self._strip(filename)
154
155 def file_details(self, filename):
156
157 return 'FileDetails/%s.html'%self._strip(filename)
158
159 def special(self, name):
160
161 return name + '.html'
162
163 def scoped_special(self, name, scope, ext='.html'):
164
165 return quote_name(name + '/' + '/'.join(scope)) + ext
166
167 def xref(self, page):
168
169 return 'XRef/xref%d.html'%page
170
171 def module_tree(self):
172
173 return 'Modules.html'
174
175 def module_index(self, scope):
176
177 if not len(scope):
178 return 'Modules/global.html'
179 else:
180 return quote_name('Modules/' + '/'.join(scope)) + '.html'
181
Generated on Tue Jul 20 09:07:16 2010 by
synopsis (version devel)