From cb8cdcc124a91c91b6010346c0ff6cf01ee7581f Mon Sep 17 00:00:00 2001 From: Jeremy Carbaugh Date: Wed, 5 Jan 2011 15:01:54 -0500 Subject: [PATCH] remove CSS_PATH and JS_PATH settings --- README.rst | 25 +++----------------- mediasync/__init__.py | 9 ++------ mediasync/conf.py | 2 -- mediasync/templatetags/media.py | 22 ++++++++---------- mediasync/views.py | 41 +++------------------------------ 5 files changed, 18 insertions(+), 81 deletions(-) diff --git a/README.rst b/README.rst index 4bd1bc7..8ceb472 100644 --- a/README.rst +++ b/README.rst @@ -30,8 +30,8 @@ Requirements Upgrading from mediasync 1.x ---------------------------- -1. Update your mediasync settings as described in the next section. -1. Run *./manage.py syncmedia --force* to force updates of all files: +#. Update your mediasync settings as described in the next section. +#. Run *./manage.py syncmedia --force* to force updates of all files: * gzip instead of deflate compression * sync both compressed and original versions of files @@ -495,26 +495,6 @@ When served remotely, one HTML tag will be rendered with the name of the joined -Media Path Shortcuts -==================== - -In some cases, all CSS and JS files will be in their own directory. It can be a -pain to write full paths from *MEDIA_ROOT* when they can be inferred from the -type of media being used. Shortcuts can be used in template tags and the joined -files configuration if the default paths to JS and CSS files are set. - -:: - - 'CSS_PATH': 'styles', - 'JS_PATH': 'scripts', - -When these paths are set, you can leave them off of the media paths in template -tags. Using the above path settings, styles/reset.css and scripts/jquery.js -can be referred to using:: - - {% css 'reset.css' %} - {% js 'jquery.js' %} - Smart GZIP for S3 ================= @@ -543,6 +523,7 @@ Change Log 2.0 (in progress) ================= +* remove CSS_PATH and JS_PATH settings * use gzip instead of deflate for compression (better browser support) * smart gzip client support detection * add pluggable backends diff --git a/mediasync/__init__.py b/mediasync/__init__.py index a640fd0..b0653ec 100644 --- a/mediasync/__init__.py +++ b/mediasync/__init__.py @@ -74,10 +74,8 @@ def combine_files(joinfile, sourcefiles, client): joinfile = joinfile.strip('/') if joinfile.endswith('.css'): - dirname = msettings['CSS_PATH'].strip('/') separator = '\n' elif joinfile.endswith('.js'): - dirname = msettings['JS_PATH'].strip('/') separator = ';\n' else: # By-pass this file since we only join CSS and JS. @@ -86,7 +84,7 @@ def combine_files(joinfile, sourcefiles, client): buffer = cStringIO.StringIO() for sourcefile in sourcefiles: - sourcepath = os.path.join(client.media_root, dirname, sourcefile) + sourcepath = os.path.join(client.media_root, sourcefile) if os.path.isfile(sourcepath): f = open(sourcepath) buffer.write(f.read()) @@ -95,7 +93,7 @@ def combine_files(joinfile, sourcefiles, client): filedata = buffer.getvalue() buffer.close() - return (filedata, dirname) + return filedata def sync(client=None, force=False, verbose=True): """ Let's face it... pushing this stuff to S3 is messy. @@ -123,13 +121,10 @@ def sync(client=None, force=False, verbose=True): if filedata is None: # combine_files() is only interested in CSS/JS files. continue - filedata, dirname = filedata content_type = mimetypes.guess_type(joinfile)[0] or 'application/octet-stream' remote_path = joinfile - if dirname: - remote_path = "%s/%s" % (dirname, remote_path) if client.process_and_put(filedata, content_type, remote_path, force=force): if verbose: diff --git a/mediasync/conf.py b/mediasync/conf.py index b4eec89..bb9835b 100644 --- a/mediasync/conf.py +++ b/mediasync/conf.py @@ -2,12 +2,10 @@ from django.conf import settings from mediasync import processors _settings = { - 'CSS_PATH': "", 'DOCTYPE': 'html5', 'EMULATE_COMBO': False, 'EXPIRATION_DAYS': 365, 'JOINED': {}, - 'JS_PATH': "", 'MEDIA_ROOT': settings.MEDIA_ROOT, 'MEDIA_URL': settings.MEDIA_URL, 'PROCESSORS': (processors.css_minifier, processors.js_minifier), diff --git a/mediasync/templatetags/media.py b/mediasync/templatetags/media.py index 0fe4121..1f14fb9 100644 --- a/mediasync/templatetags/media.py +++ b/mediasync/templatetags/media.py @@ -202,25 +202,24 @@ class CssTagNode(BaseTagNode): def render(self, context): media_url = self.get_media_url(context) - css_path = msettings['CSS_PATH'] joined = msettings['JOINED'] if msettings['SERVE_REMOTE'] and self.path in joined: # Serving from S3/Cloud Files. - return self.linktag(media_url, css_path, self.path, self.media_type, context) + return self.linktag(media_url, self.path, self.media_type, context) elif not msettings['SERVE_REMOTE'] and msettings['EMULATE_COMBO']: # Don't split the combo file into its component files. Emulate # the combo behavior, but generate/serve it locally. Useful for # testing combo CSS before deploying. - return self.linktag(media_url, css_path, self.path, self.media_type, context) + return self.linktag(media_url, self.path, self.media_type, context) else: # If this is a combo file seen in the JOINED key on the # MEDIASYNC dict, break it apart into its component files and # write separate tags for each. filenames = joined.get(self.path, (self.path,)) - return ' '.join((self.linktag(media_url, css_path, fn, self.media_type, context) for fn in filenames)) + return ' '.join((self.linktag(media_url, fn, self.media_type, context) for fn in filenames)) - def linktag(self, url, path, filename, media, context): + def linktag(self, url, filename, media, context): """ Renders a tag for the stylesheet(s). """ @@ -228,7 +227,7 @@ class CssTagNode(BaseTagNode): markup = """""" else: markup = """""" - return markup % (self.mkpath(url, path, filename, gzip=self.supports_gzip(context)), media) + return markup % (self.mkpath(url, '', filename, gzip=self.supports_gzip(context)), media) """ # JavaScript related tags @@ -253,25 +252,24 @@ class JsTagNode(BaseTagNode): """ def render(self, context): media_url = self.get_media_url(context) - js_path = msettings['JS_PATH'] joined = msettings['JOINED'] if msettings['SERVE_REMOTE'] and self.path in joined: # Serving from S3/Cloud Files. - return self.scripttag(media_url, js_path, self.path, context) + return self.scripttag(media_url, self.path, context) elif not msettings['SERVE_REMOTE'] and msettings['EMULATE_COMBO']: # Don't split the combo file into its component files. Emulate # the combo behavior, but generate/serve it locally. Useful for # testing combo JS before deploying. - return self.scripttag(media_url, js_path, self.path, context) + return self.scripttag(media_url, self.path, context) else: # If this is a combo file seen in the JOINED key on the # MEDIASYNC dict, break it apart into its component files and # write separate tags for each. filenames = joined.get(self.path, (self.path,)) - return ' '.join((self.scripttag(media_url, js_path, fn, context) for fn in filenames)) + return ' '.join((self.scripttag(media_url, fn, context) for fn in filenames)) - def scripttag(self, url, path, filename, context): + def scripttag(self, url, filename, context): """ Renders a """ else: markup = """""" - return markup % self.mkpath(url, path, filename, gzip=self.supports_gzip(context)) + return markup % self.mkpath(url, '', filename, gzip=self.supports_gzip(context)) diff --git a/mediasync/views.py b/mediasync/views.py index 7ebe66e..112c5f9 100644 --- a/mediasync/views.py +++ b/mediasync/views.py @@ -32,57 +32,22 @@ def combo_serve(request, path, client): return HttpResponse(combo_data, mimetype=mime_type) -def _form_key_str(path): - """ - Given a URL path, massage it into a key we can perform a lookup on the - MEDIASYNC['JOINED'] dict with. - - This mostly involves figuring into account the CSS_PATH and JS_PATH - settings, if they have been set. - """ - if path.endswith('.css'): - media_path_prefix = msettings['CSS_PATH'] - elif path.endswith('.js'): - media_path_prefix = msettings['JS_PATH'] - else: - # This isn't a CSS/JS file, no combo for you. - return None - - if media_path_prefix: - # CS/JSS path prefix has been set. Factor that into the key lookup. - if not media_path_prefix.endswith('/'): - # We need to add this slash so we can lop it off the 'path' - # variable, to match the value in the JOINED dict. - media_path_prefix += '/' - - if path.startswith(media_path_prefix): - # Given path starts with the CSS/JS media prefix. Lop this off - # so we can perform a lookup in the JOINED dict. - return path[len(media_path_prefix):] - else: - # Path is in a root dir, send along as-is. - return path - - # No CSS/JS path prefix set. Keep it raw. - return path - def _find_combo_match(path): """ Calculate the key to check the MEDIASYNC['JOINED'] dict for, perform the lookup, and return the matching key string if a match is found. If no match is found, return None instead. """ - key_str = _form_key_str(path) - if not key_str: + if not path: # _form_key_str() says this isn't even a CSS/JS file. return None - if not msettings['JOINED'].has_key(key_str): + if not msettings['JOINED'].has_key(path): # No combo file match found. Must be an single file. return None else: # Combo match found, return the JOINED key. - return key_str + return path def static_serve(request, path, client): """