/*
_browse.php - rudimentary api browser designed to expose flaws in
either the dojo doc parser or the effort to document the Dojo Toolkit
API. it is embarasingly inefficient and sloppy, but works.
this file requires PHP5, and a full source tree of the dojo toolkit.
it parses a module, and dumps relevant API information made in real
time. PLEASE use this to preview how the parse tool will interpret
your code.
it covers all files in dojtool's modules/ directory dynamically, so
can be used to preview documentation in custom namespace code, as well.
*/ ?>
if (empty($_REQUEST['ajaxy'])){ ?>
API Preview tool | The Dojo Toolkit
} // empty($_REQUEST['ajaxy']
include_once('includes/dojo.inc');
$tree = '';
// no dojo.require() call made?
$u = 0;
$files = dojo_get_files();
foreach ($files as $set){
list($namespace, $file) = $set;
$data[$namespace][] = $file;
$tmptree = explode("/",$file);
if(count($tmptree)>1){
$treefilename = array_pop($tmptree);
$treepath = join("/",$tmptree);
}else{
$treefilename = array_pop($tmptree);
$treepath = '/';
}
$tree['items'][] = array(
'label' => $treefilename,
'ns' => $namespace,
'type' => "file",
'id' => "node".$node++
);
}
$namespaces = array_keys($data);
$nshtml = "";
$regexp = "";
foreach ($namespaces as $ns){
$regexp .= $ns."|";
if($_REQUEST['ns'] != $ns){
$nshtml .= "- ".$ns."
";
}else{
$nshtml .= "- ".$ns."
";
}
}
define('REGEXP','('.$regexp.')');
$nshtml .= "
";
unset($files);
if(!empty($_REQUEST['ns'])){
$ns = $_REQUEST['ns'];
$ifile = $_REQUEST['file'];
$tree .= "";
foreach ($data[$ns] as $file){
if(!preg_match('/tests\//i',$file)){
if($ifile == $file){ $tree .= "- ".$file."
";
}else{ $tree .= "- ".$ns."/".$file."
"; }
}else{ $testfiles[] = $ns."/".$file; }
}
$tree .= "
";
if($ifile){
$apiData = dojo_get_contents($ns,$ifile);
$print .= "".$ns."/".$ifile."
";
foreach($apiData as $key => $val){
switch($key){
case "#resource" : break;
case "#requires" :
$print .= "Requires:
";
foreach($val[0] as $resource){
$print .= "- ".$resource."
";
}
$print .= "
";
break;
case "#provides" : break;
default:
$print .= "".$key."
";
foreach($val as $key2 => $val2){
switch($key2){
// most things using dojo.declare() trigger this, eg: dijits
case "classlike": $knownClasses[] = $key; break;
// these are partially useless for our "overview" api, but set showall=1 in the
// url if you want to see these, too. sortof.
case "type" : $print .= "- ".$key2."
"; break;
case "private_parent" :
case "prototype" :
case "instance" :
case "private" :
if($_REQUEST['showall']){ $print .= "- ".$key2." - ".$val2."
"; }
break;
// another array we want inspect more closely
case "parameters" :
$print .= "- parameters:
";
foreach($val2 as $param => $paramData){
$print .= "- ".$param.": (typeof ".$paramData['type'].")
";
if(!empty($paramData['summary'])){
$print .= "
".htmlentities($paramData['summary'])."
";
}
$print .= "
";
} //print_r($val2);
$print .= "
";
break;
// the stripped source, and some minimal toggling to show/hide
case "source" :
/*
$print .= "- source: [view]
\n
".ltrim(str_replace("\n","
",str_replace("\t"," ",$val2)))."
";
*/
break;
case "chains" :
if (!empty($val2)) {
$print .= " - chain:
";
foreach ($val2 as $subtype => $chains) {
foreach ($chains as $chain) {
$print .= "- $chain: ($subtype)
";
}
}
$print .= "
";
}
break;
// these are the ones we care about, and are fulltext/sometimes html
case "examples" :
foreach ($val2 as $example){
$print .= "- example
".htmlentities($example)."
";
}
break;
case "returns" :
case "exceptions" :
case "description" :
case "summary" : $print .= "- ".$key2."
"; break;
// this is a key we don't know about above, so show it just in case
default: $print .= "- ?? ".$key2." = ".$val2." (debug: ".gettype($val2).") ??
"; break;
}
}
$print .= "
"; break;
}
}
$print .= "
";
}
}
// ... aaaaaand some basic dijit layout to make this quick thing somewhat user friendly. i have guilt in my heart loading all this
// dijit-ness, and not just capturing the onclick of the links and just targeting #apiPane ... would have to only echo $print.
// set ?ajaxy=1 on a url to only print the content part of a request.
if(empty($_REQUEST['ajaxy'])){ ?>
echo $nshtml; ?>
echo $tree; ?>
echo $print; ?>
}else{ echo $print; }?>