Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

Change bundle path and fix relative URL's #41

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Change bundle path and fix relative URL's #41

wants to merge 4 commits into from

Conversation

rehandalal
Copy link
Contributor

Feel free to say: "THESE ARE USELESS CHANGES AND NOBODY NEEDS THEM!".

This does a couple of things:

  • CSS bundles will now be in MEDIA_PATH/bundled/css MEDIA_PATH/BUNDLES_DIR/css
  • JS bundles will now be in MEDIA_PATH/bundled/js MEDIA_PATH/BUNDLES_DIR/js
  • Relative URL's in CSS will now be fixed to point to the correct URL when bundled. (This was a problem on SUMO and recently on Input)

r?

@rehandalal
Copy link
Contributor Author

I should also probably point out the reason for bundling to the bundled folder.

I happened to have a bundle called jquery and sadly one of the files in the bundle was jquery-min.js which (you guessed it) got replaced with the bundle file.

Now admittedly, this is a silly edge case that would normally not be an issue, and is pretty easy to get around. But I generally like the idea of tossing bundled files in another folder because it also keeps file clutter down in my js/css folders.


parse = lambda url: self._fix_urls_regex(url, relpath)

css_parsed = re.sub('url\(([^)]*?)\)', parse, css_content)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a raw string, like this

css_parsed = re.sub(r'url\(([^)]*?)\)', parse, css_content)

Otherwise, python and re get confused about the back slashes.

@willkg
Copy link
Collaborator

willkg commented Feb 24, 2013

If someone updates to this, will they be hosed? Are there things they need to do to update to this version?

@@ -34,6 +34,7 @@ class Command(BaseCommand): # pragma: no cover
minify_skipped = 0
cmd_errors = False
ext_media_path = os.path.join(get_media_root(), 'external')
bundles_dir = getattr(settings, 'BUNDLES_DIR', 'bundled')
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this not in get_media_root()?

Copy link
Collaborator

Choose a reason for hiding this comment

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

if I decide to not set settings.BUNDLES_DIR can we not do the bundled/ stuff?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure i could default that to .

@rehandalal
Copy link
Contributor Author

@willkg with the new change to the default value of BUNDLES_DIR there should be no compatibility issues.

@rehandalal
Copy link
Contributor Author

Test added ^

@rehandalal
Copy link
Contributor Author

And now tests pass ^

If this is all good I'll squash and push

@jsocol
Copy link
Owner

jsocol commented Oct 28, 2013

@cvan any outstanding comments here? @rehandalal Still want to get this merged in?

@@ -3,3 +3,4 @@ jingo==0.4
Fabric==1.4.3
-e git://github.com/jbalogh/django-nose.git@83c7867c3f90ff3c7c7471716da91b643e8b2c01#egg=django_nose-dev
mock==1.0b1
GitPython==0.1.7
Copy link

Choose a reason for hiding this comment

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

I can't find where you use that package in the diff.

Copy link
Owner

Choose a reason for hiding this comment

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

It's unrelated but missing. There's a test in #63 that demonstrates the issue. Any new tests that hit that area of code will trip over it.

@davidbgk
Copy link

davidbgk commented Apr 9, 2014

I can't understand why there is the /bundled/ path still hard-coded in some places given that there is a setting for that path.

"""Run over the regex; Fix relative URL's"""
url = url.group(1).strip('"\'')
if url.startswith(('data:', 'http:', 'https:')):
return url
Copy link

Choose a reason for hiding this comment

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

Shouldn't that one be wrapped in url() too?

dean added a commit to mozilla/kitsune that referenced this pull request Sep 3, 2014
This needs to be updated after the PR is merged into master at:
jsocol/jingo-minify#41
dean added a commit to dean/kitsune that referenced this pull request Sep 3, 2014
This needs to be updated after the PR is merged into master at:
jsocol/jingo-minify#41
dean added a commit to dean/kitsune that referenced this pull request Sep 4, 2014
This needs to be updated after the PR is merged into master at:
jsocol/jingo-minify#41
dean added a commit to dean/kitsune that referenced this pull request Sep 9, 2014
This needs to be updated after the PR is merged into master at:
jsocol/jingo-minify#41
dean added a commit to mozilla/kitsune that referenced this pull request Sep 17, 2014
This needs to be updated after the PR is merged into master at:
jsocol/jingo-minify#41
@rehandalal
Copy link
Contributor Author

I just did the following:

  • Rebased/squashed the original commits in this pull request and fixed all the conflicts
  • Updated the tests to be more thorough

I still think this is pretty useful!

r?

@rehandalal
Copy link
Contributor Author

@jsocol think you could have a quick look-see at this? THANKS!

@jsocol
Copy link
Owner

jsocol commented Nov 11, 2014

I can but not for another day or so, and I don't have the context that @cvan would

return (_get_item_path('js/%s-min.js?build=%s' % (bundle, build_id,)),)
item = 'js/%s-min.js?build=%s' % (bundle, build_id,)
item = os.path.join(getattr(settings, 'BUNDLES_DIR', ''), item)
return (_get_item_path(item),)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why again do we return a tuple of one item?

@cvan
Copy link
Collaborator

cvan commented Nov 12, 2014

looking good. sorry it's taken so long to get this in. I don't think we've understood the use case here, hence the delays.

@rehandalal
Copy link
Contributor Author

I'll clean up the code.

For me, this is why I made the changes:

  • Having a special directory that bundles get stored in makes it easier for me to filter those files out through .gitignore. I also had one edge case where I had a file which shared the same name as the final minified bundle that it belonged to which caused a whole mess. Admittedly that's easily fixed by renaming the file or the bundle but I prefer this.
  • Fixing the relative URLs helps when you're bundling files that are installed by bower and they have additional image assets that are linked to such as FancyBox. Without this, sometimes I have to copy these image files into the css folder or other places and that was just getting messy.

@rehandalal
Copy link
Contributor Author

@cvan fixed based on feedback ^

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

Successfully merging this pull request may close these issues.

None yet

6 participants