Skip to content

Commit 73e9a74

Browse files
committed
Update docgen with a few bug fixes and creating a viewer.
1 parent 3102ad5 commit 73e9a74

5 files changed

Lines changed: 202 additions & 36 deletions

File tree

docgen/output.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
require 'src/Block.php';
3+
require 'src/ClassDesc.php';
4+
require 'src/Constant.php';
5+
require 'src/Method.php';
6+
require 'src/Parameter.php';
7+
require 'src/Property.php';
8+
require 'src/ReturnType.php';
9+
require 'src/Processor.php';
10+
11+
header('Content-Type: application/json');
12+
13+
// $data = new Processor("../src/gameobjects/Sprite.js");
14+
$data = new Processor("../src/loader/Cache.js");
15+
16+
// echo $data->total() . " blocks found\n\n";
17+
// echo "\nConstants:\n\n";
18+
19+
for ($i = 0; $i < count($data->consts); $i++)
20+
{
21+
// echo $data->consts[$i]->getJSON() . ",";
22+
}
23+
24+
/*
25+
echo "\nMethods:\n\n";
26+
27+
for ($i = 0; $i < count($data->methods); $i++)
28+
{
29+
$method = $data->methods[$i];
30+
echo "\n\n";
31+
echo $method->name;
32+
echo "\n";
33+
print_r($method->help);
34+
print_r($method->parameters);
35+
print_r($method->returns);
36+
}
37+
38+
echo "\nProperties:\n\n";
39+
40+
for ($i = 0; $i < count($data->properties); $i++)
41+
{
42+
$property = $data->properties[$i];
43+
echo "\n\n";
44+
echo $property->name . "\n";
45+
// print_r($property->types);
46+
echo "Source code line " . $property->line . "\n";
47+
echo "Default: " . $property->default . "\n";
48+
echo "Help: " . "\n";
49+
print_r($property->help);
50+
echo "\n\n";
51+
}
52+
*/
53+
?>

docgen/process.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,38 @@
3737

3838
echo $data->total() . " blocks found\n\n";
3939

40+
/*
4041
echo "\nConstants:\n\n";
4142
4243
for ($i = 0; $i < count($data->consts); $i++)
4344
{
44-
print_r($data->consts[$i]->getJSON());
45-
// $const = $data->consts[$i];
46-
// echo "\n\n";
47-
// echo $const->name;
48-
// echo "\n";
49-
// print_r($const->types);
45+
// print_r($data->consts[$i]->getJSON());
46+
$const = $data->consts[$i];
47+
echo "\n\n";
48+
echo $const->name;
49+
echo "\n";
50+
print_r($const->types);
5051
}
52+
*/
5153

52-
/*
5354
echo "\nMethods:\n\n";
5455

5556
for ($i = 0; $i < count($data->methods); $i++)
5657
{
5758
$method = $data->methods[$i];
58-
echo "\n\n";
59-
echo $method->name;
60-
echo "\n";
61-
print_r($method->help);
62-
print_r($method->parameters);
63-
print_r($method->returns);
59+
60+
if ($method->name === 'addMissingImage')
61+
{
62+
echo "\n\n";
63+
print_r($method->title);
64+
print_r($method->help);
65+
print_r($method->parameters);
66+
print_r($method->returns);
67+
}
68+
6469
}
6570

71+
/*
6672
echo "\nProperties:\n\n";
6773
6874
for ($i = 0; $i < count($data->properties); $i++)

docgen/src/Method.php

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class Method
33
{
44
public $line; // number, line number in the source file this is found on?
55
public $name; // bringToTop, kill, etc
6+
public $title = [];
67
public $parameters = []; // an array containing the parameters
78
public $help = [];
89
public $returns = false;
@@ -11,27 +12,6 @@ class Method
1112
public $isProtected = false;
1213
public $isPrivate = false;
1314

14-
public function getArray()
15-
{
16-
$a = array(
17-
'name' => $this->name,
18-
'returns' => $this->returns,
19-
'help' => implode('\n', $this->help),
20-
'line' => $this->line,
21-
'public' => $this->isPublic,
22-
'protected' => $this->isProtected,
23-
'private' => $this->isPrivate,
24-
);
25-
26-
return $a;
27-
28-
}
29-
30-
public function getJSON()
31-
{
32-
return json_encode($this->getArray());
33-
}
34-
3515
public function __construct($block)
3616
{
3717
// Because zero offset + allowing for final line
@@ -66,6 +46,8 @@ public function __construct($block)
6646
$this->isPrivate = true;
6747
}
6848

49+
$this->title = array("name" => $this->name, "visibility" => $this->getVisibility());
50+
6951
$this->help = $block->cleanContent();
7052

7153
if ($block->getTypeBoolean('@return'))
@@ -75,5 +57,42 @@ public function __construct($block)
7557

7658
}
7759

60+
public function getVisibility()
61+
{
62+
if ($this->isPublic)
63+
{
64+
return 'public';
65+
}
66+
else if ($this->isProtected)
67+
{
68+
return 'protected';
69+
}
70+
else if ($this->isPrivate)
71+
{
72+
return 'private';
73+
}
74+
}
75+
76+
public function getArray()
77+
{
78+
$a = array(
79+
'title' => $this->title,
80+
'returns' => $this->returns,
81+
'help' => implode('\n', $this->help),
82+
'line' => $this->line,
83+
'public' => $this->isPublic,
84+
'protected' => $this->isProtected,
85+
'private' => $this->isPrivate,
86+
);
87+
88+
return $a;
89+
90+
}
91+
92+
public function getJSON()
93+
{
94+
return json_encode($this->getArray());
95+
}
96+
7897
}
7998
?>

docgen/src/Parameter.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Parameter
66
public $help = [];
77
public $optional = false;
88
public $default = false; // assigned value is the default value
9+
public $debug = '';
910

1011
public function __construct($line)
1112
{
@@ -16,18 +17,23 @@ public function __construct($line)
1617

1718
$name = $output[3];
1819

20+
// $this->debug = $name . " -- ";
21+
1922
if ($name[0] === '[')
2023
{
2124
$this->optional = true;
2225
$name = substr($name, 1, -1);
2326

27+
// $this->debug .= $name . " -- ";
28+
2429
// Default?
2530
$equals = strpos($name, '=');
2631

2732
if ($equals > 0)
2833
{
29-
$name = substr($name, 0, $equals - 1);
30-
$this->default = substr($name, $equals + 1);
34+
$this->default = (string) substr($name, $equals + 1);
35+
$name = substr($name, 0, $equals);
36+
// $this->debug .= $name . " -eq- " . $equals . " -def- " . $this->default;
3137
}
3238
}
3339

docgen/view.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
if (isset($_GET['src']))
3+
{
4+
$srcfile = $_GET['src'];
5+
}
6+
else
7+
{
8+
$srcfile = "loader/Cache";
9+
}
10+
11+
require 'src/Block.php';
12+
require 'src/ClassDesc.php';
13+
require 'src/Constant.php';
14+
require 'src/Method.php';
15+
require 'src/Parameter.php';
16+
require 'src/Property.php';
17+
require 'src/ReturnType.php';
18+
require 'src/Processor.php';
19+
20+
$data = new Processor("../src/" . $srcfile . ".js");
21+
?>
22+
<!doctype html>
23+
<html>
24+
<head>
25+
<meta charset="UTF-8" />
26+
<title>Phaser Documentation Viewer: <?php echo $srcfile ?></title>
27+
<style type="text/css">
28+
body {
29+
font-family: Arial;
30+
font-size: 14px;
31+
background-color: #fff;
32+
color: #000;
33+
}
34+
35+
textarea {
36+
width: 100%;
37+
height: 1000px;
38+
}
39+
</style>
40+
</head>
41+
<body>
42+
43+
<h1><?php echo $srcfile ?></h1>
44+
45+
<h2>Constants</h2>
46+
47+
<ul>
48+
<?php
49+
for ($i = 0; $i < count($data->consts); $i++)
50+
{
51+
$const = $data->consts[$i];
52+
echo "<li>{$const->name}</li>";
53+
}
54+
?>
55+
</ul>
56+
57+
<h2>Methods</h2>
58+
59+
<ul>
60+
<?php
61+
for ($i = 0; $i < count($data->methods); $i++)
62+
{
63+
$method = $data->methods[$i];
64+
echo "<li>{$method->name}</li>";
65+
}
66+
?>
67+
</ul>
68+
69+
<h2>Properties</h2>
70+
71+
<ul>
72+
<?php
73+
for ($i = 0; $i < count($data->properties); $i++)
74+
{
75+
$property = $data->properties[$i];
76+
echo "<li>{$property->name}</li>";
77+
}
78+
?>
79+
</ul>
80+
81+
</body>
82+
</html>

0 commit comments

Comments
 (0)