Skip to content

Commit

Permalink
major changes to XHTML renderer for 'Function' -- has complete format…
Browse files Browse the repository at this point in the history
… control now, not just CSS

git-svn-id: https://svn.php.net/repository/pear/packages/Text_Wiki/trunk@170077 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Paul M Jones committed Oct 8, 2004
1 parent 4ef0ab3 commit 5e375f8
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 26 deletions.
21 changes: 14 additions & 7 deletions Text/Wiki/Parse/Function.php
@@ -1,11 +1,6 @@
<?php

/*
<function name="" return="" access="">
type, descr
type, descr, default (if there is a default value, then it is optional!)
</function>
*/
// $Id$

class Text_Wiki_Parse_Function extends Text_Wiki_Parse {

Expand Down Expand Up @@ -90,7 +85,19 @@ function process(&$matches)

case 't':
case 'throws':
$opts['throws'][] = $val;
$tmp = explode(',', $val);
$k = count($tmp);
if ($k == 1) {
$opts['throws'][] = array(
'type' => $tmp[0],
'descr' => null
);
} else {
$opts['throws'][] = array(
'type' => $tmp[0],
'descr' => $tmp[1]
);
}
break;

default:
Expand Down
86 changes: 67 additions & 19 deletions Text/Wiki/Render/Xhtml/Function.php
@@ -1,15 +1,39 @@
<?php

/**
format_main:
access
return
name
params
throws
format_param:
type
descr
format_paramd:
type
descr
default
format_throws:
type
descr
list_sep: ', '
*/

class Text_Wiki_Render_Xhtml_Function extends Text_Wiki_Render {

var $conf = array(
'css_div' => null,
'access' => '%s',
'return' => '%s',
'name' => '<strong>%s</strong>',
'type' => '%s',
'descr' => '<em>%s</em>',
'default' => 'default %s'
'list_sep' => ', ',
'format_main' => '%access %return <b>%name</b> ( %params ) %throws',
'format_param' => '%type <i>%descr</i>',
'format_paramd' => '[%type <i>%descr</i> default %default]',
'format_throws' => '<b>throws</b> %type <i>%descr</i>'
);

/**
Expand All @@ -27,27 +51,51 @@ class Text_Wiki_Render_Xhtml_Function extends Text_Wiki_Render {

function token($options)
{
extract($options); // name, access, return, params
extract($options); // name, access, return, params, throws

$css = $this->formatConf(' class="%s"', $this->conf['css_div']);
$output = "<div$css>";

$output .= sprintf($this->conf['access'], $access) . ' ';
$output .= sprintf($this->conf['return'], $return) . ' ';
$output .= sprintf($this->conf['name'], $name) . ' ( ';
// build the baseline output
$output = $this->conf['format_main'];
$output = str_replace('%access', htmlspecialchars($access), $output);
$output = str_replace('%return', htmlspecialchars($return), $output);
$output = str_replace('%name', htmlspecialchars($name), $output);

// build the set of params
$list = array();
foreach ($params as $key => $val) {
$tmp = sprintf($this->conf['type'], $val['type']) . ' ';
$tmp .= sprintf($this->conf['descr'], $val['descr']);

// is there a default value?
if ($val['default']) {
$tmp .= ' ' . sprintf($this->conf['default'], $val['default']);
$tmp = "[$tmp]";
$tmp = $this->conf['format_paramd'];
} else {
$tmp = $this->conf['format_param'];
}

// add the param elements
$tmp = str_replace('%type', htmlspecialchars($val['type']), $tmp);
$tmp = str_replace('%descr', htmlspecialchars($val['descr']), $tmp);
$tmp = str_replace('%default', htmlspecialchars($val['default']), $tmp);
$list[] = $tmp;
}
$output .= implode(', ', $list) . " )</div>";

// insert params into output
$tmp = implode($this->conf['list_sep'], $list);
$output = str_replace('%params', $tmp, $output);

// build the set of throws
$list = array();
foreach ($throws as $key => $val) {
$tmp = $this->conf['format_throws'];
$tmp = str_replace('%type', htmlspecialchars($val['type']), $tmp);
$tmp = str_replace('%descr', htmlspecialchars($val['descr']), $tmp);
$list[] = $tmp;
}

// insert throws into output
$tmp = implode($this->conf['list_sep'], $list);
$output = str_replace('%throws', $tmp, $output);

// close the div and return the output
$output .= '</div>';
return "\n$output\n\n";
}
}
Expand Down

0 comments on commit 5e375f8

Please sign in to comment.