Commit a09d7dcb authored by Taddeus Kroes's avatar Taddeus Kroes

Implemented cache/minify controllers for JavaScript/CSS.

parent 3384abc1
import slimit
import cssmin
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/(.*)'
__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/(.*)'
__root__ = 'static/css/'
__extension__ = 'css'
def __init__(self, root):
Importer.__init__(self, root=root, extension='css')
def minify(self, output):
return cssmin.cssmin(output)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment