Commits

Anonymous committed a5381a3

implemented basic page handling with variants and slots

  • Participants
  • Parent commits c9a349c

Comments (0)

Files changed (6)

File docs/example/page.py

     
     def content(self):
         """return the main document content"""
-        return tmpls.get("content")(document)
+        return tmpls.get("content")(document=document)
         
 
 class MainEditPage(MainPage):
     """a variant of the main page which renders the edit form for the content"""
     
     def content(self):
-        return tmpls.get("editform")(document)
+        return tmpls.get("editform")(document=document)
         
     
 class MainPageRenderer(Page):
 
 def main():
     
-    renderer = MainPageRenderer(context)
+    renderer = MainPageRenderer(tmpls)
     
     # render the main page
     print renderer()
+
+    print "-----"
     
     # render the editform
     print renderer('edit')
+
+    print "-----"
     
     # just render the 'content' slot from the 'main' variant
-    print renderer.slot('main','content')
-    
-    
-    
-    
-    
-        
-        
-        
+    print renderer.render_slot('content','main')
+
+    print "-----"
+
+    print renderer.render_slot('content','edit')
+
+main()

File docs/example/templates/content.pt

+<span>
+CONTENT
+</span>

File docs/example/templates/editform.pt

+<span>
+EDITFORM
+</span>

File docs/example/templates/main.pt

         <div id="main">
 
             <div id="content">
-                This is the document content.
+                <tal:block replace="structure page['content']" />
             </div>
 
             <a href="edit" id="editbutton">Edit</a>

File quantumcore/dynamicpage/page.py

             variant_to_use = self.default_variant
         
         vobj = self.variants[variant]
-        return vobj('variant', **kw)
+        return vobj(slot, **self.kw)
         
     def __getitem__(self, slotname):
         """return a rendered slot. This will directly return HTML. It will use the variant
             
         
             
-        
+        

File quantumcore/dynamicpage/templates.py

 class TemplateStore(object):
     """a class for storing and caching templates"""
 
-    _cache = {}
+    cache = {}
 
     def add_from_package(self, name, package, filename):
         pt = pkg_resources.resource_string(package, filename)
 
     def get(self, name):
         """return a template by name"""
-        return self._cache[name]
+        return self.cache[name]
         
     __getitem__ = get