includes/wikiengine/Render/Xhtml/Function.php
changeset 1027 98c052fc3337
parent 1026 f0431eb8161e
child 1028 dde4416dea00
equal deleted inserted replaced
1026:f0431eb8161e 1027:98c052fc3337
     1 <?php
       
     2 // vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
       
     3 /**
       
     4  * Function rule end renderer for Xhtml
       
     5  *
       
     6  * PHP versions 4 and 5
       
     7  *
       
     8  * @category   Text
       
     9  * @package    Text_Wiki
       
    10  * @author     Paul M. Jones <pmjones@php.net>
       
    11  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
       
    12  * @version    CVS: $Id: Function.php,v 1.5 2006/02/10 23:07:03 toggg Exp $
       
    13  * @link       http://pear.php.net/package/Text_Wiki
       
    14  */
       
    15 
       
    16 /**
       
    17  * This class renders a function description in XHTML.
       
    18  *
       
    19  * @category   Text
       
    20  * @package    Text_Wiki
       
    21  * @author     Paul M. Jones <pmjones@php.net>
       
    22  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
       
    23  * @version    Release: @package_version@
       
    24  * @link       http://pear.php.net/package/Text_Wiki
       
    25  */
       
    26 class Text_Wiki_Render_Xhtml_Function extends Text_Wiki_Render {
       
    27 
       
    28     var $conf = array(
       
    29     	// list separator for params and throws
       
    30         'list_sep' => ', ',
       
    31 
       
    32         // the "main" format string
       
    33         'format_main' => '%access %return <b>%name</b> ( %params ) %throws',
       
    34 
       
    35         // the looped format string for required params
       
    36         'format_param' => '%type <i>%descr</i>',
       
    37 
       
    38         // the looped format string for params with default values
       
    39         'format_paramd' => '[%type <i>%descr</i> default %default]',
       
    40 
       
    41         // the looped format string for throws
       
    42         'format_throws' => '<b>throws</b> %type <i>%descr</i>'
       
    43     );
       
    44 
       
    45     /**
       
    46     *
       
    47     * Renders a token into text matching the requested format.
       
    48     *
       
    49     * @access public
       
    50     *
       
    51     * @param array $options The "options" portion of the token (second
       
    52     * element).
       
    53     *
       
    54     * @return string The text rendered from the token options.
       
    55     *
       
    56     */
       
    57 
       
    58     function token($options)
       
    59     {
       
    60         extract($options); // name, access, return, params, throws
       
    61 
       
    62         // build the baseline output
       
    63         $output = $this->conf['format_main'];
       
    64         $output = str_replace('%access', $this->textEncode($access), $output);
       
    65         $output = str_replace('%return', $this->textEncode($return), $output);
       
    66         $output = str_replace('%name', $this->textEncode($name), $output);
       
    67 
       
    68         // build the set of params
       
    69         $list = array();
       
    70         foreach ($params as $key => $val) {
       
    71 
       
    72             // is there a default value?
       
    73             if ($val['default']) {
       
    74                 $tmp = $this->conf['format_paramd'];
       
    75             } else {
       
    76                 $tmp = $this->conf['format_param'];
       
    77             }
       
    78 
       
    79             // add the param elements
       
    80             $tmp = str_replace('%type', $this->textEncode($val['type']), $tmp);
       
    81             $tmp = str_replace('%descr', $this->textEncode($val['descr']), $tmp);
       
    82             $tmp = str_replace('%default', $this->textEncode($val['default']), $tmp);
       
    83             $list[] = $tmp;
       
    84         }
       
    85 
       
    86         // insert params into output
       
    87         $tmp = implode($this->conf['list_sep'], $list);
       
    88         $output = str_replace('%params', $tmp, $output);
       
    89 
       
    90         // build the set of throws
       
    91         $list = array();
       
    92         foreach ($throws as $key => $val) {
       
    93                $tmp = $this->conf['format_throws'];
       
    94             $tmp = str_replace('%type', $this->textEncode($val['type']), $tmp);
       
    95             $tmp = str_replace('%descr', $this->textEncode($val['descr']), $tmp);
       
    96             $list[] = $tmp;
       
    97         }
       
    98 
       
    99         // insert throws into output
       
   100         $tmp = implode($this->conf['list_sep'], $list);
       
   101         $output = str_replace('%throws', $tmp, $output);
       
   102 
       
   103         // close the div and return the output
       
   104         $output .= '</div>';
       
   105         return "\n$output\n\n";
       
   106     }
       
   107 }
       
   108 ?>