Permalink
Browse files

Abstracted ResourceBundle out of Resource for tw2.jqplugins.ui.

  • Loading branch information...
ralphbean committed Mar 22, 2012
1 parent 1b43061 commit 56a6ba35abdc51b9f48f17385fc5e55c4463260b
Showing with 27 additions and 8 deletions.
  1. +27 −8 tw2/core/resources.py
@@ -45,18 +45,40 @@ def __init__(self, *args, **kw):
self.src = self._name
class Resource(wd.Widget):
class ResourceBundle(wd.Widget):
""" Just a list of resources.
Use it as follows:
>>> jquery_ui = ResourceBundle(resources=[jquery_js, jquery_css])
>>> jquery_ui.inject()
"""
@classmethod
def inject(cls):
cls.req().prepare()
def prepare(self):
super(ResourceBundle, self).prepare()
rl = core.request_local()
rl_resources = rl.setdefault('resources', [])
rl_location = rl['middleware'].config.inject_resources_location
if self not in rl_resources:
for r in self.resources:
r.req().prepare()
class Resource(ResourceBundle):
location = pm.Param(
'Location on the page where the resource should be placed.' \
'This can be one of: head, headbottom, bodytop or bodybottom. '\
'None means the resource will not be injected, which is still '\
'useful, e.g. static images.', default=None)
id = None
@classmethod
def inject(cls):
cls.req().prepare()
def prepare(self):
super(Resource, self).prepare()
@@ -68,9 +90,6 @@ def prepare(self):
if self.location is '__use_middleware':
self.location = rl_location
for r in self.resources:
r.req().prepare()
rl_resources.append(self)

0 comments on commit 56a6ba3

Please sign in to comment.