SVGHMI: added more meaningful namespaces to emit javascript code from. svghmi
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Mon, 20 Apr 2020 16:19:31 +0200
branchsvghmi
changeset 2943 304e88bae115
parent 2942 b07ad97e6019
child 2944 2a20038fbea9
SVGHMI: added more meaningful namespaces to emit javascript code from.
svghmi/detachable_pages.ysl2
svghmi/gen_index_xhtml.xslt
svghmi/gen_index_xhtml.ysl2
svghmi/widget_foreach.ysl2
svghmi/widget_jump.ysl2
svghmi/widget_keypad.ysl2
--- a/svghmi/detachable_pages.ysl2	Sun Apr 19 22:44:41 2020 +0200
+++ b/svghmi/detachable_pages.ysl2	Mon Apr 20 16:19:31 2020 +0200
@@ -99,7 +99,7 @@
 const "_detachable_elements", "func:detachable_elements($hmi_pages | $keypads)";
 const "detachable_elements", "$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]";
 
-emit "epilogue:detachable-elements" {
+emit "declarations:detachable-elements" {
     |
     | var detachable_elements = {
     foreach "$detachable_elements"{
@@ -168,7 +168,7 @@
     |   }`if "position()!=last()" > ,`
 }
 
-emit "epilogue:page-desc" {
+emit "declarations:page-desc" {
     |
     | var page_desc = {
     apply "$hmi_pages", mode="page_desc";
--- a/svghmi/gen_index_xhtml.xslt	Sun Apr 19 22:44:41 2020 +0200
+++ b/svghmi/gen_index_xhtml.xslt	Mon Apr 20 16:19:31 2020 +0200
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<xsl:stylesheet xmlns:func="http://exslt.org/functions" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:epilogue="epilogue" xmlns:svg="http://www.w3.org/2000/svg" xmlns:str="http://exslt.org/strings" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exsl="http://exslt.org/common" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:preamble="preamble" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ns="beremiz" xmlns:cc="http://creativecommons.org/ns#" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:debug="debug" xmlns:dc="http://purl.org/dc/elements/1.1/" extension-element-prefixes="ns func exsl regexp str dyn" version="1.0" exclude-result-prefixes="ns func exsl regexp str dyn debug preamble epilogue">
+<xsl:stylesheet xmlns:ns="beremiz" xmlns:definitions="definitions" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:func="http://exslt.org/functions" xmlns:epilogue="epilogue" xmlns:preamble="preamble" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:svg="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:str="http://exslt.org/strings" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:exsl="http://exslt.org/common" xmlns:declarations="declarations" xmlns:debug="debug" exclude-result-prefixes="ns func exsl regexp str dyn debug preamble epilogue declarations definitions" extension-element-prefixes="ns func exsl regexp str dyn" version="1.0">
   <xsl:output method="xml" cdata-section-elements="xhtml:script"/>
   <xsl:variable name="svg" select="/svg:svg"/>
   <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
@@ -383,8 +383,8 @@
   </func:function>
   <xsl:variable name="_detachable_elements" select="func:detachable_elements($hmi_pages | $keypads)"/>
   <xsl:variable name="detachable_elements" select="$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]"/>
-  <epilogue:detachable-elements/>
-  <xsl:template match="epilogue:detachable-elements">
+  <declarations:detachable-elements/>
+  <xsl:template match="declarations:detachable-elements">
     <xsl:text>
 </xsl:text>
     <xsl:text>var detachable_elements = {
@@ -527,8 +527,8 @@
     <xsl:text>
 </xsl:text>
   </xsl:template>
-  <epilogue:page-desc/>
-  <xsl:template match="epilogue:page-desc">
+  <declarations:page-desc/>
+  <xsl:template match="declarations:page-desc">
     <xsl:text>
 </xsl:text>
     <xsl:text>var page_desc = {
@@ -1544,8 +1544,8 @@
     <xsl:text>    apply_cache: foreach_apply_cache,
 </xsl:text>
   </xsl:template>
-  <epilogue:foreach/>
-  <xsl:template match="epilogue:foreach">
+  <definitions:foreach/>
+  <xsl:template match="definitions:foreach">
     <xsl:text>function foreach_unsubscribe(){
 </xsl:text>
     <xsl:text>    for(let item of this.items){
@@ -1956,8 +1956,8 @@
       </xsl:if>
     </xsl:if>
   </xsl:template>
-  <epilogue:jump/>
-  <xsl:template match="epilogue:jump">
+  <declarations:jump/>
+  <xsl:template match="declarations:jump">
     <xsl:text>var jumps_need_update = false;
 </xsl:text>
     <xsl:text>var jump_history = [[default_page, undefined]];
@@ -1975,8 +1975,8 @@
     <xsl:text>
 </xsl:text>
   </xsl:template>
-  <epilogue:keypad/>
-  <xsl:template match="epilogue:keypad">
+  <declarations:keypad/>
+  <xsl:template match="declarations:keypad">
     <xsl:text>
 </xsl:text>
     <xsl:text>var keypads = {
@@ -2341,7 +2341,37 @@
       <body style="margin:0;overflow:hidden;">
         <xsl:copy-of select="$result_svg"/>
         <script>
+          <xsl:text>
+//
+//
+// Early independent declarations 
+//
+//
+</xsl:text>
           <xsl:apply-templates select="document('')/*/preamble:*"/>
+          <xsl:text>
+//
+//
+// Declarations depending on preamble 
+//
+//
+</xsl:text>
+          <xsl:apply-templates select="document('')/*/declarations:*"/>
+          <xsl:text>
+//
+//
+// Order independent declaration and code 
+//
+//
+</xsl:text>
+          <xsl:apply-templates select="document('')/*/definitions:*"/>
+          <xsl:text>
+//
+//
+// Statements that needs to be at the end 
+//
+//
+</xsl:text>
           <xsl:apply-templates select="document('')/*/epilogue:*"/>
           <xsl:text>// svghmi.js
 </xsl:text>
--- a/svghmi/gen_index_xhtml.ysl2	Sun Apr 19 22:44:41 2020 +0200
+++ b/svghmi/gen_index_xhtml.ysl2	Mon Apr 20 16:19:31 2020 +0200
@@ -25,13 +25,15 @@
             /* Internal namespaces to allow emit code/content from anywhere */
             xmlns:debug="debug"
             xmlns:preamble="preamble"
+            xmlns:declarations="declarations"
+            xmlns:definitions="definitions"
             xmlns:epilogue="epilogue"
 
             /* Namespace to invoke python code */
             xmlns:ns="beremiz"
 
             extension-element-prefixes="ns func exsl regexp str dyn"
-            exclude-result-prefixes="ns func exsl regexp str dyn debug preamble epilogue" {
+            exclude-result-prefixes="ns func exsl regexp str dyn debug preamble epilogue declarations definitions" {
 
     const "svg", "/svg:svg";
     const "hmi_elements", "//svg:*[starts-with(@inkscape:label, 'HMI:')]";
@@ -69,8 +71,16 @@
                 // Inline SVG
                 copy "$result_svg";
                 script{
+                    | \n//\n//\n// Early independent declarations \n//\n//
                     apply "document('')/*/preamble:*";
 
+                    | \n//\n//\n// Declarations depending on preamble \n//\n//
+                    apply "document('')/*/declarations:*";
+
+                    | \n//\n//\n// Order independent declaration and code \n//\n//
+                    apply "document('')/*/definitions:*";
+
+                    | \n//\n//\n// Statements that needs to be at the end \n//\n//
                     apply "document('')/*/epilogue:*";
 
                     include text svghmi.js
--- a/svghmi/widget_foreach.ysl2	Sun Apr 19 22:44:41 2020 +0200
+++ b/svghmi/widget_foreach.ysl2	Mon Apr 20 16:19:31 2020 +0200
@@ -55,7 +55,7 @@
     |     apply_cache: foreach_apply_cache,
 }
 
-emit "epilogue:foreach"
+emit "definitions:foreach"
 ||
 function foreach_unsubscribe(){
     for(let item of this.items){
--- a/svghmi/widget_jump.ysl2	Sun Apr 19 22:44:41 2020 +0200
+++ b/svghmi/widget_jump.ysl2	Mon Apr 20 16:19:31 2020 +0200
@@ -127,7 +127,7 @@
     }
 }
 
-emit "epilogue:jump"
+emit "declarations:jump"
 ||
 var jumps_need_update = false;
 var jump_history = [[default_page, undefined]];
--- a/svghmi/widget_keypad.ysl2	Sun Apr 19 22:44:41 2020 +0200
+++ b/svghmi/widget_keypad.ysl2	Mon Apr 20 16:19:31 2020 +0200
@@ -1,6 +1,6 @@
 // widget_keypad.ysl2
 
-emit "epilogue:keypad" {
+emit "declarations:keypad" {
     |
     | var keypads = {
     foreach "$keypads_descs"{