Changeset 3674 for branches/0.9/vendor

Show
Ignore:
Timestamp:
01/29/08 23:45:44 (11 months ago)
Author:
guilhermeblanco
Message:

Merged changeset #3609 and #3599 into 0.9 and 0.10 branches

Files:
1 modified

Legend:

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

    r2963 r3674  
    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"'; 
     
    159163            $class = ' class="section"'; 
    160164        } 
    161          
     165 
    162166        $output .= '<div' . $class .'>' . "\n"; 
    163          
     167 
    164168        $output .= "<h$level>"; 
    165          
     169 
    166170        if ( ! ($this->_options['section'] instanceof Sensei_Doc_Section) 
    167171        || ($level > $this->_options['section']->getLevel())) { 
     
    172176            $output .= $title; 
    173177        } 
    174          
     178 
    175179        $output .= "</h$level>"; 
    176          
     180 
    177181        // Transform section contents from wiki syntax to XHTML 
    178182        $output .= $this->_wiki->transform($section->getText()); 
    179          
     183 
    180184        // Render children of this section recursively 
    181185        for ($i = 0; $i < count($section); $i++) { 
    182186            $output .= $this->_renderSection($section->getChild($i)); 
    183187        } 
    184          
     188 
    185189        $output .= '</div>' . "\n"; 
    186          
    187         return $output;        
    188     } 
    189      
     190 
     191        return $output; 
     192    } 
     193 
    190194    public function makeUrl($section) 
    191195    { 
     
    195199            $path = $section; 
    196200        } 
    197          
     201 
    198202        $url = $this->_options['url_prefix']; 
    199          
     203 
    200204        if ($this->_options['section'] instanceof Sensei_Doc_Section) { 
    201205            $level = $this->_options['section']->getLevel(); 
    202206            $url .= implode(':', array_slice(explode(':', $path), 0, $level)); 
    203207        } 
    204          
     208 
    205209        $anchor = $this->makeAnchor($section); 
    206210        if ($anchor !== '') { 
    207211            $url .= '#' . $anchor; 
    208212        } 
    209          
     213 
    210214        return $url; 
    211215    } 
    212      
     216 
    213217    public function makeAnchor($section) 
    214218    { 
     
    218222            $path = $section; 
    219223        } 
    220          
     224 
    221225        if ($this->_options['section'] instanceof Sensei_Doc_Section) { 
    222226            $level = $this->_options['section']->getLevel(); 
     
    226230        } 
    227231    } 
     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    } 
    228240}