[Checkins] SVN: five.grok/branches/sylvain-static-and-forms/ - Switch devel package to need branches for grokcore.view
Sylvain Viollon
sylvain at infrae.com
Sat Aug 23 15:41:11 EDT 2008
Log message for revision 90157:
- Switch devel package to need branches for grokcore.view
- Add a devel package for form integration (grokcore.formlib)
- Add a grokker for static resource directory
Changed:
_U five.grok/branches/sylvain-static-and-forms/devel/
U five.grok/branches/sylvain-static-and-forms/devel/EXTERNALS.txt
U five.grok/branches/sylvain-static-and-forms/docs/HISTORY.txt
U five.grok/branches/sylvain-static-and-forms/src/five/grok/components.py
U five.grok/branches/sylvain-static-and-forms/src/five/grok/meta.py
-=-
Property changes on: five.grok/branches/sylvain-static-and-forms/devel
___________________________________________________________________
Name: svn:externals
- grokcore.view svn://svn.zope.org/repos/main/grokcore.view/trunk
+ # svn ps -F EXTERNALS.txt svn:externals .
grokcore.view svn://svn.zope.org/repos/main/grokcore.view/branches/sylvain-five-grok-static
grokcore.formlib svn://svn.zope.org/repos/main/grokcore.formlib/trunk
Modified: five.grok/branches/sylvain-static-and-forms/devel/EXTERNALS.txt
===================================================================
--- five.grok/branches/sylvain-static-and-forms/devel/EXTERNALS.txt 2008-08-23 19:38:31 UTC (rev 90156)
+++ five.grok/branches/sylvain-static-and-forms/devel/EXTERNALS.txt 2008-08-23 19:41:11 UTC (rev 90157)
@@ -1,4 +1,3 @@
# svn ps -F EXTERNALS.txt svn:externals .
-grokcore.component svn://svn.zope.org/repos/main/grokcore.component/trunk
-grokcore.view svn://svn.zope.org/repos/main/grokcore.view/trunk
-martian svn://svn.zope.org/repos/main/martian/trunk
+grokcore.view svn://svn.zope.org/repos/main/grokcore.view/branches/sylvain-five-grok-static
+grokcore.formlib svn://svn.zope.org/repos/main/grokcore.formlib/trunk
Modified: five.grok/branches/sylvain-static-and-forms/docs/HISTORY.txt
===================================================================
--- five.grok/branches/sylvain-static-and-forms/docs/HISTORY.txt 2008-08-23 19:38:31 UTC (rev 90156)
+++ five.grok/branches/sylvain-static-and-forms/docs/HISTORY.txt 2008-08-23 19:41:11 UTC (rev 90157)
@@ -5,6 +5,8 @@
five.grok - 0.1 Unreleased
+ - Added support for static resource directory [thefunny42]
+
- Added support for inline templates and made Zope 2 template semantics
the default when doing 'from five import grok' and using
grok.PageTemplate.
Modified: five.grok/branches/sylvain-static-and-forms/src/five/grok/components.py
===================================================================
--- five.grok/branches/sylvain-static-and-forms/src/five/grok/components.py 2008-08-23 19:38:31 UTC (rev 90156)
+++ five.grok/branches/sylvain-static-and-forms/src/five/grok/components.py 2008-08-23 19:41:11 UTC (rev 90157)
@@ -76,3 +76,29 @@
template = self._template.__of__(view)
namespace.update(template.pt_getContext())
return template(namespace)
+
+from Products.Five.browser import resource
+
+class DirectoryResource(resource.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 (resource.DirectoryResource.resource_factories.items()):
+ if factory is resource.PageTemplateResourceFactory:
+ continue
+ resource_factories[type] = factory
+
+
+class DirectoryResourceFactory(resource.DirectoryResourceFactory):
+ # __name__ is needed if you want to get url's of resources
+
+ def __init__(self, name, path):
+ self.__name = name
+ self.__rsrc = self.factory(path, name)
+
+ def __call__(self, request):
+ resource = DirectoryResource(self.__rsrc, request)
+ resource.__name__ = self.__name # We need to add name
+ return resource
Modified: five.grok/branches/sylvain-static-and-forms/src/five/grok/meta.py
===================================================================
--- five.grok/branches/sylvain-static-and-forms/src/five/grok/meta.py 2008-08-23 19:38:31 UTC (rev 90156)
+++ five.grok/branches/sylvain-static-and-forms/src/five/grok/meta.py 2008-08-23 19:41:11 UTC (rev 90157)
@@ -1,3 +1,4 @@
+
import martian
import five.grok
import grokcore.security
@@ -2,5 +3,11 @@
+from zope import interface, component
+from zope.publisher.interfaces.browser import IDefaultBrowserLayer
+from five.grok import components
+from martian.error import GrokError
+
from Products.Five.security import protectClass
from Globals import InitializeClass as initializeClass
+import os.path
@@ -28,3 +35,40 @@
)
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())
+
+ # FIXME: This is public, we need to set security on resources ?
+ name = module_info.dotted_name
+ resource_factory = components.DirectoryResourceFactory(
+ name, resource_path)
+ adapts = (IDefaultBrowserLayer,)
+ provides = interface.Interface
+
+ config.action(
+ discriminator=('adapter', adapts, provides, name),
+ callable=component.provideAdapter,
+ args=(resource_factory, adapts, provides, name),
+ )
+ return True
More information about the Checkins
mailing list