| 1 |
lars |
1 |
<refentry id="{@id}">
|
|
|
2 |
<refnamediv>
|
|
|
3 |
<refname>Writing a New Converter</refname>
|
|
|
4 |
<refpurpose>Overview of how to write a new Converter</refpurpose>
|
|
|
5 |
</refnamediv>
|
|
|
6 |
<refsynopsisdiv>
|
|
|
7 |
<authorgroup>
|
|
|
8 |
<author>
|
|
|
9 |
Joshua Eichorn
|
|
|
10 |
<authorblurb>
|
|
|
11 |
{@link mailto:jeichorn@phpdoc.org jeichorn@phpdoc.org}
|
|
|
12 |
</authorblurb>
|
|
|
13 |
</author>
|
|
|
14 |
<author>
|
|
|
15 |
Gregory Beaver
|
|
|
16 |
<authorblurb>
|
|
|
17 |
{@link mailto:cellog@sourceforge.com cellog@sourceforge.com}
|
|
|
18 |
</authorblurb>
|
|
|
19 |
</author>
|
|
|
20 |
</authorgroup>
|
|
|
21 |
</refsynopsisdiv>
|
|
|
22 |
<refsect1 id="{@id intro}">
|
|
|
23 |
<title>Introduction to Converters</title>
|
|
|
24 |
<para>This documentation deals only with the advanced programming topic of creating a new output converter. To learn how to use phpDocumentor, read the {@tutorial phpDocumentor/phpDocumentor.pkg}. To learn how to extend an existing Converter, read {@tutorial Converters/Converters.pkg}</para>
|
|
|
25 |
</refsect1>
|
|
|
26 |
<refsect1 id="{@id concepts}">
|
|
|
27 |
<title>Basic Concepts</title>
|
|
|
28 |
<refsect2 id="{@id abstractdata}">
|
|
|
29 |
<title>Abstract Parsing Data</title>
|
|
|
30 |
<refsect3 id="{@id source}">
|
|
|
31 |
<title>Source Code Elements</title>
|
|
|
32 |
<para>A Converter's job is to take abstract data from parsing and create documentation. What is the abstract data? phpDocumentor is capable of documenting tutorials, and a php file and its re-usable or structurally important contents. In other words, phpDocumentor can document:
|
|
|
33 |
<itemizedlist>
|
|
|
34 |
<listitem><para>A XML DocBook-based tutorial (see {@tutorial phpDocumentor/tutorials.pkg})</para></listitem>
|
|
|
35 |
<listitem><para>Procedural Page (PHP source file)</para></listitem>
|
|
|
36 |
<listitem><para>Include Statements</para></listitem>
|
|
|
37 |
<listitem><para>Define Statements</para></listitem>
|
|
|
38 |
<listitem><para>Global Variables</para></listitem>
|
|
|
39 |
<listitem><para>Functions</para></listitem>
|
|
|
40 |
<listitem><para>Classes</para></listitem>
|
|
|
41 |
<listitem><para>Class Variables</para></listitem>
|
|
|
42 |
<listitem><para>Class Methods</para></listitem>
|
|
|
43 |
</itemizedlist>
|
|
|
44 |
</para>
|
|
|
45 |
<para>phpDocumentor represents these PHP elements using classes:
|
|
|
46 |
<itemizedlist>
|
|
|
47 |
<listitem><para>{@link parserTutorial}</para></listitem>
|
|
|
48 |
<listitem><para>{@link parserData, parserPage}</para></listitem>
|
|
|
49 |
<listitem><para>{@link parserInclude}</para></listitem>
|
|
|
50 |
<listitem><para>{@link parserDefine}</para></listitem>
|
|
|
51 |
<listitem><para>{@link parserGlobal}</para></listitem>
|
|
|
52 |
<listitem><para>{@link parserFunction}</para></listitem>
|
|
|
53 |
<listitem><para>{@link parserClass}</para></listitem>
|
|
|
54 |
<listitem><para>{@link parserVar}</para></listitem>
|
|
|
55 |
<listitem><para>{@link parserMethod}</para></listitem>
|
|
|
56 |
</itemizedlist>
|
|
|
57 |
</para>
|
|
|
58 |
<para>This relationship between the source code and abstract data is quite clear, and very simple. The data members of each abstract representation correspond with the information needed to display the documentation. All PHP elements contain a DocBlock, and this is represented by a class as well, {@link parserDocBlock}. The elements of a DocBlock are simple:
|
|
|
59 |
<itemizedlist>
|
|
|
60 |
<listitem><para>Short Description, containing any number of inline tags</para></listitem>
|
|
|
61 |
<listitem><para>Long Description, containing any number of inline tags</para></listitem>
|
|
|
62 |
<listitem><para>Tags, some containing any number of inline tags in their general description field</para></listitem>
|
|
|
63 |
</itemizedlist>
|
|
|
64 |
</para>
|
|
|
65 |
<para>phpDocumentor represents these elements using classes as well:
|
|
|
66 |
<itemizedlist>
|
|
|
67 |
<listitem><para>{@link parserDesc} for both short and long descriptions</para></listitem>
|
|
|
68 |
<listitem><para>{@link parserInlineTag} for inline tags</para></listitem>
|
|
|
69 |
<listitem><para>{@link parserTag} for regular tags</para></listitem>
|
|
|
70 |
</itemizedlist>
|
|
|
71 |
</para>
|
|
|
72 |
</refsect3>
|
|
|
73 |
<refsect3 id="{@id html}">
|
|
|
74 |
<title>HTML-specific issues</title>
|
|
|
75 |
<para>There are some other issues that Converters solve. In HTML, a link is represented by an <a> tag, but in the PDF Converter, it is represented by a <c:ilink> tag. How can we handle both cases? Through another abstract class, the {@link abstractLink} and its descendants:
|
|
|
76 |
<itemizedlist>
|
|
|
77 |
<listitem><para>{@link tutorialLink}</para></listitem>
|
|
|
78 |
<listitem><para>{@link pageLink}</para></listitem>
|
|
|
79 |
<listitem><para>{@link defineLink}</para></listitem>
|
|
|
80 |
<listitem><para>{@link globalLink}</para></listitem>
|
|
|
81 |
<listitem><para>{@link functionLink}</para></listitem>
|
|
|
82 |
<listitem><para>{@link classLink}</para></listitem>
|
|
|
83 |
<listitem><para>{@link varLink}</para></listitem>
|
|
|
84 |
<listitem><para>{@link methodLink}</para></listitem>
|
|
|
85 |
</itemizedlist>
|
|
|
86 |
Note the absence of an "includeLink" class - this is intentional, as only re-usable elements need to be linked. An include statement is always attached to the file that it is in, and cannot be anywhere else.
|
|
|
87 |
</para>
|
|
|
88 |
<para>These abstract linking classes contain the information necessary to differentiate between the location of any of the element's documentation. They are only used to allow linking to documentation, and not to source code. A link is then converted to the appropriate text representation for the output format by {@link Converter::returnSee()} (a href=link for html, c:ilink:link for pdf, link linkend=link in xml:docbook, and so on).</para>
|
|
|
89 |
<para>The other issues solved by a converter involves html in a DocBlock. To allow better documentation, html is allowed in DocBlocks to format the output. Unfortunately, this complicates output in other formats. To solve this issue, phpDocumentor also parses out all allowed HTML (see {@tutorial phpDocumentor.howto.pkg#basics.desc} for more detailed information) into abstract structures:
|
|
|
90 |
<itemizedlist>
|
|
|
91 |
<listitem><para><b> -- emphasize/bold text</para></listitem>
|
|
|
92 |
<listitem><para><br> -- hard line break, may be ignored by some converters</para></listitem>
|
|
|
93 |
<listitem><para><code> -- Use this to surround php code, some converters will highlight it</para></listitem>
|
|
|
94 |
<listitem><para><i> -- italicize/mark as important</para></listitem>
|
|
|
95 |
<listitem><para><li> -- list item</para></listitem>
|
|
|
96 |
<listitem><para><ol> -- ordered list</para></listitem>
|
|
|
97 |
<listitem><para><p> -- If used to enclose all paragraphs, otherwise it will be considered text</para></listitem>
|
|
|
98 |
<listitem><para><pre> -- Preserve line breaks and spacing, and assume all tags are text (like XML's CDATA)</para></listitem>
|
|
|
99 |
<listitem><para><ul> -- unordered list</para></listitem>
|
|
|
100 |
</itemizedlist>
|
|
|
101 |
is mapped to classes:
|
|
|
102 |
<itemizedlist>
|
|
|
103 |
<listitem><para>{@link parserB}</para></listitem>
|
|
|
104 |
<listitem><para>{@link parserBr}</para></listitem>
|
|
|
105 |
<listitem><para>{@link parserCode}</para></listitem>
|
|
|
106 |
<listitem><para>{@link parserI}</para></listitem>
|
|
|
107 |
<listitem><para>{@link parserList} - both types of lists are represented by this object, and each <li> is represented by an array item</para></listitem>
|
|
|
108 |
<listitem><para>{@link parserPre}</para></listitem>
|
|
|
109 |
</itemizedlist>
|
|
|
110 |
<p> is represented by partitioning text into an array, where each array item is a new paragraph. (as in {@link parserDocBlock::$processed_desc})
|
|
|
111 |
</para>
|
|
|
112 |
<para>With these simple structures and a few methods to handle them, the process of writing a new converter is straightforward.</para>
|
|
|
113 |
</refsect3>
|
|
|
114 |
<refsect3 id="{@id output}">
|
|
|
115 |
<title>Separation of data from display formatting</title>
|
|
|
116 |
<para>phpDocumentor has been designed to keep as much formatting out of the source code as possible. For many converters, there need be no new code written to support the conversion, as all output-specific information can be placed in template files. However, the complexity of generating class trees does require the insertion of some code into the source, so at the bare minimum, the {@tutorial Converter.methods.cls#override.getroottree} method must be overridden.</para>
|
|
|
117 |
</refsect3>
|
|
|
118 |
</refsect2>
|
|
|
119 |
</refsect1>
|
|
|
120 |
<refsect1 id="{@id override}">
|
|
|
121 |
<title>Methods that must be overridden</title>
|
|
|
122 |
<para>Creating a new converter can be challenging, but should not be too complicated. You need to override one data structure, {@link Converter::$leftindex}, to tell the Converter which of the individual element indexes your Converter will use. You will also need to override a few methods for the Converter to work. The most important relate to linking and output.</para>
|
|
|
123 |
<para>A Converter must override these core methods:
|
|
|
124 |
<itemizedlist>
|
|
|
125 |
<listitem><para>{@tutorial Converter.methods.cls#core.convert} - take any descendant of parserElement or a parserPackagePage and convert it into output</para></listitem>
|
|
|
126 |
<listitem><para>{@tutorial Converter.methods.cls#core.returnsee} - takes a abstract link and returns a string that links to an element's documentation</para></listitem>
|
|
|
127 |
<listitem><para>{@tutorial Converter.methods.cls#core.returnlink} - takes a URL and text to display and returns an internet-enabled link</para></listitem>
|
|
|
128 |
<listitem><para>{@tutorial Converter.methods.cls#core.output} - generate output, or perform other cleanup activities</para></listitem>
|
|
|
129 |
<listitem><para>{@tutorial Converter.methods.cls#core.convert-ric} - Converts README/INSTALL/CHANGELOG file contents for inclusion in documentation</para></listitem>
|
|
|
130 |
<listitem><para>{@tutorial Converter.methods.cls#core.converterrorlog} - formats errors and warnings from {@link $phpDocumentor_errors}. see {@link HTMLframesConverter::ConvertErrorLog()}</para></listitem>
|
|
|
131 |
<listitem><para>{@tutorial Converter.methods.cls#core.getfunctionlink} - for all of the functions below, see {@link HTMLframesConverter::getFunctionLink()} for an example </para></listitem>
|
|
|
132 |
<listitem><para>{@tutorial Converter.methods.cls#core.getclasslink}</para></listitem>
|
|
|
133 |
<listitem><para>{@tutorial Converter.methods.cls#core.getdefinelink}</para></listitem>
|
|
|
134 |
<listitem><para>{@tutorial Converter.methods.cls#core.getgloballink}</para></listitem>
|
|
|
135 |
<listitem><para>{@tutorial Converter.methods.cls#core.getmethodlink}</para></listitem>
|
|
|
136 |
<listitem><para>{@tutorial Converter.methods.cls#core.getvarlink}</para></listitem>
|
|
|
137 |
</itemizedlist>
|
|
|
138 |
</para>
|
|
|
139 |
<para>A Converter may optionally implement these abstract methods:
|
|
|
140 |
<itemizedlist>
|
|
|
141 |
<listitem><para>{@tutorial Converter.methods.cls#override.endpage} - do any post-processing of procedural page elements, possibly output documentation for the page</para></listitem>
|
|
|
142 |
<listitem><para>{@tutorial Converter.methods.cls#override.endclass} - do any post-processing of class elements, possibly output documentation for the class</para></listitem>
|
|
|
143 |
<listitem><para>{@tutorial Converter.methods.cls#override.formatindex} - format the {@link $elements} array into an index see {@link HTMLframesConverter::generateElementIndex()}</para></listitem>
|
|
|
144 |
<listitem><para>{@tutorial Converter.methods.cls#override.formatpkgindex} - format the {@link $pkg_elements} array into an index see {@link HTMLframesConverter::generatePkgElementIndex()}</para></listitem>
|
|
|
145 |
<listitem><para>{@tutorial Converter.methods.cls#override.formatleftindex} - format the {@link $elements} array into an index see {@link HTMLframesConverter::formatLeftIndex()}</para></listitem>
|
|
|
146 |
<listitem><para>{@tutorial Converter.methods.cls#override.formattutorialtoc} - format the output of a {@}toc} tag, see {@link HTMLframesConverter::formatTutorialTOC()}</para></listitem>
|
|
|
147 |
<listitem><para>{@tutorial Converter.methods.cls#override.getroottree} - generates an output-specific tree of class inheritance</para></listitem>
|
|
|
148 |
<listitem><para>{@tutorial Converter.methods.cls#override.smartyinit} - initialize a {@link Smarty} template object</para></listitem>
|
|
|
149 |
<listitem><para>{@tutorial Converter.methods.cls#override.writesource} - write out highlighted source code for a parsed file</para></listitem>
|
|
|
150 |
<listitem><para>{@tutorial Converter.methods.cls#override.writeexample} - write out highlighted source code for an example</para></listitem>
|
|
|
151 |
<listitem><para>{@tutorial Converter.methods.cls#override.unmangle} - do any post-processing of class elements, possibly output documentation for the class</para></listitem>
|
|
|
152 |
</itemizedlist>
|
|
|
153 |
</para>
|
|
|
154 |
<para>The following methods may need to be overridden for proper functionality, and are for advanced situations.
|
|
|
155 |
<itemizedlist>
|
|
|
156 |
<listitem><para>{@tutorial Converter.methods.cls#advanced.checkstate} - used by the {@link parserStringWithInlineTags::Convert()} cache to determine whether a cache hit or miss occurs</para></listitem>
|
|
|
157 |
<listitem><para>{@tutorial Converter.methods.cls#advanced.getstate} - used by the {@link parserStringWithInlineTags::Convert()} cache to save state for the next Convert() call</para></listitem>
|
|
|
158 |
<listitem><para>{@tutorial Converter.methods.cls#advanced.type-adjust} - used to enclose type names in proper tags as in {@link XMLDocBookConverter::type_adjust()}</para></listitem>
|
|
|
159 |
<listitem><para>{@tutorial Converter.methods.cls#advanced.postprocess} - called on all converted text, so that any illegal characters may be escaped. The HTML Converters, for example, pass all output through {@link htmlentities()}</para></listitem>
|
|
|
160 |
<listitem><para>{@tutorial Converter.methods.cls#advanced.gettutorialid} - called by the {@}id} inline tag to get the Converter's way of representing a document anchor</para></listitem>
|
|
|
161 |
</itemizedlist>
|
|
|
162 |
</para>
|
|
|
163 |
</refsect1>
|
|
|
164 |
<refsect1 id="{@id utility}">
|
|
|
165 |
<title>Converter methods an extended converter should use</title>
|
|
|
166 |
<para>
|
|
|
167 |
<itemizedlist>
|
|
|
168 |
<listitem><para>{@tutorial Converter.methods.cls#utility.getsortedclasstreefromclass} -- generating class trees by package</para></listitem>
|
|
|
169 |
<listitem><para>{@tutorial Converter.methods.cls#utility.hastutorial} -- use this to retrieve a tutorial, or determine if it exists</para></listitem>
|
|
|
170 |
<listitem><para>{@tutorial Converter.methods.cls#utility.gettutorialtree} -- use this to retrieve a hierarchical tree of tutorials that can be used to generate a table of contents for all tutorials</para></listitem>
|
|
|
171 |
<listitem><para>{@tutorial Converter.methods.cls#utility.vardump-tree} -- use this to assist in debugging large tree structures of tutorials</para></listitem>
|
|
|
172 |
</itemizedlist>
|
|
|
173 |
</para>
|
|
|
174 |
</refsect1>
|
|
|
175 |
</refentry>
|