source: Dev/trunk/src/client/util/docscripts/preview.php @ 529

Last change on this file since 529 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 10.6 KB
Line 
1<?php /*
2
3  preview.php - rudimentary api browser designed to expose flaws in
4  either the dojo doc parser or the effort to document the Dojo Toolkit
5  API. it is embarasingly inefficient and sloppy, but works.
6 
7  this file requires PHP5, and a full source tree of the dojo toolkit.
8
9  it parses a module, and dumps relevant API information made in real
10  time. PLEASE use this to preview how the parse tool will interpret
11  your code.
12
13  it covers all files in dojtool's modules/ directory dynamically, so
14  can be used to preview documentation in custom namespace code, as well.
15 
16  deep linking is possible via hash tags, eg:
17  http://archive.dojotoolkit.org/nightly/dojotoolkit/util/docscripts/preview.php#dojo/dom-class.js
18
19*/
20
21// hide warnings
22error_reporting(1);
23$ajaxy = !empty($_REQUEST['ajaxy']);
24$showall = isset($_REQUEST['showall']);
25
26?>
27<?php if(!$ajaxy){ ?>
28        <!DOCTYPE html>
29        <html>
30                <head>
31               
32                        <title>API Preview tool | The Dojo Toolkit</title>
33               
34                        <style type="text/css">
35                                @import "../../dojo/resources/dojo.css";
36                                @import "../../dijit/themes/claro/claro.css";
37                                @import "../../dijit/themes/claro/document.css";
38                               
39                                body, html { width:100%; height:100%; margin:0; padding:0; overflow:hidden; }
40                               
41                                .dnone { display:none; }
42                                .topbar li { display:inline; padding:5px; }
43                                .pad {
44                                        padding:20px;
45                                        padding-top:8px;
46                                }
47                                #main {
48                                        width:100%; height:100%;
49                                }
50                               
51                                .claro ul {
52                                    margin-left:10px;
53                                }
54                               
55                                .claro ul ul {
56                                    border-left: 1px dotted #ccc;
57                                    margin-top:5px;
58                                    padding-left:10px;
59                                    list-style:none;
60                                }
61                               
62                                .source pre {
63                                        margin:0; padding:0;
64                                        border: none;
65                                }
66                                pre.error {
67                                        color:red;
68                                        background:yellow;
69                                }
70                               
71                                .claro ul .source ol {
72                                    list-style: number;
73                                }
74                        </style>
75                       
76                        <script type="text/javascript" src="../../dojo/dojo.js" data-dojo-config="parseOnLoad:true"></script>
77                        <script type="text/javascript">
78                                dojo.require("dojo.data.ItemFileReadStore");
79                                dojo.require("dojo.hash");
80                                dojo.require("dijit.Tree");
81                                dojo.require("dijit.layout.BorderContainer");
82                                dojo.require("dijit.layout.ContentPane");
83                                dojo.require("dijit.layout.TabContainer");
84                                dojo.require("dojox.NodeList.delegate");
85                               
86                                var fileStore, fileTree, apiPane;
87                               
88                                function tgShow(id){
89                                        dojo.toggleClass(id, "dnone");
90                                }
91
92                                function addTab(ns, file){
93                                       
94                                        var id = ns + "." + (file.split("/").join(".")),
95                                                dij = dijit.byId(id),
96                                                href = "?ns=" + ns + "&file=" + file + "&ajaxy=1&showall=1"
97                                        ;
98                                       
99
100                                        if(!dij){
101                                                dij = new dijit.layout.ContentPane({
102                                                        id: id,
103                                                        href: href,
104                                                        title: id,
105                                                        closable: true
106                                                });
107                                                dij.placeAt(apiPane);
108                                        }else{
109                                                dij.set("href", href + "&bust=" + (+new Date()));
110                                        }
111                                        apiPane.selectChild(dij);
112                                };
113                               
114                                function gohash(hash){
115                                        // do an addTab for a ns/file extraction from the `hash` value
116                                        var all = hash.split("/"),
117                                                ns = all.shift(),
118                                                file = all.join("/")
119                                        ;
120                                        console.warn("go hash:", ns, file);
121                                        ns && file && addTab(ns, file);
122                                }
123                               
124                                dojo.subscribe("/dojo/hashchange", gohash);
125                               
126                                dojo.ready(function(){
127                                       
128                                        apiPane = dijit.byId("apiTabs");
129                                //      dojo.connect(apiPane, "selectChild", function(child){
130                                //              var hash = dojo.hash();
131                                //              if(child.id !== hash){
132                                //                      dojo.hash(child.id);
133                                //              }
134                                //      });
135                                       
136                                        dojo.query("#apiTabs").delegate(".toggler", "onclick", function(e){
137                                                e && e.preventDefault();
138                                                dojo.query(this).parent().siblings(".t").toggleClass("dnone");
139                                        });
140
141                                        //      build the tree
142                                        fileStore = new dojo.data.ItemFileReadStore({
143                                                url: "_browse_tree.php"
144                                        });
145
146                                        fileTree = new dijit.Tree({
147                                                store: fileStore,
148                                                query: { type: "namespace" },
149                                                onClick: function(item){
150                                                        var type = fileStore.getValue(item, "type");
151                                                        if(type == "file"){
152                                                                //      load it up
153                                                                var ns = fileStore.getValue(item, "ns"),
154                                                                        file = fileStore.getValue(item, "full_name")
155                                                                ;
156                                                                var c = dojo.hash();
157                                                                console.warn(c, ns, file);
158                                                                if(c == ns + "/" + file){
159                                                                        addTab(ns, file);
160                                                                }else{
161                                                                        dojo.hash(ns + "/" + file);
162                                                                }
163                                                        }
164                                                }
165                                        });
166                                        dojo.place(fileTree.domNode, dijit.byId("fileTreePane").domNode);
167
168                                        // if we landed with a hash, lets use it:
169                                        var current = dojo.hash();
170                                        current && ~current.indexOf("/") && gohash(current);
171
172                                });
173                        </script>
174
175                </head>
176                <body class="claro">
177<?php
178
179} // $ajaxy
180
181include_once('lib/parser2/dojo2.inc');
182
183//*
184$tree = '';
185// no dojo.require() call made?
186$u = 0;
187$files = dojo_get_files();
188foreach ($files as $set){
189        list($namespace, $file) = $set;
190        $data[$namespace][] = $file;
191}
192$namespaces = array_keys($data);
193unset($files);
194
195if(!empty($_REQUEST['ns'])){
196
197        $ns = $_REQUEST['ns'];
198        $ifile = $_REQUEST['file'];
199 
200
201        if($ifile){
202                $apiData = dojo_get_contents($ns,$ifile);
203
204                $waserror = FALSE;
205                $errorline = 0;
206               
207                $print .= "<h2>".htmlspecialchars($ns)."/".htmlspecialchars($ifile)."</h2><ul>";
208                foreach($apiData as $key => $val){
209                        switch($key){
210                                case "#resource" : break;
211                                case "#requires" :
212                                        $print .= "<li><h3>Requires:</h3><ul>";
213                                        foreach($val as $resource){
214                                                $print .= "<li>{$resource[1]} in {$resource[0]}";
215                                                if ($resource[2]) {
216                                                        $print .= " in project {$resource[2]}";
217                                                }
218                                                $print .= "</li>";
219                                        }
220                                        $print .= "</ul></li>";
221                                        break;
222                                case "#provides" :
223                                        $print .= "<li><h3>Provides:</h3><ul>";
224                                        $print .= "<li>$val</li>";
225                                        $print .= "</ul></li>";
226                                        break;
227                                case "#debug":
228                                        $print .= "<div><h4>Debugging:</h4><ul>";
229                                        foreach($val as $message){
230                                                $print .= "<li>";
231                                                if(is_string($message)){
232                                                        $print .= $message;
233                                                }else{
234                                                        $er = $message->getMessage();
235                                                        preg_match("/Line\ (\d+)/", $er, $matches);
236                                                        if($matches[1]){
237                                                                $waserror = TRUE;
238                                                                $errorline = $matches[1];
239                                                        }
240                                                        $print .= "<pre>" . $message->getMessage() . "</pre>";
241                                                }
242                                                $print .= "</li>";
243                                        }
244                                        $print .= "</ul></div>";
245                                        break;
246                                case "#raw_source":
247                                        $lines = explode("\n", $val);
248                                        $print .= "<div class='source'><h4><a href='#' class='toggler'>Source</a></h4><div class='t dnone'><ol>";
249                                        $i = 0;
250                                        foreach($lines as $line){
251                                                $i++;
252                                                $print .= "<li value='$i'>";
253                                                if($waserror && ($i == $errorline || $errorline + 1 == $i || $errorline - 1 == $i)){
254                                                        $print .= "<pre class='error'>";
255                                                }else{
256                                                        $print .= "<pre>";
257                                                }
258                                                $print .= htmlentities($line) . " </pre></li>";
259                                        }
260                                        $print .= "</ol></div></div>";
261                                        break;
262                                case "#unwrapped_source":
263                                        if(!empty($val)){
264                                                $print .= "<div><h4><a href='#' class='toggler'>" . $key . "</a></h4><pre class='t dnone'>" . htmlentities($val) . "</pre></div>";
265                                        }
266                                        break;
267                                default:
268                                        $print .= "<li><h4>".$key."</h4><ul> ";
269                                        foreach($val as $key2 => $val2){
270 
271                                                switch($key2){
272                                                        // most things using dojo.declare() trigger this, eg: dijits
273                                                        case "classlike":
274                                                                $knownClasses[] = $key;
275                                                                if ($_REQUEST['showall']) {
276                                                                        $print .= "<li>$key2</li>";
277                                                                }
278                                                                break;
279
280                                                        // these are partially useless for our "overview" api, but set showall=1 in the
281                                                        // url if you want to see these, too. sortof.
282                                                        case "type" :
283                                                                $print .= "<li><em>".$key2."</em><div><pre>".htmlentities($val2)."</pre></div></li>";
284                                                                break;
285                                                        case "private_parent" :
286                                                        case "prototype" :
287                                                        case "instance" :
288                                                        case "private" :
289                                                        case "deprecated" :
290                                                        case "protected" :
291                                                        case "attached" :
292                                                                if($_REQUEST['showall']){ $print .= "<li>".$key2." - ".$val2."</li>"; }
293                                                                break;
294                                                        case "alias" :
295                                                        case "constructor" :
296                                                                $print .= "<li>".$key2." - ".$val2."</li>";
297                                                                break;
298                               
299                                                        // another array we want inspect more closely
300                                                        case "parameters" :
301                                                                $print .= "<li><em>parameters:</em> <ul>";
302                                                                foreach($val2 as $param => $paramData){
303                                                                        $print .= "<li>".$param;
304                                                                        if (!empty($paramData['type'])) {
305                                                                                $print .= ": <em>(typeof ".$paramData['type'].")</em>";
306                                                                        }
307                                                                        $print .= "<div>";
308                                                                        if(!empty($paramData['summary'])){
309                                                                                $print .= "<pre>".htmlentities($paramData['summary'])."</pre>";
310                                                                        }
311                                                                        $print .= "</div></li>";
312                                                                } //print_r($val2);                             
313                                                                $print .= "</ul></li>";
314                                                                break;
315                               
316                                                                // the stripped source, and some minimal toggling to show/hide 
317                                                        case "source" :
318                                                                $print .= "<li class=\"source\"><em>source: [<a onclick=\"tgShow('unique".++$u."');\">view</a>]</em>
319                                                                        <div class=\"dnone\" id=\"unique".$u."\">\n
320                                                                        ".ltrim(str_replace("\n","<br>",str_replace("\t","&nbsp;",$val2)))."
321                                                                        </div>"; 
322                                                                break;
323
324                                                        case "tags":
325                                                                $print .= "<li><em>$key2</em>: " . implode(' ', $val2) . '</li>';
326                                                                break;
327
328                                                        case "optional":
329                                                                if ($val2) {
330                                                                        $print .= "<li><em>$key2</em></li>";
331                                                                }
332                                                                break;
333
334                                                        case "chains" :
335                                                        case "mixins" :
336                                                                if (!empty($val2)) {
337                                                                        $print .= "<li><em>" . $key2 . ":</em> <ul>";
338                                                                        foreach ($val2 as $subtype => $chains) {
339                                                                                foreach ($chains as $chain) {
340                                                                                        $print .= "<li>$chain: <em>($subtype)</em></li>";
341                                                                                }
342                                                                        }
343                                                                        $print .= "</ul></li>";
344                                                                }
345                                                                break;
346
347                                                        // these are the ones we care about, and are fulltext/sometimes html
348                                                        case "examples" :
349                                                                foreach ($val2 as $example){
350                                                                        $print .= "<li><em>example</em><div><pre>".htmlentities($example)."</pre></div></li>";
351                                                                }
352                                                                break;
353
354                                                        case "returns" :
355                                                        case "return_summary" :
356                                                        case "exceptions" :
357                                                        case "description" :
358                                                        case "summary" : $print .= "<li><em>".$key2."</em><div><pre>".htmlentities($val2)."</pre></div></li>"; break;
359
360                                                        // this is a key we don't know about above, so show it just in case
361                                                        default:
362                                                                $print .= "<li>?? ".$key2." = ".$val2." (debug: ".gettype($val2).") ??</li>";
363                                                                break;
364                                                }
365                                        }
366                                        $print .= "</ul></li>";
367                                        break;
368                                }
369                        }
370                        $print .= "</ul>";
371                }
372        }
373
374if(!$ajaxy){ ?>
375<div dojoType="dijit.layout.BorderContainer" id="main">
376        <div dojoType="dijit.layout.ContentPane" id="fileTreePane" region="left" style="width: 250px; overflow: auto;" splitter="true"></div>
377        <div dojoType="dijit.layout.TabContainer" id="apiTabs" region="center">
378                <div dojoType="dijit.layout.ContentPane" id="apiPane" title="Crude API Browser">
379                        <div class="pad"><?php echo $print; ?></div>
380                </div>
381        </div>
382</div>
383</body>
384</html>
385<?php }else{
386        // we just want the content we parsed
387        echo '<div class="pad">'.$print.'</div>';
388}
389?>
Note: See TracBrowser for help on using the repository browser.