File: formatter_DocBookX.py

package info (click to toggle)
python-happydoc 2.0-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 4,176 kB
  • ctags: 3,347
  • sloc: python: 11,321; makefile: 88; sh: 77
file content (241 lines) | stat: -rw-r--r-- 7,919 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#
# Structured docset and formatters for HappyDoc.
# 
# Copyright (C) 2001 by wrobell <wrobell@ite.pl>.
# 
# This software comes with ABSOLUTELY NO WARRANTY.
# This is free software, and you are welcome to redistribute it
# under certain conditions. For details see COPYING file.
#

"""XML DocBook formatter.
"""

import os.path
import string

from types import *

import happydoclib.formatter.xmlformatterbase

from happydoclib.docset.mstruct_const import *


__rcs_info__ = {
    # creation Information
    'module_name': '$RCSfile: formatter_DocBookX.py,v $',
    'creator':     'wrobell <wrobell@ite.pl>',
    'project':     'HappyDoc',
    'created':     '24-08-2001',

    # current information
    'author':      '$Author: doughellmann $',
    'version':     '$Revision: 1.2 $',
    'date':        '$Date: 2001/10/29 12:11:32 $',
}


def entryPoint():
    "Return information about this module to the dynamic loader."
    return {
        'name':    'docbookx',
        'factory':  XMLDocBookFormatter,
    }


class XMLDocBookFormatter(happydoclib.formatter.xmlformatterbase.XMLFormatter):
    """XML DocBook formatter.
    """

    def __init__(self, docset, title='', encoding='iso-8859-1', index_file_name='index', \
        file_name_ext='xml', **conf):

        """Initialize the XMLDocBookFormatter.

        Parameters

            'docset' -- the DocSet instance containing global cross-reference
                      information

             'title' -- documentation title

             'encoding' -- documentation file encoding (default 'iso-8859-1')

             'index_file_name' -- package index filename (default 'index')

             'file_name_ext' -- documentation filename extension (default 'xml')
            
            '**conf' -- additional, optional, configuration values

        """
        
        apply(happydoclib.formatter.formatter_xml.XMLFormatter.__init__, \
            (self, docset, encoding, index_file_name, file_name_ext), conf)
        self.filename_ext='docb'
        self.title=title


    #
    # XMLFormatter class abstract methods implementation.
    #

    def processRoot(self, output, stage, rtype):
        """XMLFormatter class abstract method implementation.
        """
        if rtype==INDEX_FILE:
            if stage==START:
                self.writeRaw('<?xml version="1.0" encoding="%s"?>\n' % self.getEncoding(), output)
                self.writeRaw('<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "file:///usr/share/sgml/docbook/xml-dtd-4.1.2/docbookx.dtd">\n', output)

                self.tag('chapter', output, {'xmlns:xi': 'http://www.w3.org/2001/XInclude'})
                if self.title:
                    self.writeTaggedText('title', self.title, output)
            elif stage==END:
                self.endTag('chapter', output)


    def processPackage(self, info, output, stage):
        """XMLFormatter class abstract method implementation.
        """
        #if stage==START:
        #    self.tag('chapter', output)
        #    self.writeTaggedText('title', 'Package %s' % info.getName(), output)
        #elif stage==END:
        #    self.endTag('chapter', output)
        pass


    def processModule(self, info, output, stage):
        """XMLFormatter class abstract method implementation.
        """
        if stage==START:
            self.tag('section', output, {'xmlns:xi': 'http://www.w3.org/2001/XInclude'})
            name=info.getFullyQualifiedName(self.getFilenamePrefix())
            name=string.replace(name, '/', '.')[:len(name)-3]
            self.writeTaggedText('title', 'Module %s' % name, output)
        elif stage==END:
            self.endTag('section', output)


    def processDocString(self, info, output, stage):
        """XMLFormatter class abstract method implementation.
        """
        pass


    def processImport(self, iinfo, minfo, output, stage):
        """XMLFormatter class abstract method implementation.
        """
        if stage==PRE:
            self.tag('para', output)
            self.writeText('Imported modules and (or) symbols:', output)
            self.tag('itemizedlist', output)
        elif stage==START:
            self.tag('listitem', output)
            self.tag('para', output)
            self.writeText(iinfo, output)
        elif stage==END:
            self.endTag('para', output)
            self.endTag('listitem', output)
        elif stage==POST:
            self.endTag('itemizedlist', output)
            self.endTag('para', output)


    def processImportSymbol(self, info, output, stage):
        """XMLFormatter class abstract method implementation.
        """
        if stage==START:
            if len(info)==1 and info[0]=='*':
                self.writeText('- all symbols', output)
            else:
                self.writeText('- %s' % string.join(info, ','), output)


    def processClass(self, info, output, stage):
        """XMLFormatter class abstract method implementation.
        """
        if stage==START:
            self.tag('section', output)
            self.writeTaggedText('title', 'Class %s' % info.getName(), output)
        elif stage==END:
            self.endTag('section', output)


    def processException(self, einfo, output, stage):
        """XMLFormatter class abstract method implementation.
        """
        if stage==PRE:
            self.tag('para', output)
            self.writeText('Raised exceptions:', output)
            self.tag('itemizedlist', output)

        elif stage==START:
            self.tag('listitem', output)

            if type(einfo)==StringType: name=einfo
            else: name=einfo.getName()
            self.writeTaggedText('para', name, output)

            self.endTag('listitem', output)

        elif stage==POST:
            self.endTag('itemizedlist', output)
            self.endTag('para', output)


    def processFunction(self, info, output, stage):
        """XMLFormatter class abstract method implementation.
        """
        if stage==START:
            self.tag('funcsynopsis', output)
            self.tag('funcprototype', output)
            self.tag('funcdef', output)
            self.writeTaggedText('function', info.getName(), output)
        elif stage==END:
            self.endTag('funcdef', output)
            self.endTag('funcprototype', output)
            self.endTag('funcsynopsis', output)


    def processClassBase(self, info, cinfo, output, stage):
        """XMLFormatter class abstract method implementation.
        """
        pass


    def processParam(self, info, output, stage):
        """XMLFormatter class abstract method implementation.
        """
        if stage==START:
            name, finfo, default_specified, default_value, default_value_type=info
            self.tag('paramdef', output)

            if default_specified:
                self.writeTaggedText('parameter', '%s=%s' % (name, default_value), output)
            else:
                self.writeTaggedText('parameter', name, output)
        elif stage==END:
            self.endTag('paramdef', output)


    def classIndex(self, class_info, output):
        """XMLFormatter class abstract method implementation.
        """
        name=os.path.basename(self.getOutputNameForObject(class_info))
        self.emptyTag('xi:include', output, { 'href': name })


    def moduleIndex(self, module_info, output):
        """XMLFormatter class abstract method implementation.
        """
        name=os.path.basename(self.getOutputNameForObject(module_info))
        self.emptyTag('xi:include', output, { 'href': name })


    def packageIndex(self, package_info, output):
        """XMLFormatter class abstract method implementation.
        """
        name='%s/%s#%s' \
            % (package_info.getName(), self.getIndexFileName(), 'xpointer(/chapter/section)')
        self.emptyTag('xi:include', output, { 'href': name })