• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python slimmer.css_slimmer函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_registerCSSFiles__one_slimmed_and_gzipped

    def test_registerCSSFiles__one_slimmed_and_gzipped(self):
        """ test the registerCSSFiles() with slim_if_possible=True but one
        of the files shouldn't be slimmed because its filename indicates
        that it's already been slimmed/packed/minified. 

        In this test, the big challange is when two js files are combined 
        and one of them should be slimmed, the other one not slimmed.
        """
        if css_slimmer is None:
            return

        class MyProduct:
            pass

        files = ["test-min.css", "test.css"]
        files.append(tuple(files))
        registerCSSFiles(
            MyProduct, files, rel_path="tests", set_expiry_header=True, slim_if_possible=True, gzip_if_possible=True
        )

        REQUEST = self.app.REQUEST
        RESPONSE = REQUEST.RESPONSE

        instance = MyProduct()
        for filename in files:
            if isinstance(filename, tuple):
                filename = ",".join(filename)
            static = getattr(instance, filename)
            self.assertTrue(isinstance(static, BetterImageFile))

            # if you just call static.__str__() you're not calling it
            # with a REQUEST that accepts gzip encoding
            REQUEST.set("HTTP_ACCEPT_ENCODING", "gzip")
            bin_rendered = static.index_html(REQUEST, RESPONSE)

            # expect this to be slimmed
            if len(filename.split(",")) > 1:

                content_parts = []
                for filename in filename.split(","):
                    content = open(right_here(filename)).read()
                    if filename.find("min") > -1:
                        content_parts.append(content)
                    else:
                        content_parts.append(css_slimmer(content))

                expected_content = "\n".join(content_parts)
                expected_content = expected_content.strip()

            else:
                if filename.find("min") > -1:
                    expected_content = open(right_here(filename)).read()
                else:
                    expected_content = css_slimmer(open(right_here(filename)).read())
                expected_content = expected_content.strip()

            rendered = _gzip2ascii(bin_rendered)

            self.assertEqual(rendered.strip(), expected_content)
开发者ID:peterbe,项目名称:FriedZopeBase,代码行数:59,代码来源:testZope.py


示例2: test_registering_with_slimming_and_images_in_css

    def test_registering_with_slimming_and_images_in_css(self):
        try:
            from slimmer import js_slimmer, css_slimmer
        except ImportError:
            # not possible to test this
            return

        class MyProduct:
            pass

        instance = MyProduct()

        # it will only fix images that have otherwise been registered
        registerImage(MyProduct, right_here("image.jpg"), rel_path="tests")

        registerCSSFile(
            MyProduct,
            "containsimages.css",
            rel_path="tests",
            set_expiry_header=True,
            slim_if_possible=True,
            replace_images_with_aliases=True,
        )
        static = getattr(instance, "containsimages.css")

        # Not the same...
        self.assertNotEqual(str(static), css_slimmer(open(right_here("containsimages.css")).read()))
        # unless you remove all '.\d+.'
        self.assertEqual(
            re.sub("\.\d{10,11}\.", ".", str(static)), css_slimmer(open(right_here("containsimages.css")).read())
        )

        # because we haven't registered large.jpg it won't be aliased
        self.assertTrue("large.jpg" in str(static))
        self.assertTrue("image.jpg" not in str(static))

        self.assertEqual(
            sorted(["containsimages.css-slimmed.css-aliased.css", "containsimages.css-slimmed.css"]),
            sorted(os.listdir(_get_autogenerated_dir())),
        )

        # if you don it again it should just overwrite the old one
        registerCSSFile(
            MyProduct,
            "containsimages.css",
            rel_path="tests",
            set_expiry_header=True,
            slim_if_possible=True,
            replace_images_with_aliases=True,
        )

        self.assertEqual(
            sorted(["containsimages.css-slimmed.css-aliased.css", "containsimages.css-slimmed.css"]),
            sorted(os.listdir(_get_autogenerated_dir())),
        )
开发者ID:peterbe,项目名称:FriedZopeBase,代码行数:55,代码来源:testZope.py


示例3: test_registerCSSFiles__both_slimmed_and_gzipped

    def test_registerCSSFiles__both_slimmed_and_gzipped(self):
        """ test the registerCSSFiles() with slim_if_possible=True """
        if css_slimmer is None:
            return

        class MyProduct:
            pass

        # test setting a bunch of files
        files = ["large.css", "test.css"]
        files.append(tuple(files))
        registerCSSFiles(
            MyProduct, files, rel_path="tests", set_expiry_header=True, slim_if_possible=True, gzip_if_possible=True
        )

        instance = MyProduct()

        REQUEST = self.app.REQUEST
        RESPONSE = REQUEST.RESPONSE

        for filename in files:
            if isinstance(filename, tuple):
                filename = ",".join(filename)
            static = getattr(instance, filename)
            self.assertTrue(isinstance(static, BetterImageFile))

            # if you just call static.__str__() you're not calling it
            # with a REQUEST that accepts gzip encoding
            REQUEST.set("HTTP_ACCEPT_ENCODING", "gzip")
            bin_rendered = static.index_html(REQUEST, RESPONSE)
            rendered = _gzip2ascii(bin_rendered).strip()

            # expect this to be slimmed
            if len(filename.split(",")) > 1:
                content_parts = [open(right_here(x)).read() for x in filename.split(",")]

                if css_slimmer is None:
                    expected_content = "\n".join(content_parts)
                else:
                    expected_content = "\n".join([css_slimmer(x) for x in content_parts])
            else:
                content = open(right_here(filename)).read()
                if css_slimmer is None:
                    expected_content = content
                else:
                    expected_content = css_slimmer(content)

            self.assertEqual(rendered.strip(), expected_content.strip())
开发者ID:peterbe,项目名称:FriedZopeBase,代码行数:48,代码来源:testZope.py


示例4: test_registerCSSFiles__one_slimmed

    def test_registerCSSFiles__one_slimmed(self):
        """ test the registerCSSFiles() with slim_if_possible=True but one
        of the files shouldn't be slimmed because its filename indicates
        that it's already been slimmed/packed/minified. 

        In this test, the big challange is when two js files are combined 
        and one of them should be slimmed, the other one not slimmed.
        """
        if css_slimmer is None:
            return

        class MyProduct:
            pass

        files = ["test-min.css", "test.css"]
        files.append(tuple(files))
        registerCSSFiles(
            MyProduct, files, rel_path="tests", set_expiry_header=True, slim_if_possible=True, gzip_if_possible=False
        )

        instance = MyProduct()
        for filename in files:
            if isinstance(filename, tuple):
                filename = ",".join(filename)
            static = getattr(instance, filename)
            self.assertTrue(isinstance(static, BetterImageFile))
            rendered = str(static).strip()
            # expect this to be slimmed partially
            if len(filename.split(",")) > 1:

                content_parts = []
                for filename in filename.split(","):
                    content = open(right_here(filename)).read()
                    if filename.find("min") > -1:
                        content_parts.append(content)
                    else:
                        content_parts.append(css_slimmer(content))

                expected_content = "\n".join(content_parts)
                expected_content = expected_content.strip()
            else:
                if filename.find("min") > -1:
                    expected_content = open(right_here(filename)).read()
                else:
                    expected_content = css_slimmer(open(right_here(filename)).read())
                expected_content = expected_content.strip()

            self.assertEqual(rendered.strip(), expected_content)
开发者ID:peterbe,项目名称:FriedZopeBase,代码行数:48,代码来源:testZope.py


示例5: therapy

 def therapy(self):
     css = []
     for fn in self.absolute_paths:
         with open(fn, 'r') as fp:
             css.append(fp.read())
     css = css_slimmer(''.join(css))
     storage.save(self.node.destination, ContentFile(css))
开发者ID:SportsCrunch2013,项目名称:django-shrink,代码行数:7,代码来源:base.py


示例6: _get_code

 def _get_code(self):
     import slimmer
     f = open(self.path)
     code = f.read()
     f.close()
     if self.filetype == '.css':
         return slimmer.css_slimmer(code)
     if self.filetype == '.js':
         return slimmer.js_slimmer(code)
     if self.filetype == '.html':
         return slimmer.xhtml_slimmer(code)
     return code
开发者ID:kespindler,项目名称:python-livereload,代码行数:12,代码来源:compiler.py


示例7: get_code

 def get_code(self):
     import slimmer
     f = codecs.open(self.path, 'r', 'utf-8')
     code = f.read()
     f.close()
     if self.filetype == '.css':
         return slimmer.css_slimmer(code)
     if self.filetype == '.js':
         return slimmer.js_slimmer(code)
     if self.filetype == '.html':
         return slimmer.xhtml_slimmer(code)
     return code
开发者ID:typecode,项目名称:python-livereload,代码行数:12,代码来源:compiler.py


示例8: test_registering_with_slimming_and_gzip_and_images_in_css

    def test_registering_with_slimming_and_gzip_and_images_in_css(self):
        try:
            from slimmer import js_slimmer, css_slimmer
        except ImportError:
            # not possible to test this
            return

        class MyProduct:
            pass

        instance = MyProduct()

        registerJSFile(MyProduct, "test.js", rel_path="tests", set_expiry_header=True, slim_if_possible=True)

        static = getattr(instance, "test.js")
        self.assertEqual(str(static), js_slimmer(open(right_here("test.js")).read()))

        registerCSSFile(
            MyProduct,
            "test.css",
            rel_path="tests",
            set_expiry_header=True,
            slim_if_possible=True,
            gzip_if_possible=True,
        )
        static = getattr(instance, "test.css")
        self.assertEqual(str(static), css_slimmer(open(right_here("test.css")).read()))

        # if you don it again it should just overwrite the old one
        registerCSSFile(
            MyProduct,
            "test.css",
            rel_path="tests",
            set_expiry_header=True,
            slim_if_possible=True,
            gzip_if_possible=True,
        )

        static = getattr(instance, "test.css")
        self.assertEqual(str(static), css_slimmer(open(right_here("test.css")).read()))
开发者ID:peterbe,项目名称:FriedZopeBase,代码行数:40,代码来源:testZope.py


示例9: optimize

def optimize(content, type_):
    if type_ == CSS:
        if getattr(settings, 'DJANGO_STATIC_YUI_COMPRESSOR', None):
            return _run_yui_compressor(content, type_)
        return css_slimmer(content)
    elif type_ == JS:
        if getattr(settings, 'DJANGO_STATIC_CLOSURE_COMPILER', None):
            return _run_closure_compiler(content)
        if getattr(settings, 'DJANGO_STATIC_YUI_COMPRESSOR', None):
            return _run_yui_compressor(content, type_)
        return js_slimmer(content)
    else:
        raise ValueError("Invalid type %r" % type_)
开发者ID:xster,项目名称:openparliament,代码行数:13,代码来源:django_static.py


示例10: _registerCSS

def _registerCSS(product, filename, path='css', slim_if_possible=True):
    objectid = filename
    setattr(product,
            objectid,
            BetterImageFile(os.path.join(path, filename), globals())
            )
    obj = getattr(product, objectid)
    if css_slimmer is not None and OPTIMIZE:
        if slim_if_possible:
            slimmed = css_slimmer(open(obj.path,'rb').read())
            new_path = obj.path + '-slimmed.css'
            new_path = _get_autogenerated_file_path(new_path)
            open(new_path, 'wb').write(slimmed)
            setattr(obj, 'path', new_path)
开发者ID:BillTheBest,项目名称:IssueTrackerProduct,代码行数:14,代码来源:__init__.py


示例11: test_registerCSSFiles__both_slimmed

    def test_registerCSSFiles__both_slimmed(self):
        """ test the registerCSSFiles() with slim_if_possible=True """
        if css_slimmer is None:
            return
        try:

            class MyProduct:
                pass

            # test setting a bunch of files
            files = ["large.css", "test.css"]
            files.append(tuple(files))
            registerCSSFiles(
                MyProduct,
                files,
                rel_path="tests",
                set_expiry_header=True,
                slim_if_possible=True,
                gzip_if_possible=False,
            )

            instance = MyProduct()
            for filename in files:
                if isinstance(filename, tuple):
                    filename = ",".join(filename)
                static = getattr(instance, filename)
                self.assertTrue(isinstance(static, BetterImageFile))
                rendered = str(static)
                # expect this to be slimmed
                if len(filename.split(",")) > 1:
                    content_parts = [open(right_here(x)).read() for x in filename.split(",")]
                    expected_content = "\n".join([css_slimmer(x) for x in content_parts])
                else:
                    expected_content = css_slimmer(open(right_here(filename)).read())
                self.assertEqual(rendered.strip(), expected_content.strip())
        except ImportError:
            pass
开发者ID:peterbe,项目名称:FriedZopeBase,代码行数:37,代码来源:testZope.py


示例12: render

 def render(self, context):
     code = self.nodelist.render(context)
     if self.format == 'css':
         return css_slimmer(code)
     elif self.format in ('js', 'javascript'):
         return js_slimmer(code)
     elif self.format == 'html':
         return html_slimmer(code)
     else:
         format = guessSyntax(code)
         if format:
             self.format = format
             return self.render(context)
         
     return code
开发者ID:peterbe,项目名称:fwc_mobile,代码行数:15,代码来源:whitespaceoptimize.py


示例13: optimize

def optimize(content, type_):
    if type_ == CSS:
        if cssmin is not None:
            return _run_cssmin(content)
        elif getattr(settings, "DJANGO_STATIC_YUI_COMPRESSOR", None):
            return _run_yui_compressor(content, type_)
        return slimmer.css_slimmer(content)
    elif type_ == JS:
        if getattr(settings, "DJANGO_STATIC_CLOSURE_COMPILER", None):
            return _run_closure_compiler(content)
        if getattr(settings, "DJANGO_STATIC_YUI_COMPRESSOR", None):
            return _run_yui_compressor(content, type_)
        if getattr(settings, "DJANGO_STATIC_JSMIN", None):
            return _run_jsmin(content)
        return slimmer.js_slimmer(content)
    else:
        raise ValueError("Invalid type %r" % type_)
开发者ID:Akamad007,项目名称:django-static,代码行数:17,代码来源:django_static.py


示例14: test_registering_with_slimming_basic

    def test_registering_with_slimming_basic(self):
        try:
            from slimmer import js_slimmer, css_slimmer
        except ImportError:
            # not possible to test this
            return

        class MyProduct:
            pass

        instance = MyProduct()

        registerJSFile(MyProduct, "test.js", rel_path="tests", set_expiry_header=True, slim_if_possible=True)

        static = getattr(instance, "test.js")
        self.assertEqual(str(static), js_slimmer(open(right_here("test.js")).read()))

        # this will have created a file called 'test.js-slimmed.js' whose content
        # is the same as str(static)
        copy_test_js = os.path.join(_get_autogenerated_dir(), "test.js-slimmed.js")
        self.assertTrue(os.path.isfile(copy_test_js))
        self.assertEqual(open(copy_test_js).read(), str(static))
        # and it that directory there should not be any other files
        for f in os.listdir(os.path.dirname(copy_test_js)):
            self.assertEqual(f, os.path.basename(copy_test_js))

        registerCSSFile(MyProduct, "test.css", rel_path="tests", set_expiry_header=True, slim_if_possible=True)
        static = getattr(instance, "test.css")
        self.assertEqual(str(static), css_slimmer(open(right_here("test.css")).read()))

        # this will have created a file called 'test.css-slimmed.css' whose content
        # is the same as str(static)
        copy_test_css = os.path.join(_get_autogenerated_dir(), "test.css-slimmed.css")
        self.assertTrue(os.path.isfile(copy_test_css))
        self.assertEqual(open(copy_test_css).read(), str(static))
        # and it that directory there should not be any other files other
        # than the one we made before called test.js-slimmed.js
        for f in os.listdir(os.path.dirname(copy_test_css)):
            self.assertTrue(f == os.path.basename(copy_test_js) or f == os.path.basename(copy_test_css))

        # if you don it again it should just overwrite the old one
        registerCSSFile(MyProduct, "test.css", rel_path="tests", set_expiry_header=True, slim_if_possible=True)

        static = getattr(instance, "test.css")
        # there should still only be two files in the autogenerated directory
        self.assertEqual(len(os.listdir(_get_autogenerated_dir())), 2)
开发者ID:peterbe,项目名称:FriedZopeBase,代码行数:46,代码来源:testZope.py


示例15: registerCSS

def registerCSS(filename, path='css', slim_if_possible=True):
    product = OFS.misc_.misc_.IssueTrackerMassContainer
    objectid = filename
    setattr(product,
            objectid, 
            BetterImageFile(os.path.join(path, filename), globals())
            )
    obj = getattr(product, objectid)
    if css_slimmer is not None and OPTIMIZE:
        if slim_if_possible:
            slimmed = css_slimmer(open(obj.path,'rb').read())
            new_path = obj.path + '-slimmed'
            open(new_path, 'wb').write(slimmed)
            setattr(obj, 'path', new_path)

            
            
开发者ID:BillTheBest,项目名称:IssueTrackerProduct,代码行数:14,代码来源:__init__.py


示例16: render

 def render(self, context):
     code = self.nodelist.render(context)
     if slimmer is None:
         return code
     
     if self.format not in ('css','js','html','xhtml'):
         self.format = guessSyntax(code)
         
     if self.format == 'css':
         return css_slimmer(code)
     elif self.format in ('js', 'javascript'):
         return js_slimmer(code)
     elif self.format == 'xhtml':
         return xhtml_slimmer(code)
     elif self.format == 'html':
         return html_slimmer(code)
         
     return code
开发者ID:xster,项目名称:openparliament,代码行数:18,代码来源:django_static.py


示例17: render

    def render(self, context):
        code = self.nodelist.render(context)
        if slimmer is None:
            return code

        if self.format not in ('css','js','html','xhtml'):
            self.format = slimmer.guessSyntax(code)

        if self.format == 'css':
            return slimmer.css_slimmer(code)
        elif self.format in ('js', 'javascript'):
            return slimmer.js_slimmer(code)
        elif self.format == 'xhtml':
            return slimmer.xhtml_slimmer(code)
        elif self.format == 'html':
            return slimmer.html_slimmer(code)
        else:
            raise TemplateSyntaxError("Unrecognized format for slimming content")

        return code
开发者ID:bclermont,项目名称:django-static,代码行数:20,代码来源:django_static.py


示例18: render

    def render(self, context):
        code = self.nodelist.render(context)
        if slimmer is None:
            return code

        if self.format not in ("css", "js", "html", "xhtml"):
            self.format = slimmer.guessSyntax(code)

        if self.format == "css":
            return slimmer.css_slimmer(code)
        elif self.format in ("js", "javascript"):
            return slimmer.js_slimmer(code)
        elif self.format == "xhtml":
            return slimmer.xhtml_slimmer(code)
        elif self.format == "html":
            return slimmer.html_slimmer(code)
        else:
            raise TemplateSyntaxError("Unrecognized format for slimming content")

        return code
开发者ID:Akamad007,项目名称:django-static,代码行数:20,代码来源:django_static.py


示例19: compress

    def compress(self, css):
        lint = self.lintian(css)
        if lint.validate(ignore_hacks=True):
            return css_slimmer(css)

        return css
开发者ID:heynemann,项目名称:django-media-lint,代码行数:6,代码来源:compressor.py


示例20: test_registering_with_slimming_and_gzip

    def test_registering_with_slimming_and_gzip(self):
        try:
            from slimmer import js_slimmer, css_slimmer
        except ImportError:
            # not possible to test this
            return

        class MyProduct:
            pass

        instance = MyProduct()

        registerJSFile(
            MyProduct, "test.js", rel_path="tests", set_expiry_header=True, slim_if_possible=True, gzip_if_possible=True
        )

        static = getattr(instance, "test.js")
        # Note, using str(static) means it does not send the Accept-Encoding: gzip
        # header.
        self.assertEqual(str(static), js_slimmer(open(right_here("test.js")).read()))

        # this will have created a file called 'test.js-slimmed.js' whose content
        # is the same as str(static)
        copy_test_js = os.path.join(_get_autogenerated_dir(), "test.js-slimmed.js")
        self.assertTrue(os.path.isfile(copy_test_js))
        self.assertEqual(open(copy_test_js).read(), str(static))
        # it would also have generated another copy called
        # test.js-slimmed.js.gz
        copy_test_js_gz = os.path.join(_get_autogenerated_dir(), "test.js-slimmed.js.gz")
        self.assertTrue(os.path.isfile(copy_test_js_gz))

        self.assertEqual(gzip.open(copy_test_js_gz).read(), str(static))

        registerCSSFile(
            MyProduct,
            "test.css",
            rel_path="tests",
            set_expiry_header=True,
            slim_if_possible=True,
            gzip_if_possible=True,
        )
        static = getattr(instance, "test.css")
        self.assertEqual(str(static), css_slimmer(open(right_here("test.css")).read()))

        # this will have created a file called 'test.css-slimmed.css' whose content
        # is the same as str(static)
        copy_test_css = os.path.join(_get_autogenerated_dir(), "test.css-slimmed.css")
        self.assertTrue(os.path.isfile(copy_test_css))
        self.assertEqual(open(copy_test_css).read(), str(static))
        # it would also have generated another copy called
        # test.css-slimmed.css.gz
        copy_test_css_gz = os.path.join(_get_autogenerated_dir(), "test.css-slimmed.css.gz")
        self.assertTrue(os.path.isfile(copy_test_css_gz))

        self.assertEqual(gzip.open(copy_test_css_gz).read(), str(static))

        # if you don it AGAIN it should just overwrite the old one
        registerCSSFile(
            MyProduct,
            "test.css",
            rel_path="tests",
            set_expiry_header=True,
            slim_if_possible=True,
            gzip_if_possible=True,
        )

        static = getattr(instance, "test.css")
        self.assertEqual(str(static), css_slimmer(open(right_here("test.css")).read()))
开发者ID:peterbe,项目名称:FriedZopeBase,代码行数:68,代码来源:testZope.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python slimmer.js_slimmer函数代码示例发布时间:2022-05-27
下一篇:
Python parser.Parser类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap