Skip to content

Commit ce65846

Browse files
committed
Bugfixes + basic styling support
Fix #22, #23, #21, #12, #24, #26, #27 thereby cleaning up for 1.4
1 parent 768a213 commit ce65846

25 files changed

+779
-669
lines changed

index.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Set up include path for source handling
44
*/
5-
set_include_path(get_include_path().":".__DIR__.'/src/');
5+
set_include_path(get_include_path() . ":" . __DIR__ . '/src/');
66

77
/**
88
* Set up required classes (with the autoloader)
@@ -14,13 +14,23 @@
1414
use PHPDraft\Parse\JsonToHTML;
1515

1616
define('VERSION', '0');
17-
1817
$values = UI::main($argv);
1918

2019
$apib = new ApibFileParser($values['file']);
2120
$json = new Drafter($apib);
2221
$html = new JsonToHTML($json->parseToJson());
23-
$html->get_html($values['template'], $values['image']);
22+
$html->sorting = $values['sorting'];
23+
$html->get_html($values['template'], $values['image'], $values['css'], $values['js']);
24+
2425

26+
function phpdraft_var_dump($var)
27+
{
28+
if (defined('__PHPDRAFT_PHAR__')) {
29+
return;
30+
}
31+
echo '<pre>';
32+
var_dump($var);
33+
echo '</pre>';
34+
}
2535

2636
?>

src/PHPDraft/In/ApibFileParser.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ class ApibFileParser
1212
{
1313
/**
1414
* Complete API Blueprint
15+
*
1516
* @var string
1617
*/
1718
protected $full_apib;
1819

1920
/**
2021
* Location of the API Blueprint to parse
22+
*
2123
* @var string
2224
*/
2325
protected $location;
@@ -29,7 +31,7 @@ class ApibFileParser
2931
*/
3032
public function __construct($filename = 'index.apib')
3133
{
32-
$this->location = pathinfo($filename, PATHINFO_DIRNAME) . '/';
34+
$this->location = pathinfo($filename, PATHINFO_DIRNAME) . '/';
3335

3436
$this->full_apib = $this->get_apib($filename);
3537
}
@@ -49,16 +51,16 @@ function get_apib($filename)
4951
$matches = [];
5052
preg_match_all('<!-- include\(([a-z_.\/]*?).apib\) -->', $file, $matches);
5153
foreach ($matches[1] as $value) {
52-
$file = str_replace('<!-- include(' . $value . '.apib) -->', $this->get_apib($this->location . $value . '.apib'), $file);
54+
$file = str_replace('<!-- include(' . $value . '.apib) -->',
55+
$this->get_apib($this->location . $value . '.apib'), $file);
5356
}
5457

5558
return $file;
5659
}
5760

5861
private function file_check($filename)
5962
{
60-
if(!file_exists($filename))
61-
{
63+
if (!file_exists($filename)) {
6264
file_put_contents('php://stderr', "API File not found: $filename\n");
6365
exit(1);
6466
}

src/PHPDraft/Model/Category.php

+5-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Category extends HierarchyElement
1414
{
1515
/**
1616
* API Structure element
17+
*
1718
* @var DataStructureElement[]
1819
*/
1920
public $structures = [];
@@ -28,10 +29,8 @@ class Category extends HierarchyElement
2829
function parse($object)
2930
{
3031
parent::parse($object);
31-
foreach ($object->content as $key => $item)
32-
{
33-
switch ($item->element)
34-
{
32+
foreach ($object->content as $key => $item) {
33+
switch ($item->element) {
3534
case 'resource':
3635
$resource = new Resource($this);
3736
$this->children[] = $resource->parse($item);
@@ -42,12 +41,9 @@ function parse($object)
4241
$struct->deps = $deps;
4342
$struct->parse($item, $deps);
4443

45-
if (isset($item->content[0]->meta->id))
46-
{
44+
if (isset($item->content[0]->meta->id)) {
4745
$this->structures[$item->content[0]->meta->id] = $struct;
48-
}
49-
else
50-
{
46+
} else {
5147
$this->structures[] = $struct;
5248
}
5349

src/PHPDraft/Model/Elements/ArrayStructureElement.php

+17-14
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@
1313
class ArrayStructureElement extends DataStructureElement implements StructureElement
1414
{
1515

16+
/**
17+
* Type of objects in the array
18+
*
19+
* @var
20+
*/
21+
public $type_of;
22+
1623
public function parse($item, &$dependencies)
1724
{
1825
$this->element = (isset($item->element)) ? $item->element : 'array';
19-
$this->value = (isset($item->content)) ? $item->content : NULL;
26+
$this->value = (isset($item->content)) ? $item->content : null;
2027

21-
if (isset($item->content))
22-
{
23-
foreach ($item->content as $key => $sub_item)
24-
{
28+
if (isset($item->content)) {
29+
foreach ($item->content as $key => $sub_item) {
2530
$this->type[$key] = $sub_item->element;
26-
switch ($sub_item->element)
27-
{
31+
switch ($sub_item->element) {
2832
case 'array':
2933
$value = new ArrayStructureElement();
3034
$this->value[$key] = $value->parse($sub_item, $dependencies);
@@ -38,7 +42,7 @@ public function parse($item, &$dependencies)
3842
$this->value[$key] = $value->parse($sub_item, $dependencies);
3943
break;
4044
default:
41-
$this->value[$key] = (isset($sub_item->content)) ? $sub_item->content : NULL;
45+
$this->value[$key] = (isset($sub_item->content)) ? $sub_item->content : null;
4246
break;
4347
}
4448
}
@@ -49,18 +53,17 @@ public function parse($item, &$dependencies)
4953

5054
function __toString()
5155
{
52-
if (!is_array($this->type))
53-
{
56+
if (!is_array($this->type)) {
5457
return '';
5558
}
5659
$return = '<ul class="list-group">';
57-
foreach ($this->type as $key => $item)
58-
{
60+
foreach ($this->type as $key => $item) {
5961
$type =
60-
(in_array($item, self::DEFAULTS)) ? $item : '<a href="#object-' . str_replace(' ', '-', strtolower($item)) . '">' . $item . '</a>';
62+
(in_array($item, self::DEFAULTS)) ? $item : '<a href="#object-' . str_replace(' ', '-',
63+
strtolower($item)) . '">' . $item . '</a>';
6164

6265
$value =
63-
(isset($this->value[$key])) ? ': <span class="example-value pull-right">' . json_encode($this->value[$key]) . '</span>' : NULL;
66+
(isset($this->value[$key])) ? ': <span class="example-value pull-right">' . json_encode($this->value[$key]) . '</span>' : null;
6467

6568
$return .= '<li class="list-group-item">' . $type . $value . '</li>';
6669
}

0 commit comments

Comments
 (0)