Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to ASSET_CONTENT #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 10 additions & 3 deletions django_assets/templatetags/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ class AssetsNode(template.Node):
# For testing, to inject a mock bundle
BundleClass = Bundle

def __init__(self, filters, output, debug, files, childnodes):
def __init__(self, filters, output, debug, files, childnodes, need_content):
self.childnodes = childnodes
self.output = output
self.files = files
self.filters = filters
self.debug = debug
self.need_content = need_content

def resolve(self, context={}):
"""We allow variables to be used for all arguments; this function
Expand Down Expand Up @@ -64,7 +65,11 @@ def resolve_bundle(name):

def render(self, context):
bundle = self.resolve(context)

if self.need_content:
content = ''
for filehunk in bundle.build(env=get_env()):
content = content + filehunk.data()
context.update({'ASSET_CONTENT': content})
result = u""
for url in bundle.urls(env=get_env()):
context.update({'ASSET_URL': url, 'EXTRA': bundle.extra})
Expand Down Expand Up @@ -119,10 +124,12 @@ def assets(parser, token):
else:
raise template.TemplateSyntaxError('Unsupported keyword argument "%s"'%name)

need_content = len([True for t in parser.tokens if 'ASSET_CONTENT' in t.contents]) > 0

# capture until closing tag
childnodes = parser.parse(("endassets",))
parser.delete_first_token()
return AssetsNode(filters, output, debug, files, childnodes)
return AssetsNode(filters, output, debug, files, childnodes, need_content)



Expand Down