Skip to content

Commit 2edb181

Browse files
committed
Include all readme files
1 parent eeecc76 commit 2edb181

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

src/PHPFUI/InstaDoc/NamespaceTree.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static function addNamespace(string $namespace, string $directory, bool $
100100
$file = \str_replace('//', '/', $file);
101101
$node->classes[$class] = $file;
102102
}
103-
elseif (\strpos($filename, '.md') == $filenameLength - 3)
103+
elseif (\str_ends_with($filename, '.md') || \str_ends_with($filename, '.MD'))
104104
{
105105
$node->md[$directory . '/' . $filename] = true;
106106
}

src/PHPFUI/InstaDoc/Section/Home.php

+11-7
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ public function generate(\PHPFUI\InstaDoc\PageInterface $page, string $fullClass
2424

2525
foreach (\PHPFUI\InstaDoc\NamespaceTree::getAllMDFiles() as $file)
2626
{
27-
if (\stripos($file, 'readme.md'))
28-
{
29-
$file = \str_replace('\\', '/', $file);
30-
$parts = \explode('/', \str_replace('.', '', $file));
31-
\array_pop($parts);
32-
$accordion->addTab(\implode('\\', $parts) . ' Readme', $parsedown->fileText($file));
33-
}
27+
$parts = \explode('/', \str_replace('\\', '/', $file));
28+
// remove the first part, which is ../
29+
\array_shift($parts);
30+
// $section is the file name
31+
$section = \array_pop($parts);
32+
// remove .md
33+
$section = \substr($section, 0, \strlen($section) - 3);
34+
// make more readable
35+
$section = \str_replace('_', ' ', \ucwords(\strtolower($section)));
36+
// proper case words
37+
$accordion->addTab(\implode('\\', $parts) . ' ' . $section, $parsedown->fileText($file));
3438
}
3539
$container->add($accordion);
3640

src/PHPFUI/InstaDoc/Section/Landing.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ public function generate(\PHPFUI\InstaDoc\PageInterface $page, string $namespace
2323
foreach ($files as $file)
2424
{
2525
$parts = \explode('/', \str_replace('\\', '/', $file));
26+
// $section is the file name
2627
$section = \array_pop($parts);
28+
// remove .md
29+
$section = \substr($section, 0, \strlen($section) - 3);
30+
// make more readable and proper case words
2731
$section = \str_replace('_', ' ', \strtolower($section));
28-
$section = \str_replace('.md', '', $section);
2932
$accordion->addTab(\ucwords($section), $parsedown->fileText($file));
3033
}
3134
$container->add($accordion);

tests/SectionTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ public function setUp() : void
4444
}
4545

4646
$this->fileManager = new \PHPFUI\InstaDoc\FileManager('./');
47+
$this->fileManager->excludeNamespace('cebe');
4748
$this->fileManager->addNamespace('PHPFUI', './src', true);
4849
$this->fileManager->rescan();
4950
$this->controller = new \PHPFUI\InstaDoc\Controller($this->fileManager);
50-
$this->controller->setGitFileOffset('/src');
51+
$this->controller->setGitFileOffset('src');
5152
}
5253

5354
public function testHaveSections() : void
@@ -76,6 +77,8 @@ public function testClassesGenerateValidHTML() : void
7677
foreach ([\PHPFUI\InstaDoc\Controller::DOC_PAGE, \PHPFUI\InstaDoc\Controller::FILE_PAGE, \PHPFUI\InstaDoc\Controller::GIT_PAGE] as $type)
7778
{
7879
$this->controller->setParameter(\PHPFUI\InstaDoc\Controller::PAGE, $type);
80+
$parts = \explode('\\', $section);
81+
$this->controller->setParameter(\PHPFUI\InstaDoc\Controller::CLASS_NAME, \array_pop($parts));
7982
$page = $this->controller->display(\PHPFUI\InstaDoc\Controller::VALID_CLASS_PAGES, $this->controller->getPage());
8083
$this->assertValidHtml("{$page}");
8184
$this->assertNotWarningHtml("{$page}");

0 commit comments

Comments
 (0)