Skip to content

Commit

Permalink
Adding the display of the library function modules
Browse files Browse the repository at this point in the history
  • Loading branch information
lcahlander committed Nov 30, 2021
1 parent f5e35b0 commit 0bd3670
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>org.xqdoc</groupId>
<artifactId>exist-xqdoc</artifactId>
<version>0.6.1</version>
<version>0.6.2</version>

<name>xqDoc Function Documentation</name>
<description>Application and library to generate and display XQuery function documentation for eXist-db</description>
Expand Down
4 changes: 2 additions & 2 deletions src/main/js/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/main/js/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xqDoc",
"version": "0.6.1",
"version": "0.6.2",
"private": true,
"homepage": ".",
"proxy": "http://localhost:8080/",
Expand Down
4 changes: 2 additions & 2 deletions src/main/js/frontend/src/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class Layout extends Component {
</Navbar.Collapse>
</Navbar>
<Container style={{marginTop: "70px"}} fluid>
<Row xs={1}>
<Row>
<Col md={4} xl={3} xs={12} className="sidenav"
>
<TreeMenu
Expand All @@ -105,7 +105,7 @@ export default class Layout extends Component {
}}
/>
</Col>
<Col md={8} xl={7} xs={12} style={{marginLeft:450}}>
<Col style={{marginLeft:450, marginRight: 20}}>
<Outlet/>
</Col>
</Row>
Expand Down
55 changes: 52 additions & 3 deletions src/main/js/frontend/src/LibraryModule.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,61 @@
import 'bootstrap/dist/css/bootstrap.min.css';
import React from 'react';
import React, { useEffect, useState } from 'react';
import ReactMarkdown from "react-markdown";
import {Card, Spinner} from "react-bootstrap";
import { useParams } from "react-router-dom";
import './App.css';

function LibraryModule() {
let {libraryID} = useParams();
return (
<h1>Library {libraryID}</h1>
const [resultData, setResultData] = useState({});
const [loading, setLoading] = useState(false);

useEffect(() => {
setLoading(true);
fetch("/exist/restxq/xqdoc/library/" + libraryID)
.then((response) => response.json())
.then(
(result) => {
setResultData(result.response);
setLoading(false);
},
(error) => {
setResultData({});
setLoading(false);
}
);
}, [libraryID]);
return (loading ? <span><Spinner animation="grow" /> Loading</span>
:
<div style={{width: "100%"}}>
<h1>Library {resultData.uri}</h1>
<ReactMarkdown>{resultData.comment ? resultData.comment.description : ""}</ReactMarkdown>
<div>
{resultData.dummy ?
resultData.dummy.map((xqfunc) => {
return (
<Card style={{width: "100%", marginBottom: 5}}>
<Card.Header>{resultData.name + ":" + xqfunc.name}</Card.Header>
<Card.Body>
<div style={{width: "100%", border: "thin solid black", padding: 3, marginBottom: 3}}>{resultData.name + ":" + xqfunc.name + "(" +
xqfunc.parameters.map((param) => {
return param.name + " " + param.type + param.occurrence;
}).join(", ")
+ ") as " + xqfunc.return.type + (xqfunc.return.occurence ? xqfunc.return.occurence : "")}</div>
<ReactMarkdown>{xqfunc.comment ? xqfunc.comment.description : ""}</ReactMarkdown>
{xqfunc.comment.params.map((param) => {
return (<div>{param}</div>);
})}
<div style={{marginTop: 5}}><b>Returns:</b></div>
<ReactMarkdown>{xqfunc.return.description}</ReactMarkdown>
</Card.Body>
</Card>
)
})
: ""
}
</div>
</div>
);
}

Expand Down
97 changes: 93 additions & 4 deletions src/main/xar-resources/modules/xqdoc-lib.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ declare function xq:functions($functions as node()*, $module-path as xs:string)
map {
"name": fn:string-join($parameter/xqdoc:name/text(), " "),
"type": fn:string-join($parameter/xqdoc:type/text(), " "),
"occurrence": xq:occurrence($parameter/xqdoc:type),
"occurrence": $parameter/xqdoc:type/@occurrence/string(),
"description": $description
}
},
Expand All @@ -141,7 +141,7 @@ declare function xq:functions($functions as node()*, $module-path as xs:string)
"occurrence":
if (fn:string-length(xs:string($function/xqdoc:return/xqdoc:type)) gt 0)
then
xq:occurrence($function/xqdoc:return/xqdoc:type)
$function/xqdoc:return/xqdoc:type/@occurrence/string()
else
"",
"description":
Expand Down Expand Up @@ -479,8 +479,9 @@ declare
%output:method("json")
function xq:app($appName as xs:string*)
{
array {
}
array {(

)}
};

(:~
Expand Down Expand Up @@ -617,3 +618,91 @@ $module as xs:string*
fn:false()
}
};

declare function xq:module-content($doc as element(xqdoc:xqdoc)?)
{
let $module-comment := $doc/xqdoc:module/xqdoc:comment
return
map {
"response":
if ($doc)
then
let $decoded-module := fn:substring-after(fn:base-uri($doc), $xqutil:XQDOC_ROOT_COLLECTION)
return
map {
"control": map {
"date": $doc/xqdoc:control/xqdoc:date/text(),
"version": $doc/xqdoc:control/xqdoc:version/text()
},
"comment": xq:comment($module-comment),
"uri": $doc/xqdoc:module/xqdoc:uri/text(),
"name":
if ($doc/xqdoc:module/xqdoc:name)
then
$doc/xqdoc:module/xqdoc:name/text()
else
fn:false(),
"dummy": array {(
xq:variables($doc/xqdoc:variables/xqdoc:variable, $decoded-module),
xq:imports($doc/xqdoc:imports/xqdoc:import),
xq:functions($doc/xqdoc:functions/xqdoc:function, $decoded-module)
)},
"invoked":
array {
xq:invoked(
$doc/xqdoc:module/xqdoc:invoked,
$decoded-module,
($doc/xqdoc:module/xqdoc:uri/text(), "http://www.w3.org/2005/xquery-local-functions")[1])
},
"refVariables":
array {
xq:ref-variables(
$doc/xqdoc:module/xqdoc:ref-variable,
$decoded-module,
($doc/xqdoc:module/xqdoc:uri/text(), "http://www.w3.org/2005/xquery-local-functions")[1])
},
"variables":
if ($doc/xqdoc:variables)
then
array {
xq:variables($doc/xqdoc:variables/xqdoc:variable, $decoded-module)
}
else
fn:false(),
"imports":
if ($doc/xqdoc:imports)
then
array {
xq:imports($doc/xqdoc:imports/xqdoc:import)
}
else
fn:false(),
"functions":
if ($doc/xqdoc:functions)
then
array {
xq:functions($doc/xqdoc:functions/xqdoc:function, $decoded-module)
}
else
fn:false(),
"body": fn:string-join($doc/xqdoc:module/xqdoc:body/text(), " ")
}
else
fn:false()
}
};

declare
%rest:GET
%rest:path("/xqdoc/library/{$tildedURI}")
%rest:produces("application/json")
%output:media-type("application/json")
%output:method("json")
function xq:get-lib(
$tildedURI as xs:string*
)
{
let $decoded-uri := if (fn:count($tildedURI) gt 0) then xmldb:decode(fn:replace($tildedURI[1], "~", "/")) else ""
let $doc := fn:collection($xqutil:XQDOC_LIB_COLLECTION)//xqdoc:xqdoc[xqdoc:module/xqdoc:uri = $decoded-uri]
return xq:module-content($doc)
};
19 changes: 15 additions & 4 deletions src/main/xquery/xqdoc-module.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ declare function xqutil:generate-internal-xqdoc($module as element(module)) {
for $func in $module/function
return
<xqdoc:function>
<xqdoc:name>{if (fn:contains($func/@name/string(), ":"))
then fn:substring-after($func/@name/string(), ":")
else $func/@name/string() }</xqdoc:name>
<xqdoc:signature>{xqutil:generate-signature($func)}</xqdoc:signature>
<xqdoc:comment>
<xqdoc:description>{$func/description/string()}</xqdoc:description>
{
Expand All @@ -174,6 +170,21 @@ declare function xqutil:generate-internal-xqdoc($module as element(module)) {
()
}
</xqdoc:comment>
<xqdoc:name>{if (fn:contains($func/@name/string(), ":"))
then fn:substring-after($func/@name/string(), ":")
else $func/@name/string() }</xqdoc:name>
<xqdoc:signature>{xqutil:generate-signature($func)}</xqdoc:signature>
<xqdoc:parameters>{
for $param in $func/argument
return
<xqdoc:parameter>
<xqdoc:name>${$param/@var/string()}</xqdoc:name>
<xqdoc:type occurrence="{xqutil:cardinality($param/@cardinality)}">{$param/@type/string()}</xqdoc:type>
</xqdoc:parameter>
}</xqdoc:parameters>
<xqdoc:return>
<xqdoc:type occurence="{xqutil:cardinality($func/returns/@cardinality)}">{$func/returns/@type/string()}</xqdoc:type>
</xqdoc:return>
</xqdoc:function>
}
</xqdoc:functions>
Expand Down

0 comments on commit 0bd3670

Please sign in to comment.