Changeset 3674 for branches/0.9/vendor
- Timestamp:
- 01/29/08 23:45:44 (11 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/0.9/vendor/Sensei/Sensei/Doc/Renderer/Xhtml.php
r2963 r3674 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"'; … … 159 163 $class = ' class="section"'; 160 164 } 161 165 162 166 $output .= '<div' . $class .'>' . "\n"; 163 167 164 168 $output .= "<h$level>"; 165 169 166 170 if ( ! ($this->_options['section'] instanceof Sensei_Doc_Section) 167 171 || ($level > $this->_options['section']->getLevel())) { … … 172 176 $output .= $title; 173 177 } 174 178 175 179 $output .= "</h$level>"; 176 180 177 181 // Transform section contents from wiki syntax to XHTML 178 182 $output .= $this->_wiki->transform($section->getText()); 179 183 180 184 // Render children of this section recursively 181 185 for ($i = 0; $i < count($section); $i++) { 182 186 $output .= $this->_renderSection($section->getChild($i)); 183 187 } 184 188 185 189 $output .= '</div>' . "\n"; 186 187 return $output; 188 } 189 190 191 return $output; 192 } 193 190 194 public function makeUrl($section) 191 195 { … … 195 199 $path = $section; 196 200 } 197 201 198 202 $url = $this->_options['url_prefix']; 199 203 200 204 if ($this->_options['section'] instanceof Sensei_Doc_Section) { 201 205 $level = $this->_options['section']->getLevel(); 202 206 $url .= implode(':', array_slice(explode(':', $path), 0, $level)); 203 207 } 204 208 205 209 $anchor = $this->makeAnchor($section); 206 210 if ($anchor !== '') { 207 211 $url .= '#' . $anchor; 208 212 } 209 213 210 214 return $url; 211 215 } 212 216 213 217 public function makeAnchor($section) 214 218 { … … 218 222 $path = $section; 219 223 } 220 224 221 225 if ($this->_options['section'] instanceof Sensei_Doc_Section) { 222 226 $level = $this->_options['section']->getLevel(); … … 226 230 } 227 231 } 232 233 public function codeListingsNumberingCallback() 234 { 235 $this->_codeListingsIndex++; 236 $html = '<p class="caption">Listing ' . $this->_chapter . '.' 237 . $this->_codeListingsIndex . "</p>\n"; 238 return $html; 239 } 228 240 }