| 1 | <?php |
| 2 | |
| 3 | // $Id: Function.php,v 1.3 2004/10/08 17:46:47 pmjones Exp $ |
| 4 | |
| 5 | class Text_Wiki_Render_Xhtml_Function extends Text_Wiki_Render { |
| 6 | |
| 7 | var $conf = array( |
| 8 | // list separator for params and throws |
| 9 | 'list_sep' => ', ', |
| 10 | |
| 11 | // the "main" format string |
| 12 | 'format_main' => '%access %return <b>%name</b> ( %params ) %throws', |
| 13 | |
| 14 | // the looped format string for required params |
| 15 | 'format_param' => '%type <i>%descr</i>', |
| 16 | |
| 17 | // the looped format string for params with default values |
| 18 | 'format_paramd' => '[%type <i>%descr</i> default %default]', |
| 19 | |
| 20 | // the looped format string for throws |
| 21 | 'format_throws' => '<b>throws</b> %type <i>%descr</i>' |
| 22 | ); |
| 23 | |
| 24 | /** |
| 25 | * |
| 26 | * Renders a token into text matching the requested format. |
| 27 | * |
| 28 | * @access public |
| 29 | * |
| 30 | * @param array $options The "options" portion of the token (second |
| 31 | * element). |
| 32 | * |
| 33 | * @return string The text rendered from the token options. |
| 34 | * |
| 35 | */ |
| 36 | |
| 37 | function token($options) |
| 38 | { |
| 39 | extract($options); // name, access, return, params, throws |
| 40 | |
| 41 | // build the baseline output |
| 42 | $output = $this->conf['format_main']; |
| 43 | $output = str_replace('%access', htmlspecialchars($access), $output); |
| 44 | $output = str_replace('%return', htmlspecialchars($return), $output); |
| 45 | $output = str_replace('%name', htmlspecialchars($name), $output); |
| 46 | |
| 47 | // build the set of params |
| 48 | $list = array(); |
| 49 | foreach ($params as $key => $val) { |
| 50 | |
| 51 | // is there a default value? |
| 52 | if ($val['default']) { |
| 53 | $tmp = $this->conf['format_paramd']; |
| 54 | } else { |
| 55 | $tmp = $this->conf['format_param']; |
| 56 | } |
| 57 | |
| 58 | // add the param elements |
| 59 | $tmp = str_replace('%type', htmlspecialchars($val['type']), $tmp); |
| 60 | $tmp = str_replace('%descr', htmlspecialchars($val['descr']), $tmp); |
| 61 | $tmp = str_replace('%default', htmlspecialchars($val['default']), $tmp); |
| 62 | $list[] = $tmp; |
| 63 | } |
| 64 | |
| 65 | // insert params into output |
| 66 | $tmp = implode($this->conf['list_sep'], $list); |
| 67 | $output = str_replace('%params', $tmp, $output); |
| 68 | |
| 69 | // build the set of throws |
| 70 | $list = array(); |
| 71 | foreach ($throws as $key => $val) { |
| 72 | $tmp = $this->conf['format_throws']; |
| 73 | $tmp = str_replace('%type', htmlspecialchars($val['type']), $tmp); |
| 74 | $tmp = str_replace('%descr', htmlspecialchars($val['descr']), $tmp); |
| 75 | $list[] = $tmp; |
| 76 | } |
| 77 | |
| 78 | // insert throws into output |
| 79 | $tmp = implode($this->conf['list_sep'], $list); |
| 80 | $output = str_replace('%throws', $tmp, $output); |
| 81 | |
| 82 | // close the div and return the output |
| 83 | $output .= '</div>'; |
| 84 | return "\n$output\n\n"; |
| 85 | } |
| 86 | } |
| 87 | ?> |