Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions build/src/php/FileGenerator/Application/ApiMarkdownGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,29 @@ public function generate(): array
{
$result = $this->zolaHeaders();

/** @var list<PhelFunction> $groupedPhelFns */
$groupedPhelFns = $this->apiFacade->getPhelFunctions();

foreach ($groupedPhelFns as $fn) {
$result[] = "## `{$fn->name()}`";
$result[] = "<small><strong>Namespace</strong> `{$fn->namespace()}`</small>";
$result[] = $fn->doc();
if ($fn->githubUrl() !== '') {
$result[] = sprintf('<small>[[View source](%s)]</small>', $fn->githubUrl());
}elseif ($fn->docUrl() !== '') {
$result[] = sprintf('<small>[[Read more](%s)]</small>', $fn->docUrl());
/** @var list<PhelFunction> $phelFns */
$phelFns = $this->apiFacade->getPhelFunctions();

$groupedByNamespace = [];
foreach ($phelFns as $fn) {
$groupedByNamespace[$fn->namespace()][] = $fn;
}

foreach ($groupedByNamespace as $namespace => $fns) {

$result[] = "";
$result[] = "---";
$result[] = "";
$result[] = "## `{$namespace}`";

foreach ($fns as $fn) {
$result[] = "### `{$fn->nameWithNamespace()}`";
$result[] = $fn->doc();
if ($fn->githubUrl() !== '') {
$result[] = sprintf('<small>[[View source](%s)]</small>', $fn->githubUrl());
} elseif ($fn->docUrl() !== '') {
$result[] = sprintf('<small>[[Read more](%s)]</small>', $fn->docUrl());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public function generateSearchIndex(): array
$anchor = $groupKey;
$groupFnNameAppearances[$groupKey]++;
} else {
$sanitizedFnName = str_replace(['/', ...self::SPECIAL_ENDING_CHARS], ['-', ''], $fn->fnName());
$sanitizedFnName = str_replace(['/', ...self::SPECIAL_ENDING_CHARS], ['-', ''], $fn->name());
$anchor = rtrim($sanitizedFnName, '-') . '-' . $groupFnNameAppearances[$groupKey]++;
}

$result[] = [
'id' => 'api_' . $fn->name(),
'fnName' => $fn->name(),
'fnSignature' => $fn->signature(),
'name' => $fn->nameWithNamespace(),
'signature' => $fn->signature(),
'desc' => $this->formatDescription($fn->description()),
'anchor' => $anchor,
'type' => 'api',
Expand Down
41 changes: 31 additions & 10 deletions build/tests/php/FileGenerator/Domain/ApiMarkdownGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public function test_generate_page_with_one_phel_function(): void
$apiFacade->method('getPhelFunctions')
->willReturn([
PhelFunction::fromArray([
'fnName' => 'function-1',
'name' => 'function-1',
'doc' => 'The doc from function 1',
'groupKey' => 'group-1',
'namespace' => 'ns-1',
]),
]);

Expand All @@ -52,7 +53,11 @@ public function test_generate_page_with_one_phel_function(): void
'aliases = [ "/api" ]',
'+++',
'',
'## `function-1`',
'',
'---',
'',
'## `ns-1`',
'### `ns-1/function-1`',
'The doc from function 1',
];

Expand All @@ -65,12 +70,14 @@ public function test_generate_page_with_multiple_phel_functions_in_same_group():
$apiFacade->method('getPhelFunctions')
->willReturn([
PhelFunction::fromArray([
'fnName' => 'function-1',
'name' => 'function-1',
'doc' => 'The doc from function 1',
'namespace' => 'core',
]),
PhelFunction::fromArray([
'fnName' => 'function-2',
'name' => 'function-2',
'doc' => 'The doc from function 2',
'namespace' => 'core',
]),
]);

Expand All @@ -84,9 +91,13 @@ public function test_generate_page_with_multiple_phel_functions_in_same_group():
'aliases = [ "/api" ]',
'+++',
'',
'## `function-1`',
'',
'---',
'',
'## `core`',
'### `function-1`',
'The doc from function 1',
'## `function-2`',
'### `function-2`',
'The doc from function 2',
];

Expand All @@ -99,12 +110,14 @@ public function test_generate_page_with_multiple_phel_functions_in_different_gro
$apiFacade->method('getPhelFunctions')
->willReturn([
PhelFunction::fromArray([
'fnName' => 'function-1',
'name' => 'function-1',
'doc' => 'The doc from function 1',
'namespace' => 'ns-1',
]),
PhelFunction::fromArray([
'fnName' => 'function-2',
'name' => 'function-2',
'doc' => 'The doc from function 2',
'namespace' => 'ns-2',
]),
]);

Expand All @@ -118,9 +131,17 @@ public function test_generate_page_with_multiple_phel_functions_in_different_gro
'aliases = [ "/api" ]',
'+++',
'',
'## `function-1`',
'',
'---',
'',
'## `ns-1`',
'### `ns-1/function-1`',
'The doc from function 1',
'## `function-2`',
'',
'---',
'',
'## `ns-2`',
'### `ns-2/function-2`',
'The doc from function 2',
];

Expand Down
88 changes: 44 additions & 44 deletions build/tests/php/FileGenerator/Domain/ApiSearchGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public function test_generate_search_index_one_item(): void
$apiFacade->method('getPhelFunctions')
->willReturn([
PhelFunction::fromArray([
'fnName' => 'table?',
'fnSignature' => '(table? x)',
'name' => 'table?',
'signature' => '(table? x)',
'desc' => 'doc for table?',
'groupKey' => 'table'
]),
Expand All @@ -30,8 +30,8 @@ public function test_generate_search_index_one_item(): void
$expected = [
[
'id' => 'api_table?',
'fnName' => 'table?',
'fnSignature' => '(table? x)',
'name' => 'table?',
'signature' => '(table? x)',
'desc' => 'doc for table?',
'anchor' => 'table',
'type' => 'api',
Expand All @@ -51,14 +51,14 @@ public function test_multiple_items_in_different_groups(): void
$apiFacade->method('getPhelFunctions')
->willReturn([
PhelFunction::fromArray([
'fnName' => 'table',
'fnSignature' => '(table & xs)',
'name' => 'table',
'signature' => '(table & xs)',
'desc' => 'doc for table',
'groupKey' => 'table',
]),
PhelFunction::fromArray([
'fnName' => 'not',
'fnSignature' => '(not x)',
'name' => 'not',
'signature' => '(not x)',
'desc' => 'doc for not',
'groupKey' => 'not',
]),
Expand All @@ -70,16 +70,16 @@ public function test_multiple_items_in_different_groups(): void
$expected = [
[
'id' => 'api_table',
'fnName' => 'table',
'fnSignature' => '(table & xs)',
'name' => 'table',
'signature' => '(table & xs)',
'desc' => 'doc for table',
'anchor' => 'table',
'type' => 'api',
],
[
'id' => 'api_not',
'fnName' => 'not',
'fnSignature' => '(not x)',
'name' => 'not',
'signature' => '(not x)',
'desc' => 'doc for not',
'anchor' => 'not',
'type' => 'api',
Expand All @@ -99,14 +99,14 @@ public function test_multiple_items_in_the_same_group(): void
$apiFacade->method('getPhelFunctions')
->willReturn([
PhelFunction::fromArray([
'fnName' => 'table',
'fnSignature' => '(table & xs)',
'name' => 'table',
'signature' => '(table & xs)',
'desc' => 'doc for table',
'groupKey' => 'table',
]),
PhelFunction::fromArray([
'fnName' => 'table?',
'fnSignature' => '(table? x)',
'name' => 'table?',
'signature' => '(table? x)',
'desc' => 'doc for table?',
'groupKey' => 'table',
]),
Expand All @@ -118,16 +118,16 @@ public function test_multiple_items_in_the_same_group(): void
$expected = [
[
'id' => 'api_table',
'fnName' => 'table',
'fnSignature' => '(table & xs)',
'name' => 'table',
'signature' => '(table & xs)',
'desc' => 'doc for table',
'anchor' => 'table',
'type' => 'api',
],
[
'id' => 'api_table?',
'fnName' => 'table?',
'fnSignature' => '(table? x)',
'name' => 'table?',
'signature' => '(table? x)',
'desc' => 'doc for table?',
'anchor' => 'table-1',
'type' => 'api',
Expand All @@ -147,14 +147,14 @@ public function test_fn_name_with_slash_in_the_middle(): void
$apiFacade->method('getPhelFunctions')
->willReturn([
PhelFunction::fromArray([
'fnName' => 'http/response',
'fnSignature' => '',
'name' => 'http/response',
'signature' => '',
'desc' => '',
'groupKey' => 'http-response',
]),
PhelFunction::fromArray([
'fnName' => 'http/response?',
'fnSignature' => '',
'name' => 'http/response?',
'signature' => '',
'desc' => '',
'groupKey' => 'http-response-1',
]),
Expand All @@ -166,16 +166,16 @@ public function test_fn_name_with_slash_in_the_middle(): void
$expected = [
[
'id' => 'api_http/response',
'fnName' => 'http/response',
'fnSignature' => '',
'name' => 'http/response',
'signature' => '',
'desc' => '',
'anchor' => 'http-response',
'type' => 'api',
],
[
'id' => 'api_http/response?',
'fnName' => 'http/response?',
'fnSignature' => '',
'name' => 'http/response?',
'signature' => '',
'desc' => '',
'anchor' => 'http-response-1',
'type' => 'api',
Expand All @@ -195,14 +195,14 @@ public function test_fn_name_ending_with_minus(): void
$apiFacade->method('getPhelFunctions')
->willReturn([
PhelFunction::fromArray([
'fnName' => 'defn',
'fnSignature' => '',
'name' => 'defn',
'signature' => '',
'desc' => '',
'groupKey' => 'defn',
]),
PhelFunction::fromArray([
'fnName' => 'defn-',
'fnSignature' => '',
'name' => 'defn-',
'signature' => '',
'desc' => '',
'groupKey' => 'defn',
]),
Expand All @@ -214,16 +214,16 @@ public function test_fn_name_ending_with_minus(): void
$expected = [
[
'id' => 'api_defn',
'fnName' => 'defn',
'fnSignature' => '',
'name' => 'defn',
'signature' => '',
'desc' => '',
'anchor' => 'defn',
'type' => 'api',
],
[
'id' => 'api_defn-',
'fnName' => 'defn-',
'fnSignature' => '',
'name' => 'defn-',
'signature' => '',
'desc' => '',
'anchor' => 'defn-1',
'type' => 'api',
Expand All @@ -243,14 +243,14 @@ public function test_fn_name_with_upper_case(): void
$apiFacade->method('getPhelFunctions')
->willReturn([
PhelFunction::fromArray([
'fnName' => 'NAN',
'fnSignature' => '',
'name' => 'NAN',
'signature' => '',
'desc' => '',
'groupKey' => 'nan',
]),
PhelFunction::fromArray([
'fnName' => 'nan?',
'fnSignature' => '',
'name' => 'nan?',
'signature' => '',
'desc' => '',
'groupKey' => 'nan',
]),
Expand All @@ -262,16 +262,16 @@ public function test_fn_name_with_upper_case(): void
$expected = [
[
'id' => 'api_NAN',
'fnName' => 'NAN',
'fnSignature' => '',
'name' => 'NAN',
'signature' => '',
'desc' => '',
'anchor' => 'nan',
'type' => 'api',
],
[
'id' => 'api_nan?',
'fnName' => 'nan?',
'fnSignature' => '',
'name' => 'nan?',
'signature' => '',
'desc' => '',
'anchor' => 'nan-1',
'type' => 'api',
Expand Down
Loading
Loading