Updated external resource declaration to handle resources types not based on URLs
authorThierry Florac <thierry.florac@onf.fr>
Mon, 29 Oct 2018 16:50:51 +0100
changeset 246 06b84cd42bf3
parent 245 30ffdaf9c5c1
child 247 6baaa4ce8a60
Updated external resource declaration to handle resources types not based on URLs
src/pyams_utils/fanstatic.py
--- a/src/pyams_utils/fanstatic.py	Tue Oct 23 12:07:32 2018 +0200
+++ b/src/pyams_utils/fanstatic.py	Mon Oct 29 16:50:51 2018 +0100
@@ -28,7 +28,7 @@
 class ExternalResource(Resource):
     """Fanstatic external resource"""
 
-    def __init__(self, library, path, defer=False, **kwargs):
+    def __init__(self, library, path, defer=False, resource_type=None, **kwargs):
         set_resource_file_existence_checking(False)
         try:
             if 'renderer' in kwargs:
@@ -39,11 +39,15 @@
         finally:
             set_resource_file_existence_checking(True)
         self.defer = defer
+        if resource_type:
+            self.resource_type = resource_type
+        else:
+            self.resource_type = path.rsplit('.', 1)[1].lower()
 
     def render(self, library_url):
-        if self.relpath.endswith('.css'):
+        if self.resource_type == 'css':
             return render_css(self.relpath)
-        elif self.relpath.endswith('.js'):
+        elif self.resource_type == 'js':
             return render_js(self.relpath, self.defer)
         else:
             return ''