Skip to content

Commit

Permalink
ref tags pointing to the current page now display as code, not as a l…
Browse files Browse the repository at this point in the history
…ink.

Section headers only display on the index page if there are members of that category.
  • Loading branch information
mattball committed Aug 23, 2008
1 parent 88d19a8 commit 3c3041e
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 42 deletions.
127 changes: 107 additions & 20 deletions doxyclean.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@

def usage ():
sys.stderr.write('''\
Usage: doxyclean.py [-h] [-i indir] [-o outdir]
Usage: doxyclean.py [-h] [-i indir] [-o outdir]
Options: -h Converts the cleaned XML to XHTML styled similarly to Apple's documentation
-i indir Specifies the directory with XML files generated by Doxygen
-o outdir Specifies the directory to place the cleaned XML files
Options: -h Converts the cleaned XML to XHTML styled similarly to Apple's documentation
-i indir Specifies the directory with XML files generated by Doxygen
-o outdir Specifies the directory to place the cleaned XML files
Converts the XML files generated by Doxygen to
be more easily-read and more catered to Objective-C.
Converts the XML files generated by Doxygen to be more easily-read and more catered to Objective-C.
''')
sys.exit(1)

Expand Down Expand Up @@ -114,28 +114,28 @@ def cleanXML(fileName, inputDirectory, outputDirectory):

return (objectName, objectType)

def convertToXHTML(objectName, objectType, inputDirectory, outputDirectory):
# Set the path for different kinds of objects
classXHTMLPath = xhtmlOutputDirectory + '/Classes'
categoryXHTMLPath = xhtmlOutputDirectory + '/Categories'
protocolXHTMLPath = xhtmlOutputDirectory + '/Protocols'
def convertToXHTML(filePath, outputDirectory):
# Get info about the object
classFile = minidom.parse(filePath)
# Get the object name
nameList = classFile.getElementsByTagName('name')
objectName = nameList[0].firstChild.data
# Get the object type
objectList = classFile.getElementsByTagName('object')
objectType = objectList[0].attributes['kind'].value

if objectType == 'class':
inputDirectory += '/Classes'
outputDirectory += '/Classes'
elif objectType == 'category':
inputDirectory += '/Categories'
outputDirectory += '/Categories'
elif objectType == 'protocol':
inputDirectory += '/Protocols'
outputDirectory += '/Protocols'
_mkdir(outputDirectory)

inputPath = inputDirectory + '/' + objectName + '.xml'
outputPath = outputDirectory + '/' + objectName + '.html'

stylesheetPath = sys.path[0] + '/object2xhtml.xslt'
os.system('xsltproc -o "' + outputPath + '" "' + stylesheetPath + '" "' + inputPath + '"')
os.system('xsltproc -o "' + outputPath + '" "' + stylesheetPath + '" "' + filePath + '"')

def createIndexXML(inputDirectory):
# Create the index xml file
Expand Down Expand Up @@ -239,6 +239,77 @@ def convertIndexToXHTML(xmlPath, outputDirectory):
outputPath = outputDirectory + '/index.html'
os.system('xsltproc -o "' + outputPath + '" "' + stylesheetPath + '" "' + xmlPath + '"')

def linkify(inputDirectory):
indexFile = minidom.parse(inputDirectory + '/index.xml')
documentedObjects = indexFile.getElementsByTagName('name')
# for currentObject in documentedObjects:
# Get info about the current object
# objectName = currentObject.getElementsByTagName('name')[0].firstChild.data
# objectType = currentObject.attributes['kind'].value

# Remove newlines and tabs from the object name
# This is needed because of a "feature" in the minidom's prettyprint
# objectName = objectName.replace('\n', '').replace('\t', '')

# Determine the path to the current object
# objectPath = inputDirectory
# if objectType == 'class':
# objectPath += '/Classes'
# elif objectType == 'category':
# objectPath += '/Categories'
# elif objectType == 'protocol':
# objectPath += '/Protocols'
# objectPath += '/' + objectName + '.xml'

# Get each file
for (path, dirs, files) in os.walk(inputDirectory):
for fileName in files:
# Skip the index
if fileName == 'index.xml':
break

filePath = path + '/' + fileName

# Get all the paragraphs in the file
fileXML = minidom.parse(filePath)
fileType = fileXML.getElementsByTagName('object')[0].attributes['kind'].value
refNodes = fileXML.getElementsByTagName('ref')

# Replace all instances of the current object with a <ref>
for node in refNodes:
refName = node.firstChild.data

# Search for the corresponding node in the index
for documentedObject in documentedObjects:
# We need to get rid of whitespace (it's a "feature" of minidom)
objectName = documentedObject.firstChild.data.replace('\n', '').replace('\t', '')
if objectName == refName:
objectType = documentedObject.parentNode.attributes['kind'].value
objectPath = ''

# Determine the proper directory
if fileType != objectType:
if objectType == 'class':
objectPath += '../Classes/'
elif objectType == 'category':
objectPath += '../Categories/'
elif objectType == 'protocol':
objectPath += '../Protocols/'

objectPath += refName

node.setAttribute('id', objectPath)
break

# Check if the ref has a "kind" attribute
if not node.hasAttribute('id'):
refText = fileXML.createTextNode(refName)
node.parentNode.replaceChild(refText, node)

# Write the xml file
f = open(filePath, 'w')
f.write(fileXML.toxml())
f.close()

if __name__ == '__main__':
# If no arguments are given, show the usage message
Expand Down Expand Up @@ -270,18 +341,34 @@ def convertIndexToXHTML(xmlPath, outputDirectory):
xmlOutputDirectory = outputDirectory + "/DoxyCleaned/xml"
xhtmlOutputDirectory = outputDirectory + '/DoxyCleaned/xhtml'

# Clean up the XML files
for fileName in os.listdir(inputDirectory):
if fnmatch.fnmatch(fileName, 'interface_*.xml') or fnmatch.fnmatch(fileName, 'protocol_*.xml'):

shouldConvert = fileIsDocumented(inputDirectory + '/' + fileName)

if shouldConvert:
(objectName, objectType) = cleanXML(fileName, inputDirectory, xmlOutputDirectory)

if shouldConvertToXHTML:
convertToXHTML(objectName, objectType, xmlOutputDirectory, xhtmlOutputDirectory)


indexPath = createIndexXML(xmlOutputDirectory)

# Establish inter-file links
linkify(xmlOutputDirectory)

if shouldConvertToXHTML:
# Convert each file
if (os.path.exists(xmlOutputDirectory + '/Classes')):
for fileName in os.listdir(xmlOutputDirectory + '/Classes'):
filePath = xmlOutputDirectory + '/Classes/' + fileName
convertToXHTML(filePath, xhtmlOutputDirectory)
if (os.path.exists(xmlOutputDirectory + '/Categories')):
for fileName in os.listdir(xmlOutputDirectory + '/Categories'):
filePath = xmlOutputDirectory + '/Categories/' + fileName
convertToXHTML(filePath, xhtmlOutputDirectory)
if (os.path.exists(xmlOutputDirectory + '/Protocols')):
for fileName in os.listdir(xmlOutputDirectory + '/Protocols'):
print fileName
filePath = xmlOutputDirectory + '/Protocols/' + fileName
convertToXHTML(filePath, xhtmlOutputDirectory)

convertIndexToXHTML(indexPath, xhtmlOutputDirectory)
34 changes: 20 additions & 14 deletions index2xhtml.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,29 @@
<div id="mainContainer">
<h1><a name="title" /><xsl:apply-templates select="project" mode="title"/></h1>

<div class="column">
<h5>Class References</h5>
<ul>
<xsl:apply-templates select="project/object[@kind='class']"/>
</ul>
</div>
<xsl:if test="count(project/object[@kind='class']) > 0">
<div class="column">
<h5>Class References</h5>
<ul>
<xsl:apply-templates select="project/object[@kind='class']"/>
</ul>
</div>
</xsl:if>

<div class="column">
<h5>Protocol References</h5>
<ul>
<xsl:apply-templates select="project/object[@kind='protocol']"/>
</ul>
<xsl:if test="count(project/object[@kind='protocol']) > 0">
<h5>Protocol References</h5>
<ul>
<xsl:apply-templates select="project/object[@kind='protocol']"/>
</ul>
</xsl:if>

<h5>Category References</h5>
<ul>
<xsl:apply-templates select="project/object[@kind='category']"/>
</ul>
<xsl:if test="count(project/object[@kind='category']) > 0">
<h5>Category References</h5>
<ul>
<xsl:apply-templates select="project/object[@kind='category']"/>
</ul>
</xsl:if>
</div>

<div class="clear"></div>
Expand Down
9 changes: 4 additions & 5 deletions object.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,17 @@
</xsl:copy>
</xsl:template>-->

<!-- <xsl:template match="ref">
<xsl:template match="ref">
<ref>
<xsl:attribute name="id">
<!-- <xsl:attribute name="id">
<xsl:value-of select="text()"/>
</xsl:attribute>
<xsl:attribute name="kind">
<xsl:value-of select="@kindref"/>
</xsl:attribute>
</xsl:attribute>-->
<xsl:apply-templates/>
</ref>
</xsl:template>-->
</xsl:template>

<xsl:template match="para">
<para><xsl:apply-templates/></para>
Expand Down
15 changes: 12 additions & 3 deletions object2xhtml.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,18 @@
</li>
</xsl:template>

<!-- <xsl:template match="ref">
<code><xsl:apply-templates/></code>
</xsl:template>-->
<xsl:template match="ref">
<code>
<xsl:choose>
<xsl:when test="/object/name != @id">
<a><xsl:attribute name="href"><xsl:value-of select="@id"/>.html</xsl:attribute><xsl:apply-templates/></a>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</code>
</xsl:template>

<xsl:template match="member/file">
<xsl:text>
Expand Down

0 comments on commit 3c3041e

Please sign in to comment.