Commit 4b997dac authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

adds function documentation

parent 3aae2070
xquery version "3.1";
(:~
: This module provides an interface to DokuWiki, transforms and stores exported
: data including images from a configured wikispace. see config.xml.
:
: @author: Mathias Göbel
: @version: 1.0
: @see: https://fontane-nb.dariah.eu/doku.html
:)
module namespace wiki="http://textgrid.de/ns/SADE/wiki";
import module namespace config="http://textgrid.de/ns/SADE/config" at "../config/config.xqm";
......@@ -6,17 +14,30 @@ import module namespace config="http://textgrid.de/ns/SADE/config" at "../config
declare namespace http="http://expath.org/ns/http-client";
declare namespace xhtml="http://www.w3.org/1999/xhtml";
(:~
: returns the transformed wiki-text without a superior element (e.g. <div class="dokuwiki"/>)
: @param $id – a pagename in the wikispace according to config.xml
: @param $node – the current node form the html-template with context
: @param $model – the current execution model
:)
declare function wiki:include($node as node(), $model as map(*), $id as xs:string)
{
wiki:dokuwiki($node, $model, $id)/*
as node()* {
wiki:dokuwiki($node, $model, $id)/*
};
declare function wiki:dokuwiki($node as node(), $model as map(*), $id as xs:string) as node()* {
(:~
: returns the transformed wiki-text
: @param $id – a pagename in the wikispace according to config.xml
: @param $node – the current node form the html-template with context
: @param $model – the current execution model
:)
declare function wiki:dokuwiki($node as node(), $model as map(*), $id as xs:string)
as node()* {
(: replace id not in whitelist :)
let $id:= if($id = doc('/db/sade-projects/textgrid/data/xml/data/2shfj.xml')//text()) then $id else 'gesamtdokumentation'
(: trigger image reload :)
let $reload := if( request:get-parameter-names() = "reload" ) then local:dokuwikiImageReload($id, $model) else false()
(: test 4 new edits in DokuWiki :)
(: get last revision number stored here :)
let $lastRevinDb := local:dokuwikiGetLastRevInDb($id)
let $revisionInWiki := local:dokuwikiNewModification($id, $model, $lastRevinDb)
......@@ -39,10 +60,22 @@ let $doc :=
return
$result
return
<div id="dokuwiki">{$doc}</div>
element xhtml:div {
attribute class {
"dokuwiki",
$id
},
$doc
}
};
declare function local:dokuwikiGetLastRevInDb($id) {
(:~
: Gets the currently stored revision number in the database for a given id
: @param $id – a pagename in the wikispace according to config.xml
: @return the revision number stored in the database
:)
declare function local:dokuwikiGetLastRevInDb($id as xs:string)
as xs:string {
for $item in xmldb:get-child-resources('/sade-projects/textgrid/data/xml/doku/')
where substring-before($item, '.rev') = $id
return
......@@ -65,17 +98,23 @@ return
$lastRevinWiki
};
declare function local:HTML2html($node) {
for $node in $node
return
(:~
: Helper function to recursivly translate upper case element names to lower case
:)
declare function local:HTML2html($node as node())
as node() {
for $node in $node
return
typeswitch ( $node )
case element() return element { lower-case($node/local-name()) } { $node/@*, local:HTML2html($node/node()) }
case element() return
element { lower-case($node/local-name()) } { $node/@*, local:HTML2html($node/node()) }
default return $node
};
declare function local:dokuwikiparser($nodes as node()*){
local:dokuwikiparser($nodes, false())
};
declare function local:dokuwikiparser($nodes as node()*, $char as xs:boolean){
for $node in $nodes return
typeswitch($node)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment