import os from KidKit.Examples.KidExamplePage import KidExamplePage class View(KidExamplePage): """View the source of a Kid template. For each Kid example, you will see a sidebar with various menu items, one of which is "View source of example". This link points to the View servlet and passes the filename of the current servlet. The View servlet then loads that Kid file's source code and displays it in the browser for your viewing pleasure. Note that if the View servlet isn't passed a Kid filename, it prints the View's docstring which you are reading right now. """ def writeContent(self): req = self.request() if req.hasField('filename'): filename = req.field('filename') basename = os.path.basename(filename) filename = self.request().serverSidePath(basename) if not os.path.exists(filename): self.write('
' 'No such file %r exists
' % basename) return text = open(filename).read() text = self.htmlEncode(text) text = text.replace('\n', '%s' % text) else: doc = self.__class__.__doc__.split('\n', 1) doc[1] = '\n
'.join(doc[1].split('\n\n')) self.writeln('
%s
' % tuple(doc))