Skip to content

Commit

Permalink
Added missing docbook tags in the xsl conversion + minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ezimuel committed Jul 11, 2012
1 parent 556e900 commit 813d6bb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 27 deletions.
45 changes: 23 additions & 22 deletions bin/doc2rst.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@
echo "Unable to locate autoloader via include_path; aborting" . PHP_EOL;
exit(2);
}
} else {
// Try to load StandardAutoloader from library
if (false === include($libPath . '/Zend/Loader/StandardAutoloader.php')) {
echo "Unable to locate autoloader via library; aborting" . PHP_EOL;
exit(2);
}
} elseif (false === include($libPath . '/Zend/Loader/StandardAutoloader.php')) {
echo "Unable to locate autoloader via library; aborting" . PHP_EOL;
exit(2);
}

// Setup autoloading
Expand Down Expand Up @@ -93,7 +90,7 @@
$xml = new \DOMDocument;
$xml->load($docbook);

$xsltFile = 'doc2rst.xsl';
$xsltFile = __DIR__ . '/doc2rst.xsl';

// Load the XSLT file
$xsl = new \DOMDocument;
Expand Down Expand Up @@ -170,7 +167,7 @@ public static function note($text) {
} else {
$output = '';
}
for ($i=1; $i<$tot; $i++) {
for ($i=1; $i < $tot; $i++) {
if ('' !== trim($rows[$i])) {
$output .= " {$rows[$i]}\n";
}
Expand Down Expand Up @@ -203,10 +200,10 @@ public static function listitem($text) {
* @return string
*/
public static function maintitle($text) {
$text = str_replace("\\", "\\\\", trim($text));
$text = str_replace('\\', '\\\\', trim($text));
$count = strlen($text);
$output = $text . "\n";
$output .= str_repeat("=", $count) . "\n";
$output .= str_repeat('=', $count) . "\n";
return $output;
}

Expand All @@ -217,10 +214,10 @@ public static function maintitle($text) {
* @return string
*/
public static function title($text) {
$text = str_replace("\\", "\\\\", trim($text));
$text = str_replace('\\', '\\\\', trim($text));
$count = strlen($text);
$output = "\n" . $text . "\n";
$output .= str_repeat("-", $count) . "\n";
$output .= str_repeat('-', $count) . "\n";
return $output;
}

Expand All @@ -231,7 +228,7 @@ public static function title($text) {
* @return string
*/
public static function formatText($text) {
return str_replace("\\", "\\\\", trim(preg_replace('/\s+/', ' ', str_replace("\n", '', $text))));
return str_replace('\\', '\\\\', trim(preg_replace('/\s+/', ' ', str_replace("\n", '', $text))));
}

/**
Expand All @@ -249,6 +246,7 @@ public static function link($node) {
return " `$value`_ ";
}
}

/**
* Get all the external links of the document
*
Expand All @@ -261,6 +259,7 @@ public static function getLinks() {
}
return $output;
}

/**
* Convert the table tag
*
Expand Down Expand Up @@ -299,9 +298,9 @@ public static function table($node) {
'columnWidths' => $widthCol,
'decorator' => 'ascii'
));
for ($j=0; $j<$totRow; $j++) {
for ($j=0; $j < $totRow; $j++) {
$row = new Table\Row();
for ($i=0; $i<$totCol; $i++) {
for ($i=0; $i < $totCol; $i++) {
$row->appendColumn(new Table\Column($table[$j][$i]));
}
$tableText->appendRow($row);
Expand All @@ -310,20 +309,22 @@ public static function table($node) {
// if thead exists change the table style with head (= instead of -)
if ($head) {
$table = explode("\n", $output);
$output = '';
$newOutput = '';
$i = 0;
foreach ($table as $row) {
if ('+-' === substr($row,0,2)) {
if ('+-' === substr($row, 0, 2)) {
$i++;
}
if (2 === $i) {
$row = str_replace('-','=', $row);
$row = str_replace('-', '=', $row);
}
$output .= "$row\n";
$newOutput .= "$row\n";
}
return $newOutput;
}
return $output;
}

/**
* Convert an XML file name to the RST ZF2 standard naming convention
* For instance, Zend_Config-XmlIntro.xml become zend.config.xml-intro.rst
Expand All @@ -332,13 +333,13 @@ public static function table($node) {
* @return string
*/
public static function XmlFileNameToRst($name) {
if ('.xml' === strtolower(substr($name,-4))) {
if ('.xml' === strtolower(substr($name, -4))) {
$name = substr($name, 0, strlen($name)-4);
}
$tot = strlen($name);
$output = '';
$word = false;
for ($i=0; $i<$tot; $i++) {
for ($i=0; $i < $tot; $i++) {

if (preg_match('/[A-Z]/', $name[$i])) {
if ($word) {
Expand All @@ -355,4 +356,4 @@ public static function XmlFileNameToRst($name) {
}
return $output.'.rst';
}
}
}
36 changes: 31 additions & 5 deletions bin/doc2rst.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<xsl:template match="doc:para">
<xsl:text>
</xsl:text>
<xsl:if test="name(..) != 'section'">
<xsl:if test="name(..) = 'note'">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:apply-templates/>
Expand All @@ -53,17 +53,43 @@
.. include:: <xsl:value-of select="php:function('ZendBin\RstConvert::XmlFileNameToRst', string(@href))" />
</xsl:template>

<!-- classname, methodname, type, command, property -->
<xsl:template match="//doc:classname|//doc:methodname|//doc:type|//doc:command|//doc:property"> ``<xsl:value-of select="normalize-space()" />`` </xsl:template>
<!-- classname, interfacename, methodname, type, command, property, constant, filename, varname -->
<xsl:template match="//doc:classname|//doc:interfacename|//doc:methodname|//doc:type|//doc:command|//doc:property|//doc:constant|//doc:filename|//doc:varname"> ``<xsl:value-of select="normalize-space()" />`` </xsl:template>

<!-- acronym, emphasis -->
<xsl:template match="//doc:acronym|/doc:emphasis"> *<xsl:value-of select="normalize-space()" />* </xsl:template>
<!-- acronym -->
<xsl:template match="//doc:acronym"> *<xsl:value-of select="normalize-space()" />* </xsl:template>

<!-- emphasis -->
<xsl:template match="/doc:emphasis"> **<xsl:value-of select="normalize-space()" />** </xsl:template>

<!-- example -->
<xsl:template match ="//doc:example">
<xsl:apply-templates />
</xsl:template>

<!-- programlisting -->
<xsl:template match="//doc:programlisting">
<xsl:value-of select="php:function('ZendBin\RstConvert::programlisting', string(.))" />
</xsl:template>

<!-- varlistentry -->
<xsl:template match="//doc:varlistentry">
<xsl:if test="@xml:id != ''">
.. _<xsl:value-of select="@xml:id" />:
<xsl:text>
</xsl:text>
</xsl:if>
**<xsl:value-of select="doc:term" />**
<xsl:text>
</xsl:text>
<xsl:if test="doc:listitem/doc:methodsynopsis">
``<xsl:value-of select="doc:listitem/doc:methodsynopsis/doc:methodname" />(<xsl:value-of select="php:function('ZendBin\RstConvert::formatText', string(doc:listitem/doc:methodsynopsis/doc:methodparam/doc:funcparams))" />)``
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:apply-templates select="doc:listitem/doc:para" />
</xsl:template>

<!-- itemizedlist -->
<xsl:template match="//doc:itemizedlist">
<xsl:value-of select="php:function('ZendBin\RstConvert::listitem', string(.))" />
Expand Down

0 comments on commit 813d6bb

Please sign in to comment.