com.lokorin.lokorin.lib
[ class tree: com.lokorin.lokorin.lib ] [ index: com.lokorin.lokorin.lib ] [ all elements ]

Source for file lib_readme.php

Documentation is available at lib_readme.php

  1. <?php
  2. /*
  3. * Lokorin.com
  4. * Copyright 2004-2006
  5. * Licensed under the GNU LGPL. See COPYING for full terms.
  6. */
  7. /**
  8. * A library that contains everything related to readmes.
  9. * @author Andreas Launila
  10. * @version $Revision: 1.8 $
  11. * @package com.lokorin.lokorin.lib
  12. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  13. */
  14.  
  15. /**
  16. * For access to common constants and functions.
  17. */
  18. require_once('common.php');
  19.  
  20. /**
  21. * Describes a readme. A readme is a guide with several chapters of
  22. * information which are ordered into a more navigatable fashion for the users
  23. * convenience.
  24. * @author Andreas Launila
  25. * @package com.lokorin.lokorin.lib
  26. */
  27. class Readme {
  28. /**
  29. * An array of Chapter instances describing all chapters, except the
  30. * introduction, contained in the readme.
  31. * @var array
  32. */
  33. private $chapters;
  34. /**
  35. * The introduction chapter, may be null in which case no introduction
  36. * chapter exists.
  37. * @var Chapter
  38. */
  39. private $intro;
  40. /**
  41. * Constructor for Readme.
  42. */
  43. public function __construct() {
  44. $this->chapters = array();
  45. $this->intro = null;
  46. }
  47. /**
  48. * Adds a new chapter to the readme.
  49. * @param Chapter $newChapter The new chapter that should be added.
  50. * @param boolean $isIntro Whether or not the chapter should be used as an
  51. * introduction.
  52. */
  53. public function addChapter(Chapter $newChapter, $isIntro = false) {
  54. if($isIntro) {
  55. $this->intro = $newChapter;
  56. } else {
  57. $this->chapters[] = $newChapter;
  58. }
  59. }
  60. /**
  61. * Gets the readme as XHTML compliant code.
  62. * @return string XHTML compliant code that represents the readme.
  63. */
  64. public function getReadme() {
  65. if($this->intro != null) {
  66. //Display the contents of the intro chapter before anything else.
  67. $intro = $this->intro->getContents();
  68. } else {
  69. $intro = '';
  70. }
  71.  
  72. $contents = '';
  73. $navigation = '<h2>Table of Contents</h2><ul id="readme_toc">';
  74. foreach($this->chapters as $key => $chapter) {
  75. $navigation .= '<li><a href="#'.$key.'">'.$chapter->getTopic().
  76. '</a></li>';
  77. $contents .= '<a name="'.$key.'"></a>'.$chapter->getAsHtml()."\n";
  78. }
  79. $navigation .= '</ul>';
  80.  
  81. return '<div id="readme_contents">'.$intro.$navigation.$contents.'</div>';
  82. }
  83. }
  84.  
  85. /**
  86. * Describes a readme chapter. A chapter contains information about one
  87. * specific topic.
  88. * @author Andreas Launila
  89. * @package com.lokorin.lokorin.lib
  90. */
  91. class Chapter {
  92. /**
  93. * The topic of the chapter.
  94. * @var string
  95. */
  96. private $topic;
  97. /**
  98. * The actual contents of the chapter. The text (XHTML) informing about the
  99. * chapter's topic.
  100. */
  101. private $contents;
  102. /**
  103. * Constructor for Chapter.
  104. * @param string $topic The opic that the chapter is about.
  105. * @param string $contents The (XHTML) text that informs about the
  106. * chapter's topic.
  107. */
  108. public function __construct($topic, $contents) {
  109. $this->topic = $topic;
  110. $this->contents = $contents;
  111. }
  112. /**
  113. * Gets the chapter's topic.
  114. * @return string A chapter topic.
  115. */
  116. public function getTopic() {
  117. return $this->topic;
  118. }
  119. /**
  120. * Gets the chapter as XHTML compliant code.
  121. * @return string XHTML compliant code that represents the chapter.
  122. */
  123. public function getAsHtml() {
  124. return '<h2>'.$this->topic.'</h2>'."\n".$this->contents;
  125. }
  126. /**
  127. * Gets the contents of the chapter.
  128. * @return string The chapter's contents.
  129. */
  130. public function getContents() {
  131. return $this->contents;
  132. }
  133. }
  134. ?>

Documentation generated on Sun, 16 Apr 2006 21:03:49 +0200 by phpDocumentor 1.3.0RC4