Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bowerstatic/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
class Bower(object):
"""Contains a bunch of bower_components directories.
"""
def __init__(self, publisher_signature='bowerstatic', autoversion=None):
def __init__(self, publisher_signature='bowerstatic', autoversion=None, inject_point=None):
self.publisher_signature = publisher_signature
self._component_collections = {}
self._renderer = Renderer()
self.autoversion = autoversion or filesystem_second_autoversion
self.inject_point = inject_point or b'</head>'

def components(self, name, path):
if name in self._component_collections:
Expand Down
9 changes: 7 additions & 2 deletions bowerstatic/injector.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ def __call__(self, request):
if inclusions is None:
return response
body = response.body
inject_pt = self.bower.inject_point
head_tag = b'</head>'
if inject_pt != head_tag and body.find(inject_pt) == -1:
inject_pt = head_tag

response.body = b''
rendered_inclusions = (inclusions.render() + '</head>').encode('utf-8')
body = body.replace(b'</head>', rendered_inclusions)
rendered_inclusions = (inclusions.render() + inject_pt).encode('utf-8')
body = body.replace(inject_pt, rendered_inclusions)
response.write(body)
return response

Expand Down