PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/doclets/github_wiki/packageWriter.php

https://github.com/peej/phpdoctor
PHP | 254 lines | 172 code | 43 blank | 39 comment | 24 complexity | 0d66017dcf8206cbbd9fd7bcf9b997fc MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. PHPDoctor: The PHP Documentation Creator
  4. Copyright (C) 2004 Paul James <paul@peej.co.uk>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /** This generates the README.md files that list the interfaces and
  18. * classes for a given package.
  19. *
  20. * @package PHPDoctor\Doclets\GithubWiki
  21. */
  22. class PackageWriter extends MDWriter {
  23. /** Build the package summaries.
  24. *
  25. * @param Doclet doclet
  26. */
  27. function packageWriter(&$doclet) {
  28. parent::MDWriter($doclet);
  29. $rootDoc = & $this->_doclet->rootDoc();
  30. $phpdoctor = & $this->_doclet->phpdoctor();
  31. $displayTree = $phpdoctor->getOption("tree");
  32. if ($displayTree) {
  33. $this->_id = "tree";
  34. $tree = array();
  35. $classes = & $rootDoc->classes();
  36. if ($classes) {
  37. foreach ($classes as $class) {
  38. $this->_buildTree($tree, $class);
  39. }
  40. }
  41. ob_start();
  42. echo "\n\n- - -\n\n";
  43. echo "#Class Hierarchy#\n\n";
  44. $this->_displayTree($tree);
  45. $this->_output = ob_get_contents();
  46. ob_end_clean();
  47. $this->_write("overview-tree.md");
  48. }
  49. $this->_id = "package";
  50. $packages = & $rootDoc->packages();
  51. ksort($packages);
  52. foreach ($packages as $packageName => $package) {
  53. $this->_depth = $package->depth() + 1;
  54. ob_start();
  55. echo "\n\n- - -\n\n";
  56. echo "#Namespace ", $package->name(), "#\n\n";
  57. if ($displayTree) {
  58. echo "<div><a href='{$this->_asURL($package)}/package-tree.md'>View Class Hierarchy for this Package</a></div>\n\n";
  59. }
  60. $textTag = & $package->tags("@text");
  61. if ($textTag) {
  62. echo "<div class=\"comment\">", $this->_processInlineTags($textTag, TRUE), "</div>\n\n";
  63. echo "<dl><dt>See:</dt><dd><b><a href=\"#overview_description\">Description</a></b></dd></dl>", "\n\n";
  64. }
  65. $classes = & $package->ordinaryClasses();
  66. if ($classes) {
  67. ksort($classes);
  68. echo "<table class=\"title\">", "\n";
  69. echo "<tr><th colspan=\"2\" class=\"title\">Class Summary</th></tr>", "\n";
  70. foreach ($classes as $name => $class) {
  71. $textTag = & $classes[$name]->tags("@text");
  72. echo "<tr><td class=\"name\"><a href=\"", $this->_asURL($classes[$name]), "\">", $classes[$name]->name(), "</a></td>";
  73. echo "<td class=\"description\">";
  74. if ($textTag)
  75. echo strip_tags($this->_processInlineTags($textTag, TRUE), "<a><b>**<u><em>");
  76. echo "</td></tr>\n";
  77. }
  78. echo "</table>\n\n";
  79. }
  80. $interfaces = & $package->interfaces();
  81. if ($interfaces) {
  82. ksort($interfaces);
  83. echo "<table class=\"title\">" . "\n";
  84. echo "<tr><th colspan=\"2\" class=\"title\">Interface Summary</th></tr>" . "\n";
  85. foreach ($interfaces as $name => $interface) {
  86. $textTag = & $interfaces[$name]->tags("@text");
  87. echo "<tr><td class=\"name\"><a href=\"", $this->_asURL($interfaces[$name]), "\">", $interfaces[$name]->name(), "</a></td>";
  88. echo "<td class=\"description\">";
  89. if ($textTag)
  90. echo strip_tags($this->_processInlineTags($textTag, TRUE), "<a><b>**<u><em>");
  91. echo "</td></tr>\n";
  92. }
  93. echo "</table>\n\n";
  94. }
  95. $exceptions = & $package->exceptions();
  96. if ($exceptions) {
  97. ksort($exceptions);
  98. echo "<table class=\"title\">" . "\n";
  99. echo "<tr><th colspan=\"2\" class=\"title\">Exception Summary</th></tr>" . "\n";
  100. foreach ($exceptions as $name => $exception) {
  101. $textTag = & $exceptions[$name]->tags("@text");
  102. echo "<tr><td class=\"name\"><a href=\"", $this->_asURL($exceptions[$name]), "\">", $exceptions[$name]->name(), "</a></td>";
  103. echo "<td class=\"description\">";
  104. if ($textTag)
  105. echo strip_tags($this->_processInlineTags($textTag, TRUE), "<a><b>**<u><em>");
  106. echo "</td></tr>\n";
  107. }
  108. echo "</table>\n\n";
  109. }
  110. $functions = & $package->functions();
  111. if ($functions) {
  112. ksort($functions);
  113. echo "<table class=\"title\">", "\n";
  114. echo "<tr><th colspan=\"2\" class=\"title\">Function Summary</th></tr>", "\n";
  115. foreach ($functions as $name => $function) {
  116. $textTag = & $functions[$name]->tags("@text");
  117. echo "<tr><td class=\"name\"><a href=\"package-functions.md#", $functions[$name]->name(), "\">", $functions[$name]->name(), "</a></td>";
  118. echo "<td class=\"description\">";
  119. if ($textTag)
  120. echo strip_tags($this->_processInlineTags($textTag, TRUE), "<a><b>**<u><em>");
  121. echo "</td></tr>\n";
  122. }
  123. echo "</table>\n\n";
  124. }
  125. $globals = & $package->globals();
  126. if ($globals) {
  127. ksort($globals);
  128. echo "<table class=\"title\">", "\n";
  129. echo "<tr><th colspan=\"2\" class=\"title\">Global Summary</th></tr>", "\n";
  130. foreach ($globals as $name => $global) {
  131. $textTag = & $globals[$name]->tags("@text");
  132. echo "<tr><td class=\"name\"><a href=\"package-globals.md#", $globals[$name]->name(), "\">", $globals[$name]->name(), "</a></td>";
  133. echo "<td class=\"description\">";
  134. if ($textTag)
  135. echo strip_tags($this->_processInlineTags($textTag, TRUE), "<a><b>**<u><em>");
  136. echo "</td></tr>\n";
  137. }
  138. echo "</table>\n\n";
  139. }
  140. $textTag = & $package->tags("@text");
  141. if ($textTag) {
  142. echo "#Namespace ", $package->name(), " Description#\n\n";
  143. echo "<div class=\"comment\" id=\"overview_description\">" . $this->_processInlineTags($textTag), "</div>\n\n";
  144. }
  145. echo "- - -\n\n";
  146. $this->_output = ob_get_contents();
  147. ob_end_clean();
  148. $this->_write($this->_normalize($package->_name) . "_README.md");
  149. if ($displayTree) {
  150. $this->_id = "tree";
  151. $tree = array();
  152. $classes = & $package->ordinaryClasses();
  153. if ($classes) {
  154. ksort($classes);
  155. foreach ($classes as $class) {
  156. $this->_buildTree($tree, $class);
  157. }
  158. }
  159. ob_start();
  160. echo "- - -\n\n";
  161. echo "#Class Hierarchy for Package {$package->name()}";
  162. echo "\n\n<div><a href='{$this->_asURL($package)}'>Back to package summary</a></div>\n\n";
  163. $this->_displayTree($tree);
  164. $this->_output = ob_get_contents();
  165. ob_end_clean();
  166. $this->_write($this->_normalize($package->_name) . "_package-tree.md", $package->name(), TRUE);
  167. }
  168. }
  169. }
  170. /**
  171. * Build the class tree branch for the given element
  172. *
  173. * @param ClassDoc[] tree
  174. * @param ClassDoc element
  175. */
  176. function _buildTree(&$tree, &$element) {
  177. $tree[$element->name()] = $element;
  178. if ($element->superclass()) {
  179. $rootDoc = & $this->_doclet->rootDoc();
  180. $superclass = & $rootDoc->classNamed($element->superclass());
  181. if ($superclass) {
  182. $this->_buildTree($tree, $superclass);
  183. }
  184. }
  185. }
  186. /**
  187. * Build the class tree branch for the given element
  188. *
  189. * @param ClassDoc[] tree
  190. * @param str parent
  191. */
  192. function _displayTree($tree, $parent = NULL) {
  193. $outputList = TRUE;
  194. foreach ($tree as $name => $element) {
  195. if ($element->superclass() == $parent) {
  196. if ($outputList)
  197. echo "<ul>\n";
  198. echo "<li><a href=\"", $this->_asURL($element), "\">", $element->qualifiedName(), "</a>";
  199. $this->_displayTree($tree, $name);
  200. echo "</li>\n";
  201. $outputList = FALSE;
  202. }
  203. }
  204. if (!$outputList)
  205. echo "</ul>\n";
  206. }
  207. }
  208. ?>