From 0bd36707a511395450e1cd3d88fecf05c834371a Mon Sep 17 00:00:00 2001 From: lcahlander Date: Tue, 30 Nov 2021 13:38:34 -0500 Subject: [PATCH] Adding the display of the library function modules --- pom.xml | 2 +- src/main/js/frontend/package-lock.json | 4 +- src/main/js/frontend/package.json | 2 +- src/main/js/frontend/src/Layout.js | 4 +- src/main/js/frontend/src/LibraryModule.js | 55 ++++++++++- src/main/xar-resources/modules/xqdoc-lib.xqy | 97 +++++++++++++++++++- src/main/xquery/xqdoc-module.xqm | 19 +++- 7 files changed, 166 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index 0590507..f2f5991 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.xqdoc exist-xqdoc - 0.6.1 + 0.6.2 xqDoc Function Documentation Application and library to generate and display XQuery function documentation for eXist-db diff --git a/src/main/js/frontend/package-lock.json b/src/main/js/frontend/package-lock.json index 7d91966..ba2bb29 100644 --- a/src/main/js/frontend/package-lock.json +++ b/src/main/js/frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "xqDoc", - "version": "0.6.1", + "version": "0.6.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "xqDoc", - "version": "0.6.1", + "version": "0.6.2", "dependencies": { "@testing-library/jest-dom": "^5.15.1", "@testing-library/react": "^12.1.2", diff --git a/src/main/js/frontend/package.json b/src/main/js/frontend/package.json index 7444d13..340c7ee 100644 --- a/src/main/js/frontend/package.json +++ b/src/main/js/frontend/package.json @@ -1,6 +1,6 @@ { "name": "xqDoc", - "version": "0.6.1", + "version": "0.6.2", "private": true, "homepage": ".", "proxy": "http://localhost:8080/", diff --git a/src/main/js/frontend/src/Layout.js b/src/main/js/frontend/src/Layout.js index b870497..d9a7852 100644 --- a/src/main/js/frontend/src/Layout.js +++ b/src/main/js/frontend/src/Layout.js @@ -94,7 +94,7 @@ export default class Layout extends Component { - + - + diff --git a/src/main/js/frontend/src/LibraryModule.js b/src/main/js/frontend/src/LibraryModule.js index c294b98..ecb37b6 100644 --- a/src/main/js/frontend/src/LibraryModule.js +++ b/src/main/js/frontend/src/LibraryModule.js @@ -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 ( -

Library {libraryID}

+ 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 ? Loading + : +
+

Library {resultData.uri}

+ {resultData.comment ? resultData.comment.description : ""} +
+ {resultData.dummy ? + resultData.dummy.map((xqfunc) => { + return ( + + {resultData.name + ":" + xqfunc.name} + +
{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 : "")}
+ {xqfunc.comment ? xqfunc.comment.description : ""} + {xqfunc.comment.params.map((param) => { + return (
{param}
); + })} +
Returns:
+ {xqfunc.return.description} +
+
+ ) + }) + : "" + } +
+
); } diff --git a/src/main/xar-resources/modules/xqdoc-lib.xqy b/src/main/xar-resources/modules/xqdoc-lib.xqy index c2bab9b..368b2a0 100644 --- a/src/main/xar-resources/modules/xqdoc-lib.xqy +++ b/src/main/xar-resources/modules/xqdoc-lib.xqy @@ -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 } }, @@ -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": @@ -479,8 +479,9 @@ declare %output:method("json") function xq:app($appName as xs:string*) { - array { - } + array {( + + )} }; (:~ @@ -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) +}; diff --git a/src/main/xquery/xqdoc-module.xqm b/src/main/xquery/xqdoc-module.xqm index 0a24bd9..498a167 100644 --- a/src/main/xquery/xqdoc-module.xqm +++ b/src/main/xquery/xqdoc-module.xqm @@ -152,10 +152,6 @@ declare function xqutil:generate-internal-xqdoc($module as element(module)) { for $func in $module/function return - {if (fn:contains($func/@name/string(), ":")) - then fn:substring-after($func/@name/string(), ":") - else $func/@name/string() } - {xqutil:generate-signature($func)} {$func/description/string()} { @@ -174,6 +170,21 @@ declare function xqutil:generate-internal-xqdoc($module as element(module)) { () } + {if (fn:contains($func/@name/string(), ":")) + then fn:substring-after($func/@name/string(), ":") + else $func/@name/string() } + {xqutil:generate-signature($func)} + { + for $param in $func/argument + return + + ${$param/@var/string()} + {$param/@type/string()} + + } + + {$func/returns/@type/string()} + }