[Checkins] SVN: z3c.pt/trunk/ Genshi macros are now available globally.

Malthe Borch mborch at gmail.com
Thu Aug 21 11:27:10 EDT 2008


Log message for revision 90080:
  Genshi macros are now available globally.

Changed:
  U   z3c.pt/trunk/CHANGES.txt
  U   z3c.pt/trunk/src/z3c/pt/clauses.py
  U   z3c.pt/trunk/src/z3c/pt/genshi.py
  U   z3c.pt/trunk/src/z3c/pt/genshi.txt
  U   z3c.pt/trunk/src/z3c/pt/translation.py
  U   z3c.pt/trunk/src/z3c/pt/zpt.py

-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt	2008-08-21 15:26:14 UTC (rev 90079)
+++ z3c.pt/trunk/CHANGES.txt	2008-08-21 15:27:09 UTC (rev 90080)
@@ -4,6 +4,8 @@
 Version 1.0dev
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+- Genshi macros (py:def) are now available globally. [malthe]
+
 - A syntax error is now raised when an interpolation expression is not
   exhausted, e.g. only a part of the string is a valid
   Python-expression. [malthe]

Modified: z3c.pt/trunk/src/z3c/pt/clauses.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/clauses.py	2008-08-21 15:26:14 UTC (rev 90079)
+++ z3c.pt/trunk/src/z3c/pt/clauses.py	2008-08-21 15:27:09 UTC (rev 90080)
@@ -872,7 +872,6 @@
         
     def end(self, stream):
         stream.cook()
-        
         if self.defer:
             stream.out(self.string)
 

Modified: z3c.pt/trunk/src/z3c/pt/genshi.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/genshi.py	2008-08-21 15:26:14 UTC (rev 90079)
+++ z3c.pt/trunk/src/z3c/pt/genshi.py	2008-08-21 15:27:09 UTC (rev 90080)
@@ -63,7 +63,7 @@
         translation_domain = None
 
         @property
-        def method(self):
+        def macro(self):
             return self.element.py_def
 
         use_macro = None

Modified: z3c.pt/trunk/src/z3c/pt/genshi.txt
===================================================================
--- z3c.pt/trunk/src/z3c/pt/genshi.txt	2008-08-21 15:26:14 UTC (rev 90079)
+++ z3c.pt/trunk/src/z3c/pt/genshi.txt	2008-08-21 15:27:09 UTC (rev 90080)
@@ -381,19 +381,14 @@
 
   >>> print render_genshi("""\
   ... <div xmlns="http://www.w3.org/1999/xhtml"
-  ...       xmlns:py="http://genshi.edgewall.org">
-  ... <ul py:def="rendermenu(menu)" py:if="menu">
-  ...   Menu entry
-  ...   ${rendermenu([])}
-  ... </ul>
+  ...     xmlns:py="http://genshi.edgewall.org">
+  ...   <ul py:def="rendermenu(menu)" py:if="menu">
+  ...     ${rendermenu([])}
+  ...   </ul>
   ... </div>""")
-  <div xmlns="http://www.w3.org/1999/xhtml"
-        xmlns:py="http://genshi.edgewall.org">
-  <ul py:def="rendermenu(menu)" py:if="menu">
-    Menu entry
-  </ul>
+  <div>
   </div>
-
+  
 :: Slightly more complex recursive function calls
  
   >>> print render_genshi("""\
@@ -404,18 +399,23 @@
   ...         py:attrs="{'class' : entry['current'] and 'current' or None}">
   ...       <a py:attrs="dict(href=entry['url'])"
   ...          py:content="entry['title']">Merken</a>
-  ...       
   ...       ${rendermenu(entry.get('children', []))}
   ...     </li>
   ...   </ul>
-  ...   ${rendermenu(menu))}
+  ...   ${rendermenu(menu)}
   ... </div>""", menu=[dict(title=u"Menu entry", url="/test", current=True)])
-  <div xmlns="http://www.w3.org/1999/xhtml"
-        xmlns:py="http://genshi.edgewall.org">
-  <ul>
-    <li>
-    </li>
-  </ul>
+  <div>
+    <ul>
+      <li class="current">
+        <a href="/test">Menu entry</a>
+        <ul>
+  <BLANKLINE>
+    </ul>
+  <BLANKLINE>
+      </li>
+  <BLANKLINE>
+    </ul>
+  <BLANKLINE>
   </div>
   
 .. _py:with specs: http://genshi.edgewall.org/wiki/Documentation/0.4.x/xml-templates.html#py-with

Modified: z3c.pt/trunk/src/z3c/pt/translation.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/translation.py	2008-08-21 15:26:14 UTC (rev 90079)
+++ z3c.pt/trunk/src/z3c/pt/translation.py	2008-08-21 15:27:09 UTC (rev 90080)
@@ -52,7 +52,7 @@
     def visit(self, skip_macro=True):
         assert self.stream is not None, "Must use ``start`` method."
 
-        if skip_macro and (self.method or self.define_macro):
+        if skip_macro and (self.define_macro):
             return
 
         for element in self.element:
@@ -84,23 +84,14 @@
                     _.append(clauses.Define(declaration, expression))
 
         # macro method
-        for element in tuple(self.element):
-            if not isinstance(element, Element):
-                continue
-
-            macro = element.node.method
-            if macro is not None:
-                # define macro
-                subclauses = []
-                subclauses.append(clauses.Method(
-                    self.symbols.macro, macro.args))
-                subclauses.append(clauses.Visit(element.node))
-                _.append(clauses.Group(subclauses))
+        macro = self.macro
+        if macro is not None:
+            _.append(clauses.Method(
+                macro.name, macro.args))
+            _.append(clauses.Assign(
+                types.value(macro.name), "%s['%s']" % \
+                (self.symbols.scope, macro.name)))
                 
-                # assign to variable
-                _.append(clauses.Define(
-                    macro.name, types.parts((types.value(self.symbols.macro),))))
-
         # tag tail (deferred)
         tail = self.element.tail
         if tail and not self.fill_slot:

Modified: z3c.pt/trunk/src/z3c/pt/zpt.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/zpt.py	2008-08-21 15:26:14 UTC (rev 90079)
+++ z3c.pt/trunk/src/z3c/pt/zpt.py	2008-08-21 15:27:09 UTC (rev 90080)
@@ -75,7 +75,7 @@
         def translation_domain(self):
             return self.element.i18n_domain
 
-        method = None
+        macro = None
         
         @property
         def use_macro(self):



More information about the Checkins mailing list