Added support for SSI include statements to the HTML preview function.

Fri, 15 Feb 2013 19:50:49 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 15 Feb 2013 19:50:49 +0100
changeset 2415
814c66cb0746
parent 2412
0545dddf3d51
child 2416
28a585ba3531

Added support for SSI include statements to the HTML preview function.

Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric5.ViewManager.ViewManager.html file | annotate | diff | comparison | revisions
ViewManager/ViewManager.py file | annotate | diff | comparison | revisions
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Thu Feb 14 18:43:27 2013 +0100
+++ b/Documentation/Help/source.qhp	Fri Feb 15 19:50:49 2013 +0100
@@ -11862,6 +11862,7 @@
       <keyword name="ViewManager.__previousTask" id="ViewManager.__previousTask" ref="eric5.ViewManager.ViewManager.html#ViewManager.__previousTask" />
       <keyword name="ViewManager.__previousUncovered" id="ViewManager.__previousUncovered" ref="eric5.ViewManager.ViewManager.html#ViewManager.__previousUncovered" />
       <keyword name="ViewManager.__previousWarning" id="ViewManager.__previousWarning" ref="eric5.ViewManager.ViewManager.html#ViewManager.__previousWarning" />
+      <keyword name="ViewManager.__processSSI" id="ViewManager.__processSSI" ref="eric5.ViewManager.ViewManager.html#ViewManager.__processSSI" />
       <keyword name="ViewManager.__quickSearch" id="ViewManager.__quickSearch" ref="eric5.ViewManager.ViewManager.html#ViewManager.__quickSearch" />
       <keyword name="ViewManager.__quickSearchEnter" id="ViewManager.__quickSearchEnter" ref="eric5.ViewManager.ViewManager.html#ViewManager.__quickSearchEnter" />
       <keyword name="ViewManager.__quickSearchEscape" id="ViewManager.__quickSearchEscape" ref="eric5.ViewManager.ViewManager.html#ViewManager.__quickSearchEscape" />
--- a/Documentation/Source/eric5.ViewManager.ViewManager.html	Thu Feb 14 18:43:27 2013 +0100
+++ b/Documentation/Source/eric5.ViewManager.ViewManager.html	Fri Feb 15 19:50:49 2013 +0100
@@ -454,6 +454,9 @@
 <td><a href="#ViewManager.__previousWarning">__previousWarning</a></td>
 <td>Private method to handle the previous warning action.</td>
 </tr><tr>
+<td><a href="#ViewManager.__processSSI">__processSSI</a></td>
+<td>Private method to process the given text for SSI statements.</td>
+</tr><tr>
 <td><a href="#ViewManager.__quickSearch">__quickSearch</a></td>
 <td>Private slot to handle the incremental quick search.</td>
 </tr><tr>
@@ -1431,7 +1434,30 @@
 <b>__previousWarning</b>(<i></i>)
 <p>
         Private method to handle the previous warning action.
-</p><a NAME="ViewManager.__quickSearch" ID="ViewManager.__quickSearch"></a>
+</p><a NAME="ViewManager.__processSSI" ID="ViewManager.__processSSI"></a>
+<h4>ViewManager.__processSSI</h4>
+<b>__processSSI</b>(<i>txt, filename, root</i>)
+<p>
+        Private method to process the given text for SSI statements.
+</p><p>
+        Note: Only a limited subset of SSI statements are supported.
+</p><dl>
+<dt><i>txt</i></dt>
+<dd>
+text to be processed (string)
+</dd><dt><i>filename</i></dt>
+<dd>
+name of the file associated with the given text (string)
+</dd><dt><i>root</i></dt>
+<dd>
+directory of the document root (string)
+</dd>
+</dl><dl>
+<dt>Returns:</dt>
+<dd>
+processed text (string)
+</dd>
+</dl><a NAME="ViewManager.__quickSearch" ID="ViewManager.__quickSearch"></a>
 <h4>ViewManager.__quickSearch</h4>
 <b>__quickSearch</b>(<i></i>)
 <p>
--- a/ViewManager/ViewManager.py	Thu Feb 14 18:43:27 2013 +0100
+++ b/ViewManager/ViewManager.py	Fri Feb 15 19:50:49 2013 +0100
@@ -8,6 +8,7 @@
 """
 
 import os
+import re
 
 from PyQt4.QtCore import QSignalMapper, QTimer, QFileInfo, pyqtSignal, QRegExp, \
     QObject, Qt, QUrl
@@ -4892,8 +4893,8 @@
         line, index = aw.getCursorPosition()
         text = aw.text(line)
         
-        re = QRegExp('[^\w_]')
-        end = re.indexIn(text, index)
+        reg = QRegExp('[^\w_]')
+        end = reg.indexIn(text, index)
         if end > index:
             ext = text[index:end]
             txt += ext
@@ -5142,13 +5143,66 @@
             if fn:
                 project = e5App().getObject("Project")
                 if project.isProjectFile(fn):
-                    baseUrl = QUrl.fromLocalFile(project.getProjectPath())
+                    baseUrl = QUrl.fromLocalFile(project.getAbsoluteUniversalPath(fn))
+                    fullName = project.getAbsoluteUniversalPath(fn)
+                    rootPath = project.getProjectPath()
                 else:
                     baseUrl = QUrl.fromLocalFile(fn)
+                    fullName = fn
+                    rootPath = os.path.dirname(os.path.abspath(fn))
             else:
                 baseUrl = QUrl()
+                fullName = ""
+                rootPath = ""
+            txt = self.__processSSI(aw.text(), fullName, rootPath)
             previewer = self.ui.getHelpViewer(preview=True).previewer()
-            previewer.setHtml(aw.text(), baseUrl)
+            previewer.setHtml(txt, baseUrl)
+    
+    def __processSSI(self, txt, filename, root):
+        """
+        Private method to process the given text for SSI statements.
+        
+        Note: Only a limited subset of SSI statements are supported.
+        
+        @param txt text to be processed (string)
+        @param filename name of the file associated with the given text (string)
+        @param root directory of the document root (string)
+        @return processed text (string)
+        """
+        if not filename:
+            return txt
+        
+        # SSI include
+        incRe = re.compile(
+            r"""<!--#include[ \t]+(virtual|file)=[\"']([^\"']+)[\"']\s*-->""",
+            re.IGNORECASE)
+        baseDir = os.path.dirname(os.path.abspath(filename))
+        docRoot = root if root != "" else baseDir
+        while True:
+            incMatch = incRe.search(txt)
+            if incMatch is None:
+                break
+            
+            if incMatch.group(1) == "virtual":
+                incFile = Utilities.normjoinpath(docRoot, incMatch.group(2))
+            elif incMatch.group(1) == "file":
+                incFile = Utilities.normjoinpath(baseDir, incMatch.group(2))
+            else:
+                incFile = ""
+            if os.path.exists(incFile):
+                try:
+                    f = open(incFile, "r")
+                    incTxt = f.read()
+                    f.close()
+                except (IOError, OSError):
+                    # remove SSI include
+                    incTxt = ""
+            else:
+                # remove SSI include
+                incTxt = ""
+            txt = txt[:incMatch.start(0)] + incTxt + txt[incMatch.end(0):]
+        
+        return txt
     
     ##################################################################
     ## Below are the action methods for the macro menu

eric ide

mercurial