class YUI(Controller): def __init__(self, context): Controller.__init__(self, context, __file__) # BAD!!!!! Should really use the context for this kind of stuff. self.__yuiDir = os.environ["YUI_ROOT"] self.__cache = YUICache(self.__yuiDir) #TODO: Add in backwards compatibility #TODO: Could make this the index #TODO: Return the files in the right order, regardless of how they are requested #TODO: Fill in missing files from dependancy tree #FIXME: In case of missing file should raise an HTTP error. @expose def yui(self, *args, **kwargs): """cat together the YUI include files and return a single js include get css by calling: /YUI/yui/css/?script=/container/assets/menu/assets/menu.css get js by calling: /YUI/yui/js/?script=yahoo.js""" data = '' if 'script' in kwargs.keys(): assetType = args[0] scripts = [] if type(kwargs['script']) == type('str'): scripts = [kwargs['script']] else: scripts = kwargs['script'] for f in scripts: content = self.__cache.getContentByLabel(f) if not content: raise cherrypy.HTTPError(404) data = "\n".join([data, content.data]) setHeaders(content.contentType) cherrypy.config.update({ 'tools.encode.on': True, 'tools.gzip.on': True }) return self.templatePage('data', {'data': data}) if len(args) == 1: content = self.__cache.getContentByLabel(args[0]) setHeaders(content.contentType, content.lenght) return content.data raise cherrypy.HTTPError(404)
class YUI(Controller): def __init__(self, context): Controller.__init__(self, context, __file__) # BAD!!!!! Should really use the context for this kind of stuff. self.__yuiDir = os.environ["YUI_ROOT"] self.__cache = YUICache(self.__yuiDir) # TODO: Add in backwards compatibility # TODO: Could make this the index # TODO: Return the files in the right order, regardless of how they are requested # TODO: Fill in missing files from dependancy tree # FIXME: In case of missing file should raise an HTTP error. @expose def yui(self, *args, **kwargs): """cat together the YUI include files and return a single js include get css by calling: /YUI/yui/css/?script=/container/assets/menu/assets/menu.css get js by calling: /YUI/yui/js/?script=yahoo.js""" data = "" if "script" in kwargs.keys(): assetType = args[0] scripts = [] if type(kwargs["script"]) == type("str"): scripts = [kwargs["script"]] else: scripts = kwargs["script"] for f in scripts: content = self.__cache.getContentByLabel(f) if not content: raise cherrypy.HTTPError(404) data = "\n".join([data, content.data]) setHeaders(content.contentType) cherrypy.config.update({"tools.encode.on": True, "tools.gzip.on": True}) return self.templatePage("data", {"data": data}) if len(args) == 1: content = self.__cache.getContentByLabel(args[0]) setHeaders(content.contentType, content.lenght) return content.data raise cherrypy.HTTPError(404)
from Tools.YUICache import YUICache import os from pprint import pprint try: os.environ["YUI_ROOT"] except: assert (False) cache = YUICache (os.environ["YUI_ROOT"]) assert (cache.size ()) assert (cache.getContentByLabel ("datatable.js")) assert (cache.getContentByLabel ("datatable.js")) assert (cache.getContentByLabel ("datatable.css")) assert (cache.getContentByLabel ("/container/assets/container.css")) assert (cache.getContentByLabel ("/menu/assets/menu.css")) assert (cache.getContentByLabel ("/grids/grids-min.css")) assert (cache.getContentByLabel ("menu.css")) assert (cache.getContentByLabel ("menu.css").lenght != 0) assert (cache.getContentByLabel ("/datatable/datatable.js")) assert (cache.getContentByLabel ("menu.css").data != cache.getContentByLabel ("/menu/assets/menu.css").data) assert (cache.getContentByLabel ("menu.css").data == cache.getContentByLabel ("/menu/assets/skins/sam/menu.css").data) assert (cache.getContentByLabel ("datatable").data != cache.getContentByLabel ("datatable.css").data) assert (cache.getContentByLabel ("datatable").data == cache.getContentByLabel ("datatable.js").data) assert (cache.getContentByLabel ("datatable").data == cache.getContentByLabel ("/datatable/datatable.js").data) assert (cache.getContentByLabel ("datatable").data == cache.getContentByLabel ("datatable.js").data) #for (key, content) in cache.iteritems (): # pprint (key)
from Tools.YUICache import YUICache import os from pprint import pprint try: os.environ["YUI_ROOT"] except: assert (False) cache = YUICache(os.environ["YUI_ROOT"]) assert (cache.size()) assert (cache.getContentByLabel("datatable.js")) assert (cache.getContentByLabel("datatable.js")) assert (cache.getContentByLabel("datatable.css")) assert (cache.getContentByLabel("/container/assets/container.css")) assert (cache.getContentByLabel("/menu/assets/menu.css")) assert (cache.getContentByLabel("/grids/grids-min.css")) assert (cache.getContentByLabel("menu.css")) assert (cache.getContentByLabel("menu.css").lenght != 0) assert (cache.getContentByLabel("/datatable/datatable.js")) assert (cache.getContentByLabel("menu.css").data != cache.getContentByLabel("/menu/assets/menu.css").data) assert (cache.getContentByLabel("menu.css").data == cache.getContentByLabel( "/menu/assets/skins/sam/menu.css").data) assert (cache.getContentByLabel("datatable").data != cache.getContentByLabel("datatable.css").data) assert (cache.getContentByLabel("datatable").data == cache.getContentByLabel( "datatable.js").data) assert (cache.getContentByLabel("datatable").data == cache.getContentByLabel( "/datatable/datatable.js").data) assert (cache.getContentByLabel("datatable").data == cache.getContentByLabel( "datatable.js").data)