コード例 #1
0
ファイル: compressed.py プロジェクト: Amli/django-compress
    def render(self, context):
        css_name = self.resolve_name(context)

        try:
            css = settings.COMPRESS_CSS[css_name]
        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(css['output_filename'],
                    css['source_filenames'])
                if u:
                    filter_css(css)
            elif not css.get('extra_context', {}).get('prefix', None):
                filename_base, filename = os.path.split(css['output_filename'])
                path_name = compress_root(filename_base)
                version = get_version_from_file(path_name, filename)

            return render_css(css, css['output_filename'], version)
        else:
            # output source files
            r = ''
            for source_file in css['source_filenames']:
                r += render_css(css, source_file)

            return r
コード例 #2
0
ファイル: compressed.py プロジェクト: enki/bbq-compress
    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
コード例 #3
0
    def render(self, context):
        css_name = template.Variable(self.name).resolve(context)
        actual_request = self.request.resolve(context)

        try:
            css = settings.COMPRESS_CSS[css_name]
        except KeyError:
            return ''  # fail silently, do not return anything if an invalid group is specified
        css['request'] = actual_request
        if settings.COMPRESS:

            version = None

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

            return render_css(css, css['output_filename'], version)
        else:
            # output source files
            r = ''
            for source_file in css['source_filenames']:
                r += render_css(css, source_file)

            return r
コード例 #4
0
def compressed_css(css_name):
    try:
        css = settings.COMPRESS_CSS[css_name]
    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(css['output_filename'], 
                css['source_filenames'])
            if u:
                filter_css(css)
        else:
            filename_base, filename = os.path.split(css['output_filename'])
            path_name = media_root(filename_base)
            version = get_version_from_file(path_name, filename)
            
        return render_css(css, css['output_filename'], version)
    else:
        # output source files
        r = ''
        for source_file in css['source_filenames']:
            r += render_css(css, source_file)

        return r
コード例 #5
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
コード例 #6
0
    def render(self, context):
        css_name = template.Variable(self.name).resolve(context)
        actual_request = self.request.resolve(context)

        try:
            css = settings.COMPRESS_CSS[css_name]
        except KeyError:
            return '' # fail silently, do not return anything if an invalid group is specified
        css['request'] = actual_request
        if settings.COMPRESS:

            version = None

            if settings.COMPRESS_AUTO:
                u, version = needs_update(css['output_filename'], 
                    css['source_filenames'])
                if u:
                    filter_css(css)
            else:
                filename_base, filename = os.path.split(css['output_filename'])
                path_name = media_root(filename_base)
                version = get_version_from_file(path_name, filename)
                
            return render_css(css, css['output_filename'], version)
        else:
            # output source files
            r = ''
            for source_file in css['source_filenames']:
                r += render_css(css, source_file)

            return r
コード例 #7
0
ファイル: compressed.py プロジェクト: robertbak/wolnelektury
    def render(self, context):
        css_name = template.Variable(self.name).resolve(context)

        try:
            css = settings.COMPRESS_CSS[css_name]
        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(css['output_filename'], css['source_filenames'])
                if u:
                    filter_css(css)

            return render_css(css, css['output_filename'], version)
        else:
            # output source files
            r = ''
            for source_file in css['source_filenames']:
                r += render_css(css, source_file)

            return r
コード例 #8
0
ファイル: compressed.py プロジェクト: LongMan/django-compress
    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
コード例 #9
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
コード例 #10
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():
            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
コード例 #11
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()
コード例 #12
0
ファイル: synccompress.py プロジェクト: enki/bbq-compress
    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
コード例 #13
0
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
コード例 #14
0
ファイル: compressed.py プロジェクト: sampad/url-shortener
    def render(self, context):
        css_name = template.Variable(self.name).resolve(context)

        try:
            css = settings.COMPRESS_CSS[css_name]
        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(css['output_filename'], 
                    css['source_filenames'])
                if u:
                    filter_css(css)
            else:
                filename_base, filename = os.path.split(css['output_filename'])
                path_name = media_root(filename_base)
                version = get_version(path_name, filename)
            if self.variable is None:
                return render_css(css, css['output_filename'], version)
            else:
                context[self.variable] = [media_url(css['output_filename'], context.get('prefix', None))]
                return ''
        else:
            # output source files
            if self.variable is None:
                r = ''
                for source_file in css['source_filenames']:
                    r += render_css(css, source_file)
                return r
            else:
                context[self.variable] = [media_url(a_css_file, context.get('prefix', None)) for a_css_file in css['source_filenames']]
                return ''
コード例 #15
0
ファイル: synccompress.py プロジェクト: enki/bbq-compress
import os
os.environ['BBQ_SETTINGS_MODULE'] = 'bbq.settings'
from bbq.conf import settings
from compress.utils import needs_update, filter_css, filter_js
import sys

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

force = True
verbosity = 4

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'])