[Zope3-checkins]
SVN: Zope3/branches/roger-bostonskin/src/zope/viewlet/
Added base viewlets for javascript and css resource files
Roger Ineichen
roger at projekt01.ch
Fri Oct 7 09:42:40 EDT 2005
Log message for revision 38884:
Added base viewlets for javascript and css resource files
Changed:
A Zope3/branches/roger-bostonskin/src/zope/viewlet/css_viewlet.pt
A Zope3/branches/roger-bostonskin/src/zope/viewlet/javascript_viewlet.pt
U Zope3/branches/roger-bostonskin/src/zope/viewlet/viewlet.py
-=-
Added: Zope3/branches/roger-bostonskin/src/zope/viewlet/css_viewlet.pt
===================================================================
--- Zope3/branches/roger-bostonskin/src/zope/viewlet/css_viewlet.pt 2005-10-07 13:41:40 UTC (rev 38883)
+++ Zope3/branches/roger-bostonskin/src/zope/viewlet/css_viewlet.pt 2005-10-07 13:42:40 UTC (rev 38884)
@@ -0,0 +1,4 @@
+<link type="text/css" rel="stylesheet" href="somestyle.css" media="all"
+ tal:attributes="rel viewlet/getRel;
+ href viewlet/getURL;
+ media viewlet/getMedia" />
Property changes on: Zope3/branches/roger-bostonskin/src/zope/viewlet/css_viewlet.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Zope3/branches/roger-bostonskin/src/zope/viewlet/javascript_viewlet.pt
===================================================================
--- Zope3/branches/roger-bostonskin/src/zope/viewlet/javascript_viewlet.pt 2005-10-07 13:41:40 UTC (rev 38883)
+++ Zope3/branches/roger-bostonskin/src/zope/viewlet/javascript_viewlet.pt 2005-10-07 13:42:40 UTC (rev 38884)
@@ -0,0 +1,3 @@
+<script type="text/javascript" src="some-library.js"
+ tal:attributes="src viewlet/getURL">
+</script>
Property changes on: Zope3/branches/roger-bostonskin/src/zope/viewlet/javascript_viewlet.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: Zope3/branches/roger-bostonskin/src/zope/viewlet/viewlet.py
===================================================================
--- Zope3/branches/roger-bostonskin/src/zope/viewlet/viewlet.py 2005-10-07 13:41:40 UTC (rev 38883)
+++ Zope3/branches/roger-bostonskin/src/zope/viewlet/viewlet.py 2005-10-07 13:42:40 UTC (rev 38884)
@@ -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