-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
embed chisel documentation front-end application
- Loading branch information
craigahobbs@gmail.com
authored and
craigahobbs@gmail.com
committed
Sep 23, 2024
1 parent
7c7efa0
commit a78f126
Showing
10 changed files
with
188 additions
and
165 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Licensed under the MIT License | ||
# https://github.com/craigahobbs/chisel/blob/main/LICENSE | ||
|
||
include <args.mds> | ||
|
||
|
||
# The Chisel documentation application main entry point | ||
async function chiselDoc(): | ||
args = argsParse(chiselDocArguments) | ||
name = objectGet(args, 'name') | ||
if name != null: | ||
chiselDocRequestPage(name) | ||
else: | ||
chiselDocIndexPage() | ||
endif | ||
endfunction | ||
|
||
|
||
# The Chisel documentation application arguments | ||
chiselDocArguments = argsValidate(arrayNew( \ | ||
objectNew('name', 'name') \ | ||
)) | ||
|
||
|
||
# Render the Chisel documentation application index page | ||
async function chiselDocIndexPage(): | ||
# Fetch the documentation index API | ||
indexURL = 'doc_index' | ||
docIndexJSON = systemFetch(indexURL) | ||
docIndex = if(docIndexJSON != null, jsonParse(docIndexJSON)) | ||
if docIndex == null: | ||
markdownPrint('**Error:** Failed to fetch chisel index API "' + indexURL + '"') | ||
return | ||
endif | ||
title = objectGet(docIndex, 'title') | ||
groups = objectGet(docIndex, 'groups') | ||
|
||
# Render the index page | ||
documentSetTitle(title) | ||
markdownPrint('# ' + markdownEscape(title)) | ||
for groupName in arraySort(objectKeys(groups)): | ||
markdownPrint('', '## ' + markdownEscape(groupName)) | ||
for requestName in arraySort(objectGet(groups, groupName)): | ||
markdownPrint('', argsLink(chiselDocArguments, requestName, objectNew('name', requestName))) | ||
endfor | ||
endfor | ||
endfunction | ||
|
||
|
||
# Render the Chisel documentation application request page | ||
async function chiselDocRequestPage(typeName): | ||
# Fetch the request API | ||
requestURL = 'doc_request?name=' + urlEncodeComponent(typeName) | ||
docRequestJSON = systemFetch(requestURL) | ||
docRequest = if(docRequestJSON != null, jsonParse(docRequestJSON)) | ||
if docRequest == null: | ||
markdownPrint('**Error:** Failed to fetch chisel request API "' + requestURL + '"') | ||
return | ||
endif | ||
doc = objectGet(docRequest, 'doc') | ||
urls = objectGet(docRequest, 'urls') | ||
types = objectGet(docRequest, 'types') | ||
|
||
# Render the request page | ||
documentSetTitle(typeName) | ||
markdownPrint(argsLink(chiselDocArguments, 'Index', objectNew('name', null))) | ||
|
||
# Action request? | ||
if types != null: | ||
elementModelRender(schemaElements(types, typeName, urls)) | ||
return | ||
endif | ||
|
||
# Non-action request | ||
markdownPrint('', '# ' + markdownEscape(typeName)) | ||
if doc != null: | ||
markdownPrint('', doc) | ||
endif | ||
if urls != null && arrayLength(urls) > 0: | ||
markdownPrint('', '**Note:** The request is exposed at the following ' + if(arrayLength(urls) == 1, 'URL:', 'URLs:')) | ||
for requestURL in urls: | ||
method = objectGet(requestURL, 'method', '') | ||
path = objectGet(requestURL, 'path') | ||
markdownPrint('', ' [' + markdownEscape(method) + ' ' + markdownEscape(path) + '](' + path + ')') | ||
endfor | ||
endif | ||
endfunction |
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,51 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Chisel Documentation Application</title> | ||
<meta charset="UTF-8"> | ||
<meta name="description" content="Chisel Documentation Application"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="stylesheet" href="https://craigahobbs.github.io/markdown-up/app.css"> | ||
|
||
<!-- Preloads --> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/data.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/library.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/model.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/options.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/parser.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/runtime.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/runtimeAsync.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/value.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/element-model/lib/elementModel.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/app.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/dataTable.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/dataUtil.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/lineChart.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/script.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/scriptLibrary.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/markdown-model/lib/elements.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/markdown-model/lib/parser.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown-doc/lib/schemaMarkdownDoc.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/encode.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/parser.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/schema.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/schemaUtil.js" as="script"> | ||
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/typeModel.js" as="script"> | ||
<link rel="preload" href="https://craigahobbs.github.io/markdown-up/app.css" as="style"> | ||
<link rel="preload" href="https://craigahobbs.github.io/markdown-up/markdown-model/static/markdown-model.css" as="style"> | ||
</head> | ||
<body> | ||
</body> | ||
<script type="module"> | ||
import {MarkdownUp} from 'https://craigahobbs.github.io/markdown-up/lib/app.js'; | ||
const app = new MarkdownUp(window, { | ||
'markdownText': `\ | ||
~~~ markdown-script | ||
include 'chiselDoc.bare' | ||
chiselDoc() | ||
~~~ | ||
`}); | ||
app.run(); | ||
</script> | ||
</html> |
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
2 changes: 1 addition & 1 deletion
2
static/doc/test/testApp.mds → src/chisel/static/test/testChiselDoc.bare
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.