Skip to content

Commit 0bd3670

Browse files
committed
Adding the display of the library function modules
1 parent f5e35b0 commit 0bd3670

File tree

7 files changed

+166
-17
lines changed

7 files changed

+166
-17
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<groupId>org.xqdoc</groupId>
1515
<artifactId>exist-xqdoc</artifactId>
16-
<version>0.6.1</version>
16+
<version>0.6.2</version>
1717

1818
<name>xqDoc Function Documentation</name>
1919
<description>Application and library to generate and display XQuery function documentation for eXist-db</description>

src/main/js/frontend/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/js/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xqDoc",
3-
"version": "0.6.1",
3+
"version": "0.6.2",
44
"private": true,
55
"homepage": ".",
66
"proxy": "http://localhost:8080/",

src/main/js/frontend/src/Layout.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default class Layout extends Component {
9494
</Navbar.Collapse>
9595
</Navbar>
9696
<Container style={{marginTop: "70px"}} fluid>
97-
<Row xs={1}>
97+
<Row>
9898
<Col md={4} xl={3} xs={12} className="sidenav"
9999
>
100100
<TreeMenu
@@ -105,7 +105,7 @@ export default class Layout extends Component {
105105
}}
106106
/>
107107
</Col>
108-
<Col md={8} xl={7} xs={12} style={{marginLeft:450}}>
108+
<Col style={{marginLeft:450, marginRight: 20}}>
109109
<Outlet/>
110110
</Col>
111111
</Row>

src/main/js/frontend/src/LibraryModule.js

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,61 @@
11
import 'bootstrap/dist/css/bootstrap.min.css';
2-
import React from 'react';
2+
import React, { useEffect, useState } from 'react';
3+
import ReactMarkdown from "react-markdown";
4+
import {Card, Spinner} from "react-bootstrap";
35
import { useParams } from "react-router-dom";
46
import './App.css';
57

68
function LibraryModule() {
79
let {libraryID} = useParams();
8-
return (
9-
<h1>Library {libraryID}</h1>
10+
const [resultData, setResultData] = useState({});
11+
const [loading, setLoading] = useState(false);
12+
13+
useEffect(() => {
14+
setLoading(true);
15+
fetch("/exist/restxq/xqdoc/library/" + libraryID)
16+
.then((response) => response.json())
17+
.then(
18+
(result) => {
19+
setResultData(result.response);
20+
setLoading(false);
21+
},
22+
(error) => {
23+
setResultData({});
24+
setLoading(false);
25+
}
26+
);
27+
}, [libraryID]);
28+
return (loading ? <span><Spinner animation="grow" /> Loading</span>
29+
:
30+
<div style={{width: "100%"}}>
31+
<h1>Library {resultData.uri}</h1>
32+
<ReactMarkdown>{resultData.comment ? resultData.comment.description : ""}</ReactMarkdown>
33+
<div>
34+
{resultData.dummy ?
35+
resultData.dummy.map((xqfunc) => {
36+
return (
37+
<Card style={{width: "100%", marginBottom: 5}}>
38+
<Card.Header>{resultData.name + ":" + xqfunc.name}</Card.Header>
39+
<Card.Body>
40+
<div style={{width: "100%", border: "thin solid black", padding: 3, marginBottom: 3}}>{resultData.name + ":" + xqfunc.name + "(" +
41+
xqfunc.parameters.map((param) => {
42+
return param.name + " " + param.type + param.occurrence;
43+
}).join(", ")
44+
+ ") as " + xqfunc.return.type + (xqfunc.return.occurence ? xqfunc.return.occurence : "")}</div>
45+
<ReactMarkdown>{xqfunc.comment ? xqfunc.comment.description : ""}</ReactMarkdown>
46+
{xqfunc.comment.params.map((param) => {
47+
return (<div>{param}</div>);
48+
})}
49+
<div style={{marginTop: 5}}><b>Returns:</b></div>
50+
<ReactMarkdown>{xqfunc.return.description}</ReactMarkdown>
51+
</Card.Body>
52+
</Card>
53+
)
54+
})
55+
: ""
56+
}
57+
</div>
58+
</div>
1059
);
1160
}
1261

src/main/xar-resources/modules/xqdoc-lib.xqy

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ declare function xq:functions($functions as node()*, $module-path as xs:string)
127127
map {
128128
"name": fn:string-join($parameter/xqdoc:name/text(), " "),
129129
"type": fn:string-join($parameter/xqdoc:type/text(), " "),
130-
"occurrence": xq:occurrence($parameter/xqdoc:type),
130+
"occurrence": $parameter/xqdoc:type/@occurrence/string(),
131131
"description": $description
132132
}
133133
},
@@ -141,7 +141,7 @@ declare function xq:functions($functions as node()*, $module-path as xs:string)
141141
"occurrence":
142142
if (fn:string-length(xs:string($function/xqdoc:return/xqdoc:type)) gt 0)
143143
then
144-
xq:occurrence($function/xqdoc:return/xqdoc:type)
144+
$function/xqdoc:return/xqdoc:type/@occurrence/string()
145145
else
146146
"",
147147
"description":
@@ -479,8 +479,9 @@ declare
479479
%output:method("json")
480480
function xq:app($appName as xs:string*)
481481
{
482-
array {
483-
}
482+
array {(
483+
484+
)}
484485
};
485486

486487
(:~
@@ -617,3 +618,91 @@ $module as xs:string*
617618
fn:false()
618619
}
619620
};
621+
622+
declare function xq:module-content($doc as element(xqdoc:xqdoc)?)
623+
{
624+
let $module-comment := $doc/xqdoc:module/xqdoc:comment
625+
return
626+
map {
627+
"response":
628+
if ($doc)
629+
then
630+
let $decoded-module := fn:substring-after(fn:base-uri($doc), $xqutil:XQDOC_ROOT_COLLECTION)
631+
return
632+
map {
633+
"control": map {
634+
"date": $doc/xqdoc:control/xqdoc:date/text(),
635+
"version": $doc/xqdoc:control/xqdoc:version/text()
636+
},
637+
"comment": xq:comment($module-comment),
638+
"uri": $doc/xqdoc:module/xqdoc:uri/text(),
639+
"name":
640+
if ($doc/xqdoc:module/xqdoc:name)
641+
then
642+
$doc/xqdoc:module/xqdoc:name/text()
643+
else
644+
fn:false(),
645+
"dummy": array {(
646+
xq:variables($doc/xqdoc:variables/xqdoc:variable, $decoded-module),
647+
xq:imports($doc/xqdoc:imports/xqdoc:import),
648+
xq:functions($doc/xqdoc:functions/xqdoc:function, $decoded-module)
649+
)},
650+
"invoked":
651+
array {
652+
xq:invoked(
653+
$doc/xqdoc:module/xqdoc:invoked,
654+
$decoded-module,
655+
($doc/xqdoc:module/xqdoc:uri/text(), "http://www.w3.org/2005/xquery-local-functions")[1])
656+
},
657+
"refVariables":
658+
array {
659+
xq:ref-variables(
660+
$doc/xqdoc:module/xqdoc:ref-variable,
661+
$decoded-module,
662+
($doc/xqdoc:module/xqdoc:uri/text(), "http://www.w3.org/2005/xquery-local-functions")[1])
663+
},
664+
"variables":
665+
if ($doc/xqdoc:variables)
666+
then
667+
array {
668+
xq:variables($doc/xqdoc:variables/xqdoc:variable, $decoded-module)
669+
}
670+
else
671+
fn:false(),
672+
"imports":
673+
if ($doc/xqdoc:imports)
674+
then
675+
array {
676+
xq:imports($doc/xqdoc:imports/xqdoc:import)
677+
}
678+
else
679+
fn:false(),
680+
"functions":
681+
if ($doc/xqdoc:functions)
682+
then
683+
array {
684+
xq:functions($doc/xqdoc:functions/xqdoc:function, $decoded-module)
685+
}
686+
else
687+
fn:false(),
688+
"body": fn:string-join($doc/xqdoc:module/xqdoc:body/text(), " ")
689+
}
690+
else
691+
fn:false()
692+
}
693+
};
694+
695+
declare
696+
%rest:GET
697+
%rest:path("/xqdoc/library/{$tildedURI}")
698+
%rest:produces("application/json")
699+
%output:media-type("application/json")
700+
%output:method("json")
701+
function xq:get-lib(
702+
$tildedURI as xs:string*
703+
)
704+
{
705+
let $decoded-uri := if (fn:count($tildedURI) gt 0) then xmldb:decode(fn:replace($tildedURI[1], "~", "/")) else ""
706+
let $doc := fn:collection($xqutil:XQDOC_LIB_COLLECTION)//xqdoc:xqdoc[xqdoc:module/xqdoc:uri = $decoded-uri]
707+
return xq:module-content($doc)
708+
};

src/main/xquery/xqdoc-module.xqm

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ declare function xqutil:generate-internal-xqdoc($module as element(module)) {
152152
for $func in $module/function
153153
return
154154
<xqdoc:function>
155-
<xqdoc:name>{if (fn:contains($func/@name/string(), ":"))
156-
then fn:substring-after($func/@name/string(), ":")
157-
else $func/@name/string() }</xqdoc:name>
158-
<xqdoc:signature>{xqutil:generate-signature($func)}</xqdoc:signature>
159155
<xqdoc:comment>
160156
<xqdoc:description>{$func/description/string()}</xqdoc:description>
161157
{
@@ -174,6 +170,21 @@ declare function xqutil:generate-internal-xqdoc($module as element(module)) {
174170
()
175171
}
176172
</xqdoc:comment>
173+
<xqdoc:name>{if (fn:contains($func/@name/string(), ":"))
174+
then fn:substring-after($func/@name/string(), ":")
175+
else $func/@name/string() }</xqdoc:name>
176+
<xqdoc:signature>{xqutil:generate-signature($func)}</xqdoc:signature>
177+
<xqdoc:parameters>{
178+
for $param in $func/argument
179+
return
180+
<xqdoc:parameter>
181+
<xqdoc:name>${$param/@var/string()}</xqdoc:name>
182+
<xqdoc:type occurrence="{xqutil:cardinality($param/@cardinality)}">{$param/@type/string()}</xqdoc:type>
183+
</xqdoc:parameter>
184+
}</xqdoc:parameters>
185+
<xqdoc:return>
186+
<xqdoc:type occurence="{xqutil:cardinality($func/returns/@cardinality)}">{$func/returns/@type/string()}</xqdoc:type>
187+
</xqdoc:return>
177188
</xqdoc:function>
178189
}
179190
</xqdoc:functions>

0 commit comments

Comments
 (0)