Changeset 3599 for trunk/vendor/Sensei
- Timestamp:
- 01/23/08 16:37:39 (12 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/vendor/Sensei/Sensei/Doc/Renderer/Xhtml.php
r2963 r3599 35 35 /** 36 36 * Available options 37 * 37 * 38 38 * (Sensei_Doc_Section|null) section : 39 39 * Section to be rendered. If null all sections will be rendered. 40 40 * 41 41 * (string) url_prefix : 42 * All URLs pointing to sections will be prefixed with this. 42 * All URLs pointing to sections will be prefixed with this. 43 43 */ 44 44 protected $_options = array( … … 46 46 'url_prefix' => '' 47 47 ); 48 48 49 private $_chapter; 50 private $_codeListingsIndex; 51 49 52 public function __construct(Sensei_Doc_Toc $toc, array $options = array()) 50 53 { 51 54 parent::__construct($toc, $options); 52 55 53 56 $this->_wiki->setRenderConf('xhtml', 'Doclink', 'url_callback', array(&$this, 'makeUrl')); 57 $this->_wiki->setRenderConf('xhtml', 'Code', 'code_begin_callback', array(&$this, 'codeListingsNumberingCallback')); 54 58 } 55 59 56 60 /** 57 61 * Renders table of contents as nested unordered lists. 58 * 62 * 59 63 * @return string rendered table of contents 60 64 */ … … 73 77 { 74 78 $output = ''; 75 79 76 80 if ($section instanceof Sensei_Doc_Toc) { 77 81 $class = ' class="tree"'; … … 81 85 $class = ''; 82 86 } 83 84 $output .= '<ul' . $class . '>' . "\n"; 85 87 88 $output .= '<ul' . $class . '>' . "\n"; 89 86 90 for ($i = 0; $i < $section->count(); $i++) { 87 91 $child = $section->getChild($i); 88 92 89 93 $text = $child->getIndex() . ' ' . $child->getName(); 90 94 $href = $this->makeUrl($child); 91 95 92 96 $output .= '<li><a href="' . $href . '">' . $text . '</a>'; 93 97 94 98 if ($child->count() > 0) { 95 99 $output .= "\n"; 96 100 $output .= $this->_renderToc($child); 97 101 } 98 102 99 103 $output .= '</li>' . "\n"; 100 104 } 101 105 102 106 $output .= '</ul>' . "\n"; 103 107 104 108 return $output; 105 109 } … … 114 118 { 115 119 $section = $this->_options['section']; 116 120 117 121 if ($section instanceof Sensei_Doc_Section) { 118 122 119 123 $content = $this->_renderSection($section); 120 121 } else { 122 123 // No section was set, so let's render all sections 124 125 } else { 126 127 // No section was set, so let's render all sections 124 128 $content = ''; 125 129 for ($i = 0; $i < count($this->_toc); $i++) { … … 127 131 } 128 132 } 129 133 130 134 $output = $this->_options['template']; 131 135 132 136 $output = str_replace('%TITLE%', $this->_options['title'], $output); 133 137 $output = str_replace('%AUTHOR%', $this->_options['author'], $output); … … 136 140 $output = str_replace('%TOC%', $this->renderToc(), $output); 137 141 $output = str_replace('%CONTENT%', $content, $output); 138 142 139 143 return $output; 140 144 } … … 149 153 { 150 154 $output = ''; 151 155 152 156 $title = $section->getIndex() . ' ' . $section->getName(); 153 157 $level = $section->getLevel(); 154 158 155 159 if ($level === 1) { 156 160 $class = ' class="chapter"'; 157 161 $title = 'Chapter ' . $title; 162 $this->_chapter = $section->getIndex(); 163 $this->_codeListingsIndex = 0; 158 164 } else { 159 165 $class = ' class="section"'; 160 166 } 161 167 162 168 $output .= '<div' . $class .'>' . "\n"; 163 169 164 170 $output .= "<h$level>"; 165 171 166 172 if ( ! ($this->_options['section'] instanceof Sensei_Doc_Section) 167 173 || ($level > $this->_options['section']->getLevel())) { … … 172 178 $output .= $title; 173 179 } 174 180 175 181 $output .= "</h$level>"; 176 182 177 183 // Transform section contents from wiki syntax to XHTML 178 184 $output .= $this->_wiki->transform($section->getText()); 179 185 180 186 // Render children of this section recursively 181 187 for ($i = 0; $i < count($section); $i++) { 182 188 $output .= $this->_renderSection($section->getChild($i)); 183 189 } 184 190 185 191 $output .= '</div>' . "\n"; 186 187 return $output; 188 } 189 192 193 return $output; 194 } 195 190 196 public function makeUrl($section) 191 197 { … … 195 201 $path = $section; 196 202 } 197 203 198 204 $url = $this->_options['url_prefix']; 199 205 200 206 if ($this->_options['section'] instanceof Sensei_Doc_Section) { 201 207 $level = $this->_options['section']->getLevel(); 202 208 $url .= implode(':', array_slice(explode(':', $path), 0, $level)); 203 209 } 204 210 205 211 $anchor = $this->makeAnchor($section); 206 212 if ($anchor !== '') { 207 213 $url .= '#' . $anchor; 208 214 } 209 215 210 216 return $url; 211 217 } 212 218 213 219 public function makeAnchor($section) 214 220 { … … 218 224 $path = $section; 219 225 } 220 226 221 227 if ($this->_options['section'] instanceof Sensei_Doc_Section) { 222 228 $level = $this->_options['section']->getLevel(); … … 226 232 } 227 233 } 234 235 public function codeListingsNumberingCallback() 236 { 237 $this->_codeListingsIndex++; 238 $html = '<p class="caption">Listing ' . $this->_chapter . '.' 239 . $this->_codeListingsIndex . "</p>\n"; 240 return $html; 241 } 228 242 }