Changeset 3599 for trunk/vendor/Sensei

Show
Ignore:
Timestamp:
01/23/08 16:37:39 (12 months ago)
Author:
jepso
Message:

fixes #527

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/vendor/Sensei/Sensei/Doc/Renderer/Xhtml.php

    r2963 r3599  
    3535    /** 
    3636     * Available options 
    37      *  
     37     * 
    3838     * (Sensei_Doc_Section|null) section : 
    3939     *     Section to be rendered. If null all sections will be rendered. 
    4040     * 
    4141     * (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. 
    4343     */ 
    4444    protected $_options = array( 
     
    4646        'url_prefix' => '' 
    4747    ); 
    48      
     48 
     49    private $_chapter; 
     50    private $_codeListingsIndex; 
     51 
    4952    public function __construct(Sensei_Doc_Toc $toc, array $options = array()) 
    5053    { 
    5154        parent::__construct($toc, $options); 
    52          
     55 
    5356        $this->_wiki->setRenderConf('xhtml', 'Doclink', 'url_callback', array(&$this, 'makeUrl')); 
     57        $this->_wiki->setRenderConf('xhtml', 'Code', 'code_begin_callback', array(&$this, 'codeListingsNumberingCallback')); 
    5458    } 
    5559 
    5660    /** 
    5761     * Renders table of contents as nested unordered lists. 
    58      *  
     62     * 
    5963     * @return string  rendered table of contents 
    6064     */ 
     
    7377    { 
    7478        $output = ''; 
    75      
     79 
    7680        if ($section instanceof Sensei_Doc_Toc) { 
    7781            $class = ' class="tree"'; 
     
    8185            $class = ''; 
    8286        } 
    83          
    84         $output .= '<ul' . $class . '>' . "\n";        
    85         
     87 
     88        $output .= '<ul' . $class . '>' . "\n"; 
     89 
    8690        for ($i = 0; $i < $section->count(); $i++) { 
    8791            $child = $section->getChild($i); 
    88              
     92 
    8993            $text = $child->getIndex() . ' ' . $child->getName(); 
    9094            $href = $this->makeUrl($child); 
    91              
     95 
    9296            $output .= '<li><a href="' . $href . '">' . $text . '</a>'; 
    93              
     97 
    9498            if ($child->count() > 0) { 
    9599                $output .= "\n"; 
    96100                $output .= $this->_renderToc($child); 
    97101            } 
    98      
     102 
    99103            $output .= '</li>' . "\n"; 
    100104        } 
    101      
     105 
    102106        $output .= '</ul>' . "\n"; 
    103          
     107 
    104108        return $output; 
    105109    } 
     
    114118    { 
    115119        $section = $this->_options['section']; 
    116          
     120 
    117121        if ($section instanceof Sensei_Doc_Section) { 
    118          
     122 
    119123            $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 
    124128            $content = ''; 
    125129            for ($i = 0; $i < count($this->_toc); $i++) { 
     
    127131            } 
    128132        } 
    129          
     133 
    130134        $output = $this->_options['template']; 
    131          
     135 
    132136        $output = str_replace('%TITLE%', $this->_options['title'], $output); 
    133137        $output = str_replace('%AUTHOR%', $this->_options['author'], $output); 
     
    136140        $output = str_replace('%TOC%', $this->renderToc(), $output); 
    137141        $output = str_replace('%CONTENT%', $content, $output); 
    138          
     142 
    139143        return $output; 
    140144    } 
     
    149153    { 
    150154        $output = ''; 
    151          
     155 
    152156        $title = $section->getIndex() . ' ' . $section->getName(); 
    153157        $level = $section->getLevel(); 
    154          
     158 
    155159        if ($level === 1) { 
    156160            $class = ' class="chapter"'; 
    157161            $title = 'Chapter ' . $title; 
     162            $this->_chapter = $section->getIndex(); 
     163            $this->_codeListingsIndex = 0; 
    158164        } else { 
    159165            $class = ' class="section"'; 
    160166        } 
    161          
     167 
    162168        $output .= '<div' . $class .'>' . "\n"; 
    163          
     169 
    164170        $output .= "<h$level>"; 
    165          
     171 
    166172        if ( ! ($this->_options['section'] instanceof Sensei_Doc_Section) 
    167173        || ($level > $this->_options['section']->getLevel())) { 
     
    172178            $output .= $title; 
    173179        } 
    174          
     180 
    175181        $output .= "</h$level>"; 
    176          
     182 
    177183        // Transform section contents from wiki syntax to XHTML 
    178184        $output .= $this->_wiki->transform($section->getText()); 
    179          
     185 
    180186        // Render children of this section recursively 
    181187        for ($i = 0; $i < count($section); $i++) { 
    182188            $output .= $this->_renderSection($section->getChild($i)); 
    183189        } 
    184          
     190 
    185191        $output .= '</div>' . "\n"; 
    186          
    187         return $output;        
    188     } 
    189      
     192 
     193        return $output; 
     194    } 
     195 
    190196    public function makeUrl($section) 
    191197    { 
     
    195201            $path = $section; 
    196202        } 
    197          
     203 
    198204        $url = $this->_options['url_prefix']; 
    199          
     205 
    200206        if ($this->_options['section'] instanceof Sensei_Doc_Section) { 
    201207            $level = $this->_options['section']->getLevel(); 
    202208            $url .= implode(':', array_slice(explode(':', $path), 0, $level)); 
    203209        } 
    204          
     210 
    205211        $anchor = $this->makeAnchor($section); 
    206212        if ($anchor !== '') { 
    207213            $url .= '#' . $anchor; 
    208214        } 
    209          
     215 
    210216        return $url; 
    211217    } 
    212      
     218 
    213219    public function makeAnchor($section) 
    214220    { 
     
    218224            $path = $section; 
    219225        } 
    220          
     226 
    221227        if ($this->_options['section'] instanceof Sensei_Doc_Section) { 
    222228            $level = $this->_options['section']->getLevel(); 
     
    226232        } 
    227233    } 
     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    } 
    228242}