Skip to content

Commit 5a59110

Browse files
author
Andrelec1
committed
✨ feat(All): rework menu, add doc
1 parent 099d95e commit 5a59110

File tree

11 files changed

+314
-29
lines changed

11 files changed

+314
-29
lines changed

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"build-inc": "node_modules/.bin/vik patch",
88
"build-tag": "(node -p \"require('./package.json').version\" | xargs git tag) && git push --tags",
99
"build-bump": "npm run build-inc && git add . && git commit -m '🔖 Version Bump' && git push --follow-tags",
10-
"dc-up": "docker-compose up --build"
10+
"dc:up": "docker-compose up --build",
11+
"dc:cmd": "docker exec -it docdocgenerator_php_1 bash"
1112
},
1213
"repository": {
1314
"type": "git",

public/Pages/DocDocGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
use App\DocumentGenerator;
4-
use App\Enum\TextAlign;
5-
use App\Model\Title\TitleElement;
3+
use DocGenerator\DocumentGenerator;
4+
use DocGenerator\Enum\TextAlign;
5+
use DocGenerator\Model\Title\TitleElement;
66

77
require dirname(__DIR__).'/../vendor/autoload.php';
88

public/Pages/Install.php

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,61 @@
11
<?php
22

3-
use App\DocumentGenerator;
4-
use App\Enum\TextAlign;
5-
use App\Enum\TextDecoration;
6-
use App\Model\Title\TitleElement;
3+
use DocGenerator\ContentModifier\PaginationModifier;
4+
use DocGenerator\DocumentGenerator;
5+
use DocGenerator\Enum\TextDecoration;
6+
use DocGenerator\Enum\TitleSize;
7+
use DocGenerator\Model\Code\SimpleCodeBlockElement;
8+
use DocGenerator\Model\Text\SimpleTextElement;
9+
use DocGenerator\Model\Title\TitleElement;
710

811
require dirname(__DIR__).'/../vendor/autoload.php';
912

1013
$document = new DocumentGenerator();
14+
$paginator = new PaginationModifier();
1115
$document->addElement(
1216
(new TitleElement('# Install'))
1317
->textDecorationStyle(TextDecoration::UNDERLINE)
1418
);
1519

20+
$document->addElements([
21+
(new TitleElement('Index'))
22+
->textDecorationStyle(TextDecoration::UNDERLINE)
23+
->titleSize(TitleSize::H2)
24+
->padding(1)
25+
->addContentModifier($paginator),
26+
(new SimpleTextElement('
27+
Create index.php like this:
28+
'))
29+
->padding(2),
30+
(new SimpleCodeBlockElement('
31+
use App\Kernel;
32+
33+
require dirname(__DIR__).\'/vendor/autoload.php\';
34+
35+
$documentation = new Kernel();
36+
37+
// Option here
38+
39+
$documentation->render();
40+
'
41+
))
42+
->padding(2),
43+
]
44+
);
45+
46+
$document->addElements([
47+
(new TitleElement('Title'))
48+
->textDecorationStyle(TextDecoration::UNDERLINE)
49+
->titleSize(TitleSize::H2)
50+
->padding(1)
51+
->addContentModifier($paginator),
52+
(new SimpleTextElement('Setup Documentation title with:'))
53+
->padding(2),
54+
(new SimpleCodeBlockElement('
55+
$documentation->setTitle(\'DocDocGenerator\');
56+
'))
57+
->padding(2),
58+
]
59+
);
60+
1661
$document->render();

public/Pages/Menu/Menu.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
use DocGenerator\DocumentGenerator;
4+
use DocGenerator\Enum\TextDecoration;
5+
use DocGenerator\Enum\TitleSize;
6+
use DocGenerator\Model\Code\SimpleCodeBlockElement;
7+
use DocGenerator\Model\List\SimpleListElement;
8+
use DocGenerator\Model\Text\SimpleTextElement;
9+
use DocGenerator\Model\Title\TitleElement;
10+
11+
require dirname(__DIR__).'/../../vendor/autoload.php';
12+
13+
$document = new DocumentGenerator();
14+
$document->addElement(
15+
(new TitleElement('# Menu'))
16+
->textDecorationStyle(TextDecoration::UNDERLINE)
17+
);
18+
19+
$document->addElement(
20+
(new TitleElement('MenuLink object:'))
21+
->textDecorationStyle(TextDecoration::UNDERLINE)
22+
->titleSize(TitleSize::H2)
23+
);
24+
25+
$document->addElement(
26+
(new SimpleTextElement('MenuLink Obj'))
27+
);
28+
$document->addElement((new SimpleCodeBlockElement('
29+
new MenuLink($name, ?$path);
30+
'
31+
)));
32+
$document->addElement(
33+
(new SimpleListElement())
34+
->addStringElement('$name: String Display in menu')
35+
->addStringElement('$path: Path to the file with ext (.php), if null link isn\'t clickable')
36+
);
37+
38+
$document->addElement(
39+
(new TitleElement('Adding menu:'))
40+
->textDecorationStyle(TextDecoration::UNDERLINE)
41+
->titleSize(TitleSize::H2)
42+
);
43+
44+
$document->addElement(
45+
(new SimpleTextElement('Adding MenuLink or Array of MenuLink to $documentation for generating documentation menu.'))
46+
);
47+
48+
$document->addElements([
49+
(new SimpleCodeBlockElement('
50+
$documentation->addMenuLink(
51+
new MenuLink(\'DocDocGenerator\', \'Pages/DocDocGenerator\'),
52+
);
53+
'
54+
)),
55+
(new SimpleCodeBlockElement('
56+
$documentation->addMenuLinks([
57+
new MenuLink(\'DocDocGenerator\', \'Pages/DocDocGenerator\'),
58+
new MenuLink(\'OtherPage\', \'Pages/OtherPage\'),
59+
]);
60+
'
61+
)),
62+
]);
63+
64+
$document->render();

public/Pages/Menu/SubMenu.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
use DocGenerator\DocumentGenerator;
4+
use DocGenerator\Enum\TextDecoration;
5+
use DocGenerator\Enum\TitleSize;
6+
use DocGenerator\Model\Code\SimpleCodeBlockElement;
7+
use DocGenerator\Model\List\SimpleListElement;
8+
use DocGenerator\Model\Text\SimpleTextElement;
9+
use DocGenerator\Model\Title\TitleElement;
10+
11+
require dirname(__DIR__).'/../../vendor/autoload.php';
12+
13+
$document = new DocumentGenerator();
14+
$document->addElement(
15+
(new TitleElement('# Menu'))
16+
->textDecorationStyle(TextDecoration::UNDERLINE)
17+
);
18+
19+
$document->addElement(
20+
(new TitleElement('subMenuLink:'))
21+
->textDecorationStyle(TextDecoration::UNDERLINE)
22+
->titleSize(TitleSize::H2)
23+
);
24+
25+
$document->addElement(
26+
(new SimpleTextElement("You can call ->addSubLink(\$menuLink) on MenuLink object to add subLink ...<br />
27+
SubLink is rendered with 20px padding."))
28+
);
29+
$document->addElement((new SimpleCodeBlockElement('
30+
(new MenuLink($name, ?$path))
31+
->addSubLink((new MenuLink($name, ?$path))
32+
->addSubLink(new MenuLink($name, ?$path))
33+
)
34+
;
35+
'
36+
)));
37+
38+
$document->render();

public/Pages/Pages.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
use DocGenerator\ContentModifier\PaginationModifier;
4+
use DocGenerator\DocumentGenerator;
5+
use DocGenerator\Enum\TextDecoration;
6+
use DocGenerator\Enum\TitleSize;
7+
use DocGenerator\Model\Code\SimpleCodeBlockElement;
8+
use DocGenerator\Model\Text\SimpleTextElement;
9+
use DocGenerator\Model\Title\TitleElement;
10+
11+
require dirname(__DIR__).'/../vendor/autoload.php';
12+
13+
$document = new DocumentGenerator();
14+
$paginator = new PaginationModifier();
15+
$document->addElement(
16+
(new TitleElement('# Use'))
17+
->textDecorationStyle(TextDecoration::UNDERLINE)
18+
);
19+
20+
$document->addElements([
21+
(new TitleElement('Pages'))
22+
->textDecorationStyle(TextDecoration::UNDERLINE)
23+
->titleSize(TitleSize::H2)
24+
->padding(1)
25+
->addContentModifier($paginator),
26+
(new SimpleTextElement('Create some page like this in sub-folder:'))
27+
->padding(2),
28+
(new SimpleCodeBlockElement('
29+
use DocGenerator\DocumentGenerator;
30+
use DocGenerator\Enum\TextAlign;
31+
use DocGenerator\Model\Title\TitleElement;
32+
33+
require dirname(__DIR__).\'/../vendor/autoload.php\';
34+
35+
$document = new DocumentGenerator();
36+
$document->addElement(
37+
(new TitleElement(\'DocDocGenerator\'))
38+
->textAlign(TextAlign::CENTER)
39+
);
40+
41+
$document->render();
42+
'))
43+
->padding(2),
44+
]
45+
);
46+
47+
48+
49+
$document->render();

public/index.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
<?php
22

33
use App\Kernel;
4+
use App\MenuLink;
45

56
require dirname(__DIR__).'/vendor/autoload.php';
67

78
$documentation = new Kernel();
89

910
$documentation->setTitle('DocDocGenerator');
10-
$documentation->loadMenu([
11-
'DocDocGenerator' => 'DocDocGenerator',
12-
'Install' => 'Install'
11+
12+
$documentation->addMenuLinks([
13+
new MenuLink('DocDocGenerator', 'Pages/DocDocGenerator'),
14+
new MenuLink('Install', 'Pages/Install'),
15+
new MenuLink('Pages', 'Pages/Pages'),
16+
(new MenuLink('Menu'))
17+
->addSubLink(new MenuLink('Menu', 'Pages/Menu/Menu'))
18+
->addSubLink(new MenuLink('SubMenu', 'Pages/Menu/SubMenu')),
1319
]);
1420

1521
$documentation->render();

src/Kernel.php

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,25 @@ class Kernel
1111
private string $title = '';
1212

1313
/**
14-
* @param array $menu
15-
* @return void
14+
* @param MenuLink $menuLink
15+
* @return $this
1616
*/
17-
public function loadMenu(array $menu): void
17+
public function addMenuLink(MenuLink $menuLink): self
1818
{
19-
$this->menu = $menu;
19+
$this->menu[] = $menuLink;
20+
21+
return $this;
22+
}
23+
24+
/**
25+
* @param array $menuLinks
26+
* @return $this
27+
*/
28+
public function addMenuLinks(array $menuLinks): self
29+
{
30+
array_push($this->menu, ...$menuLinks);
31+
32+
return $this;
2033
}
2134

2235
/**
@@ -41,14 +54,37 @@ private function getCurrentPage(): string
4154
* @param string $text
4255
* @param string $path
4356
* @return string
57+
* @throws \ReflectionException
4458
*/
45-
private function linkGenerator(string $text, string $path): string
59+
private function linkGenerator(MenuLink $menuLink, int $deep = 0): string
4660
{
47-
if ($path === $this->getCurrentPage()) {
48-
return sprintf('<a href="?page=%s" class="active">%s</a>',$path, $text);
61+
$reflectionMethod = new \ReflectionMethod(get_class($menuLink), 'getInfo');
62+
$reflectionMethod->setAccessible(true);
63+
$obj = $reflectionMethod->invoke($menuLink);
64+
65+
$paddingLeft = $deep > 0 ? 'style="padding-left: '. $deep * 30 + 8 .'px"' : '';
66+
67+
$balise = '';
68+
if ($obj['path'] === null ) {
69+
$balise = "<p $paddingLeft>" . $obj['name'] . '</p>';
70+
} else {
71+
$balise = "<a $paddingLeft";
72+
$balise .= 'href="?page=' . $obj['path'] . '" ';
73+
74+
if ($obj['path'] === $this->getCurrentPage()) {
75+
$balise .= ' class="active"';
76+
}
77+
$balise .= '>' . $obj['name'] . '</a>';
78+
}
79+
80+
$sublinks = '';
81+
if (count($obj['subLinks']) > 0) {
82+
foreach ($obj['subLinks'] as $subLink) {
83+
$sublinks .= $this->linkGenerator($subLink, $deep + 1);
84+
}
4985
}
5086

51-
return sprintf('<a href="?page=%s">%s</a>',$path, $text);
87+
return $balise . $sublinks;
5288
}
5389

5490
/**
@@ -57,7 +93,7 @@ private function linkGenerator(string $text, string $path): string
5793
private function contentGenerator(): string
5894
{
5995
$page = $this->getCurrentPage();
60-
$path = "Pages/$page.php";
96+
$path = "$page.php";
6197

6298
return sprintf('<iframe src="%s" frameborder="0" class="frame"></iframe>', $path);
6399
}
@@ -68,8 +104,8 @@ private function contentGenerator(): string
68104
private function menuGenerator(): string
69105
{
70106
$links = [];
71-
foreach ($this->menu as $title => $path) {
72-
$links[] = $this->linkGenerator($title, $path);
107+
foreach ($this->menu as $menuLink) {
108+
$links[] = $this->linkGenerator($menuLink);
73109
}
74110

75111
return implode('', $links);

0 commit comments

Comments
 (0)