Permalink
Browse files

Merge branch 'feature/refactoring-resources' into develop

  • Loading branch information...
ralphbean committed Mar 4, 2012
2 parents c65f24a + 7030676 commit f21f4f97a95507f653f5661878185063d6b69eab
Showing with 9 additions and 6 deletions.
  1. +4 −4 tests/test_resources.py
  2. +5 −2 tw2/core/resources.py
View
@@ -150,20 +150,20 @@ def test_no_inject_head(self):
def test_inject_head(self):
rl = testapi.request(1, mw)
js.req().prepare()
js.inject()
out = twc.inject_resources(html)
assert eq_xhtml(out, '<html><head><script type="text/javascript" src="paj"></script><title>a</title></head><body>hello</body></html>')
def test_inject_body(self):
rl = testapi.request(1, mw)
jssrc.req().prepare()
jssrc.inject()
out = twc.inject_resources(html)
assert eq_xhtml(out, '<html><head><title>a</title></head><body>hello<script type="text/javascript">bob</script></body></html>')
def test_inject_both(self):
rl = testapi.request(1, mw)
js.req().prepare()
jssrc.req().prepare()
js.inject()
jssrc.inject()
out = twc.inject_resources(html)
assert eq_xhtml(out, '<html><head><script type="text/javascript" src="paj"></script><title>a</title></head><body>hello<script type="text/javascript">bob</script></body></html>')
View
@@ -64,6 +64,10 @@ class Resource(wd.Widget):
'useful, e.g. static images.', default=None)
id = None
@classmethod
def inject(cls):
cls.req().prepare()
def prepare(self):
super(Resource, self).prepare()
@@ -89,7 +93,6 @@ class Link(Resource):
filename = pm.Param('Path to file, relative to module base.', default=None)
no_inject = pm.Param("Don't inject this link. (Default: False)", default=False)
def prepare(self):
rl = core.request_local()
if not self.no_inject:
@@ -315,7 +318,7 @@ class _ResourceInjector(util.MultipleReplacer):
but they can also be injected explicitly, example::
>>> from tw2.core.resources import JSLink, inject_resources
>>> JSLink(link="http://example.com").req().prepare()
>>> JSLink(link="http://example.com").inject()
>>> html = "<html><head></head><body></body></html>"
>>> inject_resources(html)
'<html><head><script type="text/javascript" src="http://example.com"></script></head><body></body></html>'

0 comments on commit f21f4f9

Please sign in to comment.