当前位置: 首页>>代码示例>>Python>>正文


Python compressor.CssCompressor类代码示例

本文整理汇总了Python中compressor.CssCompressor的典型用法代码示例。如果您正苦于以下问题:Python CssCompressor类的具体用法?Python CssCompressor怎么用?Python CssCompressor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CssCompressor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render

    def render(self, context):
        content = self.nodelist.render(context)
        if not settings.COMPRESS or not len(content.strip()):
            return content
        if self.kind == "css":
            compressor = CssCompressor(content)
        if self.kind == "js":
            compressor = JsCompressor(content)
        in_cache = cache.get(compressor.cachekey)
        if in_cache:
            return in_cache
        else:
            # do this to prevent dog piling
            in_progress_key = "django_compressor.in_progress.%s" % compressor.cachekey
            in_progress = cache.get(in_progress_key)
            if in_progress:
                while cache.get(in_progress_key):
                    sleep(0.1)
                output = cache.get(compressor.cachekey)
            else:
                cache.set(in_progress_key, True, 300)
                try:
                    output = compressor.output()
                    cache.set(
                        compressor.cachekey, output, 2591000
                    )  # rebuilds the cache every 30 days if nothign has changed.
                except:
                    from traceback import format_exc

                    raise Exception(format_exc())
                # finally:
                #    in_progress_key = False
                cache.set(in_progress_key, False, 300)
            return output
开发者ID:gdestuynder,项目名称:secinv,代码行数:34,代码来源:compress.py

示例2: render

 def render(self, context):
     content = self.nodelist.render(context)
     if not settings.COMPRESS:
         soup = BeautifulSoup(content)
         if self.kind == 'css':
             output = soup.link['href']
         elif self.kind == 'js':
             output = soup.script['src']
         return output 
     if self.kind == 'css':
         compressor = CssCompressor(content)
     if self.kind == 'js':
         compressor = JsCompressor(content)
     in_cache = cache.get(compressor.cachekey)
     if in_cache:
         return in_cache
     else:
         output = compressor.output()
         soup = BeautifulSoup(output)
         if self.kind == 'css':
             output = soup.link['href']
         elif self.kind == 'js':
             output = soup.script['src']
         cache.set(compressor.cachekey, output, 86400) # rebuilds the cache once a day if nothign has changed.
         return output
开发者ID:dziegler,项目名称:daves_django_compressor,代码行数:25,代码来源:compress.py

示例3: render

 def render(self, context):
     content = self.nodelist.render(context)
     if 'COMPRESS_URL' in context:
         media_url = context['COMPRESS_URL']
     else:
         media_url = settings.MEDIA_URL
     if self.kind == 'css':
         compressor = CssCompressor(content, xhtml=self.xhtml, media_url=media_url)
     if self.kind == 'js':
         compressor = JsCompressor(content, xhtml=self.xhtml, media_url=media_url)
     in_cache = cache.get(compressor.cachekey)
     if in_cache:
         return in_cache
     else:
         # do this to prevent dog piling
         in_progress_key = '%s.django_css.in_progress.%s' % (DOMAIN, compressor.cachekey)
         added_to_cache = cache.add(in_progress_key, True, 300)
         if added_to_cache:
             output = compressor.output()
             cache.set(compressor.cachekey, output, 2591000) # rebuilds the cache every 30 days if nothing has changed.
             cache.set(in_progress_key, False, 300)
         else:
             while cache.get(in_progress_key):
                 sleep(0.1)
             output = cache.get(compressor.cachekey)
         return output
开发者ID:hedberg,项目名称:django-css,代码行数:26,代码来源:compress.py

示例4: render

 def render(self, context):
     content = self.nodelist.render(context)
     if self.kind == 'css':
         compressor = CssCompressor(content, xhtml=self.xhtml)
     if self.kind == 'js':
         compressor = JsCompressor(content, xhtml=self.xhtml)
     in_cache = cache.get(compressor.cachekey)
     if in_cache:
         return in_cache
     else:
         # do this to prevent dog piling
         in_progress_key = 'django_css.in_progress.%s' % compressor.cachekey
         in_progress = cache.get(in_progress_key)
         if in_progress:
             while cache.get(in_progress_key):
                 sleep(0.1)
             output = cache.get(compressor.cachekey)
         else:
             cache.set(in_progress_key, True, 300)
             try:
                 output = compressor.output()
                 cache.set(compressor.cachekey, output, 2591000) # rebuilds the cache every 30 days if nothign has changed.
             except:
                 from traceback import format_exc
                 raise Exception(format_exc())
             cache.set(in_progress_key, False, 300)
         return output
开发者ID:parulian1,项目名称:fashionment,代码行数:27,代码来源:compress.py

示例5: preg_file

    def preg_file(self, fname):
        css = ""
        js = ""
        
        search = re.search("(?P<name>[^\.]*)\.(?P<extension>.*)$",fname)
        if search and search.groupdict()['extension'] == 'html':
            template_file = "%s/%s" % (self.template_path, fname)
            print "\tparsing %s" % template_file
            try:
                css_files, js_files, css_matchs, js_matchs = self.filter(template_file)
                css_name = ""
                js_name = ""
                if css_files:
                    css_name = "/%s.min.css" % search.groupdict()['name']
                    compress = CssCompressor(files=css_files, file_output=self.css_path + css_name, media_dir=self.media_dir )
                    css = compress.run()

                if js_files:
                    js_name = "/%s.min.js" % search.groupdict()['name']
                    compress = JsCompressor(files=js_files, file_output=self.js_path + js_name, media_dir=self.media_dir )
                    js = compress.run()

                self.parse(template_file, self.css_url_base + css_name, self.js_url_base + js_name, css_matchs, js_matchs)
            except Exception, e:                        
                print "template file %s could not be filtered" % template_file
                raise e
开发者ID:marcelnicolay,项目名称:simple-minify,代码行数:26,代码来源:filter.py

示例6: handle

    def handle(self, *args, **options):
        # Passing -1 to chown leaves the ownership unchanged, hence the default
        uid = -1
        gid = -1
        chown = options.get("chown", None)
        chgrp = options.get("chgrp", None)
        verbosity = int(options.get("verbosity", 1))
        if chown or chgrp:
            # pwd is only available on POSIX-compliant systems
            try:
                import pwd
            except ImportError:
                raise OptionError("Ownership changes are not supported by your operating system.", "--chown")
            try:
                if chown:
                    uid = pwd.getpwnam(chown).pw_uid
                if chgrp:
                    gid = pwd.getpwnam(chgrp).pw_gid
            except (KeyError, TypeError):
                raise OptionError('The specified username "%s" does not exist or is invalid.' % chown, "--chown")
        if not hasattr(os, "chmod"):
            raise NotImplementedError("Permission changes are not supported by your operating system")
        if not hasattr(settings, "COMPILER_FORMATS") or not settings.COMPILER_FORMATS:
            raise ImproperlyConfigured("COMPILER_FORMATS not specified in settings.")

        if verbosity:
            print "Looking for slateable CSS files in %s" % settings.MEDIA_ROOT

        # Find all files in MEDIA_ROOT that have a COMPILER_FORMATS-supported
        # extension, and return them as a list of (full path to file without
        # extension, extension) tuples.
        files_to_compile = []
        for root, dirs, files in os.walk(settings.MEDIA_ROOT):
            for _dir in dirs:
                for _file in files:
                    name, ext = os.path.splitext(_file)
                    if ext in settings.COMPILER_FORMATS:
                        files_to_compile.append((os.path.join(root, name), ext))

        if verbosity:
            print "Found %s files to be slated..." % len(files_to_compile)

        for filename, extension in files_to_compile:
            if verbosity > 1:
                print "Compiling %s%s" % (filename, extension)
            CssCompressor.compile(filename, settings.COMPILER_FORMATS[extension])
            css_file = "%s.css" % filename
            if chown or chgrp:
                # Change file ownership to specified group and/or user
                os.chown(css_file, uid, gid)
                # Make sure owner can write and everyone can read
                os.chmod(css_file, 0644)
            else:
                # Allow everyone to read and write
                os.chmod(css_file, 0666)

        if verbosity:
            print "Finished slating."
开发者ID:schinckel,项目名称:django-css,代码行数:58,代码来源:css_slate.py

示例7: render

 def render(self, context):
     content = self.nodelist.render(context)
     if self.kind == 'css':
         compressor = CssCompressor(content, xhtml=self.xhtml, output_filename=self.output_filename)
     if self.kind == 'js':
         compressor = JsCompressor(content, xhtml=self.xhtml, output_filename=self.output_filename)
     in_cache = cache.get(compressor.cachekey)
     if in_cache: 
         return in_cache
     else:
         output = compressor.output()
         cache.set(compressor.cachekey, output, 86400) # rebuilds the cache once a day if nothing has changed.
         return output
开发者ID:tymofij,项目名称:django-css,代码行数:13,代码来源:compress.py

示例8: render

 def render(self, context):
     content = self.nodelist.render(context)
     if not settings.COMPRESS:
         return content
     if self.kind == 'css':
         compressor = CssCompressor(content)
     if self.kind == 'js':
         compressor = JsCompressor(content)
     in_cache = cache.get(compressor.cachekey)
     if in_cache:
         return in_cache
     else:
         output = compressor.output()
         cache.set(compressor.cachekey, output, 86400) # Rebuilds the cache once a day if nothing has changed.
         return output
开发者ID:danfairs,项目名称:django_compressor,代码行数:15,代码来源:compress.py

示例9: setUp

    def setUp(self):
        super(CompressorTestCase, self).setUp()
        
        
        self.ccssFile = os.path.join(settings.MEDIA_ROOT, u'css/three.css')
        self.css = dedent("""
        <link rel="stylesheet" href="/media/css/one.css" type="text/css">
        <style type="text/css">p { border:5px solid green;}</style>
        <link rel="stylesheet" href="/media/css/two.css" type="text/css">
        <link rel="stylesheet" href="/media/css/three.ccss" type="text/css">
        <style type="text/ccss">
        """)+ \
        '\n'.join((
        "small:\n  font-size:10px",
        '</style>\n<style type="ccss">',
        "h1:\n  font-weight:bold",
        "</style>"))
        self.css_hash = "1ff892c21b66"
        self.js_hash = "3f33b9146e12"
        self.cssNode = CssCompressor(self.css)

        self.js = """
        <script src="/media/js/one.js" type="text/javascript"></script>
        <script type="text/javascript">obj.value = "value";</script>
        """
        self.jsNode = JsCompressor(self.js)
开发者ID:wil,项目名称:django-css,代码行数:26,代码来源:tests.py

示例10: setUp

    def setUp(self):
        settings.COMPRESS = True
        settings.COMPILER_FORMATS = {
            '.ccss': {
                'binary_path': 'python ' + os.path.join(django_settings.TEST_DIR,'clevercss.py'),
                'arguments': '*.ccss'
            },
        }
        self.ccssFile = os.path.join(settings.MEDIA_ROOT, u'css/three.css')
        self.css = dedent("""
        <link rel="stylesheet" href="/media/css/one.css" type="text/css">
        <style type="text/css">p { border:5px solid green;}</style>
        <link rel="stylesheet" href="/media/css/two.css" type="text/css">
        <link rel="stylesheet" href="/media/css/three.ccss" type="text/css">
        <style type="text/ccss">
        """)+ \
        '\n'.join((
        "small:\n  font-size:10px",
        '</style>\n<style type="ccss">',
        "h1:\n  font-weight:bold",
        "</style>"))
        
        self.cssNode = CssCompressor(self.css)

        self.js = """
        <script src="/media/js/one.js" type="text/javascript"></script>
        <script type="text/javascript">obj.value = "value";</script>
        """
        self.jsNode = JsCompressor(self.js)
开发者ID:attilaolah,项目名称:django-css,代码行数:29,代码来源:tests.py

示例11: render

 def render(self, context):
     content = self.nodelist.render(context)
     if not settings.COMPRESS or not len(content.strip()):
         return content
     if self.kind == 'css':
         compressor = CssCompressor(content)
     if self.kind == 'js':
         compressor = JsCompressor(content)
     output = self.cache_get(compressor.cachekey)
     if output is None:
         try:
             output = compressor.output()
             self.cache_set(compressor.cachekey, output)
         except:
             from traceback import format_exc
             raise Exception(format_exc())
     return output
开发者ID:dheeru0198,项目名称:agiliq,代码行数:17,代码来源:compress.py

示例12: setUp

 def setUp(self):
     self.css = """
     <link rel="stylesheet" href="/media/css/one.css" type="text/css" media="screen" charset="utf-8">
     <style type="text/css" media="print">p { border:5px solid green;}</style>
     <link rel="stylesheet" href="/media/css/two.css" type="text/css" charset="utf-8" media="all">
     <style type="text/css">h1 { border:5px solid green;}</style>
     """
     self.cssNode = CssCompressor(self.css)
开发者ID:abal09,项目名称:django_compressor,代码行数:8,代码来源:tests.py

示例13: setUp

    def setUp(self):
        settings.COMPRESS = True
        self.css = """
        <link rel="stylesheet" href="/media/css/one.css" type="text/css" charset="utf-8">
        <style type="text/css">p { border:5px solid green;}</style>
        <link rel="stylesheet" href="/media/css/two.css" type="text/css" charset="utf-8">
        """
        self.cssNode = CssCompressor(self.css)

        self.js = """
        <script src="/media/js/one.js" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript" charset="utf-8">obj.value = "value";</script>
        """
        self.jsNode = JsCompressor(self.js)
开发者ID:fgallina,项目名称:wethemen,代码行数:14,代码来源:tests.py

示例14: render

 def render(self, context):
     content = self.nodelist.render(context)
     if self.kind == 'css':
         compressor = CssCompressor(content, xhtml=self.xhtml)
     if self.kind == 'js':
         compressor = JsCompressor(content, xhtml=self.xhtml)
     output = cache.get(compressor.cachekey)
     if output is None:
         # do this to prevent dog piling
         in_progress_key = '%s.django_css.in_progress.%s' % (DOMAIN, compressor.cachekey)
         added_to_cache = cache.add(in_progress_key, True, 300)
         if added_to_cache:
             output = compressor.output()
             cache.set(compressor.cachekey, output, 2591000) # rebuilds the cache every 30 days if nothing has changed.
             cache.set(in_progress_key, False, 300)
         else:
             while cache.get(in_progress_key):
                 sleep(0.1)
             output = cache.get(compressor.cachekey)
     if settings.COMPRESS:
         return render_to_string(compressor.template_name, {'filepath':output, 'xhtml':self.xhtml}, context)
     else:
         return output
开发者ID:attilaolah,项目名称:django-css,代码行数:23,代码来源:compress.py

示例15: render

    def render(self, context):
        content = self.nodelist.render(context)
        if not settings.COMPRESS or not len(content.strip()):
            return content
        if self.kind == 'css':
            compressor = CssCompressor(content)
        if self.kind == 'js':
            compressor = JsCompressor(content)
 	if self.kind == 'embeddedcss':            
            compressor = EmbeddedCssCompressor(content)
        if self.kind == 'embeddedjs':            
            compressor = EmbeddedJsCompressor(content)


        output = self.cache_get(compressor.cachekey)
        if output is None:
            try:
                output = compressor.output()
                # rebuilds the cache every 30 days if nothing has changed.
                self.cache_set(compressor.cachekey, output, 2591000)
            except:
                from traceback import format_exc
                raise Exception(format_exc())
        return output
开发者ID:danielhasselrot,项目名称:django_compressor,代码行数:24,代码来源:compress.py


注:本文中的compressor.CssCompressor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。