Skip to content

Commit

Permalink
Merge branch 'feature/refactoring-resources' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Mar 4, 2012
2 parents c65f24a + 7030676 commit f21f4f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>')

Expand Down
7 changes: 5 additions & 2 deletions tw2/core/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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:
Expand Down Expand Up @@ -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>'
Expand Down

0 comments on commit f21f4f9

Please sign in to comment.