src/pyams_utils/fanstatic.py
changeset 380 c062ab4db6cd
parent 292 b338586588ad
child 408 cf2304af0fab
--- a/src/pyams_utils/fanstatic.py	Tue Jun 18 16:53:34 2019 +0200
+++ b/src/pyams_utils/fanstatic.py	Wed Jun 26 10:39:34 2019 +0200
@@ -10,6 +10,14 @@
 # FOR A PARTICULAR PURPOSE.
 #
 
+"""PyAMS_utils.fanstatic module
+
+This module is a helper module to handle Fanstatic resources.
+
+It includes several TALES extensions which can be used to include resources from a Chameleon
+template, or to get path of a given resources from a template.
+"""
+
 __docformat__ = 'restructuredtext'
 
 from fanstatic import Resource
@@ -22,6 +30,7 @@
 
 
 def render_js(url, defer=False):
+    """Render tag to include Javascript resource"""
     return '<script type="text/javascript" src="%s" %s></script>' % (url, 'defer' if defer else '')
 
 
@@ -47,6 +56,7 @@
             self.resource_type = path.rsplit('.', 1)[1].lower()
 
     def render(self, library_url):
+        """Render resource tag"""
         if self.resource_type == 'css':
             return render_css(self.relpath)
         elif self.resource_type == 'js':
@@ -61,21 +71,26 @@
     return '{0}/{1}'.format(res.library_url(resource.library), resource.relpath)
 
 
-@adapter_config(name='resource_path', context=(Interface, Interface, Interface), provides=ITALESExtension)
+@adapter_config(name='resource_path', context=(Interface, Interface, Interface),
+                provides=ITALESExtension)
 class FanstaticTalesExtension(ContextRequestViewAdapter):
     """tales:resource_path() TALES extension
 
     This TALES extension generates an URL matching a given Fanstatic resource.
-    Resource is given as a string made of package name (in dotted form) followed by a colon and by the resource name.
+    Resource is given as a string made of package name (in dotted form) followed by a colon and
+    by the resource name.
 
     For example::
 
     .. code-block:: html
 
-        <div tal:attributes="data-ams-plugin-pyams_content-src extension:resource_path('pyams_content.zmi:pyams_content')" />
+        <div tal:attributes="data-ams-plugin-pyams_content-src
+                             extension:resource_path('pyams_content.zmi:pyams_content')" />
     """
 
-    def render(self, resource):
+    @staticmethod
+    def render(resource):
+        """TALES extension rendering method"""
         library, resource_name = resource.split(':')
         resolver = DottedNameResolver()
         module = resolver.maybe_resolve(library)
@@ -83,13 +98,15 @@
         return get_resource_path(resource)
 
 
-@adapter_config(name='need_resource', context=(Interface, Interface, Interface), provides=ITALESExtension)
+@adapter_config(name='need_resource', context=(Interface, Interface, Interface),
+                provides=ITALESExtension)
 class FanstaticNeededResourceTalesExtension(ContextRequestViewAdapter):
     """tales:need_resource() TALES extension
 
     This extension generates a call to Fanstatic resource.need() function to include given resource
     into generated HTML code.
-    Resource is given as a string made of package name (in dotted form) followed by a colon and by the resource name.
+    Resource is given as a string made of package name (in dotted form) followed by a colon and by
+    the resource name.
 
     For example::
 
@@ -98,7 +115,9 @@
         <tal:var define="tales:need_resource('pyams_content.zmi:pyams_content')" />
     """
 
-    def render(self, resource):
+    @staticmethod
+    def render(resource):
+        """TALES extension rendering method"""
         library, resource_name = resource.split(':')
         resolver = DottedNameResolver()
         module = resolver.maybe_resolve(library)