[Checkins] SVN: grok/branches/ksmith_mcweekly-layers/ Hmmm... sadly
layers are Interface definitions and interface definitions
don't allow concrete attributes. So grok.skin in a grok.Layer
instance fails. This implementation uses
grok.defineskin('MySkinName', MySkinLayer) at the module level.
Kevin Smith
kevin at mcweekly.com
Sun Apr 15 04:10:01 EDT 2007
Log message for revision 74145:
Hmmm... sadly layers are Interface definitions and interface definitions don't allow concrete attributes. So grok.skin in a grok.Layer instance fails. This implementation uses grok.defineskin('MySkinName', MySkinLayer) at the module level.
Changed:
U grok/branches/ksmith_mcweekly-layers/buildout.cfg
U grok/branches/ksmith_mcweekly-layers/src/grok/__init__.py
U grok/branches/ksmith_mcweekly-layers/src/grok/components.py
U grok/branches/ksmith_mcweekly-layers/src/grok/directive.py
U grok/branches/ksmith_mcweekly-layers/src/grok/ftests/view/layer.py
U grok/branches/ksmith_mcweekly-layers/src/grok/interfaces.py
U grok/branches/ksmith_mcweekly-layers/src/grok/meta.py
-=-
Modified: grok/branches/ksmith_mcweekly-layers/buildout.cfg
===================================================================
--- grok/branches/ksmith_mcweekly-layers/buildout.cfg 2007-04-15 08:03:10 UTC (rev 74144)
+++ grok/branches/ksmith_mcweekly-layers/buildout.cfg 2007-04-15 08:10:00 UTC (rev 74145)
@@ -1,10 +1,11 @@
[buildout]
develop = . grokwiki ldapaddressbook
-parts = zope3 data instance testdata testinstance test
+parts = data instance testdata testinstance test
[zope3]
-recipe = zc.recipe.zope3checkout
-url = svn://svn.zope.org/repos/main/Zope3/branches/3.3
+location=/root/zope3
+#recipe = zc.recipe.zope3checkout
+#url = svn://svn.zope.org/repos/main/Zope3/branches/3.3
[data]
recipe = zc.recipe.filestorage
@@ -54,7 +55,7 @@
[test]
recipe = zc.recipe.testrunner
eggs = grok
-extra-paths = parts/zope3/src
+extra-paths = /root/zope3/src
working-directory = parts/testinstance
defaults = ['--tests-pattern', '^f?tests$',
'-v'
Modified: grok/branches/ksmith_mcweekly-layers/src/grok/__init__.py
===================================================================
--- grok/branches/ksmith_mcweekly-layers/src/grok/__init__.py 2007-04-15 08:03:10 UTC (rev 74144)
+++ grok/branches/ksmith_mcweekly-layers/src/grok/__init__.py 2007-04-15 08:10:00 UTC (rev 74145)
@@ -30,13 +30,13 @@
IContainerModifiedEvent, ContainerModifiedEvent)
from grok.components import ClassGrokker, InstanceGrokker, ModuleGrokker
-from grok.components import Model, Adapter, MultiAdapter, View, XMLRPC
+from grok.components import Model, Adapter, MultiAdapter, View, XMLRPC, Layer
from grok.components import PageTemplate, PageTemplateFile, Container, Traverser
from grok.components import Site, GlobalUtility, LocalUtility, Annotation
from grok.components import Application, Form, AddForm, EditForm, DisplayForm
from grok.directive import (context, name, template, templatedir, provides,
baseclass, global_utility, local_utility,
- define_permission, require, layer)
+ define_permission, require, layer, defineskin)
from grok._grok import do_grok as grok # Avoid name clash within _grok
from grok._grok import SubscribeDecorator as subscribe
from grok.error import GrokError, GrokImportError
Modified: grok/branches/ksmith_mcweekly-layers/src/grok/components.py
===================================================================
--- grok/branches/ksmith_mcweekly-layers/src/grok/components.py 2007-04-15 08:03:10 UTC (rev 74144)
+++ grok/branches/ksmith_mcweekly-layers/src/grok/components.py 2007-04-15 08:10:00 UTC (rev 74145)
@@ -108,6 +108,10 @@
interface.implements(IAttributeAnnotatable)
+class Layer(interface.Interface):
+ pass
+
+
class Site(SiteManagerContainer):
pass
Modified: grok/branches/ksmith_mcweekly-layers/src/grok/directive.py
===================================================================
--- grok/branches/ksmith_mcweekly-layers/src/grok/directive.py 2007-04-15 08:03:10 UTC (rev 74144)
+++ grok/branches/ksmith_mcweekly-layers/src/grok/directive.py 2007-04-15 08:10:00 UTC (rev 74145)
@@ -199,6 +199,19 @@
"%s." % self.name)
+
+class DefineSkinDirective(MultipleTimesDirective):
+ def check_arguments(self, name, iface):
+ pass
+
+ def value_factory(self, *args, **kw):
+ return DefineSkinInfo(*args, **kw)
+
+class DefineSkinInfo(object):
+ def __init__(self, name, iface):
+ self.name = name
+ self.iface = iface
+
class GlobalUtilityDirective(MultipleTimesDirective):
def check_arguments(self, factory, provides=None, name=u''):
if provides is not None and not IInterface.providedBy(provides):
@@ -279,3 +292,12 @@
define_permission = MultipleTextDirective('grok.define_permission',
ModuleDirectiveContext())
require = RequireDirective('grok.require', ClassDirectiveContext())
+
+defineskin = DefineSkinDirective('grok.defineskin',
+ ModuleDirectiveContext())
+
+
+# from zope.component.interface import provideInterface
+# def defineskin(name, iface):
+# provideInterface(name, iface, IBrowserSkinType)
+
Modified: grok/branches/ksmith_mcweekly-layers/src/grok/ftests/view/layer.py
===================================================================
--- grok/branches/ksmith_mcweekly-layers/src/grok/ftests/view/layer.py 2007-04-15 08:03:10 UTC (rev 74144)
+++ grok/branches/ksmith_mcweekly-layers/src/grok/ftests/view/layer.py 2007-04-15 08:10:00 UTC (rev 74145)
@@ -14,7 +14,7 @@
<h1>Hello, world!</h1>
</body>
</html>
-
+
>>> browser.open("http://localhost/++skin++Rotterdam/manfred/@@cavedrawings")
Traceback (most recent call last):
...
@@ -22,16 +22,24 @@
>>> browser.open("http://localhost/++skin++Rotterdam/manfred/@@moredrawings")
>>> print browser.contents
Pretty
+ >>> browser.open("http://localhost/++skin++MySkin/manfred/@@evenmoredrawings")
+ >>> print browser.contents
+ Awesome
"""
import grok
from zope.app.basicskin import IBasicSkin
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.app.rotterdam import rotterdam
+from zope import interface
grok.layer(IBasicSkin)
+class MySkinLayer(grok.Layer):
+ pass
+grok.defineskin('MySkin', MySkinLayer)
+
class Mammoth(grok.Model):
pass
@@ -51,3 +59,9 @@
def render(self):
return "Pretty"
+
+class EvenMoreDrawings(grok.View):
+ grok.layer(MySkinLayer)
+
+ def render(self):
+ return "Awesome"
Modified: grok/branches/ksmith_mcweekly-layers/src/grok/interfaces.py
===================================================================
--- grok/branches/ksmith_mcweekly-layers/src/grok/interfaces.py 2007-04-15 08:03:10 UTC (rev 74144)
+++ grok/branches/ksmith_mcweekly-layers/src/grok/interfaces.py 2007-04-15 08:10:00 UTC (rev 74145)
@@ -41,8 +41,8 @@
AddForm = interface.Attribute("Base class for add forms.")
EditForm = interface.Attribute("Base class for edit forms.")
DisplayForm = interface.Attribute("Base class for display forms.")
+ Layer = interface.Attribute("Base interface for skin layers.")
-
class IGrokErrors(interface.Interface):
def GrokError(message, component):
@@ -75,6 +75,16 @@
This directive can only be used on class level."""
+ def layer(layer):
+ """Declare the layer the view is applied.
+
+ This directive can only be used on class level."""
+
+ def skin(skin):
+ """Declare this layer as a named skin.
+
+ This directive can only be used on class level."""
+
def template(template):
"""Declare the template name for a view.
@@ -120,6 +130,8 @@
The site should in this case be a container.
name_in_container - the name to use for storing the utility
"""
+ def defineskin(name, iface):
+ """Register skin name for layer."""
def define_permission(permission):
"""Defines a new permission with the id ``permission``."""
Modified: grok/branches/ksmith_mcweekly-layers/src/grok/meta.py
===================================================================
--- grok/branches/ksmith_mcweekly-layers/src/grok/meta.py 2007-04-15 08:03:10 UTC (rev 74144)
+++ grok/branches/ksmith_mcweekly-layers/src/grok/meta.py 2007-04-15 08:10:00 UTC (rev 74145)
@@ -118,6 +118,15 @@
defineChecker(method_view, checker)
+class LayerGrokker(grok.ClassGrokker):
+ component_class = grok.Layer
+
+ def register(self, context, name, factory, module_info, templates):
+ import pdb; pdb.set_trace()
+ view_skin = util.class_annotation(factory, 'grok.skin', None)
+
+
+
class ViewGrokker(grok.ClassGrokker):
component_class = grok.View
@@ -287,7 +296,16 @@
resource_factory, (IDefaultBrowserLayer,),
interface.Interface, name=module_info.dotted_name)
+from zope.publisher.interfaces.browser import IBrowserSkinType
+class DefineSkinDirectiveGrokker(grok.ModuleGrokker):
+ def register(self, context, module_info, templates):
+ infos = module_info.getAnnotation('grok.defineskin',[])
+ if infos:
+ for skin in infos:
+ zope.component.interface.provideInterface(skin.name, skin.iface,
+ IBrowserSkinType)
+
class GlobalUtilityDirectiveGrokker(grok.ModuleGrokker):
def register(self, context, module_info, templates):
More information about the Checkins
mailing list