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


Python filter.get_filter函数代码示例

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


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

示例1: test_cssrewrite_change_folder

 def test_cssrewrite_change_folder(self):
     """Test the replace mode of the cssrewrite filter.
     """
     self.create_files({"in.css": """h1 { background: url(old/sub/icon.png) }"""})
     try:
         from collections import OrderedDict
     except ImportError:
         # Without OrderedDict available, use a simplified version
         # of this test.
         cssrewrite = get_filter(
             "cssrewrite",
             replace=dict((("o", "/error/"), ("old", "/new/"))),  # o does NOT match the old/ dir  # this will match
         )
     else:
         cssrewrite = get_filter(
             "cssrewrite",
             replace=OrderedDict(
                 (
                     ("o", "/error/"),  # o does NOT match the old/ dir
                     ("old", "/new/"),  # this will match
                     ("old/sub", "/error/"),  # the first match is used, so this won't be
                     ("new", "/error/"),  # neither will this one match
                 )
             ),
         )
     self.mkbundle("in.css", filters=cssrewrite, output="out.css").build()
     assert self.get("out.css") == """h1 { background: url(/new/sub/icon.png) }"""
开发者ID:statico,项目名称:webassets,代码行数:27,代码来源:test_filters.py

示例2: test_get_filter

def test_get_filter():
    """Test filter resolving.
    """
    # By name - here using one of the builtins.
    assert isinstance(get_filter('jsmin'), Filter)
    assert_raises(ValueError, get_filter, 'notafilteractually')

    # By class.
    class MyFilter(Filter): pass
    assert isinstance(get_filter(MyFilter), MyFilter)
    assert_raises(ValueError, get_filter, object())

    # Passing an instance doesn't do anything.
    f = MyFilter()
    assert id(get_filter(f)) == id(f)

    # Passing a lone callable will give us a a filter back as well.
    assert hasattr(get_filter(lambda: None), 'output')

    # Arguments passed to get_filter are used for instance creation.
    assert get_filter('sass', scss=True).use_scss == True
    # However, this is not allowed when a filter instance is passed directly,
    # or a callable object.
    assert_raises(AssertionError, get_filter, f, 'test')
    assert_raises(AssertionError, get_filter, lambda: None, 'test')
开发者ID:cnu,项目名称:webassets,代码行数:25,代码来源:test_filters.py

示例3: test_debug_info_option

    def test_debug_info_option(self):
        # The debug_info argument to the sass filter can be configured via
        # a global SASS_DEBUG_INFO option.
        self.m.config['SASS_DEBUG_INFO'] = False
        self.mkbundle('foo.sass', filters=get_filter('sass'), output='out.css').build()
        assert not '-sass-debug-info' in self.get('out.css')

        # However, an instance-specific debug_info option takes precedence.
        self.mkbundle('foo.sass', filters=get_filter('sass', debug_info=True), output='out2.css').build()
        assert '-sass-debug-info' in self.get('out2.css')
开发者ID:arturosevilla,项目名称:webassets,代码行数:10,代码来源:test_filters.py

示例4: test_sass_import

 def test_sass_import(self):
     """Test referencing other files in sass.
     """
     sass = get_filter('sass', debug_info=False)
     self.create_files({'import-test.sass': '''@import foo.sass'''})
     self.mkbundle('import-test.sass', filters=sass, output='out.css').build()
     assert doctest_match("""/* line 1, ...foo.sass */\nh1 {\n  font-family: "Verdana";\n  color: white;\n}\n""", self.get('out.css'))
开发者ID:cnu,项目名称:webassets,代码行数:7,代码来源:test_filters.py

示例5: __init__

    def __init__(self, *args, **kwargs):
        ignore_filters = kwargs.pop('ignore_filters', False) or False
        kwargs['debug'] = False

        try:
            filters = list(kwargs.pop('filters'))
        except KeyError:
            filters = []

        try:
            vars = kwargs.pop('vars')
        except KeyError:
            vars = {}

        fltr = get_filter('vars', vars=vars)

        if not ignore_filters:
            filters.extend([fltr])
        else:
            filters = fltr

        kwargs.update({
            'filters': filters
        })

        Bundle.__init__(self, *args, **kwargs)
开发者ID:joymax,项目名称:kharkivpy3_javascript_and_python_backend,代码行数:26,代码来源:vars.py

示例6: test_register_filter

def test_register_filter():
    """Test registration of custom filters.
    """
    # Needs to be a ``Filter`` subclass.
    assert_raises(ValueError, register_filter, object)

    # A name is required.
    class MyFilter(Filter):
        name = None

        def output(self, *a, **kw):
            pass

    assert_raises(ValueError, register_filter, MyFilter)

    # We should be able to register a filter with a name.
    MyFilter.name = "foo"
    register_filter(MyFilter)

    # A filter should be able to override a pre-registered filter of the same
    # name.
    class OverrideMyFilter(Filter):
        name = "foo"

        def output(self, *a, **kw):
            pass

    register_filter(OverrideMyFilter)
    assert_true(isinstance(get_filter("foo"), OverrideMyFilter))
开发者ID:rawberg,项目名称:webassets,代码行数:29,代码来源:test_filters.py

示例7: test_clevercss

 def test_clevercss(self):
     try:
         import clevercss
     except ImportError: 
         raise SkipTest()
     clevercss = get_filter('clevercss')
     self.mkbundle('foo.clevercss', filters=clevercss, output='out.css').build()
     assert self.get('out.css') == """a {
开发者ID:lyschoening,项目名称:webassets,代码行数:8,代码来源:test_filters.py

示例8: test_custom_include_path

 def test_custom_include_path(self):
     """Test a custom include_path.
     """
     sass_output = get_filter("sass", debug_info=False, as_output=True, includes_dir=self.path("includes"))
     self.create_files(
         {"includes/vars.sass": "$a_color: #FFFFFF", "base.sass": "@import vars.sass\nh1\n  color: $a_color"}
     )
     self.mkbundle("base.sass", filters=sass_output, output="out.css").build()
     assert self.get("out.css") == """/* line 2 */\nh1 {\n  color: white;\n}\n"""
开发者ID:ghk,项目名称:webassets,代码行数:9,代码来源:test_filters.py

示例9: test_as_output_filter

 def test_as_output_filter(self):
     """The sass filter can be configured to work as on output filter,
     first merging the sources together, then applying sass.
     """
     # To test this, split a sass rules into two files.
     sass_output = get_filter('sass', debug_info=False, as_output=True)
     self.create_files({'p1': 'h1', 'p2': '\n  color: #FFFFFF'})
     self.mkbundle('p1', 'p2', filters=sass_output, output='out.css').build()
     assert self.get('out.css') == """/* line 1 */\nh1 {\n  color: white;\n}\n"""
开发者ID:cnu,项目名称:webassets,代码行数:9,代码来源:test_filters.py

示例10: test_sass_import

 def test_sass_import(self):
     """Test referencing other files in sass.
     """
     sass = get_filter("sass", debug_info=False)
     self.create_files({"import-test.sass": """@import foo.sass"""})
     self.mkbundle("import-test.sass", filters=sass, output="out.css").build()
     assert (
         self.get("out.css") == """/* line 1, ./foo.sass */\nh1 {\n  font-family: "Verdana";\n  color: white;\n}\n"""
     )
开发者ID:statico,项目名称:webassets,代码行数:9,代码来源:test_filters.py

示例11: test_custom_include_path

 def test_custom_include_path(self):
     """Test a custom include_path.
     """
     sass_output = get_filter('sass', debug_info=False, as_output=True,
                              includes_dir=self.path('includes'))
     self.create_files({
         'includes/vars.sass': '$a_color: #FFFFFF',
         'base.sass': '@import vars.sass\nh1\n  color: $a_color'})
     self.mkbundle('base.sass', filters=sass_output, output='out.css').build()
     assert self.get('out.css') == """/* line 2 */\nh1 {\n  color: white;\n}\n"""
开发者ID:cnu,项目名称:webassets,代码行数:10,代码来源:test_filters.py

示例12: test_replace_with_cache

    def test_replace_with_cache(self):
        """[Regression] Test replace mode while cache is active.

        This used to fail due to an unhashable key being returned by
        the filter."""
        cssrewrite = get_filter("cssrewrite", replace={"old": "new"})
        self.env.cache = True
        self.create_files({"in.css": """h1 { background: url(old/sub/icon.png) }"""})
        # Does not raise an exception.
        self.mkbundle("in.css", filters=cssrewrite, output="out.css").build()
开发者ID:ghk,项目名称:webassets,代码行数:10,代码来源:test_filters.py

示例13: test_replace_with_cache

    def test_replace_with_cache(self):
        """[Regression] Test replace mode while cache is active.

        This used to fail due to an unhashable key being returned by
        the filter."""
        cssrewrite = get_filter('cssrewrite', replace={'old': 'new'})
        self.env.cache = True
        self.create_files({'in.css': '''h1 { background: url(old/sub/icon.png) }'''})
        # Does not raise an exception.
        self.mkbundle('in.css', filters=cssrewrite, output='out.css').build()
开发者ID:kmike,项目名称:webassets,代码行数:10,代码来源:test_filters.py

示例14: test_coffeescript

    def test_coffeescript(self):
        coffeescript = get_filter("coffeescript")
        self.mkbundle("foo.coffee", filters=coffeescript, output="out.js").build()
        assert (
            self.get("out.js")
            == """if (typeof elvis != "undefined" && elvis !== null) {
  alert("I knew it!");
}
"""
        )
开发者ID:statico,项目名称:webassets,代码行数:10,代码来源:test_filters.py

示例15: __init__

    def __init__(self, flask_app):
        self.app = flask_app
        self.styles_path = os.path.join(self.app.config['ASSETS_PATH'], 'styles')
        self.scripts_path = os.path.join(self.app.config['ASSETS_PATH'], 'scripts')

        # add filters
        self.pyscss = get_filter('pyscss')
        self.pyscss.load_paths = [self.styles_path]

        self.css_filters = (self.pyscss, 'cssmin')
        self.js_filters = (Pipeline.pycoffee, 'jsmin')
开发者ID:TheNixNinja,项目名称:rsvp-python,代码行数:11,代码来源:pipeline.py


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