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

Allow Inlining of Asset Contents #384

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

mankyd
Copy link
Contributor

@mankyd mankyd commented Jan 25, 2015

Fixes #246. This adds a urls_with_bodies method that is complementary to the existing urls method. It updates the Jinja extension to add an ASSET_CONTENTS variable. Tests are passing.

if with_bodies:
# The hunks returned by the _build() method aren't useful as
# they sometimes have %(version)s in them. Can this be changed?
hunk = FileHunk(self.resolve_output(ctx))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That amazing work, thanks a bunch for putting in the time. Unfortunately, I think we have a problem here that is possibly complex, which is that before this patch, you could set auto_build to False, and the correct urls could be generated without the filesystem being touched; indeed, the actual files needn't be available. That's incredibly useful for when your static files are on S3 or the like, or if you just want to avoid the performance hit.

Of course, if ASSETS_CONTENT is used, that is no longer possible. We can also ignore the question whether webassets should cache the content in memory for now; but the problem is that right now, by always using urls_with_content in the template tag, unless I am mistaken, you are essentially forcing a file read in all cases.

Ideally, the tag could detect the presence of ASSETS_CONTENT itself. I'm not sure if that is possible.

@miracle2k
Copy link
Owner

Maybe it is possible - there is an idea from another pull request: https://github.com/miracle2k/django-assets/pull/25/files

Another solution might be to use a smart object that has a __html__ method and thus executes code on use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow for Template Extensions to Easily Inline Code
2 participants