[Checkins] SVN: grok/trunk/ - added package_dotted_name to
ModuleInfo
Christian Theune
ct at gocept.com
Tue Oct 17 17:17:42 EDT 2006
Log message for revision 70765:
- added package_dotted_name to ModuleInfo
- refactored annotating PageTemplates with name, location and module_info
- addded 'static' name to page templates to easily generate urls to static
resources
Changed:
U grok/trunk/TODO.txt
U grok/trunk/src/grok/_grok.py
U grok/trunk/src/grok/ftests/static/simple.py
A grok/trunk/src/grok/ftests/static/simple_fixture/ellie.py
U grok/trunk/src/grok/scan.py
U grok/trunk/src/grok/tests/scan/scan.py
-=-
Modified: grok/trunk/TODO.txt
===================================================================
--- grok/trunk/TODO.txt 2006-10-17 19:57:13 UTC (rev 70764)
+++ grok/trunk/TODO.txt 2006-10-17 21:17:42 UTC (rev 70765)
@@ -60,6 +60,9 @@
Need to discuss
---------------
+- fall back to a static resource that is defined in a package on a higher
+ level if no static resource directory is defined locally in a package?
+
- change naming convention for template directories from
"<modulename>" to "template_<modulename>" or similar, to avoid
confusion?
Modified: grok/trunk/src/grok/_grok.py
===================================================================
--- grok/trunk/src/grok/_grok.py 2006-10-17 19:57:13 UTC (rev 70764)
+++ grok/trunk/src/grok/_grok.py 2006-10-17 21:17:42 UTC (rev 70765)
@@ -66,6 +66,12 @@
namespace['request'] = self.request
namespace['view'] = self
namespace['context'] = self.context
+
+ module_info = template.__grok_module_info__
+ directory_resource = component.queryAdapter(self.request,
+ interface.Interface, name=module_info.package_dotted_name)
+ # XXX need to check whether we really want None here
+ namespace['static'] = directory_resource
return template.pt_render(namespace)
def before(self):
@@ -81,6 +87,8 @@
"unicode or ASCII.")
self.write(template)
+ # __grok_module__ is needed to make defined_locally() return True for
+ # inline templates
# XXX unfortunately using caller_module means that
# PageTemplate cannot be subclassed
self.__grok_module__ = caller_module()
@@ -89,6 +97,12 @@
return '<%s template in %s>' % (self.__grok_name__,
self.__grok_location__)
+ def _annotateGrokInfo(self, module_info, name, location):
+ self.__grok_module_info__ = module_info
+ self.__grok_name__ = name
+ self.__grok_location__ = location
+
+
def grok(dotted_name):
# register the name 'index' as the default view name
# TODO this needs to be moved to grok startup time (similar to ZCML-time)
@@ -153,8 +167,7 @@
views.append(obj)
elif isinstance(obj, PageTemplate):
templates.register(name, obj)
- obj.__grok_name__ = name
- obj.__grok_location__ = module_info.dotted_name
+ obj._annotateGrokInfo(module_info, name, module_info.dotted_name)
return models, adapters, multiadapters, views, templates, subscribers
@@ -180,8 +193,10 @@
f.close()
template = PageTemplate(contents)
- template.__grok_name__ = template_name
- template.__grok_location__ = template_path
+ template._annotateGrokInfo(module_info, template_name,
+ template_path)
+ #template.__grok_name__ = template_name
+ #template.__grok_location__ = template_path
inline_template = templates.get(template_name)
if inline_template:
Modified: grok/trunk/src/grok/ftests/static/simple.py
===================================================================
--- grok/trunk/src/grok/ftests/static/simple.py 2006-10-17 19:57:13 UTC (rev 70764)
+++ grok/trunk/src/grok/ftests/static/simple.py 2006-10-17 21:17:42 UTC (rev 70765)
@@ -7,16 +7,21 @@
>>> from zope.testbrowser.testing import Browser
>>> browser = Browser()
>>> browser.handleErrors = False
- >>> browser.open('http://localhost/++resource++grok.ftests.static.simple_fixture/file.txt')
+ >>> browser.open('http://localhost/@@/grok.ftests.static.simple_fixture/file.txt')
>>> print browser.contents
some text
-"""
-import grok
-# class Mammoth(grok.Model):
-# pass
+We use a special name 'static' in page templates to allow easy linking to resources:
-# index = grok.PageTemplate("""\
-# <html>
-# <body>
-# <h1 tal
+ >>> root = getRootFolder()
+ >>> from grok.ftests.static.simple_fixture.ellie import Mammoth
+ >>> root[u'ellie'] = Mammoth()
+ >>> browser.open('http://localhost/ellie')
+ >>> print browser.contents
+ <html>
+ <body>
+ <a href="http://localhost/@@/grok.ftests.static.simple_fixture/file.txt">Some text in a file</a>
+ </body>
+ </html>
+
+"""
Added: grok/trunk/src/grok/ftests/static/simple_fixture/ellie.py
===================================================================
--- grok/trunk/src/grok/ftests/static/simple_fixture/ellie.py 2006-10-17 19:57:13 UTC (rev 70764)
+++ grok/trunk/src/grok/ftests/static/simple_fixture/ellie.py 2006-10-17 21:17:42 UTC (rev 70765)
@@ -0,0 +1,11 @@
+import grok
+
+class Mammoth(grok.Model):
+ pass
+
+index = grok.PageTemplate("""\
+<html>
+<body>
+<a tal:attributes="href static/file.txt">Some text in a file</a>
+</body>
+</html>""")
Property changes on: grok/trunk/src/grok/ftests/static/simple_fixture/ellie.py
___________________________________________________________________
Name: svn:keywords
+ Id Rev Date
Name: svn:eol-style
+ native
Modified: grok/trunk/src/grok/scan.py
===================================================================
--- grok/trunk/src/grok/scan.py 2006-10-17 19:57:13 UTC (rev 70764)
+++ grok/trunk/src/grok/scan.py 2006-10-17 21:17:42 UTC (rev 70765)
@@ -36,7 +36,14 @@
path = path[:-1]
self.path = path
self.dotted_name = dotted_name
- self.name = dotted_name.split('.')[-1]
+
+ name_parts = dotted_name.split('.')
+ self.name = name_parts[-1]
+ if self.isPackage():
+ self.package_dotted_name = dotted_name
+ else:
+ self.package_dotted_name = '.'.join(name_parts[:-1])
+
self._module = None
def getResourcePath(self, name):
Modified: grok/trunk/src/grok/tests/scan/scan.py
===================================================================
--- grok/trunk/src/grok/tests/scan/scan.py 2006-10-17 19:57:13 UTC (rev 70764)
+++ grok/trunk/src/grok/tests/scan/scan.py 2006-10-17 21:17:42 UTC (rev 70765)
@@ -9,6 +9,8 @@
True
>>> module_info.dotted_name
'grok.tests.scan.stoneage'
+ >>> module_info.package_dotted_name
+ 'grok.tests.scan.stoneage'
>>> module_info.name
'stoneage'
@@ -38,6 +40,8 @@
False
>>> cave_module_info.dotted_name
'grok.tests.scan.stoneage.cave'
+ >>> module_info.package_dotted_name
+ 'grok.tests.scan.stoneage'
>>> cave_module_info.name
'cave'
>>> cave_module_info.getSubModuleInfos()
More information about the Checkins
mailing list