本文整理汇总了Python中webassets.filter.get_filter函数的典型用法代码示例。如果您正苦于以下问题:Python get_filter函数的具体用法?Python get_filter怎么用?Python get_filter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_filter函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: get_rules
def get_rules(kind):
if kind == '.css':
return Bunch(
final_filter = ["yui_css", get_filter('cssrewrite', replace=proxied)],
compilers = {".scss": "pyscss"},
kwargs = defaultdict(dict)
)
elif kind == '.js':
return Bunch(final_filter="yui_js", compilers={".coffee": "coffeescript", ".jst": "register_jst"},
kwargs=defaultdict(dict))
raise RuntimeError("unknown bundle kind: %s" % (kind,))
开发者ID:Rydgel,项目名称:flask-todo,代码行数:11,代码来源:assets.py
示例17: 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.env.config["SASS_DEBUG_INFO"] = False
self.mkbundle("foo.sass", filters=get_filter("sass"), output="out.css").build(force=True)
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="out.css").build(force=True)
assert "-sass-debug-info" in self.get("out.css")
# If the value is None (the default), then the filter will look
# at the debug setting to determine whether to include debug info.
self.env.config["SASS_DEBUG_INFO"] = None
self.env.debug = True
self.mkbundle("foo.sass", filters=get_filter("sass"), output="out.css", debug=False).build(force=True)
assert "-sass-debug-info" in self.get("out.css")
self.env.debug = False
self.mkbundle("foo.sass", filters=get_filter("sass"), output="out.css").build(force=True)
assert not "-sass-debug-info" in self.get("out.css")
开发者ID:ghk,项目名称:webassets,代码行数:20,代码来源:test_filters.py
示例18: test_template
def test_template(self):
self.create_files({
'media/foo.html': 'Ünicôdé-Chèck: {{ num|filesizeformat }}',
})
self.mkbundle(
'foo.html',
output="out",
filters=get_filter('template', context={'num': 23232323}),
).build()
# Depending on Django version "filesizeformat" may contain a breaking space
assert self.get('media/out') in ('Ünicôdé-Chèck: 22.2\xa0MB', 'Ünicôdé-Chèck: 22.2 MB')
开发者ID:Aaron7,项目名称:django-assets,代码行数:12,代码来源:test_django.py
示例19: input
def input(self, _in, out, **kwargs):
filepath = kwargs['source_path']
source = kwargs.get('source')
if not source:
# this happens when this filters is not used as a "source" filter, i.e _in
# is a webasset hunk instance
source = filepath
# output = kwargs['output']
base_dir = os.path.dirname(filepath)
rel_dir = os.path.dirname(source)
self.logger.debug('process "%s"', filepath)
for line in _in.readlines():
import_match = self._IMPORT_RE.search(line)
if import_match is None:
out.write(line)
continue
filename = import_match.group('filename')
abs_filename = os.path.abspath(os.path.join(base_dir, filename))
rel_filename= os.path.normpath(os.path.join(rel_dir, filename))
start, end = import_match.span()
if start > 0:
out.write(line[:start])
out.write('\n')
with open(abs_filename, 'r') as included:
# rewrite url() statements
buf = StringIO()
url_rewriter = get_filter('cssrewrite')
url_rewriter.set_context(self.ctx)
url_rewriter.setup()
url_rewriter.input(included, buf,
source=rel_filename,
source_path=abs_filename,
output=source,
output_path=filepath)
buf.seek(0)
# now process '@includes' directives in included file
self.input(buf, out,
source=rel_filename,
source_path=abs_filename,
output=source,
output_path=filepath)
if end < len(line):
out.write(line[end:])
else:
out.write('\n')
开发者ID:mmariani,项目名称:abilian-core,代码行数:52,代码来源:filters.py
示例20: test_change_folder
def test_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/'), # o does NOT match the old/ dir
('old', '/new/'), # 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:cnu,项目名称:webassets,代码行数:22,代码来源:test_filters.py
注:本文中的webassets.filter.get_filter函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论