[Checkins] SVN: grok/branches/grokcore.xxx/ move templates and
resource related components and grokkers to grokcore.view
Godefroid Chapelle
gotcha at bubblenet.be
Thu Jul 17 12:59:57 EDT 2008
Log message for revision 88459:
move templates and resource related components and grokkers to grokcore.view
Changed:
U grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/__init__.py
U grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/components.py
U grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/interfaces.py
U grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/meta.zcml
U grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/templatereg.py
U grok/branches/grokcore.xxx/src/grok/__init__.py
U grok/branches/grokcore.xxx/src/grok/components.py
U grok/branches/grokcore.xxx/src/grok/interfaces.py
U grok/branches/grokcore.xxx/src/grok/meta.py
U grok/branches/grokcore.xxx/src/grok/testing.py
U grok/branches/grokcore.xxx/src/grok/tests/template/pluggability.py
-=-
Modified: grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/__init__.py
===================================================================
--- grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/__init__.py 2008-07-17 16:55:39 UTC (rev 88458)
+++ grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/__init__.py 2008-07-17 16:59:56 UTC (rev 88459)
@@ -1,3 +1,4 @@
from directive import layer, view, require, template, templatedir
from util import url
from components import ViewMixin, Permission, GrokForm
+from components import PageTemplate, PageTemplateFile
Modified: grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/components.py
===================================================================
--- grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/components.py 2008-07-17 16:55:39 UTC (rev 88458)
+++ grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/components.py 2008-07-17 16:59:56 UTC (rev 88459)
@@ -1,3 +1,6 @@
+import os
+import sys
+
from zope import component
from zope import interface
@@ -3,8 +6,15 @@
from zope.publisher.publish import mapply
from zope.security.permission import Permission
+from zope.pagetemplate import pagetemplate, pagetemplatefile
+from zope.app.pagetemplate.engine import TrustedAppPT
+from zope.app.publisher.browser import directoryresource
+from zope.app.publisher.browser.pagetemplateresource import \
+ PageTemplateResourceFactory
-from grokcore.view import util
+import martian
+from grokcore.view import util, interfaces
+
class Permission(Permission):
pass
@@ -133,3 +143,142 @@
self.update_form()
return self.render()
+
+
+class BaseTemplate(object):
+ """Any sort of page template"""
+
+ interface.implements(interfaces.ITemplate)
+
+ __grok_name__ = ''
+ __grok_location__ = ''
+
+ def __repr__(self):
+ return '<%s template in %s>' % (self.__grok_name__,
+ self.__grok_location__)
+
+ def _annotateGrokInfo(self, name, location):
+ self.__grok_name__ = name
+ self.__grok_location__ = location
+
+ def _initFactory(self, factory):
+ pass
+
+
+class GrokTemplate(BaseTemplate):
+ """A slightly more advanced page template
+
+ This provides most of what a page template needs and is a good base for
+ writing your own page template"""
+
+ def __init__(self, string=None, filename=None, _prefix=None):
+
+ # __grok_module__ is needed to make defined_locally() return True for
+ # inline templates
+ # XXX unfortunately using caller_module means that care must be taken
+ # when GrokTemplate is subclassed. You can not do a super().__init__
+ # for example.
+ self.__grok_module__ = martian.util.caller_module()
+
+ if not (string is None) ^ (filename is None):
+ raise AssertionError(
+ "You must pass in template or filename, but not both.")
+
+ if string:
+ self.setFromString(string)
+ else:
+ if _prefix is None:
+ module = sys.modules[self.__grok_module__]
+ _prefix = os.path.dirname(module.__file__)
+ self.setFromFilename(filename, _prefix)
+
+ def __repr__(self):
+ return '<%s template in %s>' % (self.__grok_name__,
+ self.__grok_location__)
+
+ def _annotateGrokInfo(self, name, location):
+ self.__grok_name__ = name
+ self.__grok_location__ = location
+
+ def _initFactory(self, factory):
+ pass
+
+ def namespace(self, view):
+ # By default use the namespaces that are defined as the
+ # default by the view implementation.
+ return view.default_namespace()
+
+ def getNamespace(self, view):
+ namespace = self.namespace(view)
+ namespace.update(view.namespace())
+ return namespace
+
+
+class TrustedPageTemplate(TrustedAppPT, pagetemplate.PageTemplate):
+ pass
+
+
+class TrustedFilePageTemplate(TrustedAppPT, pagetemplatefile.PageTemplateFile):
+ pass
+
+
+class PageTemplate(GrokTemplate):
+
+ def setFromString(self, string):
+ zpt = TrustedPageTemplate()
+ if martian.util.not_unicode_or_ascii(string):
+ raise ValueError("Invalid page template. Page templates must be "
+ "unicode or ASCII.")
+ zpt.write(string)
+ self._template = zpt
+
+ def setFromFilename(self, filename, _prefix=None):
+ self._template = TrustedFilePageTemplate(filename, _prefix)
+
+ def _initFactory(self, factory):
+ factory.macros = self._template.macros
+
+ def render(self, view):
+ namespace = self.getNamespace(view)
+ template = self._template
+ namespace.update(template.pt_getContext())
+ return template.pt_render(namespace)
+
+
+class PageTemplateFile(PageTemplate):
+ # For BBB
+
+ def __init__(self, filename, _prefix=None):
+ self.__grok_module__ = martian.util.caller_module()
+ if _prefix is None:
+ module = sys.modules[self.__grok_module__]
+ _prefix = os.path.dirname(module.__file__)
+ self.setFromFilename(filename, _prefix)
+
+
+class DirectoryResource(directoryresource.DirectoryResource):
+ # We subclass this, because we want to override the default factories for
+ # the resources so that .pt and .html do not get created as page
+ # templates
+
+ resource_factories = {}
+ for type, factory in (directoryresource.DirectoryResource.
+ resource_factories.items()):
+ if factory is PageTemplateResourceFactory:
+ continue
+ resource_factories[type] = factory
+
+
+class DirectoryResourceFactory(object):
+ # We need this to allow hooking up our own GrokDirectoryResource
+ # and to set the checker to None (until we have our own checker)
+
+ def __init__(self, path, name):
+ # XXX we're not sure about the checker=None here
+ self.__dir = directoryresource.Directory(path, None, name)
+ self.__name = name
+
+ def __call__(self, request):
+ resource = DirectoryResource(self.__dir, request)
+ resource.__name__ = self.__name
+ return resource
Modified: grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/interfaces.py
===================================================================
--- grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/interfaces.py 2008-07-17 16:55:39 UTC (rev 88458)
+++ grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/interfaces.py 2008-07-17 16:59:56 UTC (rev 88459)
@@ -78,3 +78,25 @@
hierarchy or the URL of a named object (``name`` parameter)
relative to the closest application object.
"""
+
+
+class ITemplateFileFactory(interface.Interface):
+ """Utility that generates templates from files in template directories.
+ """
+
+ def __call__(filename, _prefix=None):
+ """Creates an ITemplate from a file
+
+ _prefix is the directory the file is located in
+ """
+
+
+class ITemplate(interface.Interface):
+ """Template objects
+ """
+
+ def _initFactory(factory):
+ """Template language specific initializations on the view factory."""
+
+ def render(view):
+ """Renders the template"""
Modified: grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/meta.zcml
===================================================================
--- grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/meta.zcml 2008-07-17 16:55:39 UTC (rev 88458)
+++ grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/meta.zcml 2008-07-17 16:59:56 UTC (rev 88459)
@@ -3,6 +3,7 @@
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:grok="http://namespaces.zope.org/grok">
+ <grok:grok package=".meta" />
<!-- ZPT support -->
<grok:grok package=".templatereg" />
Modified: grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/templatereg.py
===================================================================
--- grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/templatereg.py 2008-07-17 16:55:39 UTC (rev 88458)
+++ grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/templatereg.py 2008-07-17 16:59:56 UTC (rev 88459)
@@ -1,11 +1,16 @@
+import os
+
+import zope.component
+from zope.interface import implements
+
from martian.error import GrokError
-from martian import util
-import os
-import zope.component
import grok
+import grokcore.view
+import grokcore.component
import warnings
+
class TemplateRegistry(object):
def __init__(self):
@@ -24,7 +29,7 @@
return entry['template']
def findFilesystem(self, module_info):
- template_dir_name = grok.templatedir.bind().get(
+ template_dir_name = grokcore.view.templatedir.bind().get(
module=module_info.getModule())
if template_dir_name is None:
template_dir_name = module_info.name + '_templates'
@@ -89,17 +94,16 @@
def checkTemplates(self, module_info, factory, component_name,
has_render, has_no_render):
factory_name = factory.__name__.lower()
- template_name = grok.template.bind().get(factory)
+ template_name = grokcore.view.template.bind().get(factory)
if template_name is None:
template_name = factory_name
if factory_name != template_name:
- # grok.template is being used
-
+ # grokcore.view.template is being used
if self.get(factory_name):
raise GrokError("Multiple possible templates for %s %r. It "
- "uses grok.template('%s'), but there is also "
- "a template called '%s'."
+ "uses grok.template('%s'), but there "
+ "is also a template called '%s'."
% (component_name, factory, template_name,
factory_name), factory)
template = self.get(template_name)
@@ -122,10 +126,10 @@
"'render' method." %
(component_name.title(), factory), factory)
-class PageTemplateFileFactory(grok.GlobalUtility):
- grok.implements(grok.interfaces.ITemplateFileFactory)
- grok.name('pt')
+class PageTemplateFileFactory(grokcore.component.GlobalUtility):
+ implements(grok.interfaces.ITemplateFileFactory)
+ grokcore.component.name('pt')
def __call__(self, filename, _prefix=None):
return grok.components.PageTemplate(filename=filename, _prefix=_prefix)
Modified: grok/branches/grokcore.xxx/src/grok/__init__.py
===================================================================
--- grok/branches/grokcore.xxx/src/grok/__init__.py 2008-07-17 16:55:39 UTC (rev 88458)
+++ grok/branches/grokcore.xxx/src/grok/__init__.py 2008-07-17 16:59:56 UTC (rev 88459)
@@ -33,7 +33,7 @@
from grokcore.component import Adapter, MultiAdapter, GlobalUtility
from grok.components import Model, View
from grok.components import XMLRPC, REST, JSON
-from grok.components import PageTemplate, PageTemplateFile, Traverser
+from grok.components import Traverser
from grok.components import Container, OrderedContainer
from grok.components import Site, LocalUtility, Annotation
from grok.components import Application, Form, AddForm, EditForm, DisplayForm
@@ -43,6 +43,8 @@
from grok.components import RESTProtocol, IRESTLayer
from grok.interfaces import IRESTSkinType
from grok.components import ViewletManager, Viewlet
+from grokcore.view import Permission
+from grokcore.view import PageTemplate, PageTemplateFile
from martian import baseclass
from grokcore.component.directive import (
@@ -54,7 +56,6 @@
from martian.error import GrokError, GrokImportError
from grokcore.view import layer, view, require, template, templatedir
-from grokcore.view import Permission
# BBB These two functions are meant for test fixtures and should be
# imported from grok.testing, not from grok.
Modified: grok/branches/grokcore.xxx/src/grok/components.py
===================================================================
--- grok/branches/grokcore.xxx/src/grok/components.py 2008-07-17 16:55:39 UTC (rev 88458)
+++ grok/branches/grokcore.xxx/src/grok/components.py 2008-07-17 16:59:56 UTC (rev 88459)
@@ -13,7 +13,6 @@
##############################################################################
"""Grok components"""
-import sys
import os
import persistent
import datetime
@@ -30,16 +29,11 @@
from zope.publisher.interfaces import NotFound
from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.publisher.interfaces.http import IHTTPRequest
-from zope.pagetemplate import pagetemplate, pagetemplatefile
from zope.publisher.publish import mapply
from zope.formlib import form
from zope.annotation.interfaces import IAttributeAnnotatable
-from zope.app.pagetemplate.engine import TrustedAppPT
from zope.app.publisher.browser import getDefaultViewName
-from zope.app.publisher.browser import directoryresource
-from zope.app.publisher.browser.pagetemplateresource import \
- PageTemplateResourceFactory
from zope.app.container.btree import BTreeContainer
from zope.app.container.contained import Contained
from zope.app.container.interfaces import IReadContainer, IObjectAddedEvent
@@ -60,6 +54,8 @@
from grok import interfaces, util
from grokcore.view import formlib
from grokcore.view import GrokForm
+from grokcore.view import PageTemplate
+from grokcore.view import PageTemplateFile
class Model(Contained, persistent.Persistent):
@@ -228,139 +224,6 @@
return simplejson.dumps(method_result)
-class BaseTemplate(object):
- """Any sort of page template"""
-
- interface.implements(interfaces.ITemplate)
-
- __grok_name__ = ''
- __grok_location__ = ''
-
- def __repr__(self):
- return '<%s template in %s>' % (self.__grok_name__,
- self.__grok_location__)
-
- def _annotateGrokInfo(self, name, location):
- self.__grok_name__ = name
- self.__grok_location__ = location
-
- def _initFactory(self, factory):
- pass
-
-
-class GrokTemplate(BaseTemplate):
- """A slightly more advanced page template
-
- This provides most of what a page template needs and is a good base for
- writing your own page template"""
-
- def __init__(self, string=None, filename=None, _prefix=None):
-
- # __grok_module__ is needed to make defined_locally() return True for
- # inline templates
- # XXX unfortunately using caller_module means that care must be taken
- # when GrokTemplate is subclassed. You can not do a super().__init__
- # for example.
- self.__grok_module__ = martian.util.caller_module()
-
- if not (string is None) ^ (filename is None):
- raise AssertionError(
- "You must pass in template or filename, but not both.")
-
- if string:
- self.setFromString(string)
- else:
- if _prefix is None:
- module = sys.modules[self.__grok_module__]
- _prefix = os.path.dirname(module.__file__)
- self.setFromFilename(filename, _prefix)
-
- def __repr__(self):
- return '<%s template in %s>' % (self.__grok_name__,
- self.__grok_location__)
-
- def _annotateGrokInfo(self, name, location):
- self.__grok_name__ = name
- self.__grok_location__ = location
-
- def _initFactory(self, factory):
- pass
-
- def namespace(self, view):
- # By default use the namespaces that are defined as the
- # default by the view implementation.
- return view.default_namespace()
-
- def getNamespace(self, view):
- namespace = self.namespace(view)
- namespace.update(view.namespace())
- return namespace
-
-class TrustedPageTemplate(TrustedAppPT, pagetemplate.PageTemplate):
- pass
-
-class TrustedFilePageTemplate(TrustedAppPT, pagetemplatefile.PageTemplateFile):
- pass
-
-class PageTemplate(GrokTemplate):
-
- def setFromString(self, string):
- zpt = TrustedPageTemplate()
- if martian.util.not_unicode_or_ascii(string):
- raise ValueError("Invalid page template. Page templates must be "
- "unicode or ASCII.")
- zpt.write(string)
- self._template = zpt
-
- def setFromFilename(self, filename, _prefix=None):
- self._template = TrustedFilePageTemplate(filename, _prefix)
-
- def _initFactory(self, factory):
- factory.macros = self._template.macros
-
- def render(self, view):
- namespace = self.getNamespace(view)
- template = self._template
- namespace.update(template.pt_getContext())
- return template.pt_render(namespace)
-
-class PageTemplateFile(PageTemplate):
- # For BBB
- def __init__(self, filename, _prefix=None):
- self.__grok_module__ = martian.util.caller_module()
- if _prefix is None:
- module = sys.modules[self.__grok_module__]
- _prefix = os.path.dirname(module.__file__)
- self.setFromFilename(filename, _prefix)
-
-class DirectoryResource(directoryresource.DirectoryResource):
- # We subclass this, because we want to override the default factories for
- # the resources so that .pt and .html do not get created as page
- # templates
-
- resource_factories = {}
- for type, factory in (directoryresource.DirectoryResource.
- resource_factories.items()):
- if factory is PageTemplateResourceFactory:
- continue
- resource_factories[type] = factory
-
-
-class DirectoryResourceFactory(object):
- # We need this to allow hooking up our own GrokDirectoryResource
- # and to set the checker to None (until we have our own checker)
-
- def __init__(self, path, name):
- # XXX we're not sure about the checker=None here
- self.__dir = directoryresource.Directory(path, None, name)
- self.__name = name
-
- def __call__(self, request):
- resource = DirectoryResource(self.__dir, request)
- resource.__name__ = self.__name
- return resource
-
-
class Traverser(object):
interface.implements(IBrowserPublisher)
Modified: grok/branches/grokcore.xxx/src/grok/interfaces.py
===================================================================
--- grok/branches/grokcore.xxx/src/grok/interfaces.py 2008-07-17 16:55:39 UTC (rev 88458)
+++ grok/branches/grokcore.xxx/src/grok/interfaces.py 2008-07-17 16:59:56 UTC (rev 88459)
@@ -21,6 +21,8 @@
from grokcore.component.interfaces import IContext
import grokcore.view.interfaces
+from grokcore.view.interfaces import ITemplateFileFactory
+from grokcore.view.interfaces import ITemplate
class IGrokBaseClasses(interface.Interface):
ClassGrokker = interface.Attribute("Base class to define a class "
@@ -423,26 +425,6 @@
"""Skin type for REST requests.
"""
-class ITemplateFileFactory(interface.Interface):
- """Utility that generates templates from files in template directories.
- """
-
- def __call__(filename, _prefix=None):
- """Creates an ITemplate from a file
-
- _prefix is the directory the file is located in
- """
-
-class ITemplate(interface.Interface):
- """Template objects
- """
-
- def _initFactory(factory):
- """Template language specific initializations on the view factory."""
-
- def render(view):
- """Renders the template"""
-
class IContainer(IContext, IContainerBase):
"""A Grok container.
"""
Modified: grok/branches/grokcore.xxx/src/grok/meta.py
===================================================================
--- grok/branches/grokcore.xxx/src/grok/meta.py 2008-07-17 16:55:39 UTC (rev 88458)
+++ grok/branches/grokcore.xxx/src/grok/meta.py 2008-07-17 16:59:56 UTC (rev 88459)
@@ -13,8 +13,6 @@
##############################################################################
"""Grokkers for the various components."""
-import os
-
import zope.component.interface
from zope import interface, component
from zope.publisher.interfaces.browser import (IDefaultBrowserLayer,
@@ -48,7 +46,6 @@
from martian import util
import grokcore.view
-import grokcore.view.templatereg
from grokcore.view.meta import ViewGrokkerBase
from grokcore.view.util import default_view_name
@@ -199,109 +196,8 @@
return True
-class TemplateGrokker(martian.GlobalGrokker):
- # this needs to happen before any other grokkers execute that use
- # the template registry
- martian.priority(1001)
- def grok(self, name, module, module_info, config, **kw):
- module.__grok_templates__ = grokcore.view.templatereg.TemplateRegistry()
- return True
-
-class ModulePageTemplateGrokker(martian.InstanceGrokker):
- martian.component(grok.components.BaseTemplate)
- # this needs to happen before any other grokkers execute that actually
- # use the templates
- martian.priority(1000)
-
- def grok(self, name, instance, module_info, config, **kw):
- templates = module_info.getAnnotation('grok.templates', None)
- if templates is None:
- return False
- config.action(
- discriminator=None,
- callable=templates.register,
- args=(name, instance)
- )
- config.action(
- discriminator=None,
- callable=instance._annotateGrokInfo,
- args=(name, module_info.dotted_name)
- )
- return True
-
-
-class FilesystemPageTemplateGrokker(martian.GlobalGrokker):
- # do this early on, but after ModulePageTemplateGrokker, as
- # findFilesystem depends on module-level templates to be
- # already grokked for error reporting
- martian.priority(999)
-
- def grok(self, name, module, module_info, config, **kw):
- templates = module_info.getAnnotation('grok.templates', None)
- if templates is None:
- return False
- config.action(
- discriminator=None,
- callable=templates.findFilesystem,
- args=(module_info,)
- )
- return True
-
-
-class UnassociatedTemplatesGrokker(martian.GlobalGrokker):
- martian.priority(-1001)
-
- def grok(self, name, module, module_info, config, **kw):
- templates = module_info.getAnnotation('grok.templates', None)
- if templates is None:
- return False
-
- config.action(
- discriminator=None,
- callable=templates.checkUnassociated,
- args=(module_info,)
- )
- return True
-
-
-class StaticResourcesGrokker(martian.GlobalGrokker):
-
- def grok(self, name, module, module_info, config, **kw):
- # we're only interested in static resources if this module
- # happens to be a package
- if not module_info.isPackage():
- return False
-
- resource_path = module_info.getResourcePath('static')
- if os.path.isdir(resource_path):
- static_module = module_info.getSubModuleInfo('static')
- if static_module is not None:
- if static_module.isPackage():
- raise GrokError(
- "The 'static' resource directory must not "
- "be a python package.",
- module_info.getModule())
- else:
- raise GrokError(
- "A package can not contain both a 'static' "
- "resource directory and a module named "
- "'static.py'", module_info.getModule())
-
- resource_factory = components.DirectoryResourceFactory(
- resource_path, module_info.dotted_name)
- adapts = (IDefaultBrowserLayer,)
- provides = interface.Interface
- name = module_info.dotted_name
- config.action(
- discriminator=('adapter', adapts, provides, name),
- callable=component.provideAdapter,
- args=(resource_factory, adapts, provides, name),
- )
- return True
-
-
class SiteGrokker(martian.ClassGrokker):
martian.component(grok.Site)
martian.priority(500)
Modified: grok/branches/grokcore.xxx/src/grok/testing.py
===================================================================
--- grok/branches/grokcore.xxx/src/grok/testing.py 2008-07-17 16:55:39 UTC (rev 88458)
+++ grok/branches/grokcore.xxx/src/grok/testing.py 2008-07-17 16:59:56 UTC (rev 88459)
@@ -42,6 +42,7 @@
def grok(module_name):
config = ConfigurationMachine()
zcml.do_grok('grokcore.component.meta', config)
+ zcml.do_grok('grokcore.view.meta', config)
zcml.do_grok('grok.meta', config)
zcml.do_grok('grokcore.view.templatereg', config)
zcml.do_grok(module_name, config)
Modified: grok/branches/grokcore.xxx/src/grok/tests/template/pluggability.py
===================================================================
--- grok/branches/grokcore.xxx/src/grok/tests/template/pluggability.py 2008-07-17 16:55:39 UTC (rev 88458)
+++ grok/branches/grokcore.xxx/src/grok/tests/template/pluggability.py 2008-07-17 16:59:56 UTC (rev 88459)
@@ -2,12 +2,12 @@
Testing the plugging in of a template language
>>> grok.testing.grok(__name__)
-
+
>>> cave = Cave()
>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()
>>> from zope import component
-
+
# The inline template should work:
>>> view = component.getMultiAdapter((cave, request), name='sebaayeni')
>>> print view()
@@ -23,25 +23,26 @@
>>> print view()
<html><body>Kakadu is in Australia</body></html>
- # We should be able to extend the namespac in the view and
+ # We should be able to extend the namespac in the view and
>>> view = component.getMultiAdapter((cave, request), name='sierra')
>>> print view()
<html><body>Sierra de San Fransisco is in Mexico</body></html>
"""
import grok, os
+import grokcore.view.components
# Dummy template language:
class MyTemplate(object):
-
+
def __init__(self, text):
self._text = text
-
+
def render(self, **kw):
# Silliest template language ever:
return self._text % kw
-class MyPageTemplate(grok.components.GrokTemplate):
+class MyPageTemplate(grokcore.view.components.GrokTemplate):
def setFromString(self, string):
self._template = MyTemplate(string)
@@ -70,19 +71,19 @@
class Sebaayeni(grok.View):
pass
-
+
sebaayeni = MyPageTemplate('<html><body>Sebaayeni is in South Africa</body></html>')
class Lascaux(grok.View):
pass
-
+
lascaux = MyPageTemplate(filename='lascaux.html')
class Kakadu(grok.View):
pass
class Sierra(grok.View):
-
+
def namespace(self):
return {'cave': 'Sierra de San Fransisco',
'country': 'Mexico'}
More information about the Checkins
mailing list