description = $f[3];
case 3:
$this->extends = $f[2];
case 2:
$this->filename = $f[1];
case 1:
$this->name = $f[0];
default:
}
}
}
class syntax_plugin_apidoc_data_field {
public $definition="", $name="", $description="";
public function __construct( $f ) {
switch( min( count( $f ), 3 ) ) {
case 3:
$this->description = $f[2];
case 2:
$this->definition = $f[1];
case 1:
$this->name = $f[0];
default:
}
}
}
class syntax_plugin_apidoc_data_method {
public $name="", $definition="", $description="", $parameters=array(), $returns="";
public function __construct( $f ) {
switch( min( count( $f ), 4 ) ) {
case 4:
$this->description = $f[3];
case 3:
$this->returns = $f[2];
case 2:
$this->definition = $f[1];
case 1:
$this->name = $f[0];
default:
}
}
}
class syntax_plugin_apidoc_data_parameter {
public $name="", $type="", $defaultvalue="", $description="";
public function __construct( $f, &$c ) {
switch( min( count( $f ), 4 ) ) {
case 4:
$this->description = $f[3];
case 3:
$this->defaultvalue = $f[2];
case 2:
$this->type = $f[1];
case 1:
$this->name = $f[0];
default:
}
}
}
class syntax_plugin_apidoc extends DokuWiki_Syntax_Plugin {
function getInfo(){
return array(
'author' => 'Marcus Runsten',
'email' => 'marcus@stilit.se',
'date' => '2015-11-12',
'name' => 'API Documentation Plugin',
'desc' => 'Adds syntax for API Documentation to DokuWiki. Version 1.1',
'url' => 'http://www.stilit.se/?page_id=107'
);
}
function getType(){ return 'protected';}
function getPType(){ return 'block';}
function getSort(){ return 100; }
function connectTo($mode) {
$this->Lexer->addEntryPattern( '
"; $html .= $this->apidoc_highlight( $data->name, true ); $html .= "
Fields
Methods
| ";
$html .= " " . $this->apidoc_highlight( $data->name, true ) . " "; $html .= "Filename : " . $data->filename . " Description "; $html .= "" . $data->description . " "; $html .= "Fields "; foreach( $data->fields AS $f ) { $html .= "";
$html .= " ";
}
$html .= "" . $this->apidoc_highlight( $f->name, true ) . " "; $html .= "Definition : " . $this->apidoc_highlight( $f->definition, true ) . " Methods "; foreach( $data->methods AS $m ) { $html .= "";
$html .= " ";
}
return $html;
}
private function apidoc_parse( $str ) {
$data = $this->apidoc_parse_data( $str );
if( !$data ) return false;
$data = $this->apidoc_sort_data( $data );
if( !$data ) return false;
$html = $this->apidoc_out_html( $data );
return array( $html );
}
private function apidoc_parse_data( $str ) {
$rData = null;
$co = null;
$matches = preg_split( "/(CLASS|FIELD|METHOD|PARAMETER)\|/", $str, -1, PREG_SPLIT_DELIM_CAPTURE );
for( $i=0; $i < count( $matches )-1; $i++ ) {
switch( $matches[$i] ) {
case 'CLASS':
$rData = new syntax_plugin_apidoc_data_class( explode( "|", $matches[++$i] ) );
break;
case 'FIELD':
if( $rData == null ) return false;
$co = $rData->fields[] = new syntax_plugin_apidoc_data_field( explode( "|", $matches[++$i] ) );
break;
case 'METHOD':
if( $rData == null ) return false;
$co = $rData->methods[] = new syntax_plugin_apidoc_data_method( explode( "|", $matches[++$i] ) );
break;
case 'PARAMETER':
if( $rData == null || $co == null ) return false;
$co->parameters[] = new syntax_plugin_apidoc_data_parameter( explode( "|", $matches[++$i] ) );
default: // Do nothing
break;
}
}
return $rData;
}
private function apidoc_sort( $arr ) {
$tgt = array();
while( count( $arr ) > 0 ) {
$smallest = 0;
for( $i=0; $i < count( $arr ); $i++ ) if( strcasecmp( $arr[$smallest]->name, $arr[$i]->name ) > 0 ) $smallest = $i;
$tgt[] = $arr[$smallest];
unset( $arr[$smallest] );
$arr = array_values( $arr );
}
return $tgt;
}
private function apidoc_sort_data( $data ) {
$data->fields = $this->apidoc_sort( $data->fields );
$data->methods = $this->apidoc_sort( $data->methods );
for( $i=0; $i < count( $data->methods ); $i++ ) $data->methods[$i]->parameters = $this->apidoc_sort( $data->methods[$i]->parameters );
return $data;
}
}
?>
" . $this->apidoc_highlight( $m->name, true ) . " "; $html .= "Definition : " . $this->apidoc_highlight( $m->definition, true ) . " "; $html .= "Returns : " . $this->apidoc_highlight( $m->returns, true ) . " "; $html .= "Description ";
$html .= " ";
$html .= "Parameters "; foreach( $m->parameters AS $p ) { $html .= "";
$html .= " ";
}
$html .= "" . $this->apidoc_highlight( $p->name, true ) . " "; $html .= "";
$html .= "Type : " . $this->apidoc_highlight( $p->type, true ) . " Description |