Commit cbab0ae5 authored by Jerome Chauveau's avatar Jerome Chauveau
Browse files

Merge branch 'jc/dev-as-bundle' into jc/bundle-improve

parents 88a78f16 80856446
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ Exemple de configuration minimale :
Il contient le serveur BaseX. C'est un dossier (caché) purement technique dans lequel l'utilisateur n'aura pas (et ne devra pas) intervenir.


## Lien symbolique dans un environnement de développement
## Lien symbolique dans un environnement de développement du core

- `.max/basex/webapp/max/` pointe vers  `src/main`

@@ -108,8 +108,7 @@ Elles sont déclarées dans le fichier `src/main/core/routes.xqm` :
  - sinon, exécute la fonction `${bundle_vocabulaire}:doc-to-html` du bundle de vocabulaire actif (transformation de la source `{$page}.xml`)
  Par exemple, si `max-dumb-tei-bundle` est actif, la route `/fr/tdm.html` retourne le résultat de `.max/basex/webapp/max/bundles/max-dumb-tei-bundle/autoroute/tdm.xq`
- `/sources.zip` : archive zip contenant les sources XML
- `/about.html` : affiche les informations de configuration et d'environnement (disponible uniquement en mode `dev`)
- `/doc/functions.html` : documentation API XQuery de MaX (disponible uniquement en mode `dev`)


## Organisation d'un corpus numérique

+12 −0
Original line number Diff line number Diff line
Bundle max-dev
====

Fonctionnalités actives uniquement en environnement "dev".

```xml
<configuation env="dev"...>...</configuration>
```

## Routes
- `/bundles/max-dev/index.html` : affiche les informations de configuration et d'environnement
- `/bundles/max-dev/doc.html` : documentation API XQuery de MaX
 No newline at end of file
+163 −0
Original line number Diff line number Diff line
xquery version "3.0";

(:~
: MaX dev
:)

module namespace max-dev = 'https://certic.unicaen.fr/max/max-dev';
import module namespace database = 'https://certic.unicaen.fr/max/database' at '../../core/database.xqm';
import module namespace conf = 'https://certic.unicaen.fr/max/conf' at '../../core/conf.xqm';
import module namespace errors = 'https://certic.unicaen.fr/max/errors' at '../../core/errors.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';


(:~ Returns MaX technicals information - only in a dev environment
 : @return HTML page
 :)
declare
%rest:GET
%output:method("html")
%output:html-version('5')
%rest:path("/bundles/max-dev/index.html")
function max-dev:index() as element(){
    if(conf:is-dev-mode())
    then
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
            <meta charset="UTF-8"/>
            <title>MaX - infos</title>
            <link rel='stylesheet' type='text/css' href='static/max.css'/>
        </head>
        <body>

            <h1> <a href="/{$conf:default-lang}/pages/index.html">MaX</a></h1>
            <h2>Version <code>{conf:get-max-version()}</code></h2>
            <h3>BaseX {db:system()//*:version}</h3>
            <section>
                <h2>Base de données XML <strong>{$database:max-db} </strong></h2>
                    {if(db:exists($database:max-db))
                        then
                            <div>
                                <ul>{
                                for $d in db:list($database:max-db)
                                return <li>{$d}</li>
                                }</ul>
                            </div>
                        else <span style='color:red;'> NOK</span>
                    }
            </section>
            {max-dev:configuration-as-html()}
            <section>
                <h2>Contexte</h2>
                <ul>
                    <li><strong>file:current-dir </strong> {file:current-dir()}</li>
                    <li><strong>file:base-dir </strong> {file:base-dir()}</li>
                </ul>
            </section>
            <section>
                <h2>Locales</h2>
                <ul>
                 {for $p in i18n:getLocalePaths()
                    return <li>{$p}</li>
                 }
                 </ul>
            </section>
            <section>
                <h2>Bundles</h2>
                <ul>
                    {
                        for $b in file:list(utils:get-bundles-path())
                            let $name := replace($b,'/','')
                            let $enabled := not(file:exists(utils:get-bundles-path() || $b || '.ignore'))

                            return if($enabled) 
                                    then 
                                        <li>{$name} <input 
                                                    type="checkbox" 
                                                    checked="checked" 
                                                    title="désactiver le bundle" 
                                                    onclick="fetch('/setbundle?enabled=' + this.checked + '&amp;bundle={$name}').then(() => window.location.reload(true));"/></li>
                                    else <li>{$name} <input 
                                                    type="checkbox" 
                                                    title="activer le bundle" 
                                                    onclick="fetch('/setbundle?enabled=' + this.checked + '&amp;bundle={$name}').then(() => window.location.reload(true));"/></li>                                
                    }
                </ul>
            </section>
            <section>
                <h2>Routes</h2>
                {max-dev:route-list()}
            </section>

            <section>
                <h2>Documentation</h2>
                <div>
                    <a href="/bundles/max-dev/doc.html">Consulter l'API XQuery de MaX</a>
                </div>
            </section>
        </body>
    </html>
    else errors:not-found('', $conf:default-lang)
};


(:~
 : MaX functions documentation.
 : Returns an HTML documentation for MaX Xqueries functions.
 : @return HTML page
 :)
declare
%rest:GET
%output:method("html")
%output:html-version('5')
%rest:path("/bundles/max-dev/doc.html")
function max-dev:functions-documentation(){
    if(conf:is-dev-mode())
    then
        let $toIgnore := ('globals.xqm','markdown.xqm')
        let $packageDoc := doc(conf:get-package-file-path())
        let $xqDocs := <div>{for $module in $packageDoc//*:xquery/*:file where not(string($module) = $toIgnore)
                        return inspect:xqdoc(db:option('webpath') || '/max/core/' || string($module))
                    }
                    </div>

        return xslt:transform($xqDocs, doc(utils:get-bundles-path()  || 'max-dev/doc-2-html.xsl'))
    else errors:not-found('', $conf:default-lang)
};


declare %private function max-dev:configuration-as-html() as element(){
    let $config := conf:get-configuration()
    return
        <section>
            <h2>Configuration (config.xml)</h2>
            <ul>
                <li><strong>vocabulaire : </strong>{conf:get-vocabulary-bundle()} ({conf:get-vocabulary-namespace()})</li>
                <li><strong>langues : </strong>{fn:string-join(conf:get-languages(),', ')} </li>
            </ul>
        </section>
};

(:~
 : @return routes list as html
 :)
declare %private function max-dev:route-list() as element(){
    let $wadl:=rest:wadl()
    let $maxRoutes := <ul>{
        for $r in $wadl//*:resource[@*:path]
        return
            let $path:= string($r/@*:path)
            let $method := string($r/*:method/@name)
            (:ignore other basex webapp routes:)
            return if(fn:starts-with($path,'/dba') or $path='' or fn:starts-with($path,'/chat') or not(contains($method,'GET')))
                   then ()
                   else 
                     if(not(contains($path, '$')))
                            then <li><a target="_blank" href="{$path}">{$path}</a></li>
                            else <li>{$path}</li>
     }</ul>
    return $maxRoutes

};
 No newline at end of file
+17 −0
Original line number Diff line number Diff line
xquery version "3.0";

import module namespace conf = 'https://certic.unicaen.fr/max/conf' at '../../core/conf.xqm';

declare variable $html  external;
    
if(conf:is-dev-mode())
then
let $devLink :=<a
    style="position: fixed; bottom :5px; left: 5px; background-color: #333; padding: 2px 5px; color: white" href="/bundles/max-dev/index.html">?</a>
return
    copy $c := $html
    modify (
        insert node $devLink into $c//*:body
    )
    return $c
else $html
 No newline at end of file
Loading