本文整理汇总了Python中fanstatic.NeededResources.render方法的典型用法代码示例。如果您正苦于以下问题:Python NeededResources.render方法的具体用法?Python NeededResources.render怎么用?Python NeededResources.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fanstatic.NeededResources
的用法示例。
在下文中一共展示了NeededResources.render方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rendering_base_url
# 需要导入模块: from fanstatic import NeededResources [as 别名]
# 或者: from fanstatic.NeededResources import render [as 别名]
def test_rendering_base_url():
foo = Library('foo', '')
x1 = Resource(foo, 'a.js')
x2 = Resource(foo, 'b.css')
y1 = Resource(foo, 'c.js', depends=[x1, x2])
needed = NeededResources()
needed.need(y1)
assert needed.render() == '''\
<link rel="stylesheet" type="text/css" href="/fanstatic/foo/b.css" />
<script type="text/javascript" src="/fanstatic/foo/a.js"></script>
<script type="text/javascript" src="/fanstatic/foo/c.js"></script>'''
needed = NeededResources(base_url='http://localhost/static')
needed.need(y1)
assert needed.render() == '''\
<link rel="stylesheet" type="text/css" href="http://localhost/static/fanstatic/foo/b.css" />
<script type="text/javascript" src="http://localhost/static/fanstatic/foo/a.js"></script>
<script type="text/javascript" src="http://localhost/static/fanstatic/foo/c.js"></script>'''
# The base_url has been set.
assert needed.has_base_url()
needed.set_base_url('foo')
# The base_url can only be set once.
assert needed._base_url == 'http://localhost/static'
示例2: test_slot_depends_incorrect
# 需要导入模块: from fanstatic import NeededResources [as 别名]
# 或者: from fanstatic.NeededResources import render [as 别名]
def test_slot_depends_incorrect():
needed = NeededResources()
lib = Library('lib', '')
c = Resource(lib, 'c.js')
slot = Slot(lib, '.js', depends=[c])
a = Resource(lib, 'a.js', depends=[slot])
d = Resource(lib, 'd.js')
b = Resource(lib, 'b.js', depends=[d])
needed.need(a, {slot: b})
with pytest.raises(SlotError):
needed.render()
示例3: test_custom_renderer_for_resource
# 需要导入模块: from fanstatic import NeededResources [as 别名]
# 或者: from fanstatic.NeededResources import render [as 别名]
def test_custom_renderer_for_resource():
foo = Library('foo', '')
from fanstatic.core import render_print_css
a = Resource(foo, 'printstylesheet.css', renderer=render_print_css)
needed = NeededResources()
needed.need(a)
assert needed.render() == """\
<link rel="stylesheet" type="text/css" href="/fanstatic/foo/printstylesheet.css" media="print" />"""
def render_unknown(url):
return '<unknown href="%s"/>' % url
b = Resource(foo, 'nothing.unknown', renderer=render_unknown)
needed.need(b)
assert needed.render() == """\
示例4: test_empty_base_url_and_publisher_signature
# 需要导入模块: from fanstatic import NeededResources [as 别名]
# 或者: from fanstatic.NeededResources import render [as 别名]
def test_empty_base_url_and_publisher_signature():
''' When the base_url is not set and the publisher_signature is an empty string,
render a URL without them. '''
foo = Library('foo', '')
x1 = Resource(foo, 'a.js')
needed = NeededResources(publisher_signature='')
needed.need(x1)
assert needed.render() == '''\
示例5: test_render_bundle
# 需要导入模块: from fanstatic import NeededResources [as 别名]
# 或者: from fanstatic.NeededResources import render [as 别名]
def test_render_bundle():
foo = Library('foo', '')
x1 = Resource(foo, 'a.css')
x2 = Resource(foo, 'b.css')
x3 = Resource(foo, 'c.css', dont_bundle=True)
needed = NeededResources(resources=[x1, x2, x3])
assert needed.render() == '''<link rel="stylesheet" type="text/css" href="/fanstatic/foo/a.css" />
<link rel="stylesheet" type="text/css" href="/fanstatic/foo/b.css" />
<link rel="stylesheet" type="text/css" href="/fanstatic/foo/c.css" />'''
needed = NeededResources(resources=[x1, x2, x3], bundle=True)
assert needed.render() == '''<link rel="stylesheet" type="text/css" href="/fanstatic/foo/:bundle:a.css;b.css" />
<link rel="stylesheet" type="text/css" href="/fanstatic/foo/c.css" />'''
x4 = Resource(foo, 'subdir/subdir/x4.css')
x5 = Resource(foo, 'subdir/subdir/x5.css')
needed = NeededResources(resources=[x1, x2, x4, x5], bundle=True)
assert needed.render() == '''<link rel="stylesheet" type="text/css" href="/fanstatic/foo/:bundle:a.css;b.css" />
示例6: test_rendering_base_url_assign
# 需要导入模块: from fanstatic import NeededResources [as 别名]
# 或者: from fanstatic.NeededResources import render [as 别名]
def test_rendering_base_url_assign():
foo = Library('foo', '')
x1 = Resource(foo, 'a.js')
x2 = Resource(foo, 'b.css')
y1 = Resource(foo, 'c.js', depends=[x1, x2])
needed = NeededResources()
needed.need(y1)
needed.set_base_url('http://localhost/static')
assert needed.render() == '''\
示例7: test_rendering
# 需要导入模块: from fanstatic import NeededResources [as 别名]
# 或者: from fanstatic.NeededResources import render [as 别名]
def test_rendering():
foo = Library('foo', '')
x1 = Resource(foo, 'a.js')
x2 = Resource(foo, 'b.css')
y1 = Resource(foo, 'c.js', depends=[x1, x2])
needed = NeededResources()
needed.need(y1)
assert needed.render() == '''\
示例8: test_resource_subclass_render
# 需要导入模块: from fanstatic import NeededResources [as 别名]
# 或者: from fanstatic.NeededResources import render [as 别名]
def test_resource_subclass_render():
foo = Library('foo', '')
class MyResource(Resource):
def render(self, library_url):
return '<myresource reference="%s/%s"/>' % (library_url, self.relpath)
a = MyResource(foo, 'printstylesheet.css')
needed = NeededResources()
needed.need(a)
assert needed.render() == """\
示例9: test_slot_minified
# 需要导入模块: from fanstatic import NeededResources [as 别名]
# 或者: from fanstatic.NeededResources import render [as 别名]
def test_slot_minified():
needed = NeededResources(minified=True)
lib = Library('lib', '')
slot = Slot(lib, '.js')
a = Resource(lib, 'a.js', depends=[slot])
b = Resource(lib, 'b.js', minified='b-min.js')
needed.need(a, {slot: b})
assert needed.render() == '''\
示例10: test_render_filled_slots
# 需要导入模块: from fanstatic import NeededResources [as 别名]
# 或者: from fanstatic.NeededResources import render [as 别名]
def test_render_filled_slots():
needed = NeededResources()
lib = Library('lib', '')
slot = Slot(lib, '.js')
a = Resource(lib, 'a.js', depends=[slot])
b = Resource(lib, 'b.js')
needed.need(a, {slot: b})
assert needed.render() == '''\
示例11: test_slot_depends_subset
# 需要导入模块: from fanstatic import NeededResources [as 别名]
# 或者: from fanstatic.NeededResources import render [as 别名]
def test_slot_depends_subset():
needed = NeededResources()
lib = Library('lib', '')
c = Resource(lib, 'c.js')
slot = Slot(lib, '.js', depends=[c])
a = Resource(lib, 'a.js', depends=[slot])
b = Resource(lib, 'b.js', depends=[])
needed.need(a, {slot: b})
assert needed.render() == '''\
示例12: test_registered_inclusion_renderers_in_order
# 需要导入模块: from fanstatic import NeededResources [as 别名]
# 或者: from fanstatic.NeededResources import render [as 别名]
def test_registered_inclusion_renderers_in_order():
foo = Library('foo', '')
def render_unknown(url):
return '<unknown href="%s"/>' % url
register_inclusion_renderer('.later', render_unknown, 50)
a = Resource(foo, 'nothing.later')
b = Resource(foo, 'something.js')
c = Resource(foo, 'something.css')
d = Resource(foo, 'something.ico')
needed = NeededResources()
needed.need(a)
needed.need(b)
needed.need(c)
needed.need(d)
assert needed.render() == """\
<link rel="stylesheet" type="text/css" href="/fanstatic/foo/something.css" />
<script type="text/javascript" src="/fanstatic/foo/something.js"></script>
<link rel="shortcut icon" type="image/x-icon" href="/fanstatic/foo/something.ico"/>
<unknown href="/fanstatic/foo/nothing.later"/>"""
register_inclusion_renderer('.sooner', render_unknown, 5)
e = Resource(foo, 'nothing.sooner')
needed.need(e)
assert needed.render() == """\
<unknown href="/fanstatic/foo/nothing.sooner"/>
<link rel="stylesheet" type="text/css" href="/fanstatic/foo/something.css" />
<script type="text/javascript" src="/fanstatic/foo/something.js"></script>
<link rel="shortcut icon" type="image/x-icon" href="/fanstatic/foo/something.ico"/>
<unknown href="/fanstatic/foo/nothing.later"/>"""
register_inclusion_renderer('.between', render_unknown, 25)
f = Resource(foo, 'nothing.between')
needed.need(f)
assert needed.render() == """\
示例13: test_register_inclusion_renderer
# 需要导入模块: from fanstatic import NeededResources [as 别名]
# 或者: from fanstatic.NeededResources import render [as 别名]
def test_register_inclusion_renderer():
foo = Library('foo', '')
with pytest.raises(UnknownResourceExtensionError):
# The renderer for '.unknown' is not yet defined.
Resource(foo, 'nothing.unknown')
def render_unknown(url):
return '<link rel="unknown" href="%s" />' % url
register_inclusion_renderer('.unknown', render_unknown)
a = Resource(foo, 'nothing.unknown')
needed = NeededResources()
needed.need(a)
assert needed.render() == ('<link rel="unknown" href="/fanstatic/foo/nothing.unknown" />')
示例14: test_custom_renderer_keep_together
# 需要导入模块: from fanstatic import NeededResources [as 别名]
# 或者: from fanstatic.NeededResources import render [as 别名]
def test_custom_renderer_keep_together():
foo = Library('foo', '')
def render_print_css(url):
return ('<link rel="stylesheet" type="text/css" href="%s" media="print"/>' %
url)
a = Resource(foo, 'printstylesheet.css', renderer=render_print_css)
b = Resource(foo, 'regular.css')
c = Resource(foo, 'something.js')
needed = NeededResources()
needed.need(a)
needed.need(b)
needed.need(c)
assert needed.render() == """\