Quellcode durchsuchen

move as much html out of template

Daniel Sheffield vor 8 Monaten
Ursprung
Commit
9eab1b0aae
3 geänderte Dateien mit 122 neuen und 115 gelöschten Zeilen
  1. 3 4
      rest/pyapi.py
  2. 82 109
      rest/query-to-xml-xslt.tpl
  3. 37 2
      rest/query-to-xml.tpl

+ 3 - 4
rest/pyapi.py

@@ -1,6 +1,6 @@
-# Copyright (c) Daniel Sheffield 2022 - 2023
+# Copyright (c) Daniel Sheffield 2022 - 2024
 # All rights reserved.
-from bottle import route, request, run, template, response, abort
+from bottle import route, request, run, template, response, abort, static_file
 import psycopg
 from psycopg import Cursor
 from psycopg.sql import SQL, Literal
@@ -33,9 +33,8 @@ SELECT query_to_xml_and_xmlschema({q}, false, false, ''::text);
 
 @route('/pyapi/xslt')
 def table():
-    title = request.query['title'] if 'title' in request.query.keys() else None
     response.content_type = 'application/xhtml+xml; charset=utf-8'
-    return template("rest/query-to-xml-xslt", title=title)
+    return static_file("rest/query-to-xml-xslt.xml")
 
 @route('/pyapi/pg')
 def specified():

+ 82 - 109
rest/query-to-xml-xslt.tpl

@@ -14,128 +14,101 @@ All rights reserved.
       doctype-public="-//W3C/DTD XHTML 1.0 Strict//EN"
       indent="yes"/>
 
-  <xsl:template match="/*">
+  <!-- This is an identity template - it copies everything
+        that doesn't match another template -->
+  <xsl:template match="@* | node()">
+    <xsl:copy>
+      <xsl:apply-templates select="@* | node()"/>
+    </xsl:copy>
+  </xsl:template>
+  <xsl:template match="processing-instruction()">
+  </xsl:template>
+
+  <xsl:template match="//xhtml:div[@id='xmldata']/*">
     <xsl:variable name="schema" select="//xsd:schema"/>
     <xsl:variable name="tabletypename"
                   select="$schema/xsd:element[@name=name(current())]/@type"/>
     <xsl:variable name="rowtypename"
                   select="$schema/xsd:complexType[@name=$tabletypename]/xsd:sequence/xsd:element[@name='row']/@type"/>
+    
+    <table class="pure-table pure-table-bordered pure-table-striped">
+      <tr style="text-transform: capitalize">
+      <xsl:for-each select="$schema/xsd:complexType[@name=$rowtypename]/xsd:sequence/xsd:element/@name">
+          <xsl:variable name="elementtype"
+                        select="."/>
+          <xsl:choose>
+          <xsl:when test="$elementtype = 'txt'">
+        <th class="opt-all">Text</th>
+          </xsl:when>
+          <xsl:when test="$elementtype = 'category'">
+        <th class="opt-all">Section</th>
+          </xsl:when>
+          <xsl:when test="$elementtype = 'translation'">
+        <th class="opt-md opt-lg opt-xl opt-xxl">Reference</th>
+          </xsl:when>
+          <xsl:otherwise>
+          </xsl:otherwise>
+          </xsl:choose>
+      </xsl:for-each>
+      </tr>
 
-    <html>
-      <head>
-        <title>{{title}}</title>
-	<meta name="description" content="Generate a template prayer following the form of the model prayer outlined in Matthew 6:9‑13 and Luke 11:2‑4"/>
-	<meta name="keywords" content="Bible, Prayer, Generator, SWORD"/>
-	<meta name="author" content="Daniel Sheffield"/>
-	<meta name="viewport" content="width=device-width, initial-scale=1"/>
-	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/purecss@2.1.0/build/pure-min.css" integrity="sha384-yHIFVG6ClnONEA5yB5DJXfW2/KC173DIQrYoZMEtBvGzmf0PKiGyNEqe9N6BNDBH" crossorigin="anonymous"/>
-	<link rel="stylesheet" href="https://shandan.one/css/grids-responsive-min.css"/>
-	<link rel="stylesheet" href="https://shandan.one/css/responsive-visibility-collapse.css"/>
-        <style>
-span.engraved {
-    color: #A8A8A8;
-    font-size: 0.8em;
-    text-shadow: 0px 0.1em 0px rgba(168,168,168,.1), 0px -0.1em 0px rgba(0,0,0,.7);
-    float: right;
-}
-	</style>
-      </head>
-      <body>
-        <div style="background: darkgray; position: sticky; top: 0; margin: 0; padding: 0; width: 100%; z-index: 1; text-align: center;">
-        <form action="random">
-          <button type="submit" style="margin: 0.2em">Generate</button>
-          <span style="position: absolute; right: 0; padding: 0.4em">
-          <a>
-          <xsl:attribute name="href">./pg?<xsl:for-each select="//row"><xsl:value-of select="category"/>=<xsl:value-of select="translate(reference,' ','')"/>+<xsl:value-of select="translation"/><xsl:if test="position() != last()">&#038;</xsl:if></xsl:for-each></xsl:attribute>
-          Permalink
-          </a>
-          </span>
-	</form>
-        </div>
-        <div style="position: relative; max-width: 68em; min-width: min(100%, 68em); left: 50%; transform: translate(max(-50%, -34em),0)">
-        <table class="pure-table pure-table-bordered pure-table-striped">
-          <tr style="text-transform: capitalize">
-            <xsl:for-each select="$schema/xsd:complexType[@name=$rowtypename]/xsd:sequence/xsd:element/@name">
-                <xsl:variable name="elementtype"
-                              select="."/>
-                <xsl:choose>
-                <xsl:when test="$elementtype = 'txt'">
-              <th class="opt-all">Text</th>
-                </xsl:when>
-                <xsl:when test="$elementtype = 'category'">
-              <th class="opt-all">Section</th>
-                </xsl:when>
-                <xsl:when test="$elementtype = 'translation'">
-              <th class="opt-md opt-lg opt-xl opt-xxl">Reference</th>
-                </xsl:when>
-                <xsl:otherwise>
-                </xsl:otherwise>
-                </xsl:choose>
-            </xsl:for-each>
-          </tr>
-
-          <xsl:for-each select="row">
-            <tr>
-              <xsl:for-each select="*">
-                <xsl:variable name="elementtype"
-                              select="name(current())"/>
-                <xsl:choose>
-                <xsl:when test="$elementtype = 'txt'">
-                <td class="opt-all" style="text-align: justify"><xsl:value-of select="."/>&#160;<span class="engraved">
-                <xsl:value-of select="../translation"/>
-                </span>
-                </td>
-                </xsl:when>
-                <xsl:when test="$elementtype = 'category'">
-                  <xsl:choose>
-                  <xsl:when test="contains(.,'z_')">
+      <xsl:for-each select="row">
+        <tr>
+          <xsl:for-each select="*">
+            <xsl:variable name="elementtype"
+                          select="name(current())"/>
+            <xsl:choose>
+            <xsl:when test="$elementtype = 'txt'">
+            <td class="opt-all" style="text-align: justify"><xsl:value-of select="."/>&#160;<span class="engraved">
+            <xsl:value-of select="../translation"/>
+            </span>
+            </td>
+            </xsl:when>
+            <xsl:when test="$elementtype = 'category'">
+              <xsl:choose>
+                <xsl:when test="contains(.,'z_')">
                   <td class="opt-all" rowspan="2" style="text-transform: capitalize;">Kingdom</td>
-                  </xsl:when>
-                  <xsl:when test="contains(.,'a_')">
-                  </xsl:when>
-		  <xsl:otherwise>
-                  <td class="opt-all" style="text-transform: capitalize;"><xsl:value-of select="."/></td>
-                  </xsl:otherwise>
-                  </xsl:choose>
-                </xsl:when>
-                <xsl:when test="$elementtype = 'translation'">
                 </xsl:when>
+                <xsl:when test="contains(.,'a_')"></xsl:when>
                 <xsl:otherwise>
-                  <td class="opt-md opt-lg opt-xl opt-xxl">
-                  <xsl:value-of select="translate(translate(.,' ','&#160;'),'-','&#8209;')"/>
-                  <br/>
-                  <a>
-                  <xsl:attribute name="href">/license/<xsl:value-of select="preceding-sibling::translation"/>.txt</xsl:attribute>
-                  <xsl:value-of select="preceding-sibling::translation"/>
-                  </a>
-                  </td>
+                  <td class="opt-all" style="text-transform: capitalize;"><xsl:value-of select="."/></td>
                 </xsl:otherwise>
-                </xsl:choose>
-              </xsl:for-each>
-            </tr>
+              </xsl:choose>
+            </xsl:when>
+            <xsl:when test="$elementtype = 'translation'">
+            </xsl:when>
+            <xsl:otherwise>
+              <td class="opt-md opt-lg opt-xl opt-xxl">
+              <xsl:value-of select="translate(translate(.,' ','&#160;'),'-','&#8209;')"/>
+              <br/>
+              <a>
+                <xsl:attribute name="href">/license/<xsl:value-of select="preceding-sibling::translation"/>.txt</xsl:attribute>
+                <xsl:value-of select="preceding-sibling::translation"/>
+              </a>
+              </td>
+            </xsl:otherwise>
+            </xsl:choose>
           </xsl:for-each>
-        <tfoot style="line-height: 1.4">
+        </tr>
+      </xsl:for-each>
+      <tfoot style="line-height: 1.4">
         <tr>
           <td colspan="3">
-          Copyright (c) Daniel Sheffield 2022. All right reserved.
-          <br/>
-          Powered by <a href="https://www.crosswire.org/jsword/">JSword</a> an implementation of <a href="https://www.crosswire.org/sword/index.jsp">The SWORD Project</a>'s SWORD API brought to you by the <a href="https://crosswire.org">The CrossWire Bible Society</a>.
-          <br/>
-          Quotes are taken from various translations as indicated. See
-          <xsl:for-each select="//row/translation[not(.=preceding::*)]">
-          <a>
-          <xsl:attribute name="href">/license/<xsl:value-of select="."/>.txt</xsl:attribute>
-          <xsl:value-of select="."/>
-          </a>,
-          </xsl:for-each>
-          for the license and copyright information of each respective work.
+            Copyright (c) Daniel Sheffield 2022. All right reserved.
+            <br/>
+            Powered by <a href="https://www.crosswire.org/jsword/">JSword</a> an implementation of <a href="https://www.crosswire.org/sword/index.jsp">The SWORD Project</a>'s SWORD API brought to you by the <a href="https://crosswire.org">The CrossWire Bible Society</a>.
+            <br/>
+            Quotes are taken from various translations as indicated. See
+            <xsl:for-each select="//row/translation[not(.=preceding::*)]">
+            <a>
+            <xsl:attribute name="href">/license/<xsl:value-of select="."/>.txt</xsl:attribute>
+            <xsl:value-of select="."/>
+            </a>,
+            </xsl:for-each>
+            for the license and copyright information of each respective work.
           </td>
         </tr>
-        </tfoot>
-        </table>
-        </div>
-      </body>
-    </html>
+      </tfoot>
+    </table>
   </xsl:template>
-
-</xsl:stylesheet>
+</xsl:stylesheet>

+ 37 - 2
rest/query-to-xml.tpl

@@ -3,5 +3,40 @@
 Copyright (c) Daniel Sheffield 2022
 All rights reserved.
 -->
-<?xml-stylesheet type="text/xsl" href="/pyapi/xslt?title={{title}}"?>
-{{!xml}}
+<?xml-stylesheet type="text/xsl" href="/pyapi/xslt"?>
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+  <title>{{title}}</title>
+	<meta name="description" content="Generate a template prayer following the form of the model prayer outlined in Matthew 6:9‑13 and Luke 11:2‑4"/>
+	<meta name="keywords" content="Bible, Prayer, Generator, SWORD"/>
+	<meta name="author" content="Daniel Sheffield"/>
+	<meta name="viewport" content="width=device-width, initial-scale=1"/>
+	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/purecss@2.1.0/build/pure-min.css" integrity="sha384-yHIFVG6ClnONEA5yB5DJXfW2/KC173DIQrYoZMEtBvGzmf0PKiGyNEqe9N6BNDBH" crossorigin="anonymous"/>
+	<link rel="stylesheet" href="https://shandan.one/css/grids-responsive-min.css"/>
+	<link rel="stylesheet" href="https://shandan.one/css/responsive-visibility-collapse.css"/>
+    <style>
+span.engraved {
+    color: #A8A8A8;
+    font-size: 0.8em;
+    text-shadow: 0px 0.1em 0px rgba(168,168,168,.1), 0px -0.1em 0px rgba(0,0,0,.7);
+    float: right;
+}
+  </style>
+  </head>
+  <body>
+    <div style="background: darkgray; position: sticky; top: 0; margin: 0; padding: 0; width: 100%; z-index: 1; text-align: center;">
+      <form action="random">
+        <button type="submit" style="margin: 0.2em">Generate</button>
+        <span style="position: absolute; right: 0; padding: 0.4em">
+          <a>
+            <xsl:attribute name="href">./pg?<xsl:for-each select="//row"><xsl:value-of select="category"/>=<xsl:value-of select="translate(reference,' ','')"/>+<xsl:value-of select="translation"/><xsl:if test="position() != last()">&#038;</xsl:if></xsl:for-each></xsl:attribute>
+            Permalink
+          </a>
+        </span>
+	  </form>
+    </div>
+    <div id="xmldata" style="position: relative; max-width: 68em; min-width: min(100%, 68em); left: 50%; transform: translate(max(-50%, -34em),0)">
+{{!xml}}
+    </div>
+  </body>
+</html>