Skip to content

Commit

Permalink
Merge pull request #104 from NaokiTsuchiya/hotfix/rel-path
Browse files Browse the repository at this point in the history
  • Loading branch information
koriym authored Nov 21, 2021
2 parents 849ee5c + 07ef94c commit da5e513
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
1 change: 0 additions & 1 deletion bin/asd
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ if ($status !== 0) {
echo 'Warning: Graphviz error. https://graphviz.org/download/' . PHP_EOL;
}

$ext = 'html';
$index = new IndexPage($profile, $config->outputMode);
file_put_contents($index->file, $index->content);
echo "ASD generated. {$index->file}" . PHP_EOL;
Expand Down
26 changes: 9 additions & 17 deletions src/IndexPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use function nl2br;
use function pathinfo;
use function sprintf;
use function str_replace;
use function strtoupper;
use function uasort;

Expand Down Expand Up @@ -40,8 +39,9 @@ public function __construct(Profile $profile, string $mode = DumpDocs::MODE_HTML
return $order[$a->type] <=> $order[$b->type];
});
$linkRelations = $this->linkRelations($profile->linkRelations);
$semantics = $this->semantics($descriptors);
$tags = $this->tags($profile->tags);
$ext = $mode === DumpDocs::MODE_MARKDOWN ? 'md' : DumpDocs::MODE_HTML;
$semantics = $this->semantics($descriptors, $ext);
$tags = $this->tags($profile->tags, $ext);
$htmlTitle = htmlspecialchars($profile->title);
$htmlDoc = nl2br(htmlspecialchars($profile->doc));
$profileImage = $mode === DumpDocs::MODE_HTML ? 'docs/asd.html' : 'profile.svg';
Expand All @@ -55,26 +55,18 @@ public function __construct(Profile $profile, string $mode = DumpDocs::MODE_HTML
* Semantic Descriptors
{$semantics}{$tags}{$linkRelations}
EOT;
$fileBase = sprintf('%s/index.', dirname($profile->alpsFile));
if ($mode === DumpDocs::MODE_MARKDOWN) {
$this->content = str_replace('.html', '.md', $md);
$this->file = $fileBase . 'md';

return;
}

$this->content = (new MdToHtml())('ALPS', $md);
$this->file = $fileBase . 'html';
$this->file = sprintf('%s/index.%s', dirname($profile->alpsFile), $ext);
$this->content = $mode === DumpDocs::MODE_MARKDOWN ? $md : (new MdToHtml())('ALPS', $md);
}

/**
* @param array<string, AbstractDescriptor> $semantics
*/
private function semantics(array $semantics): string
private function semantics(array $semantics, string $ext): string
{
$lines = [];
foreach ($semantics as $semantic) {
$href = sprintf('docs/%s.%s.html', $semantic->type, $semantic->id);
$href = sprintf('docs/%s.%s.%s', $semantic->type, $semantic->id, $ext);
$title = $semantic->title ? sprintf(', %s', $semantic->title) : '';
$lines[] = sprintf(' * [%s](%s) (%s)%s', $semantic->id, $href, $semantic->type, $title);
}
Expand All @@ -85,15 +77,15 @@ private function semantics(array $semantics): string
/**
* @param array<string, list<string>> $tags
*/
private function tags(array $tags): string
private function tags(array $tags, string $ext): string
{
if ($tags === []) {
return '';
}

$lines = [];
foreach ($tags as $tag => $item) {
$href = "docs/tag.{$tag}.html";
$href = "docs/tag.{$tag}.{$ext}";
$lines[] = " * [{$tag}]({$href})";
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/alps_has_single_link.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://alps-io.github.io/schemas/alps.json",
"alps": {
"link": {
"href": "https://github.com/koriym/app-state-diagram/",
"href": "https://github.com/koriym/app-state-diagram/index.html",
"rel": "about"
},
"descriptor": [
Expand Down
9 changes: 8 additions & 1 deletion tests/IndexPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ public function testLinkRelationsString(): void
{
$alpsFile = __DIR__ . '/Fake/alps_has_single_link.json';
$html = (new IndexPage(new Profile($alpsFile, new LabelName())))->content;
$this->assertStringContainsString('<li>rel: about <a rel="about" href="https://github.com/koriym/app-state-diagram/">https://github.com/koriym/app-state-diagram/</a></li>', $html);
$this->assertStringContainsString('<li>rel: about <a rel="about" href="https://github.com/koriym/app-state-diagram/index.html">https://github.com/koriym/app-state-diagram/index.html</a></li>', $html);
}

public function testLinkRelationsStringMarkdownMode(): void
{
$alpsFile = __DIR__ . '/Fake/alps_has_single_link.json';
$md = (new IndexPage(new Profile($alpsFile, new LabelName()), DumpDocs::MODE_MARKDOWN))->content;
$this->assertStringContainsString('* rel: about <a rel="about" href="https://github.com/koriym/app-state-diagram/index.html">https://github.com/koriym/app-state-diagram/index.html</a>', $md);
}

public function testMultipleLinkRelationsString(): void
Expand Down

0 comments on commit da5e513

Please sign in to comment.