Commit 96249193 authored by Jérôme Chauveau's avatar Jérôme Chauveau
Browse files

v0 of an xqdoc to html feature. #9

parent d59b7ae0
Loading
Loading
Loading
Loading
+8 −1
Changes for src/main/core/conf.xqm: 8 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -45,7 +45,14 @@ declare function conf:get-configuration-path() as xs:string{
 : @return MaX expath package path
 :)
declare function conf:get-package-path() as xs:string{
    file:current-dir() ||'.max/resources/'|| $conf:package-file
    conf:get-resources-path() || $conf:package-file
};

(:~
 : @return MaX resources dir path
 :)
declare function conf:get-resources-path() as xs:string{
    file:current-dir() ||'.max/resources/'
};

(:~
+16 −9
Changes for src/main/core/routes.xqm: 16 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ import module namespace globals = 'https://certic.unicaen.fr/max/globals' at 'gl
import module namespace markdown = 'https://certic.unicaen.fr/max/markdown' at 'markdown.xqm';

(:~
 : main index page.
 : @return default html index page
 :)
declare
@@ -27,7 +28,7 @@ function routes:index($path as xs:string?){
   routes:page($conf:default-lang, 'index')
};

(:~
(:~ main index page for a specific lang.
 : @return default html index page for a specific lang
 :)
declare
@@ -269,17 +270,23 @@ function routes:file(

};


(:~
 :TEST
 : @return max routes xqdoc
 : MaX Documentation test function.
 : Generates an HTML documentation for MaX Xqueries functions.
 : @return max routes xqdoc as html
 :)
declare
%rest:GET
%output:method("xml")
%rest:path("/max-documentation.xml")
function routes:documentation(){
    inspect:xqdoc(db:option('webpath') || '/max/routes.xqm')
};

%output:method("html")
%rest:path("/max-documentation.html")
function routes:html-documentation(){
    let $packageDoc := doc(conf:get-package-path())
    let $xqDocs := <div>{for $module in $packageDoc//*:xquery/*:file
                        return inspect:xqdoc(db:option('webpath') || '/max/core/' || string($module))
                    }
                    </div>

     return xslt:transform($xqDocs, doc(conf:get-resources-path()  || 'doc-2-html.xsl'))

};
+170
Changes for src/resources/doc-2-html.xsl: 170 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xqdoc="http://www.xqdoc.org/1.0">

  <xsl:output method="xml" encoding="UTF-8"/>

  <!-- The root template that matches the <xqdoc:xqdoc> element -->
  <xsl:template match="/">
    <html>
      <head>
        <title>MaX XQuery Documentation</title>
        <style>

          body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            margin: 20px;
            display:flex;
          }
          nav{
            flex-grow:1;
            border-right: 1px solid #efefef;
          }
          main {
            flex-grow:2;
            padding:1rem;
          }

          main ul {
            padding-left: 0;
          }

          h1 {
            padding-bottom: 5px;
          }

          h2, h3 {
          color: #333;
          }

          h4 {
            color: #777;
          }
          .description, .parameters, .return {
            display: flex;
          }

          .function {
            border-top: 1px dashed #efefef;
          }
          .description, .parameters, .return {
            margin-top: 10px;
            align-items: center;
          }
          .description h4, .parameters h4, .return h4 {
            margin-right:2rem;
          }
          .parameter {
            margin-left: 20px;
          }

          pre{
            display: inline-block;
            padding: 2rem;
            background-color: #efefef;
            border: 1px solid #ddd;
          }
        </style>
      </head>
      <body>
        <!-- modules nav menu -->
        <nav>
          <h2>Modules</h2>
          <ul>
            <xsl:for-each select="//xqdoc:module">
              <li>
                <a>
                  <xsl:attribute name="href">
                    <xsl:value-of select="concat('#module-',xqdoc:name)"/>
                  </xsl:attribute>
                  <xsl:value-of select="xqdoc:name"/>
                </a>
              </li>
            </xsl:for-each>
          </ul>
        </nav>
        <main>
          <h1>MaX XQuery Documentation</h1>
          <xsl:apply-templates select="//xqdoc:xqdoc"/>
        </main>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="xqdoc:xqdoc">
    <h2>
      <xsl:attribute name="id">
        <xsl:value-of select="concat('module-',./xqdoc:module/xqdoc:name)"/>
      </xsl:attribute>
      # <xsl:value-of select="./xqdoc:module/xqdoc:name"/>
    </h2>
    <div class="module-desc">
      <xsl:value-of select="xqdoc:module/xqdoc:comment/xqdoc:description"/>
    </div>
    <xsl:apply-templates select=".//xqdoc:functions/xqdoc:function"/>
  </xsl:template>


  <!-- Template for each function -->
  <xsl:template match="xqdoc:function">
    <div class="function">
      <h3>
        <xsl:value-of select="xqdoc:name"/>
      </h3>

      <xsl:if test="xqdoc:comment/xqdoc:description">
        <div class="description">
          <h4>Description</h4>
          <p><xsl:value-of select="xqdoc:comment/xqdoc:description"/></p>
        </div>
      </xsl:if>
      <div class="signature">
        <h4>Signature</h4>
          <div>
            <pre>
              <xsl:value-of select="concat(xqdoc:name, ' ', tokenize(xqdoc:signature,xqdoc:name)[last()])"/>
            </pre>
          </div>
      </div>


      <xsl:if test="xqdoc:parameters/xqdoc:parameter">
        <div class="parameters">
          <h4>Parameters</h4>
          <ul>
            <xsl:for-each select="xqdoc:parameters/xqdoc:parameter">
              <li class="parameter">
                <strong><xsl:value-of select="xqdoc:name"/>: </strong>
                <xsl:value-of select="xqdoc:type"/>
                <xsl:if test="xqdoc:description">
                  - <span><xsl:value-of select="xqdoc:description"/></span>
                </xsl:if>
              </li>
            </xsl:for-each>
          </ul>
        </div>
      </xsl:if>

      <xsl:if test="xqdoc:return">
        <div class="return">
          <h4>Return Type</h4>
          <p><xsl:value-of select="xqdoc:return/xqdoc:type"/></p>
        </div>
      </xsl:if>

      <!--<xsl:if test="xqdoc:annotations/xqdoc:annotation">
        <div class="annotations">
          <h3>Annotations</h3>
          <ul>
            <xsl:for-each select="xqdoc:annotations/xqdoc:annotation">
              <li>
                <strong><xsl:value-of select="xqdoc:name"/>:</strong>
                <xsl:value-of select="xqdoc:literal"/>
              </li>
            </xsl:for-each>
          </ul>
        </div>
      </xsl:if>-->
    </div>
  </xsl:template>

</xsl:stylesheet>