[Zope3-checkins]
SVN: Zope3/branches/roger-contentprovider/src/zope/viewlet/
Merge new viewlets form boston branch into the content
provider branch
Roger Ineichen
roger at projekt01.ch
Fri Oct 7 09:46:27 EDT 2005
Log message for revision 38885:
Merge new viewlets form boston branch into the content provider branch
Changed:
A Zope3/branches/roger-contentprovider/src/zope/viewlet/css_viewlet.pt
A Zope3/branches/roger-contentprovider/src/zope/viewlet/javascript_viewlet.pt
U Zope3/branches/roger-contentprovider/src/zope/viewlet/viewlet.py
-=-
Copied: Zope3/branches/roger-contentprovider/src/zope/viewlet/css_viewlet.pt (from rev 38884, Zope3/branches/roger-bostonskin/src/zope/viewlet/css_viewlet.pt)
Copied: Zope3/branches/roger-contentprovider/src/zope/viewlet/javascript_viewlet.pt (from rev 38884, Zope3/branches/roger-bostonskin/src/zope/viewlet/javascript_viewlet.pt)
Modified: Zope3/branches/roger-contentprovider/src/zope/viewlet/viewlet.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/viewlet/viewlet.py 2005-10-07 13:42:40 UTC (rev 38884)
+++ Zope3/branches/roger-contentprovider/src/zope/viewlet/viewlet.py 2005-10-07 13:46:26 UTC (rev 38885)
@@ -17,11 +17,14 @@
"""
__docformat__ = 'restructuredtext'
+import os
import sys
import zope.interface
+
from zope.app.pagetemplate.simpleviewclass import simple
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.app.publisher.browser import BrowserView
+from zope.app.traversing import api
from zope.viewlet import interfaces
@@ -87,3 +90,55 @@
'__name__' : name})
return class_
+
+
+class ResourceViewletBase(object):
+
+ _path = None
+
+ def getURL(self):
+ resource = api.traverse(self.context, '++resource++' + self._path,
+ request=self.request)
+ return resource()
+
+ def __call__(self, *args, **kw):
+ return self.index(*args, **kw)
+
+
+def JavaScriptViewlet(path):
+ """Create a viewlet that can simply insert a javascript link."""
+ src = os.path.join(os.path.dirname(__file__), 'javascript_viewlet.pt')
+
+ klass = type('JavaScriptViewlet',
+ (ResourceViewletBase, SimpleViewlet),
+ {'index': ViewletPageTemplateFile(src),
+ '_path': path})
+
+ return klass
+
+
+class CSSResourceViewletBase(ResourceViewletBase):
+
+ _media = 'all'
+ _rel = 'stylesheet'
+
+ def getMedia(self):
+ return self._media
+
+ def getRel(self):
+ return self._rel
+
+
+def CSSViewlet(path, media="all", rel="stylesheet"):
+ """Create a viewlet that can simply insert a javascript link."""
+ src = os.path.join(os.path.dirname(__file__), 'css_viewlet.pt')
+
+ klass = type('CSSViewlet',
+ (CSSResourceViewletBase, SimpleViewlet),
+ {'index': ViewletPageTemplateFile(src),
+ '_path': path,
+ '_media':media,
+ '_rel':rel})
+
+ return klass
+
More information about the Zope3-Checkins
mailing list