-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
220 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
import { apiModules, getDoc } from "../utils"; | ||
import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro"; | ||
import Value from "./value.astro"; | ||
import Type from "./type.astro"; | ||
const { moduleName, filePath, link } = Astro.props; | ||
const { types, typesInOwnModule, typeHeadings, values, valueHeadings } = | ||
await getDoc(filePath); | ||
const frontmatter = { | ||
title: moduleName, | ||
}; | ||
const headings = []; | ||
if (types.length > 0) { | ||
headings.push({ | ||
depth: 2, | ||
slug: "types", | ||
text: "Types", | ||
}); | ||
headings.push(...typeHeadings); | ||
} | ||
if (values.length > 0) { | ||
headings.push({ | ||
depth: 2, | ||
slug: "values", | ||
text: "Values", | ||
}); | ||
headings.push(...valueHeadings); | ||
} | ||
--- | ||
<StarlightPage frontmatter={frontmatter} headings={headings}> | ||
{ | ||
types.length > 0 && ( | ||
<> | ||
<h2 id="types">Types</h2> | ||
{types.map((type) => ( | ||
<Type | ||
type={type} | ||
typesInOwnModule={typesInOwnModule} | ||
filePath={filePath} | ||
link={link} | ||
/> | ||
))} | ||
</> | ||
) | ||
} | ||
{ | ||
values.length > 0 && ( | ||
<> | ||
<h2 id="values">Values</h2> | ||
{values.map((value) => <Value value={value} />)} | ||
</> | ||
) | ||
} | ||
</StarlightPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
--- | ||
import * as path from "node:path"; | ||
import { existsSync } from "node:fs"; | ||
import { Code } from "@astrojs/starlight/components"; | ||
import Record from "./record.astro"; | ||
import { createTypeModuleLink } from "../utils"; | ||
const { type, typesInOwnModule, filePath, link } = Astro.props; | ||
function showRecord(details) { | ||
return details && details.kind === "record" && details.items.length > 0; | ||
} | ||
function getModuleFileName(typeName) { | ||
return `${typeName[0].toUpperCase()}${typeName.slice(1)}`; | ||
} | ||
/** | ||
* Check if there is a file representing the module for the type. | ||
* The location to be checked is a sub directory with the same name as the current file type. | ||
* @param {string} typeName | ||
* @param {string} filePath | ||
* @returns {boolean} | ||
*/ | ||
function showModule(typeName, filePath) { | ||
const moduleFileName = `${getModuleFileName(typeName)}.res`; | ||
const potentialPath = path.join(filePath.replace(".res", ""), moduleFileName); | ||
return existsSync(potentialPath); | ||
} | ||
--- | ||
|
||
<div class="rescript_type"> | ||
<h3 id={type.name}>{type.name}</h3> | ||
<div set:html={type.documentation} /> | ||
<Code lang="ReScript" code={type.signature} /> | ||
{ | ||
showRecord(type.detail) ? ( | ||
<Record | ||
name={type.name} | ||
typesInOwnModule={typesInOwnModule} | ||
{...type.detail} | ||
/> | ||
) : null | ||
} | ||
{ | ||
showModule(type.name, filePath) && ( | ||
<> | ||
<h4>Module</h4> | ||
<p> | ||
There are methods and helpers defined in{" "} | ||
<a | ||
href={`${import.meta.env.BASE_URL}/${createTypeModuleLink(link, type.name)}`} | ||
> | ||
{getModuleFileName(type.name)} | ||
</a> | ||
. | ||
</p> | ||
</> | ||
) | ||
} | ||
</div> | ||
<style> | ||
.rescript_type { | ||
margin-block: 2rem; | ||
} | ||
</style> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.