From 1bed11637768e27275cc16562d8dc737461bda4c Mon Sep 17 00:00:00 2001 From: Uwe Sikora <sikora@sub.uni-goettingen.de> Date: Thu, 22 Feb 2018 07:56:04 +0100 Subject: [PATCH] added first version of presentation and analysisation modul --- modules/app.xql | 36 +++ modules/presentation/presentation.xqm | 442 ++++++++++++++++++++++++++ presentation.html | 11 + resources/css/presentation.if.css | 25 ++ templates/page.html | 6 +- templates/test.html | 7 + 6 files changed, 526 insertions(+), 1 deletion(-) create mode 100644 modules/presentation/presentation.xqm create mode 100644 presentation.html create mode 100644 resources/css/presentation.if.css create mode 100644 templates/test.html diff --git a/modules/app.xql b/modules/app.xql index 27ce3bc..9de8f72 100644 --- a/modules/app.xql +++ b/modules/app.xql @@ -1,9 +1,13 @@ xquery version "3.1"; module namespace app="http://bdn-edition.de/intermediate_format/templates"; +declare namespace tei = "http://www.tei-c.org/ns/1.0"; import module namespace templates="http://exist-db.org/xquery/templates" ; import module namespace config="http://bdn-edition.de/intermediate_format/config" at "config.xqm"; +import module namespace presentation="http://bdn-edition.de/intermediate_format/presentation" at "presentation/presentation.xqm"; +import module namespace pre="http://bdn.edition.de/intermediate_format/preprocessing" at "intermediate_format/preprocessing.xqm"; +import module namespace ident = "http://bdn.edition.de/intermediate_format/identification" at "intermediate_format/identification.xqm"; (:~ : This is a sample templating function. It will be called by the templating module if @@ -17,4 +21,36 @@ import module namespace config="http://bdn-edition.de/intermediate_format/config declare function app:test($node as node(), $model as map(*)) { <p>Dummy template output generated by function app:test at {current-dateTime()}. The templating function was triggered by the data-template attribute <code>data-template="app:test"</code>.</p> +}; + + +declare + %templates:wrap + %templates:default("doc", "/db/apps/interformat/data/samples/samples4.xml") +function app:present($node as node(), $model as map(*), $doc) { + <div class="serialisation"> + { + let $nodes := doc($doc) + let $preprocessed-data := pre:preprocessing($nodes/tei:TEI) + let $intermediate-format := ident:walk($preprocessed-data, ()) + return + presentation:tei-body($intermediate-format) + } + </div> +}; + + +declare + %templates:wrap + %templates:default("doc", "/db/apps/interformat/data/samples/samples4.xml") +function app:tei-metadata($node as node(), $model as map(*), $doc) { + let $tei-header := doc($doc)//tei:teiHeader + return + <div class="metadata"> + <div class="value"> + <div><strong>uri:</strong></div> + <div>{ base-uri(doc($doc)) }</div> + </div> + {presentation:tei-header($tei-header)} + </div> }; \ No newline at end of file diff --git a/modules/presentation/presentation.xqm b/modules/presentation/presentation.xqm new file mode 100644 index 0000000..5c27361 --- /dev/null +++ b/modules/presentation/presentation.xqm @@ -0,0 +1,442 @@ +xquery version "3.0"; +(:~ + : PRESENTATION Module ("presentation", "http://bdn-edition.de/intermediate_format/presentation") + : ******************************************************************************************* + : This module contains presentation functions for the intermediate format web-app + : + : @version 1.0 (2018-02-21) + : @status development + : @author Uwe Sikora + :) +module namespace presentation="http://bdn-edition.de/intermediate_format/presentation"; + +declare namespace tei="http://www.tei-c.org/ns/1.0"; + + +(:############################# Modules Functions #############################:) + +(:~ + : presentation:html + : html presentation of an intermediate-format xml document + : + : @param $nodes the nodes to be converted + : @return item()* representing the converted node + : + : @version 1.2 (2017-10-15) + : @status working + : @author Uwe Sikora + :) +declare function presentation:tei-body + ($nodes as node()*) as item()* { + + for $node in $nodes + return + typeswitch($node) + case processing-instruction() return () + case comment() return ( $node ) + case text() return ( + $node + ) + + case element(tei:abbr) return () + + case element(tei:aligned) return ( + element{"span"}{ + attribute {"style"}{"display:block"}, + attribute {"class"}{"aligned ble"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:app) return ( + presentation:tei-body($node/node()) + ) + + case element(tei:body) return ( + element{"div"}{ + attribute {"class"}{"body"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:byline) return ( + element{"div"}{ + attribute {"class"}{"byline"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:choice) return ( + presentation:tei-body($node/node()) + ) + + case element(tei:div) return ( + element{"div"}{ + attribute {"class"}{"div ble"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:docAuthor) return ( + element{"div"}{ + attribute {"class"}{"docAuthor ble"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:docDate) return ( + element{"span"}{ + attribute {"class"}{"docDate"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:docEdition) return ( + element{"div"}{ + attribute {"class"}{"docEdition ble"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:docImprint) return ( + element{"div"}{ + attribute {"class"}{"docImprint ble"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:expan) return ( + element{"span"}{ + attribute {"class"}{"expan"}, +(: attribute {"data-tooltip"}{data($node/following-sibling::tei:abbr)},:) + presentation:tei-body($node/node()) + } + ) + + case element(tei:head) return ( + let $hierarchies := $node/ancestor::node()[name() = "div" or name() = "list" or name() = "table"] + let $count := count($hierarchies)+1 + return + element{concat("h", $count)}{ + attribute {"class"}{"head ble"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:hi) return ( + element{"span"}{ + attribute {"class"}{"hi"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:index) return () + + case element(tei:item) return ( + element{"li"}{ + attribute {"class"}{"item ble"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:l) return ( + element{"span"}{ + attribute {"class"}{"l"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:label) return ( + element{"span"}{ + attribute {"class"}{"label"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:lb) return ( + element{"br"}{} + ) + + case element(tei:lem) return ( + presentation:tei-body($node/node()) + ) + + case element(tei:list) return ( + element{"ul"}{ + attribute {"class"}{"list ble"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:milestone) return ( + presentation:tei-body($node/node()) + ) + + case element(tei:note) return ( + element{"p"}{ + attribute {"class"}{"note ble"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:p) return ( + element{"p"}{ + attribute {"class"}{"p ble"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:pb) return ( + "|", <sup>{$node/string(@wit), $node/string(@n)}</sup> + ) + + case element(tei:persName) return ( + element{"span"}{ + attribute {"class"}{"persName"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:rdg) return ( + presentation:rdg($node) + ) + + case element(tei:rdgMarker) return ( + element {"span"}{ + attribute {"class"}{"rdgMarker"}, + presentation:rdgMarker($node) + } + ) + + case element(tei:seg) return ( + element{"span"}{ + attribute {"class"}{"seg"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:text) return ( + element{"div"}{ + attribute {"class"}{"text"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:TEI) return ( + element{"div"}{ + attribute {"class"}{"tei"}, + presentation:tei-body($node/tei:text) + } + ) + + case element(tei:titlePage) return ( + element{"div"}{ + attribute {"class"}{"titlePage"}, + presentation:tei-body($node/node()) + } + ) + + case element(tei:titlePart) return ( + element{"div"}{ + attribute {"class"}{"titlePart ble"}, + presentation:tei-body($node/node()) + } + ) + + default return ( + element {"span"}{ + attribute {"style"}{"background:orange"}, + $node/name(), ": ", + element{$node/name()}{ + $node/@*, + presentation:tei-body($node/node()) + } + } + ) +}; + + +(:~ + : presentation:rdgMarker + : html presentation of an intermediate-format xml document + : + : @param $nodes the nodes to be converted + : @return item()* representing the converted node + : + : @version 1.2 (2017-10-15) + : @status working + : @author Uwe Sikora + :) +declare function presentation:rdgMarker + ( $marker as node() ) as item()* { + + let $wit := replace( $marker/string(@wit), " ", "" ) + let $type := data($marker/@type) + let $mark := data($marker/@mark) + let $context := data($marker/@context) + + return + if ( $marker[@type="pt" and @context="lem"] ) then ( + if ($marker[@mark="open"]) then ( + <span class="pt open lem">{concat("/", $wit)}</span> + ) + else ( + <span class="pt closeing lem">{concat($wit, "\")}</span> + ) + + ) + + else if ( $marker[@type="ptl" and @context="lem"] ) then ( + if ($marker[@mark="open"]) then ( + <span class="ptl open lem">{concat("/", $wit)}</span> + ) + else ( + <span class="ptl closeing lem">{concat($wit, "\||", $wit)}</span> + ) + + ) + + else if ( $marker[@type="ptl" and @context="rdg"] ) then ( + if ($marker[@mark="open"]) then ( + <sup>{$wit}</sup> + ) + else ( + <sup>{$wit}</sup> + ) + + ) + + else if ( $marker[@type="pp" and @context="lem"] ) then ( + if ($marker[@mark="open"]) then ( + <span class="pp open lem">{concat("~/", $wit)}</span> + ) + else ( + <span class="pp closeing lem">{concat($wit, "\~")}</span> + ) + + ) + + else if ( $marker[@type="ppl" and @context="lem"] ) then ( + if ($marker[@mark="open"]) then ( + <span class="ppl open lem">{concat("~/", $wit)}</span> + ) + else ( + <span class="ppl closeing lem">{concat($wit, "\~||", $wit)}</span> + ) + ) + + else if ( $marker[@type="ppl" and @context="rdg"] ) then ( + if ($marker[@mark="open"]) then ( + <sup>{$wit}</sup> + ) + else ( + <sup>{$wit}</sup> + ) + + ) + + else if ( $marker[@type="v"] ) then ( + if ($marker[@mark="open"]) then ( + ) + else ( + <sup>{$wit}</sup> + ) + + ) + + else if ( $marker[@type="om"] ) then ( + if ($marker[@mark="open"]) then ( + <span class="om open">{$wit}</span> + ) + else ( + <span class="om closeing">{$wit}</span> + ) + + ) + + else ( + element {"span"}{ + attribute {"style"}{"background:orange"}, + $marker/name(), ": ", + element{$marker/name()}{ + $marker/@*, + presentation:tei-body($marker/node()) + } + } + ) +}; + + +(:~ + : presentation:rdgMarker + : html presentation of an intermediate-format xml document + : + : @param $nodes the nodes to be converted + : @return item()* representing the converted node + : + : @version 1.2 (2017-10-15) + : @status working + : @author Uwe Sikora + :) +declare function presentation:rdg + ( $rdg as node() ) as item()* { + + if ( $rdg[@type = "pt" or @type = "pp" or @type = "v" or @type="om"] ) then ( + ) + + else ( + presentation:tei-body($rdg/node()) + ) +}; + + + +(:~ + : presentation:html + : html presentation of an intermediate-format xml document + : + : @param $nodes the nodes to be converted + : @return item()* representing the converted node + : + : @version 1.2 (2017-10-15) + : @status working + : @author Uwe Sikora + :) +declare function presentation:tei-header + ($nodes as node()*) as item()* { + + for $node in $nodes + return + typeswitch($node) + case processing-instruction() return () + case comment() return ( $node ) + case text() return ( + $node + ) + + case element(tei:teiHeader) return ( + presentation:tei-header($node/node()) + ) + + case element(tei:fileDesc) return ( + presentation:tei-header($node/node()) + ) + + case element(tei:titleStmt) return ( + presentation:tei-header($node/node()) + ) + + case element(tei:title) return ( + if ($node[@level]) then ( + <div class="value"> + <div><strong>title:</strong></div> + <div>{ presentation:tei-header($node/node()) }</div> + </div> + ) else ( + presentation:tei-header($node/node()) + ) + ) + + + default return () +}; diff --git a/presentation.html b/presentation.html new file mode 100644 index 0000000..ffa22fe --- /dev/null +++ b/presentation.html @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content"> + <div class="col-md-9"> + <h1>Intermediate Format - Presentation</h1> + <div data-template="app:present"/> + </div> + <div class="col-md-3"> + <h2>Metadata</h2> + <div data-template="app:tei-metadata"/> + </div> +</div> \ No newline at end of file diff --git a/resources/css/presentation.if.css b/resources/css/presentation.if.css new file mode 100644 index 0000000..0b870bb --- /dev/null +++ b/resources/css/presentation.if.css @@ -0,0 +1,25 @@ +/* Intermediate formate presentation styles go here */ + +.ble { + display: block; + background: #E9E8E9; +} + +span.label { + font-size: 100%; + color: #000000; +} + +span.rdgMarker { + font-weight: bold; + font-size: 16px; +} + +span.rdgMarker .om.open::before, span.rdgMarker .om.closeing::after { + content: "om"; + background: #FA81FE; + vertical-align: super; + font-size: 70%; + padding-left: 2px; + padding-right: 2px; +} \ No newline at end of file diff --git a/templates/page.html b/templates/page.html index acb068f..318d83e 100644 --- a/templates/page.html +++ b/templates/page.html @@ -6,7 +6,8 @@ <meta data-template="config:app-meta"/> <link rel="shortcut icon" href="$shared/resources/images/exist_icon_16x16.ico"/> <link rel="stylesheet" type="text/css" href="$shared/resources/css/exist-2.2.css"/> - <link rel="stylesheet" type="text/css" href="resources/css/style.css"/> + <link rel="stylesheet" type="text/css" href="$resources/css/style.css"/> + <link rel="stylesheet" type="text/css" href="$resources/css/presentation.if.css"/> <script type="text/javascript" src="$shared/resources/scripts/jquery/jquery-1.7.1.min.js"/> <script type="text/javascript" src="$shared/resources/scripts/bootstrap-3.0.3.min.js"/> <script type="text/javascript" src="$shared/resources/scripts/loadsource.js"/> @@ -37,6 +38,9 @@ </li> </ul> </li> + <li class="dropdown" id="about"> + <a href="output.html">Output</a> + </li> </ul> </div> </nav> diff --git a/templates/test.html b/templates/test.html new file mode 100644 index 0000000..dbde11e --- /dev/null +++ b/templates/test.html @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="../index.html" data-template-at="index-body"> + <div class="col-md-9"> + <h1>Test</h1> + <div data-template="app:present"/> + </div> +</div> \ No newline at end of file -- GitLab