Donovan Preston wrote:

> my liking. So I took it upon myself to see if I could get the TAL (Tag
> Attribute Language)  component of ZPT working with WebKit, and it was
> surprisingly easy.

Very interesting. I changed your version a little bit,
so it only regenerates the page when it is really changed.
I get a massive speedup with that.

please check my code carefully to see if everything is ok.

the new file is attached..

-- 

Tom Schwaller
[EMAIL PROTECTED]
http://www.python.de
from TAL.DummyEngine import DummyEngine
from TAL.driver import compilefile
from TAL.TALInterpreter import TALInterpreter
from WebKit.Page import Page
from cStringIO import StringIO
import os

class WebKitEngine(DummyEngine):
        """  
        Override DummyEngine's __init__ to take the WebKit page object to which we 
wish to refer in our
        TAL Template HTML. Call DummyEngine.__init__ to initialize the engine, then add
        page to the local namespace.
        """
        def __init__(self, page):
                DummyEngine.__init__(self)
                
                # Add page to the WebKitEngine's local namespace so that the variable 
'page' will be accessible
                # from TAL.
                self.setLocal('page', page)

class TALPage(Page):
        """
        TALPage makes TAL do the work of generating the HTML from a template file
        """
        base = ''
        file = ''

        def __init__(self):
                Page.__init__(self)
                self._path = self.base + self.file
                self._mtime = -1

                # Create a memory-mapped file for TALInterpreter to write the final 
HTML output to.
                self._fileObj = StringIO()

        def awake(self, transaction):
                Page.awake(self, transaction)
                if os.path.getmtime(self._path) > self._mtime:
                        self._mtime = os.path.getmtime(self._path)
                        self._fileObj.truncate()

                        # Compilefile returns a two-element tuple containing the 
program and the macros to interpret
                        program, macros = compilefile(self._path, "html")

                        # Create a WebKitEngine and pass it a reference to ourself 
(The current page object)
                        engine = WebKitEngine(self)
                        TALInterpreter(program, macros, engine, self._fileObj, wrap=0, 
tal=1, showtal=-1, strictinsert=1)()


        def writeHTML(self):
                # Send the page to WebKit for output to the web browser.
                self.writeln(self._fileObj.getvalue())

Reply via email to