Merge branch 'master' of http://git.roojs.com/roobuilder
[roobuilder] / tools / flutter_extract.php
1 <?php
2
3 // in flutter - an event is actually a property..?
4
5 // we have 2 types of data - the overall summary, and the 'detail one we use for docs..
6 //
7 /*
8  
9  TODO:
10   Generics CompoundAnimation<T> ... or 
11       children → List<Widget>  << fixed..
12     material/PopupMenuEntry-class.html     
13     http://localhost/roojs1/docs/?/flutter/#material.PopupMenuDivider
14       
15       
16   Constants on Libraries.. /? classes?
17   
18   Abstracts - no need to show them in menu?
19    
20   extends link:
21   source link?
22   generic links...
23   
24   
25   config --- constructor links...
26   
27   
28  */
29
30 require_once 'flutter_nodes.php'; // the classes..
31
32 define( 'FDIR', '/home/alan/Downloads/flutterdocs/flutter/');
33 define( 'TDIR', '/home/alan/gitlive/flutter-docs-json/');
34
35  /*
36 $c = new eClass(array(
37     'name' => 'dart:core.List',
38     'href' => 'dart-core/List-class.html',
39     'memberOf' => 'dart:core',
40     'dtype' => 'class' 
41 ));
42
43 // let's do some testing...
44 $c = new eClass(array(
45     'name' => 'dart:core.Object',
46     'href' => 'dart-core/Object-class.html',
47     'memberOf' => 'dart:core',
48     'dtype' => 'class' 
49 ));
50
51 $c = new eClass(array(
52     'name' => 'foundation.Diagnosticable',
53     'href' => 'foundation/Diagnosticable-class.html',
54     'memberOf' => 'foundation',
55     'dtype' => 'class' 
56 ));
57
58 $c = new eClass(array(
59     'name' => 'foundation.DiagnosticableTree',
60     'href' => 'foundation/DiagnosticableTree-class.html',
61     'memberOf' => 'foundation',
62     'dtype' => 'class' 
63 ));
64
65
66
67 $c = new eClass(array(
68     'name' => 'widgets.Widget',
69     'href' => 'widgets/Widget-class.html',
70     'memberOf' => 'widgets',
71     'dtype' => 'class'
72 ));
73 $c = new eClass(array(
74     'name' => 'widgets.StatelessWidget',
75     'href' => 'widgets/StatelessWidget-class.html',
76     'memberOf' => 'widgets',
77     'dtype' => 'class'
78 ));
79
80 $c = new eClass(array(
81     'name' => 'widgets.StatelessWidget',
82     'href' => 'widgets/StatelessWidget-class.html',
83     'memberOf' => 'widgets',
84     'dtype' => 'class'
85 ));
86
87 $c = new eClass(array(
88     'name' => 'material.AboutDialog',
89     'href' => 'material/AboutDialog-class.html',
90     'memberOf' => 'material',
91     'dtype' => 'class'
92 ));
93   $add =  new Prop(array(
94                 'name' => 'children',
95                 'href' => 'material/AboutDialog/children.html',
96                 'memberOf' => 'material.AboutDialog'
97             ));
98             
99             $c->props[] = $add;
100
101 $c->readDocs();
102 print_r($c);
103 exit;
104  
105 */
106
107
108 $js = json_decode(file_get_contents(FDIR.'index.json'));
109
110 foreach($js as $o) {
111    
112     
113     switch($o->type) {
114         case 'library':
115             new Ns(array(
116                 'name' => $o->name,
117                 'href' => $o->href
118             ));
119             
120             break;
121             
122         case 'class':
123         case 'mixin':
124         case 'enum':
125         case 'typedef': // func sig?
126         case 'top-level property':
127             $ctor = 'e'. ucfirst(str_replace('top-level ', '', $o->type));
128             
129             
130             new $ctor(array(
131                 'name' => $o->qualifiedName,
132                 'href' => $o->href,
133                 'isMixin' => $o->type == 'mixin',
134                 'isEnum' => $o->type == 'enum',
135                 'isTypedef' => $o->type == 'typedef',
136                 'isConstant' => $o->type == 'top-level constant',
137                 'memberOf' => $o->enclosedBy->name,
138                 'dtype' => $o->type,
139             ));
140             break;
141         
142          
143         
144         case 'constructor':
145         case 'method':
146         case 'function':
147             $ar = explode('.', $o->qualifiedName);
148             array_pop($ar);
149             $cls = implode('.', $ar);
150             $ctor = 'e'. ucfirst($o->type);
151             $add = new $ctor(array(
152                 'name' => $o->name,
153                 'href' => $o->href,
154                 'isConstructor' => $o->type == 'constructor',
155                 'memberOf' => $cls,
156             ));
157             if ($o->type != 'function') {
158                 eClass::$all[$cls]->methods[] = $add;
159             } else {
160                 eClass::$all[$o->qualifiedName] = $add;
161             }
162             break;
163         
164         case 'top-level constant':        
165         case 'constant':
166             $ar = explode('.', $o->qualifiedName);
167             array_pop($ar);
168             $memberof= implode('.', $ar);
169             
170             $add =  new eConstant(array(
171                 'name' => $o->name,
172                 'href' => $o->href,
173                 'memberOf' => $memberof,
174             ));
175             switch($o->enclosedBy->type) {
176                 case 'class':
177                     if (empty(eClass::$all[$memberof])) {
178                         print_r($o);
179                         echo "Can not find class: $memberof to add object to";
180                         exit;
181                     }
182                     eClass::$all[$memberof]->props[] = $add;
183                     break;
184                 
185                 case 'library':
186                     Ns::add($add);
187                     break;
188                 
189                 default:
190                     print_R($o);
191                     exit;
192                 
193             }
194             break;
195             
196         case 'property':
197         
198
199             $ar = explode('.', $o->qualifiedName);
200             array_pop($ar);
201             $cls = implode('.', $ar);
202             
203             
204             
205             if (substr($o->name, 0,2) == 'on' && $o->type == 'property') {
206                 // presumtionus...
207                 eClass::$all[$cls]->events[] = new eMethod(array(
208                     'name' => $o->name,
209                     'href' => $o->href,
210                     'isConstant' => $o->type == 'constant',
211                     
212                 ));
213                 break;
214             }
215             $add =  new Prop(array(
216                 'name' => $o->name,
217                 'href' => $o->href,
218                 'memberOf' => $cls
219             ));
220             
221             eClass::$all[$cls]->props[] = $add;
222         
223             break;  
224         default:
225             print_R($o);
226             die("invalid type {$o->type}");
227     }
228     
229     
230     
231 }
232
233
234
235
236 $summary = array();
237 if (!file_exists(TDIR .'symbols')) {
238     mkdir(FDIR .'symbols', 0755, true);
239 }
240 if (!file_exists(TDIR .'ns')) {
241     mkdir(FDIR .'ns', 0755, true);
242 }
243
244
245
246 foreach(eClass::$all as $c) {
247     
248     if (!method_exists($c, 'readDocs')) {
249         echo "missing readDocs";
250         print_R($c);exit;
251     }
252     $c->readDocs();
253     // constant's and other mixins.. 
254 }
255 // at this point we need to dump the whole thing.
256
257
258
259
260
261 foreach(eClass::$all as $c) {
262     
263     if (!method_exists($c, 'readDocs')) {
264         echo "missing readDocs";
265         print_R($c);exit;
266     }
267     if (is_a($c, 'eClass') ||is_a($c, 'eMixin') ) {
268         $c->expandImplementors();
269     }
270     // constant's and other mixins.. 
271 }
272
273 // output the files..
274 foreach(eClass::$all as $c) {
275     //$summary[$c->name] = $c->toSummaryArray();
276     if (is_a($c, 'eClass') ||is_a($c, 'eMixin') ) {
277         $c->realImplementors();
278         file_put_contents(TDIR .'symbols/'.$c->name. '.json', json_encode($c,JSON_PRETTY_PRINT));
279     }
280     // constant's and other mixins.. 
281 }
282 foreach(Ns::$tree as $c) {
283     //$summary[$c->name] = $c->toSummaryArray();
284     file_put_contents(TDIR .'ns/'.$c->name. '.json', json_encode($c,JSON_PRETTY_PRINT));
285     
286     // constant's and other mixins.. 
287 }
288 $tree = array();
289 foreach(Ns::$tree as $e) {
290     $e->fakeTree();
291     $tree[] = $e->toTreeArray();
292 }
293 file_put_contents(TDIR .'tree.json', json_encode($tree, JSON_PRETTY_PRINT));
294 //file_put_contents(FDIR .'json/index.json', json_encode($summary, JSON_PRETTY_PRINT)); // this is for builder.. later..
295
296 //print_r(eClass::$all);