Example #1
0
    def render(self, context):
        js_name = template.Variable(self.name).resolve(context)

        try:
            js = settings.COMPRESS_JS[js_name]
            js["source_filenames"] = get_source_filenames(js["source_filenames"])
        except KeyError:
            return ""  # fail silently, do not return anything if an invalid group is specified

        if settings.COMPRESS:

            version = None

            if settings.COMPRESS_AUTO:
                u, version = needs_update(js["output_filename"], js["source_filenames"])
                if u:
                    filter_js(js)

            return render_js(js, js["output_filename"], version)
        else:
            # output source files
            r = ""
            for source_file in js["source_filenames"]:
                r += render_js(js, source_file)
            return r
Example #2
0
    def render(self, context):
        js_name = template.Variable(self.name).resolve(context)

        try:
            js = settings.COMPRESS_JS[js_name]
        except KeyError:
            return '' # fail silently, do not return anything if an invalid group is specified
        
        if 'external_urls' in js:
            r = ''
            for url in js['external_urls']:
                r += render_js(js, url)
            return r
                    
        if settings.COMPRESS:

            version = None

            if settings.COMPRESS_AUTO:
                u, version = needs_update(js['output_filename'], 
                    js['source_filenames'])
                if u:
                    filter_js(js)
            else: 
                filename_base, filename = os.path.split(js['output_filename'])
                path_name = media_root(filename_base)
                version = get_version_from_file(path_name, filename)

            return render_js(js, js['output_filename'], version)
        else:
            # output source files
            r = ''
            for source_file in js['source_filenames']:
                r += render_js(js, source_file)
            return r
    def render(self, context):
        js_name = template.Variable(self.name).resolve(context)

        try:
            js = settings.COMPRESS_JS[js_name]
        except KeyError:
            return ''  # fail silently, do not return anything if an invalid group is specified

        if 'external_urls' in js:
            r = ''
            for url in js['external_urls']:
                r += render_js(js, url)
            return r

        if settings.COMPRESS:

            version = None

            if settings.COMPRESS_AUTO:
                u, version = needs_update(js['output_filename'],
                                          js['source_filenames'])
                if u:
                    filter_js(js)
            else:
                filename_base, filename = os.path.split(js['output_filename'])
                path_name = media_root(filename_base)
                version = get_version_from_file(path_name, filename)

            return render_js(js, js['output_filename'], version)
        else:
            # output source files
            r = ''
            for source_file in js['source_filenames']:
                r += render_js(js, source_file)
            return r
Example #4
0
    def render(self, context):
        js_name = template.Variable(self.name).resolve(context)

        try:
            js = settings.COMPRESS_JS[js_name]
        except KeyError:
            return ""  # fail silently, do not return anything if an invalid group is specified

        if "external_urls" in js:
            r = ""
            for url in js["external_urls"]:
                r += render_js(js, url)
            return r

        request = context["request"]
        if settings.COMPRESS:

            version = None

            if settings.COMPRESS_AUTO:
                u, version = needs_update(js["output_filename"], js["source_filenames"])
                if u:
                    filter_js(js)
            elif not js.get("extra_context", {}).get("prefix", None):
                filename_base, filename = os.path.split(js["output_filename"])
                path_name = compress_root(filename_base)
                version = get_version_from_file(path_name, filename)

            return render_js(js, js["output_filename"], request, version)
        else:
            # output source files
            r = ""
            for source_file in js["source_filenames"]:
                r += render_js(js, source_file, request)
            return r
    def handle_noargs(self, **options):
        
        force = options.get('force', False)
        verbosity = int(options.get('verbosity', 1))

        from compress.utils import needs_update, filter_css, filter_js

        for name, css in settings.COMPRESS_CSS.items():
            u, version = needs_update(css['output_filename'], 
                css['source_filenames'])

            if (force or u) or verbosity >= 2:
                msg = 'CSS Group \'%s\'' % name
                print msg
                print len(msg) * '-'
                print "Version: %s" % version

            if force or u:
                filter_css(css, verbosity)

            if (force or u) or verbosity >= 2:
                print

        for name, js in settings.COMPRESS_JS.items():
            if 'external_urls' in js:
                u, version = False, "External"
            else:
                u, version = needs_update(js['output_filename'], 
                    js['source_filenames'])

            if (force or u) or verbosity >= 2:
                msg = 'JavaScript Group \'%s\'' % name
                print msg
                print len(msg) * '-'
                print "Version: %s" % version

            if (force or u) and 'external_urls' not in js:
                filter_js(js, verbosity)

            if (force or u) or verbosity >= 2:
                print
Example #6
0
    def handle_noargs(self, **options):

        force = options.get('force', False)
        verbosity = int(options.get('verbosity', 1))

        from compress.utils import needs_update, filter_css, filter_js

        for name, css in list(settings.COMPRESS_CSS.items()):
            u, version = needs_update(css['output_filename'],
                                      css['source_filenames'])

            if (force or u) or verbosity >= 2:
                msg = 'CSS Group \'%s\'' % name
                print(msg)
                print(len(msg) * '-')
                print("Version: %s" % version)

            if force or u:
                filter_css(css, verbosity)

            if (force or u) or verbosity >= 2:
                print()

        for name, js in list(settings.COMPRESS_JS.items()):
            u, version = needs_update(js['output_filename'],
                                      js['source_filenames'])

            if (force or u) or verbosity >= 2:
                msg = 'JavaScript Group \'%s\'' % name
                print(msg)
                print(len(msg) * '-')
                print("Version: %s" % version)

            if force or u:
                filter_js(js, verbosity)

            if (force or u) or verbosity >= 2:
                print()
def compress_auto_update(filename):
    """
    default tags from compressed is better

    support for django-compress auto update
    COMPRESS_VERSION isn't supported
    """
    if 'compress' in settings.INSTALLED_APPS:
        from compress.conf import settings as csettings
        from compress.utils import needs_update, filter_css, filter_js, filter_common
        from compress.signals import css_filtered, js_filtered
        if csettings.COMPRESS_AUTO:
            # determine files where COMPRESS settings defined
            # to include them in version check
            try:
                import inspect
                settings_file = (inspect.getsourcefile(csettings.COMPRESS_AUTO),)
            except:
                settings_file = ()

            # try to find target file in compress settings
            for obj in csettings.COMPRESS_CSS.values() + csettings.COMPRESS_JS.values():
                if obj['output_filename'] == filename:

                    u, version = needs_update(obj['output_filename'],
                                              tuple(obj['source_filenames']) + settings_file)
                    if u:
                        if csettings.COMPRESS:
                            if filename.endswith('.css'):
                                filter_css(obj)

                            if filename.endswith('.js'):
                                filter_js(obj)
                        else:
                            # simple join
                            return filter_common(obj, 0, filters=[], attr='', separator='', signal=js_filtered)
                    break
Example #8
0
    def handle_noargs(self, **options):

        force = options.get("force", False)
        verbosity = int(options.get("verbosity", 1))

        from compress.utils import needs_update, filter_css, filter_js

        for name, css in settings.COMPRESS_CSS.items():
            u, version = needs_update(css["output_filename"], css["source_filenames"])

            if (force or u) or verbosity >= 2:
                msg = "CSS Group '%s'" % name
                print msg
                print len(msg) * "-"
                print "Version: %s" % version

            if force or u:
                filter_css(css, verbosity)

            if (force or u) or verbosity >= 2:
                print

        for name, js in settings.COMPRESS_JS.items():
            u, version = needs_update(js["output_filename"], js["source_filenames"])

            if (force or u) or verbosity >= 2:
                msg = "JavaScript Group '%s'" % name
                print msg
                print len(msg) * "-"
                print "Version: %s" % version

            if force or u:
                filter_js(js, verbosity)

            if (force or u) or verbosity >= 2:
                print
Example #9
0
    u, version = needs_update(css['output_filename'], 
        css['source_filenames'])

    if (force or u) or verbosity >= 2:
        msg = 'CSS Group \'%s\'' % name
        print msg
        print len(msg) * '-'
        print "Version: %s" % version

    if force or u:
        filter_css(css, verbosity)

    if (force or u) or verbosity >= 2:
        print

for name, js in settings.COMPRESS_JS.items():
    u, version = needs_update(js['output_filename'], 
        js['source_filenames'])

    if (force or u) or verbosity >= 2:
        msg = 'JavaScript Group \'%s\'' % name
        print msg
        print len(msg) * '-'
        print "Version: %s" % version

    if force or u:
        filter_js(js, verbosity)

    if (force or u) or verbosity >= 2:
        print