[Commits] r489 - website

commits at geoext.org commits at geoext.org
Tue Apr 28 11:00:48 CEST 2009


Author: tschaub
Date: 2009-04-28 11:00:48 +0200 (Tue, 28 Apr 2009)
New Revision: 489

Modified:
   website/jst.py
   website/jst.txt
Log:
create source file obj from string

Modified: website/jst.py
===================================================================
--- website/jst.py	2009-04-28 08:55:58 UTC (rev 488)
+++ website/jst.py	2009-04-28 09:00:48 UTC (rev 489)
@@ -101,16 +101,15 @@
     @classmethod
     def from_filename(cls, filename):
         fh = open(filename, "U")
-        source = fh.readlines()
+        source = fh.read()
         fh.close()
         return cls(source)
         
     @property
     def comments(self):
         if self._comments == _marker:
-            source = "".join(self.source)
             comments = ()
-            for comment in re.findall(r'^\s*/\*\*\s*jst\s*:\s*([\S\s]*?)\*+/', source, re.MULTILINE):
+            for comment in re.findall(r'^\s*/\*\*\s*jst\s*:\s*([\S\s]*?)\*+/', self.source, re.MULTILINE):
                 lines = [re.sub(r'^\s*\*+', '', line.rstrip()) for line in comment.split('\n')]
                 if len(lines) == 1:
                     label = "(define)"

Modified: website/jst.txt
===================================================================
--- website/jst.txt	2009-04-28 08:55:58 UTC (rev 488)
+++ website/jst.txt	2009-04-28 09:00:48 UTC (rev 489)
@@ -4,18 +4,9 @@
 Accessing data in comments
 --------------------------
 
-Set up so we can pretend string comes from file::
-
-    >>> from StringIO import StringIO
-    >>> def code(string):
-    ...     f = StringIO(string)
-    ...     lines = f.readlines()
-    ...     f.close()
-    ...     return lines
-
 Consider some code with well formatted comment blocks::
 
-    >>> lines = code("""
+    >>> code = """
     ... /**
     ...  *  This is a plain old comment block.
     ...  */
@@ -51,12 +42,12 @@
     ...  *  to = assign
     ...  *  keys = values
     ...  */
-    ... """)
+    ... """
 
 Now import jst and create an object representing the lines of code::
 
     >>> import jst
-    >>> obj = jst.SourceFile(lines)
+    >>> obj = jst.SourceFile(code)
 
 The comments are parsed as a tuple of dictionaries with 'label' and 'block'
 keys::
@@ -94,7 +85,7 @@
 
 Make sure that different comment formats don't mess things up::
 
-    >>> obj = jst.SourceFile(code("""
+    >>> obj = jst.SourceFile("""
     ... /** regular old comment */
     ... 
     ... /** jst: foo
@@ -108,7 +99,7 @@
     ... /** jst: bar
     ...  *  bar content
     ...  */
-    ... """))
+    ... """)
 
 We expect three comments.  The one liner is like a single line from a (defines) block::
 



More information about the Commits mailing list