cvs: phd /formats xhtml.php /include PhDFormat.class.php PhDTheme.class.php /themes/pear peartheme.php
| From: | Christian Weiske | Date: | Sat, 01 Nov 2008 06:02:05 +0000 |
| Subject: | cvs: phd /formats xhtml.php /include PhDFormat.class.php PhDTheme.class.php /themes/pear peartheme.php | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-2353@lists.php.net to get a copy of this message | ||
cweiske Sat Nov 1 06:02:05 2008 UTC
Modified files:
/phd/formats xhtml.php
/phd/include PhDFormat.class.php PhDTheme.class.php
/phd/themes/pear peartheme.php
Log:
Move <phd:toc> generation to the xhtml format instead of keeping it in the
theme. phpdoc also has phd:toc support now, but still misses
<chapter phd:toc-depth="2"> attribute. phpdoc theme could also use the
createToc() function instead of using the current code.
http://cvs.php.net/viewvc.cgi/phd/formats/xhtml.php?r1=1.71&r2=1.72&diff_format=u Index: phd/formats/xhtml.php diff -u phd/formats/xhtml.php:1.71 phd/formats/xhtml.php:1.72 --- phd/formats/xhtml.php:1.71 Tue Oct 28 20:10:45 2008 +++ phd/formats/xhtml.php Sat Nov 1 06:02:04 2008 @@ -1,5 +1,5 @@ <?php -/* $Id: xhtml.php,v 1.71 2008/10/28 20:10:45 cweiske Exp $ */ +/* $Id: xhtml.php,v 1.72 2008/11/01 06:02:04 cweiske Exp $ */ class XHTMLPhDFormat extends PhDFormat { protected $elementmap = array( /* {{{ */ @@ -177,6 +177,7 @@ 'partintro' => 'div', 'personname' => 'format_personname', 'personblurb' => 'div', + 'phd:toc' => 'format_phd_toc', 'phrase' => 'span', 'preface' => 'format_chunk', 'primaryie' => 'format_suppressed_tags', @@ -256,6 +257,7 @@ 'indexdiv' => 'dt', 'legalnotice' => 'h4', 'note' => 'format_note_title', + 'phd:toc' => 'strong', 'procedure' => 'b', 'refsect1' => 'h3', 'refsect2' => 'h4', @@ -411,6 +413,57 @@ public function getChunkInfo() { return $this->cchunk; } + + /** + * Creates a table of contents for the given id. + * Also creates nested TOCs if that's wanted ($depth) + * + * @param string $id ID of section for which to generate TOC + * @param string $name Tag name (for ul class) + * @param array $props Build properties (?? FIXME) + * @param integer $depth Depth of TOC + * @param boolean $header If the header shall be shown ("Table of contents") + * + * @return string HTML code for TOC + */ + public function createToc($id, $name, $props, $depth = 1, $header = true) + { + $chunks = PhDHelper::getChildren($id); + if ($depth == 0 || !count($chunks)) { + return ''; + } + + $content = ''; + if ($header) { + $content .= " <strong>" . $this->autogen("toc", $props["lang"]) . "</strong>\n"; + } + $content .= " <ul class=\"chunklist chunklist_$name\">\n"; + foreach ($chunks as $chunkid => $junk) { + $long = $this->TEXT(PhDHelper::getDescription($chunkid, true)); + $short = $this->TEXT(PhDHelper::getDescription($chunkid, false)); + if ($long && $short && $long != $short) { + $desc = $short . '</a> -- ' . $long; + } else { + $desc = ($long ? $long : $short) . '</a>'; + } + //FIXME + if ($this->theme->chunked) { + $content .= " <li><a href=\"{$chunkid}.{$this->theme->ext}\">" . $desc; + } else { + $content .= " <li><a href=\"#{$chunkid}\">" . $this->TEXT(PhDHelper::getDescription($chunkid, false)) . "</a>"; + } + if ($depth > 1) { + $content .= $this->createToc($chunkid, $name, $props, $depth - 1, false); + } + + $content .= "</li>\n";; + } + + $content .= " </ul>\n"; + + return $content; + } + public function format_suppressed_tags($open, $name, $attrs) { /* Ignore it */ return ""; @@ -838,6 +891,21 @@ } return "</ul>\n<p class=\"para\">"; } + + public function format_phd_toc($open, $name, $attrs, $props) { + if ($open) { + return '<div class="phd-toc">'; + } + return $this->createToc( + $attrs[PhDReader::XMLNS_PHD]['element'], + 'phd-toc', + $props, + isset($attrs[PhDReader::XMLNS_PHD]['toc-depth']) + ? (int)$attrs[PhDReader::XMLNS_PHD]['toc-depth'] : 1, + false + ) . "</div>\n"; + } + public function format_segmentedlist($open, $name, $attrs) { $this->cchunk["segmentedlist"] = $this->dchunk["segmentedlist"]; if ($open) { http://cvs.php.net/viewvc.cgi/phd/include/PhDFormat.class.php?r1=1.10&r2=1.11&diff_format=u Index: phd/include/PhDFormat.class.php diff -u phd/include/PhDFormat.class.php:1.10 phd/include/PhDFormat.class.php:1.11 --- phd/include/PhDFormat.class.php:1.10 Mon Feb 4 21:17:25 2008 +++ phd/include/PhDFormat.class.php Sat Nov 1 06:02:04 2008 @@ -1,15 +1,25 @@ <?php -/* $Id: PhDFormat.class.php,v 1.10 2008/02/04 21:17:25 bjori Exp $ */ +/* $Id: PhDFormat.class.php,v 1.11 2008/11/01 06:02:04 cweiske Exp $ */ abstract class PhDFormat extends PhDHelper { - private $TABLE = array(); - + private $TABLE = array(); + + /** + * @var PhDTheme + */ + protected $theme = null; + /* abstract functions */ abstract public function transformFromMap($open, $tag, $name, $attrs, $props); abstract public function CDATA($data); abstract public function TEXT($data); abstract public function __call($func, $args); + public function registerTheme(PhDTheme $theme) + { + $this->theme = $theme; + } + /* Table helper functions */ public function tgroup($attrs) { if (isset($attrs["cols"])) { http://cvs.php.net/viewvc.cgi/phd/include/PhDTheme.class.php?r1=1.1&r2=1.2&diff_format=u Index: phd/include/PhDTheme.class.php diff -u phd/include/PhDTheme.class.php:1.1 phd/include/PhDTheme.class.php:1.2 --- phd/include/PhDTheme.class.php:1.1 Sun Nov 25 20:29:30 2007 +++ phd/include/PhDTheme.class.php Sat Nov 1 06:02:04 2008 @@ -1,10 +1,11 @@ <?php -/* $Id: PhDTheme.class.php,v 1.1 2007/11/25 20:29:30 bjori Exp $ */ +/* $Id: PhDTheme.class.php,v 1.2 2008/11/01 06:02:04 cweiske Exp $ */ abstract class PhDTheme extends PhDHelper implements iPhDTheme { protected $format; public function registerFormat($format) { $this->format = $format; + $this->format->registerTheme($this); } } http://cvs.php.net/viewvc.cgi/phd/themes/pear/peartheme.php?r1=1.14&r2=1.15&diff_format=u Index: phd/themes/pear/peartheme.php diff -u phd/themes/pear/peartheme.php:1.14 phd/themes/pear/peartheme.php:1.15 --- phd/themes/pear/peartheme.php:1.14 Fri Oct 31 16:00:10 2008 +++ phd/themes/pear/peartheme.php Sat Nov 1 06:02:05 2008 @@ -103,7 +103,6 @@ 'replaceable' => 'format_replaceable', 'refentry' => 'format_chunk', 'reference' => 'format_container_chunk', - 'phd:toc' => 'format_phd_toc', 'phpdoc:exception' => 'format_exception_chunk', 'refname' => 'h1', 'refnamediv' => 'format_suppressed_tags', @@ -136,7 +135,6 @@ 'chapter' => 'format_container_chunk_title', //'example' => 'format_example_title', 'part' => 'format_container_chunk_title', - 'phd:toc' => 'strong', 'preface' => 'format_container_chunk_title', 'info' => array( /* DEFAULT */ false, @@ -211,8 +209,9 @@ 'year' => 'format_year', ); - public $role = false; - protected $chunked = true; + public $role = false; + public $chunked = true; + public $ext = null; protected $lang = "en"; protected $CURRENT_ID = ""; @@ -238,55 +237,6 @@ $this->chunked = $chunked; } - /** - * Creates a table of contents for the given id. - * Also creates nested TOCs if that's wanted ($depth) - * - * @param string $id ID of section for which to generate TOC - * @param string $name Tag name (for ul class) - * @param array $props Build properties (?? FIXME) - * @param integer $depth Depth of TOC - * @param boolean $header If the header shall be shown ("Table of contents") - * - * @return string HTML code for TOC - */ - protected function createToc($id, $name, $props, $depth = 1, $header = true) - { - $chunks = PhDHelper::getChildren($id); - if ($depth == 0 || !count($chunks)) { - return ''; - } - - $content = ''; - if ($header) { - $content .= " <strong>" . $this->autogen("toc", $props["lang"]) . "</strong>\n"; - } - $content .= " <ul class=\"chunklist chunklist_$name\">\n"; - foreach ($chunks as $chunkid => $junk) { - $long = $this->format->TEXT(PhDHelper::getDescription($chunkid, true)); - $short = $this->format->TEXT(PhDHelper::getDescription($chunkid, false)); - if ($long && $short && $long != $short) { - $desc = $short . '</a> -- ' . $long; - } else { - $desc = ($long ? $long : $short) . '</a>'; - } - if ($this->chunked) { - $content .= " <li><a href=\"{$chunkid}.{$this->ext}\">" . $desc; - } else { - $content .= " <li><a href=\"#{$chunkid}\">" . $this->format->TEXT(PhDHelper::getDescription($chunkid, false)) . "</a>"; - } - if ($depth > 1) { - $content .= $this->createToc($chunkid, $name, $props, $depth - 1, false); - } - - $content .= "</li>\n";; - } - - $content .= " </ul>\n"; - - return $content; - } - public function format_chunk($open, $name, $attrs, $props) { $id = null; if (isset($attrs[PhDReader::XMLNS_XML]["id"])) { @@ -332,7 +282,7 @@ $this->cchunk = $this->dchunk; } - $toc = $this->createToc( + $toc = $this->format->createToc( $id, $name, $props, isset($attrs[PhDReader::XMLNS_PHD]['toc-depth']) ? (int)$attrs[PhDReader::XMLNS_PHD]['toc-depth'] : 1 @@ -355,7 +305,7 @@ return "<div class=\"{$name}\">"; } - $content = $this->createToc( + $content = $this->format->createToc( $id, $name, $props, isset($attrs[PhDReader::XMLNS_PHD]['toc-depth']) ? (int)$attrs[PhDReader::XMLNS_PHD]['toc-depth'] : 1 @@ -453,20 +403,6 @@ return $this->format_table($open, $name, $attrs, $props) . '<p>'; } - public function format_phd_toc($open, $name, $attrs, $props) { - if ($open) { - return '<div class="phd-toc">'; - } - return $this->createToc( - $attrs[PhDReader::XMLNS_PHD]['element'], - 'phd-toc', - $props, - isset($attrs[PhDReader::XMLNS_PHD]['toc-depth']) - ? (int)$attrs[PhDReader::XMLNS_PHD]['toc-depth'] : 1, - false - ) . "</div>\n"; - } - public function format_programlisting($open, $name, $attrs) { if ($open) { if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"])) {
http://cvs.php.net/viewvc.cgi/phd/formats/xhtml.php?r1=1.71&r2=1.72&diff_format=u Index: phd/formats/xhtml.php diff -u phd/formats/xhtml.php:1.71 phd/formats/xhtml.php:1.72 --- phd/formats/xhtml.php:1.71 Tue Oct 28 20:10:45 2008 +++ phd/formats/xhtml.php Sat Nov 1 06:02:04 2008 @@ -1,5 +1,5 @@ <?php -/* $Id: xhtml.php,v 1.71 2008/10/28 20:10:45 cweiske Exp $ */ +/* $Id: xhtml.php,v 1.72 2008/11/01 06:02:04 cweiske Exp $ */ class XHTMLPhDFormat extends PhDFormat { protected $elementmap = array( /* {{{ */ @@ -177,6 +177,7 @@ 'partintro' => 'div', 'personname' => 'format_personname', 'personblurb' => 'div', + 'phd:toc' => 'format_phd_toc', 'phrase' => 'span', 'preface' => 'format_chunk', 'primaryie' => 'format_suppressed_tags', @@ -256,6 +257,7 @@ 'indexdiv' => 'dt', 'legalnotice' => 'h4', 'note' => 'format_note_title', + 'phd:toc' => 'strong', 'procedure' => 'b', 'refsect1' => 'h3', 'refsect2' => 'h4', @@ -411,6 +413,57 @@ public function getChunkInfo() { return $this->cchunk; } + + /** + * Creates a table of contents for the given id. + * Also creates nested TOCs if that's wanted ($depth) + * + * @param string $id ID of section for which to generate TOC + * @param string $name Tag name (for ul class) + * @param array $props Build properties (?? FIXME) + * @param integer $depth Depth of TOC + * @param boolean $header If the header shall be shown ("Table of contents") + * + * @return string HTML code for TOC + */ + public function createToc($id, $name, $props, $depth = 1, $header = true) + { + $chunks = PhDHelper::getChildren($id); + if ($depth == 0 || !count($chunks)) { + return ''; + } + + $content = ''; + if ($header) { + $content .= " <strong>" . $this->autogen("toc", $props["lang"]) . "</strong>\n"; + } + $content .= " <ul class=\"chunklist chunklist_$name\">\n"; + foreach ($chunks as $chunkid => $junk) { + $long = $this->TEXT(PhDHelper::getDescription($chunkid, true)); + $short = $this->TEXT(PhDHelper::getDescription($chunkid, false)); + if ($long && $short && $long != $short) { + $desc = $short . '</a> -- ' . $long; + } else { + $desc = ($long ? $long : $short) . '</a>'; + } + //FIXME + if ($this->theme->chunked) { + $content .= " <li><a href=\"{$chunkid}.{$this->theme->ext}\">" . $desc; + } else { + $content .= " <li><a href=\"#{$chunkid}\">" . $this->TEXT(PhDHelper::getDescription($chunkid, false)) . "</a>"; + } + if ($depth > 1) { + $content .= $this->createToc($chunkid, $name, $props, $depth - 1, false); + } + + $content .= "</li>\n";; + } + + $content .= " </ul>\n"; + + return $content; + } + public function format_suppressed_tags($open, $name, $attrs) { /* Ignore it */ return ""; @@ -838,6 +891,21 @@ } return "</ul>\n<p class=\"para\">"; } + + public function format_phd_toc($open, $name, $attrs, $props) { + if ($open) { + return '<div class="phd-toc">'; + } + return $this->createToc( + $attrs[PhDReader::XMLNS_PHD]['element'], + 'phd-toc', + $props, + isset($attrs[PhDReader::XMLNS_PHD]['toc-depth']) + ? (int)$attrs[PhDReader::XMLNS_PHD]['toc-depth'] : 1, + false + ) . "</div>\n"; + } + public function format_segmentedlist($open, $name, $attrs) { $this->cchunk["segmentedlist"] = $this->dchunk["segmentedlist"]; if ($open) { http://cvs.php.net/viewvc.cgi/phd/include/PhDFormat.class.php?r1=1.10&r2=1.11&diff_format=u Index: phd/include/PhDFormat.class.php diff -u phd/include/PhDFormat.class.php:1.10 phd/include/PhDFormat.class.php:1.11 --- phd/include/PhDFormat.class.php:1.10 Mon Feb 4 21:17:25 2008 +++ phd/include/PhDFormat.class.php Sat Nov 1 06:02:04 2008 @@ -1,15 +1,25 @@ <?php -/* $Id: PhDFormat.class.php,v 1.10 2008/02/04 21:17:25 bjori Exp $ */ +/* $Id: PhDFormat.class.php,v 1.11 2008/11/01 06:02:04 cweiske Exp $ */ abstract class PhDFormat extends PhDHelper { - private $TABLE = array(); - + private $TABLE = array(); + + /** + * @var PhDTheme + */ + protected $theme = null; + /* abstract functions */ abstract public function transformFromMap($open, $tag, $name, $attrs, $props); abstract public function CDATA($data); abstract public function TEXT($data); abstract public function __call($func, $args); + public function registerTheme(PhDTheme $theme) + { + $this->theme = $theme; + } + /* Table helper functions */ public function tgroup($attrs) { if (isset($attrs["cols"])) { http://cvs.php.net/viewvc.cgi/phd/include/PhDTheme.class.php?r1=1.1&r2=1.2&diff_format=u Index: phd/include/PhDTheme.class.php diff -u phd/include/PhDTheme.class.php:1.1 phd/include/PhDTheme.class.php:1.2 --- phd/include/PhDTheme.class.php:1.1 Sun Nov 25 20:29:30 2007 +++ phd/include/PhDTheme.class.php Sat Nov 1 06:02:04 2008 @@ -1,10 +1,11 @@ <?php -/* $Id: PhDTheme.class.php,v 1.1 2007/11/25 20:29:30 bjori Exp $ */ +/* $Id: PhDTheme.class.php,v 1.2 2008/11/01 06:02:04 cweiske Exp $ */ abstract class PhDTheme extends PhDHelper implements iPhDTheme { protected $format; public function registerFormat($format) { $this->format = $format; + $this->format->registerTheme($this); } } http://cvs.php.net/viewvc.cgi/phd/themes/pear/peartheme.php?r1=1.14&r2=1.15&diff_format=u Index: phd/themes/pear/peartheme.php diff -u phd/themes/pear/peartheme.php:1.14 phd/themes/pear/peartheme.php:1.15 --- phd/themes/pear/peartheme.php:1.14 Fri Oct 31 16:00:10 2008 +++ phd/themes/pear/peartheme.php Sat Nov 1 06:02:05 2008 @@ -103,7 +103,6 @@ 'replaceable' => 'format_replaceable', 'refentry' => 'format_chunk', 'reference' => 'format_container_chunk', - 'phd:toc' => 'format_phd_toc', 'phpdoc:exception' => 'format_exception_chunk', 'refname' => 'h1', 'refnamediv' => 'format_suppressed_tags', @@ -136,7 +135,6 @@ 'chapter' => 'format_container_chunk_title', //'example' => 'format_example_title', 'part' => 'format_container_chunk_title', - 'phd:toc' => 'strong', 'preface' => 'format_container_chunk_title', 'info' => array( /* DEFAULT */ false, @@ -211,8 +209,9 @@ 'year' => 'format_year', ); - public $role = false; - protected $chunked = true; + public $role = false; + public $chunked = true; + public $ext = null; protected $lang = "en"; protected $CURRENT_ID = ""; @@ -238,55 +237,6 @@ $this->chunked = $chunked; } - /** - * Creates a table of contents for the given id. - * Also creates nested TOCs if that's wanted ($depth) - * - * @param string $id ID of section for which to generate TOC - * @param string $name Tag name (for ul class) - * @param array $props Build properties (?? FIXME) - * @param integer $depth Depth of TOC - * @param boolean $header If the header shall be shown ("Table of contents") - * - * @return string HTML code for TOC - */ - protected function createToc($id, $name, $props, $depth = 1, $header = true) - { - $chunks = PhDHelper::getChildren($id); - if ($depth == 0 || !count($chunks)) { - return ''; - } - - $content = ''; - if ($header) { - $content .= " <strong>" . $this->autogen("toc", $props["lang"]) . "</strong>\n"; - } - $content .= " <ul class=\"chunklist chunklist_$name\">\n"; - foreach ($chunks as $chunkid => $junk) { - $long = $this->format->TEXT(PhDHelper::getDescription($chunkid, true)); - $short = $this->format->TEXT(PhDHelper::getDescription($chunkid, false)); - if ($long && $short && $long != $short) { - $desc = $short . '</a> -- ' . $long; - } else { - $desc = ($long ? $long : $short) . '</a>'; - } - if ($this->chunked) { - $content .= " <li><a href=\"{$chunkid}.{$this->ext}\">" . $desc; - } else { - $content .= " <li><a href=\"#{$chunkid}\">" . $this->format->TEXT(PhDHelper::getDescription($chunkid, false)) . "</a>"; - } - if ($depth > 1) { - $content .= $this->createToc($chunkid, $name, $props, $depth - 1, false); - } - - $content .= "</li>\n";; - } - - $content .= " </ul>\n"; - - return $content; - } - public function format_chunk($open, $name, $attrs, $props) { $id = null; if (isset($attrs[PhDReader::XMLNS_XML]["id"])) { @@ -332,7 +282,7 @@ $this->cchunk = $this->dchunk; } - $toc = $this->createToc( + $toc = $this->format->createToc( $id, $name, $props, isset($attrs[PhDReader::XMLNS_PHD]['toc-depth']) ? (int)$attrs[PhDReader::XMLNS_PHD]['toc-depth'] : 1 @@ -355,7 +305,7 @@ return "<div class=\"{$name}\">"; } - $content = $this->createToc( + $content = $this->format->createToc( $id, $name, $props, isset($attrs[PhDReader::XMLNS_PHD]['toc-depth']) ? (int)$attrs[PhDReader::XMLNS_PHD]['toc-depth'] : 1 @@ -453,20 +403,6 @@ return $this->format_table($open, $name, $attrs, $props) . '<p>'; } - public function format_phd_toc($open, $name, $attrs, $props) { - if ($open) { - return '<div class="phd-toc">'; - } - return $this->createToc( - $attrs[PhDReader::XMLNS_PHD]['element'], - 'phd-toc', - $props, - isset($attrs[PhDReader::XMLNS_PHD]['toc-depth']) - ? (int)$attrs[PhDReader::XMLNS_PHD]['toc-depth'] : 1, - false - ) . "</div>\n"; - } - public function format_programlisting($open, $name, $attrs) { if ($open) { if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"])) {