Synopsis - Cross-Reference
File: Synopsis/Formatters/HTML/DirectoryLayout.py1# 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 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 if os.path.isfile(processor.stylesheet): 38 self.copy_file(processor.stylesheet, 'style.css') 39 else: 40 print "ERROR: stylesheet %s doesn't exist"%processor.stylesheet 41 sys.exit(1) 42 self.copy_file(os.path.join(config.datadir, 'logo-small.png'), 43 'synopsis.png') 44 45 46 def copy_file(self, src, dest): 47 """Copy src to dest, if dest doesn't exist yet or is outdated.""" 48 49 copy_file(src, os.path.join(self.base, dest)) 50 51 def scope(self, scope = None): 52 """Return the filename of a scoped name (class or module). 53 The default implementation is to join the names with '-' and append 54 ".html". Additionally, special characters are quoted.""" 55 56 if not scope: return self.special('global') 57 return quote_name('.'.join(scope)) + '.html' 58 59 def _strip(self, filename): 60 61 if len(filename) and filename[-1] == '/': filename = filename[:-1] 62 return filename 63 64 def file_index(self, filename): 65 """Return the filename for the index of an input file. 66 Default implementation is to join the path with '.', prepend '_file.' 67 and append '.html' """ 68 69 filename = self._strip(filename) 70 return '_file.%s.html'%filename.replace(os.sep, '.') 71 72 def file_source(self, filename): 73 """Return the filename for the source of an input file. 74 Default implementation is to join the path with '.', prepend '_source.' 75 and append '.html' """ 76 77 file = self._strip(filename) 78 return '_source.'+file.replace(os.sep, '.')+'.html' 79 80 def file_details(self, filename): 81 """Return the filename for the details of an input file. 82 Default implementation is to join the path with '.', prepend 83 '_file_detail.' and append '.html' """ 84 85 return '_file_detail.'+self._strip(filename).replace(os.sep, '.')+'.html' 86 87 def index(self): 88 """Return the name of the main index file. Default is index.html""" 89 90 return 'index.html' 91 92 def special(self, name): 93 """Return the name of a special file (tree, etc). Default is 94 _name.html""" 95 96 return '_%s.html'%name 97 98 def scoped_special(self, name, scope, ext='.html'): 99 """Return the name of a special type of scope file. Default is to join 100 the scope with '.' and prepend '.'+name""" 101 102 return "_%s%s%s"%(name, quote_name('.'.join(scope)), ext) 103 104 def xref(self, page): 105 """Return the name of the xref file for the given page""" 106 107 return '_xref%d.html'%page 108 109 def module_tree(self): 110 """Return the name of the module tree index. Default is 111 _modules.html""" 112 113 return '_modules.html' 114 115 def module_index(self, scope): 116 """Return the name of the index of the given module. Default is to 117 join the name with '.', prepend '_module' and append '.html' """ 118 119 return quote_name('_module' + '.'.join(scope)) + '.html' 120 121 def link(self, decl): 122 """Create a link to the named declaration. This method may have to 123 deal with the directory layout.""" 124 125 if (isinstance(decl, ASG.Scope) or 126 # If this is a forward-declared class template with known specializations, 127 # we want to treat it like an ASG.Class, as far as formatting is concerned. 128 (isinstance(decl, ASG.Forward) and decl.specializations)): 129 # This is a class or module, so it has its own file 130 return self.scope(decl.name) 131 # Assume parent scope is class or module, and this is a <A> name in it 132 filename = self.scope(decl.name[:-1]) 133 fragment = quote_as_id(decl.name[-1]) 134 return filename + '#' + fragment 135 136class NestedDirectoryLayout(DirectoryLayout): 137 """Organizes files in a directory tree.""" 138 139 def scope(self, scope = None): 140 141 if not scope: return 'Scopes/global.html' 142 else: return quote_name('Scopes/' + '/'.join(scope)) + '.html' 143 144 def file_index(self, filename): 145 146 return 'File/%s.html'%self._strip(filename) 147 148 def file_source(self, filename): 149 150 return 'Source/%s.html'%self._strip(filename) 151 152 def file_details(self, filename): 153 154 return 'FileDetails/%s.html'%self._strip(filename) 155 156 def special(self, name): 157 158 return name + '.html' 159 160 def scoped_special(self, name, scope, ext='.html'): 161 162 return quote_name(name + '/' + '/'.join(scope)) + ext 163 164 def xref(self, page): 165 166 return 'XRef/xref%d.html'%page 167 168 def module_tree(self): 169 170 return 'Modules.html' 171 172 def module_index(self, scope): 173 174 if not len(scope): 175 return 'Modules/global.html' 176 else: 177 return quote_name('Modules/' + '/'.join(scope)) + '.html' 178
Generated on Tue May 13 02:39:43 2008 by
synopsis (version 0.10)
synopsis (version 0.10)