|
@@ -1,15 +1,45 @@
|
|
|
|
|
+import slimit
|
|
|
|
|
+import cssmin
|
|
|
|
|
+
|
|
|
from importer import Importer
|
|
from importer import Importer
|
|
|
|
|
|
|
|
|
|
|
|
|
-class JsCache(Importer):
|
|
|
|
|
|
|
+class CacheController:
|
|
|
|
|
+ __cached__ = 'cached/'
|
|
|
|
|
+ __aliases__ = {}
|
|
|
|
|
+
|
|
|
|
|
+ def GET(self, files):
|
|
|
|
|
+ cache = Importer(extension=self.__extension__,
|
|
|
|
|
+ root=self.__root__,
|
|
|
|
|
+ cached=self.__cached__)
|
|
|
|
|
+
|
|
|
|
|
+ for alias, path in self.__aliases__.iteritems():
|
|
|
|
|
+ cache.set_alias(alias, path)
|
|
|
|
|
+
|
|
|
|
|
+ for f in files.split(','):
|
|
|
|
|
+ cache.add(f)
|
|
|
|
|
+
|
|
|
|
|
+ output = cache.output()
|
|
|
|
|
+
|
|
|
|
|
+ if hasattr(self, 'minify'):
|
|
|
|
|
+ output = self.minify(output)
|
|
|
|
|
+
|
|
|
|
|
+ return output
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class JsCache(CacheController):
|
|
|
__url__ = '/js/(.*)'
|
|
__url__ = '/js/(.*)'
|
|
|
|
|
+ __root__ = 'static/js/'
|
|
|
|
|
+ __extension__ = 'js'
|
|
|
|
|
|
|
|
- def __init__(self, root):
|
|
|
|
|
- Importer.__init__(self, root=root, extension='js')
|
|
|
|
|
|
|
+ def minify(self, output):
|
|
|
|
|
+ return slimit.minify(output)
|
|
|
|
|
|
|
|
|
|
|
|
|
-class CssCache(Importer):
|
|
|
|
|
|
|
+class CssCache(CacheController):
|
|
|
__url__ = '/css/(.*)'
|
|
__url__ = '/css/(.*)'
|
|
|
|
|
+ __root__ = 'static/css/'
|
|
|
|
|
+ __extension__ = 'css'
|
|
|
|
|
|
|
|
- def __init__(self, root):
|
|
|
|
|
- Importer.__init__(self, root=root, extension='css')
|
|
|
|
|
|
|
+ def minify(self, output):
|
|
|
|
|
+ return cssmin.cssmin(output)
|