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

Python slimmer.js_slimmer函数代码示例

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

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



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

示例1: test_registerJSFiles__both_slimmed

    def test_registerJSFiles__both_slimmed(self):
        """ test the registerJSFiles() with slim_if_possible=True """
        if js_slimmer is None:
            return

        class MyProduct:
            pass

        # test setting a bunch of files
        files = ["large.js", "test.js"]
        files.append(tuple(files))
        registerJSFiles(
            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 = js_slimmer("\n".join(content_parts))
            else:
                expected_content = js_slimmer(open(right_here(filename)).read())
            self.assertEqual(rendered.strip(), expected_content.strip())
开发者ID:peterbe,项目名称:FriedZopeBase,代码行数:29,代码来源:testZope.py


示例2: test_registerJSFiles__one_slimmed

    def test_registerJSFiles__one_slimmed(self):
        """ test the registerJSFiles() 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.
        """

        class MyProduct:
            pass

        files = ["test.min.js", "test.js"]
        files.append(tuple(files))
        registerJSFiles(
            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
            if len(filename.split(",")) > 1:

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

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

            else:
                content = open(right_here(filename)).read()
                if filename.find("min") > -1 or js_slimmer is None:
                    expected_content = content
                else:
                    expected_content = js_slimmer(content)
                expected_content = expected_content.strip()

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


示例3: test_registerJSFiles__both_slimmed_and_gzipped

    def test_registerJSFiles__both_slimmed_and_gzipped(self):
        """ test the registerJSFiles() with slim_if_possible=True """
        if js_slimmer is None:
            return

        class MyProduct:
            pass

        # test setting a bunch of files
        files = ["large.js", "test.js"]
        files.append(tuple(files))
        registerJSFiles(
            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)
            # expect this to be slimmed
            if len(filename.split(",")) > 1:
                content_parts = [open(right_here(x)).read() for x in filename.split(",")]
                expected_content = js_slimmer("\n".join(content_parts))
            else:
                content = open(right_here(filename)).read()
                expected_content = js_slimmer(content)

            rendered = _gzip2ascii(bin_rendered)

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


示例4: 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


示例5: _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


示例6: 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


示例7: geniAnki

def geniAnki(self):
    if (web.ctx.environ['HTTP_USER_AGENT'].lower().find('iphone') < 0) and (web.ctx.environ['HTTP_USER_AGENT'].lower().find('ipod') < 0):
        iPhone = False
    else:
        iPhone = True

    # css
    f = open(iankiPath+'/static/base.css')
    css = f.read()
    f.close()
    if True: #iPhone
        f = open(iankiPath+'/static/iphone.css')
        css += f.read()
        f.close()

    if iPhone:
        f = open(iankiPath+'/static/anki-logo.png', 'rb')
        touchicon = '<link rel="apple-touch-icon" href="data:image/png;base64,%s"/>' % base64.b64encode(f.read())
        f.close()
        favicon = ""
        joose = ""
        orm = ""
    else:
        touchicon = ""
        # favicon
        f = open(iankiPath+'/static/favicon.ico', 'rb')
        favicon = '<link rel="shorcut icon" href="data:image/ico;base64,%s"/>' % base64.b64encode(f.read())
        f.close()
        f = open(iankiPath+'/static/joose.mini.js')
        joose = f.read()
        f.close()
        f = open(iankiPath+'/static/orm_async.js')
        orm = f.read()
        f.close()
    f = open(iankiPath+'/static/mootools-1.2.1-core.js')
    s1 = f.read()
    f.close()
    f = open(iankiPath+'/static/ianki.js')
    s2 = f.read()
    f.close()
    f = open(iankiPath+'/templates/ianki.html')
    iankiHTML = f.read()
    f.close()

    if makeSlim:
        s2 = slimmer.js_slimmer(s2)

    iankiHTML = iankiHTML % {'version':ui.__version__, 'favicon':favicon, 'touchicon':touchicon, 'css':css, 'joose':joose, 'orm':orm, 'mootools':s1, 'ianki':s2, 'location':web.input(loc='').loc}
        
    return iankiHTML
开发者ID:1ngmar,项目名称:ianki,代码行数:50,代码来源:__init__.py


示例8: registerJS

def registerJS(filename, path='js', 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 js_slimmer is not None and OPTIMIZE:
        if slim_if_possible:
            slimmed = js_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


示例9: 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


示例10: _registerJS

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


示例11: 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


示例12: 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


示例13: 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


示例14: 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


示例15: 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


示例16: 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


示例17: 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


示例18: evaluate

	def evaluate(self,scope, locals, block=None):
		if not hasattr(self,'output') or not self.output:
			from slimmer import js_slimmer
			self.output = js_slimmer(self.data)

		return self.output
开发者ID:OiNutter,项目名称:rivets,代码行数:6,代码来源:slimmer_compressors.py


示例19: open

import os,sys
import json
import datetime
import time
import calendar
import arrow
import os
#Y-m-d H:i:s ms tz 
#print datetime.timedelta(3600*8)

#print result
html=""
for line in open("test.html"):
    html+=line
#print html


import slimmer

html=slimmer.js_slimmer(html)
html=slimmer.html_slimmer(html)
print html



开发者ID:allenyang79,项目名称:python_exercise,代码行数:22,代码来源:ex06.py


示例20: output

 def output(self, _in, out, **kwargs):
     out.write(js_slimmer(_in.read()))
开发者ID:Hermy,项目名称:foofind-web,代码行数:2,代码来源:webassets_filters.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python envelope.Envelope类代码示例发布时间:2022-05-27
下一篇:
Python slimmer.css_slimmer函数代码示例发布时间: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