[Checkins] SVN: Sandbox/malthe/chameleon.html/ Added support for macro usage.

Malthe Borch mborch at gmail.com
Thu Nov 13 08:28:52 EST 2008


Log message for revision 92903:
  Added support for macro usage.

Changed:
  U   Sandbox/malthe/chameleon.html/CHANGES.txt
  U   Sandbox/malthe/chameleon.html/src/chameleon/html/language.py
  U   Sandbox/malthe/chameleon.html/src/chameleon/html/template.py
  U   Sandbox/malthe/chameleon.html/src/chameleon/html/template.txt

-=-
Modified: Sandbox/malthe/chameleon.html/CHANGES.txt
===================================================================
--- Sandbox/malthe/chameleon.html/CHANGES.txt	2008-11-13 12:18:51 UTC (rev 92902)
+++ Sandbox/malthe/chameleon.html/CHANGES.txt	2008-11-13 13:28:51 UTC (rev 92903)
@@ -4,6 +4,8 @@
 HEAD
 ~~~~
 
+- Added support for macro usage. [malthe]
+
 chameleon.html 0.4 (released 10/28/2008)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

Modified: Sandbox/malthe/chameleon.html/src/chameleon/html/language.py
===================================================================
--- Sandbox/malthe/chameleon.html/src/chameleon/html/language.py	2008-11-13 12:18:51 UTC (rev 92902)
+++ Sandbox/malthe/chameleon.html/src/chameleon/html/language.py	2008-11-13 13:28:51 UTC (rev 92903)
@@ -111,7 +111,7 @@
         @property
         def content(self):
             content = self.element.xss_content
-            if content is not None:
+            if content is not None and self.define_slot is None:
                 expression = types.value(
                     "%s or %s" % (self.define_symbol, repr(self.element.text)))
 
@@ -121,15 +121,26 @@
                 return expression
 
         @property
+        def define_slot(self):
+            name = self.element.xss_content
+            if name is not None:
+                variable = self.symbols.slot + name
+                for scope in self.stream.scope:
+                    if variable in scope:
+                        return name
+        
+        @property
         def static_attributes(self):
             return utils.get_attributes_from_namespace(
                 self.element, config.XHTML_NS)
 
         @property
         def skip(self):
+            if self.define_slot is not None:
+                return True
             if self.element.xss_content is not None:
                 return types.value(self.define_symbol)
-                
+        
     node = property(node)
 
     xss_omit = utils.attribute(

Modified: Sandbox/malthe/chameleon.html/src/chameleon/html/template.py
===================================================================
--- Sandbox/malthe/chameleon.html/src/chameleon/html/template.py	2008-11-13 12:18:51 UTC (rev 92902)
+++ Sandbox/malthe/chameleon.html/src/chameleon/html/template.py	2008-11-13 13:28:51 UTC (rev 92903)
@@ -13,6 +13,15 @@
         return template.TemplateFile.render(
             self, content=content, attributes=attributes, **kwargs)
 
+    def render_macro(self, macro, global_scope=False, parameters=None):
+        if parameters is None: parameters = {}
+        
+        parameters.setdefault('content', {})
+        parameters.setdefault('attributes', {})
+
+        return template.TemplateFile.render_macro(
+            self, macro, global_scope=global_scope, parameters=parameters)
+
     def mtime(self):
         """Return the most recent modification times from the template
         file itself and any XSS-files included."""

Modified: Sandbox/malthe/chameleon.html/src/chameleon/html/template.txt
===================================================================
--- Sandbox/malthe/chameleon.html/src/chameleon/html/template.txt	2008-11-13 12:18:51 UTC (rev 92902)
+++ Sandbox/malthe/chameleon.html/src/chameleon/html/template.txt	2008-11-13 13:28:51 UTC (rev 92903)
@@ -87,6 +87,21 @@
     </body>
   </html>
 
+Layouts as macros
+-----------------
+
+Layouts may be used as macros in which case the slots are filled using
+METAL's `fill-slot` construct.
+
+  >>> from chameleon.core.config import SYMBOLS
+  >>> print template(**{
+  ...    SYMBOLS.slot+"title": u"Title from macro"})
+  <html>
+    ...
+    <title>Title from macro</title>
+    ...
+  </html>
+  
 Globbing support for easy resource inclusion
 --------------------------------------------
 



More information about the Checkins mailing list