SVGHMI: added transformation of code given in inkscape's description fields into javascript functions svghmi
authorEdouard Tisserant
Thu, 19 Sep 2019 15:32:36 +0200
branchsvghmi
changeset 2782 723e420dfe72
parent 2781 fbdd0fd8ee4f
child 2783 5ee6967f721d
SVGHMI: added transformation of code given in inkscape's description fields into javascript functions
svghmi/gen_index_xhtml.xslt
svghmi/gen_index_xhtml.ysl2
yslt_noindent.yml2
--- a/svghmi/gen_index_xhtml.xslt	Thu Sep 19 10:41:39 2019 +0200
+++ b/svghmi/gen_index_xhtml.xslt	Thu Sep 19 15:32:36 2019 +0200
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<xsl:stylesheet xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/1999/xhtml" xmlns:exsl="http://exslt.org/common" xmlns:ns="beremiz" xmlns:cc="http://creativecommons.org/ns#" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/" extension-element-prefixes="ns" version="1.0" exclude-result-prefixes="ns">
+<xsl:stylesheet xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns="beremiz" xmlns:cc="http://creativecommons.org/ns#" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/1999/xhtml" xmlns:str="http://exslt.org/strings" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:exsl="http://exslt.org/common" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" exclude-result-prefixes="ns" extension-element-prefixes="ns" version="1.0">
   <xsl:output method="xml" cdata-section-elements="script"/>
   <xsl:variable name="geometry" select="ns:GetSVGGeometry()"/>
   <xsl:variable name="hmitree" select="ns:GetHMITree()"/>
@@ -8,6 +8,10 @@
       <xsl:apply-templates select="@* | node()"/>
     </xsl:copy>
   </xsl:template>
+  <xsl:variable name="mark">
+    <xsl:text>=HMI=
+</xsl:text>
+  </xsl:variable>
   <xsl:template match="/">
     <html xmlns="http://www.w3.org/1999/xhtml">
       <head/>
@@ -22,6 +26,14 @@
           <xsl:apply-templates select="@* | node()"/>
         </xsl:copy>
         <script>
+          <xsl:variable name="midmark">
+            <xsl:text>
+</xsl:text>
+            <xsl:value-of select="$mark"/>
+          </xsl:variable>
+          <xsl:apply-templates mode="code_from_descs" select="//*[contains(child::svg:desc, $midmark) or                                starts-with(child::svg:desc, $mark)]"/>
+          <xsl:text>
+</xsl:text>
           <xsl:text>(function(){
 </xsl:text>
           <xsl:text>    var relative_URI = window.location.href.replace(/^http(s?:\/\/[^\/]*)\/.*$/, 'ws$1/ws');
@@ -48,6 +60,23 @@
       </body>
     </html>
   </xsl:template>
+  <xsl:template mode="code_from_descs" match="*">
+    <xsl:text>function js_</xsl:text>
+    <xsl:value-of select="@id"/>
+    <xsl:text>() {
+</xsl:text>
+    <xsl:text>var path, role, path, priv;
+</xsl:text>
+    <xsl:text>
+</xsl:text>
+    <xsl:value-of select="substring-after(svg:desc, $mark)"/>
+    <xsl:text>
+</xsl:text>
+    <xsl:text>}
+</xsl:text>
+    <xsl:text>
+</xsl:text>
+  </xsl:template>
   <xsl:template mode="testgeo" match="bbox">
     <xsl:text>ID: </xsl:text>
     <xsl:value-of select="@Id"/>
--- a/svghmi/gen_index_xhtml.ysl2	Thu Sep 19 10:41:39 2019 +0200
+++ b/svghmi/gen_index_xhtml.ysl2	Thu Sep 19 15:32:36 2019 +0200
@@ -33,6 +33,8 @@
       xsl:copy apply "@* | node()";
     }
 
+    variable "mark" > =HMI=\n
+
     /* copy root node and add geometry as comment for a test */
     template "/" 
       html xmlns="http://www.w3.org/1999/xhtml" {
@@ -48,16 +50,34 @@
                   apply "@* | node()";
               }
               script{
+                  variable "midmark" > \n«$mark»
+                  apply """//*[contains(child::svg:desc, $midmark) or \
+                               starts-with(child::svg:desc, $mark)]""", 
+                        mode="code_from_descs";
+                  |
+
                   /*TODO add :
                     - pages content
                       + with ref to elt ?
                     - widgets parameters
                   */
+
                   include text svghmi.js
               }
           }
     }
 
+    template "*", mode="code_from_descs" {
+        | function js_«@id»() {
+        | var path, role, path, priv;
+        | 
+        value "substring-after(svg:desc, $mark)";
+        | 
+        | }
+        |
+    }
+
+
     template "bbox", mode="testgeo"{
         | ID: «@Id» x: «@x» y: «@y» w: «@w» h: «@h»
     }
--- a/yslt_noindent.yml2	Thu Sep 19 10:41:39 2019 +0200
+++ b/yslt_noindent.yml2	Thu Sep 19 15:32:36 2019 +0200
@@ -10,7 +10,9 @@
         version="1.0",
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform",
         xmlns:exsl='http://exslt.org/common',
-        extension-element-prefixes='exsl'
+        xmlns:regexp="http://exslt.org/regular-expressions",
+        xmlns:str="http://exslt.org/strings",
+        extension-element-prefixes='exsl regexp str'
     ) alias stylesheet {
         output *output;
         content;