Skip to content

Commit

Permalink
Merge pull request #250 from dstufft/no-inline3
Browse files Browse the repository at this point in the history
Statically link to the CSS instead of dynamically
  • Loading branch information
mmerickel committed Apr 21, 2016
2 parents 2db3c86 + b1473d2 commit d899615
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
13 changes: 4 additions & 9 deletions pyramid_debugtoolbar/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def inject(self, request, response):
'button_style', '')
css_path = request.static_url(STATIC_PATH + 'css/toolbar_button.css')
toolbar_html = toolbar_html_template % {
'button_style': button_style,
'button_style':
'style="{0}"'.format(button_style) if button_style else "",
'css_path': css_path,
'toolbar_url': toolbar_url}
toolbar_html = toolbar_html.encode(response.charset or 'utf-8')
Expand Down Expand Up @@ -271,16 +272,10 @@ def toolbar_tween(request):
return toolbar_tween

toolbar_html_template = """\
<script type="text/javascript">
var fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", "%(css_path)s")
document.getElementsByTagName("head")[0].appendChild(fileref)
</script>
<link rel="stylesheet" type="text/css" href="%(css_path)s">
<div id="pDebug">
<div style="display: block; %(button_style)s" id="pDebugToolbarHandle">
<div %(button_style)s id="pDebugToolbarHandle">
<a title="Show Toolbar" id="pShowToolBarButton"
href="%(toolbar_url)s" target="pDebugToolbar">&#171; FIXME: Debug Toolbar</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_unauthenticated(self):

def test_authenticated_toolbar_injection(self):
resp = self._req('/hello/secrets', remote_user='admin')
self.assertTrue(resp.html.body.script is not None, 'unexpectedly None')
self.assertTrue(resp.html.body.link is not None, 'unexpectedly None')
# dive into the request history stored by the toolbar tween
request_id = self.testapp.app.registry.request_history[0][0]
# check it against the link in the injected html
Expand Down

0 comments on commit d899615

Please sign in to comment.