Commit 88a78f16 authored by Jerome Chauveau's avatar Jerome Chauveau
Browse files

rm dumb tei, add bundle installe feature

parent b46e25f8
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -80,7 +80,8 @@ demo: ## Installation d'une édition de démo
		cp -r .max/fixtures/autoroute .;\
		cp -r .max/fixtures/config.xml .;\
		cp -r .max/fixtures/locales .;\
		echo 'demo installée.';\
		$(MAKE) init ;\
		echo 'Demo installée avec succès.';\
	fi
.PHONY: demo

@@ -138,6 +139,10 @@ feed: ## Insertion de sources XML
.PHONY: feed


init: check ## Initialisation à partir du fichier de configuration courant
	$(shell .max/basex/bin/basex -Q".max/resources/bundles-installer.xq")
.PHONY: init

help: ## Affiche cette aide
	@echo "\nChoisissez une commande. Les choix sont:\n"
	@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[0;36m%-12s\033[m %s\n", $$1, $$2}'
+0 −2
Original line number Diff line number Diff line
@@ -36,8 +36,6 @@ L'application est scindée en 2 blocs :
 - le cœur : déclaration des routes/fonctionnalités de base, accès aux sources xml et à la configuration, système de templating, traduction etc.
 - les bundles : chaque bundle ajoute une (ou des) fonctionnalité(s) à MaX.

Ce dépôt embarque `max-dumb-tei-bundle`, un bundle de vocabulaire d'exemple de gestion de l'affichage de sources XML.

Les sources XML à afficher doivent être stockées dans une base nommée `max`.

## Bundle de vocabulaire
+0 −24
Original line number Diff line number Diff line
xquery version "3.0";

import module namespace database = 'https://certic.unicaen.fr/max/database' at '../../../core/database.xqm';
import module namespace templating = 'https://certic.unicaen.fr/max/templating' at '../../../core/templating.xqm';
import module namespace i18n = 'https://certic.unicaen.fr/max/i18n' at '../../../core/i18n.xqm';
import module namespace utils = 'https://certic.unicaen.fr/max/utils' at '../../../core/utils.xqm';

declare variable $lang  external;

let $tdm :=
    <div>
        <h4>{i18n:translate('tdm',$lang)}</h4>
        <ul>{
        for $doc in collection($database:max-db)
            return <li><a href="{utils:get-document-route($doc, $lang)}">{$doc//*:title/text()}</a></li>
            }
        </ul>
        <p>
            Générée par <code>max-dumb-tei-bundle/autoroute/tdm.xq</code>
        </p>
    </div>

return
    templating:render('page.html', map{'content': $tdm, 'lang': $lang})
+0 −55
Original line number Diff line number Diff line
xquery version "3.0";

(:~
: MaX "dumb-tei" bundle
:)
module namespace dumb-tei = "https://certic.unicaen.fr/max/bundles/dumb-tei";

import module namespace templating = "https://certic.unicaen.fr/max/templating" at '../../../core/templating.xqm';
import module namespace i18n = "https://certic.unicaen.fr/max/i18n" at '../../../core/i18n.xqm';
import module namespace database = "https://certic.unicaen.fr/max/database" at '../../../core/database.xqm';
import module namespace errors = "https://certic.unicaen.fr/max/errors" at '../../../core/errors.xqm';

declare function dumb-tei:doc-to-html($document as document-node(), $lang as xs:string){
    (:generate random http link to an identified node in $document:)
    let $identifiers:= $document//*/@xml:id/string()
    let $n := count($identifiers)
    let $r := random:integer($n) + 1
    let $target := $identifiers[$r]
    let $href := fn:replace(request:path(),'.html', '') || '/id/' || $target || '.html'

    let $content := <div>
                        <h2>{i18n:translate('raw', $lang)} | {fn:replace(fn:base-uri($document), '/' || $database:max-db || '/', '')}</h2>
                        {$document}
                        <nav>
                            <h3><a href="{$href}">{i18n:translate('random-link', $lang)} ({$target})</a></h3>
                        </nav>
                    </div>
    return templating:render('page.html', map {'content': $content, 'lang': $lang})
};


(:~
 : @return an identified node as dumb html
 :)
declare
%rest:GET
%output:method("html")
%output:html-version("5.0")
%output:encoding("UTF-8")
%rest:path("/{$lang=[a-z]{2}}/{$docPath=.+}/id/{$id}.html")
function dumb-tei:id-to-html($lang as xs:string, $docPath as xs:string, $id as xs:string){
   try {
    let $node := database:get-element-by-id($docPath || '.xml', $id)
    let $content := <div>
                        <h1>id: {$id}</h1>
                        {
                            if($node) then $node else 'Node with id "' || $id || '" was not found'
                        }
                    </div>
    return templating:render('page.html', map {'content': $content, 'lang': $lang})
   }
   catch * {
        errors:error($err:code, $err:description, $err:line-number, $lang)
   }
};
+0 −13
Original line number Diff line number Diff line
<package xmlns="http://expath.org/ns/pkg"
         name="max-dumb-tei-bundle"
         abbrev="dumb-tei"
         version="0.0.1"
         spec="1.0">
   <dependency package="max"/>
   <title>MaX Dumb TEI Bundle</title>
   <home>https://git.unicaen.fr/pdn-certic/max-v2</home>
   <xquery>
      <namespace>https://certic.unicaen.fr/max/bundles/dumb-tei</namespace>
      <file>dumb-tei.xqm</file>
   </xquery>
</package>
 No newline at end of file
Loading