本文整理汇总了Python中tdi.html.from_string函数的典型用法代码示例。如果您正苦于以下问题:Python from_string函数的具体用法?Python from_string怎么用?Python from_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了from_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: element
# BEGIN INCLUDE
from tdi import html
from tdi.tools.html import decode
# This is some typcial flash embedding code.
# It serves as a "layout widget", placed via overlay
flash = html.from_string("""
<!-- <tdi> is used as neutral dummy element (removed due to the - flag) -->
<tdi tdi:scope="-flash" tdi:overlay="<-flash">
<object tdi="object_ie"
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width=""
height="">
<param tdi="url" name="movie" value="" />
<param tdi="param" />
<![if !IE]><object tdi="object_other"
type="application/x-shockwave-flash" data="" width="" height="">
<param tdi="param" />
<![endif]>
<p tdi="alternative">You need to enable <a
href="http://www.adobe.com/go/getflashplayer">Flash</a> to view this
content.</p>
<![if !IE]></object><![endif]></object>
</tdi>
""")
# page template, using the flash layout widget, passing parameters
template = html.from_string("""
<html>
<body>
<h1>some flash</h1>
<tdi tdi:scope="-flash.param" tdi="-init"
示例2: Model
#!/usr/bin/env python
import warnings as _warnings
_warnings.resetwarnings()
_warnings.filterwarnings('error')
from tdi.model_adapters import RenderAdapter
from tdi import html
template = html.from_string("""
<anode tdi="level1">
<node tdi="-*nested">
<xnode tdi="a"></xnode>
</node>
<ynode tdi="-*:nested">lalala</ynode>
</anode>
""".lstrip())
class Model(object):
def render_a(self, node):
node.content = u'hey'
model = Model()
template.render(model, adapter=RenderAdapter.for_prerender)
示例3: Model
#!/usr/bin/env python
import warnings as _warnings
_warnings.resetwarnings()
_warnings.filterwarnings('error')
import re as _re
from tdi import html
from tdi.tools import javascript
tpl = html.from_string("""
<a tdi="link" onclick="alert('__what__'); return false">Click me</a>
""".lstrip())
json = javascript.LiteralJSON(u'{"name": "Andr\xe9]]>"}')
class Model(object):
def render_link(self, node):
javascript.fill_attr(node, u'onclick', dict(
what = u'Andr\xe9',
))
tpl.render(Model())
tpl = html.from_string("""
<a tdi="link" onclick="alert('__what__'); return false">Click me</a>
""".lstrip())
json = javascript.LiteralJSON(u'{"name": "Andr\xe9]]>"}')
class Model(object):
def render_link(self, node):
javascript.fill_attr(node, u'onclick', dict(
what = json,
))
tpl.render(Model())
示例4: Model
#!/usr/bin/env python
import warnings as _warnings
_warnings.resetwarnings()
_warnings.filterwarnings('error')
from tdi.model_adapters import RenderAdapter
from tdi import html
template = html.from_string("""
<anode tdi="level1" tdi:prerender="remove-node">
<node tdi="-nested">
<xnode tdi="a">
<znode tdi="b">foo</znode>
</xnode>
</node>
<ynode tdi="-:nested">lalala</ynode>
</anode>
""".lstrip())
class Model(object):
def render_a(self, node):
node.b.content = u'hey'
node.b.hiddenelement = True
node.b['tdi:prerender'] = u'remove-node'
model = Model()
template.render(model, adapter=RenderAdapter.for_prerender)
示例5: Model
#!/usr/bin/env python
import warnings as _warnings
_warnings.resetwarnings()
_warnings.filterwarnings('error')
from tdi import html
template = html.from_string("""
<node tdi="item">
<node tdi="nested">
<node tdi="subnested"></node>
</node>
<xnode tdi="a"></xnode>
</node>
""".lstrip())
class Model(object):
def render_item(self, node):
node.nested.replace(self.replace_nested, node.a)
return True
def replace_nested(self, node):
node['been'] = u'here'
node.content = u'yes'
def render_a(self, node):
node.content = u"should not be here"
model = Model()
template.render(model)
示例6: Model
#!/usr/bin/env python
import warnings as _warnings
_warnings.resetwarnings()
_warnings.filterwarnings('error')
from tdi import html
template = html.from_string("""
<node tdi="item">
<node tdi="nested">
<node tdi="subnested"></node>
</node><tdi tdi=":-nested">
</tdi>
</node>
""".lstrip())
class Model(object):
def render_item(self, node):
for subnode, item in node.nested.iterate([1, 2, 3, 4]):
subnode['j'] = item
subnode.content = u'should be here %s' % item
if item == 3:
break
model = Model()
template.render(model)
示例7: Model
#!/usr/bin/env python
import warnings as _warnings
_warnings.resetwarnings()
_warnings.filterwarnings('error')
from tdi import html
from tdi.model_adapters import PreRenderWrapper, RenderAdapter
template = html.from_string("""
<foo>
<bar tdi:overlay=">-foo"/>
</foo>
""".lstrip()).overlay(html.from_string("""
<tdi tdi:overlay="-foo">
<script tdi="test">JAVASCRIPT</script>
</tdi>
""".lstrip()))
class Model(object):
def render_test(self, node):
node.raw.content = node.raw.content.replace('SCR', ' hey ')
def adapter(model):
return PreRenderWrapper(RenderAdapter(model))
model = Model()
html.from_string(template.render_string(None, adapter=adapter)).render(
model, startnode="test"
)
print
示例8:
""" HTML minifier factory """
return html_tools.MinifyFilter(builder, comment_filter=keep_foo)
# 3. Template Factory
html = html.replace(eventfilters=[
# ...
html_minifyfilter, # instead of html_tools.MinifyFilter
# ...
])
# 4. Do your thing.
tpl = html.from_string("""
<html>
<head>
<!-- Here comes the title -->
<title>Hello World!</title>
<style>
Some style.
</style>
</head>
<body>
<!-- foo -->
<script>
Some script.
</script>
<h1>Hello World!</h1>
<!-- bar -->
</body>
""".lstrip())
tpl.render()
示例9: FooModel
#!/usr/bin/env python
import warnings as _warnings
_warnings.resetwarnings()
_warnings.filterwarnings('error')
from tdi import html
template = html.from_string("""
<node>
<xnode tdi="zonk" tdi:scope="foo"></xnode>
</node>
""".lstrip())
class FooModel(object):
def render_zonk(self, node):
node.content = u"Yay."
class Model(object):
def __init__(self):
self.scope_foo = FooModel()
model = Model()
template.render(model)
示例10: Model
#!/usr/bin/env python
import warnings as _warnings
_warnings.resetwarnings()
_warnings.filterwarnings('error')
# BEGIN INCLUDE
from tdi import html
from tdi.tools import htmlform
template = html.from_string("""
<html>
<body>
<p>Type your name:</p>
<form tdi="form">
<div tdi="-name">
<p tdi="*error" class="error">Error message</p>
<input tdi="*field" id="name" type="text" />
</div>
<input tdi="submit" type="submit" />
</form>
</body>
</html>
""")
class Model(object):
def __init__(self, errors=None):
self._errors = errors or {}
self._form = htmlform.HTMLForm(
pre_proc=self.preproc,
post_proc=htmlform.TabIndexer(),
)
示例11: Model
import warnings as _warnings
_warnings.resetwarnings()
_warnings.filterwarnings("error")
from tdi import html
template = html.from_string(
"""
<node tdi="item">
<znode tdi="nested" tdi:overlay="foo">
<ynode tdi="subnested"></ynode>
</znode>
<xnode tdi="a"></xnode>
</node>
""".lstrip()
).overlay(
html.from_string(
"""
<anode tdi="grumpf" tdi:overlay="-foo">
<bnode tdi="gna"></bnode>
</anode>
""".lstrip()
)
)
class Model(object):
def render_nested(self, node):
node["been"] = u"here"
def render_gna(self, node):
示例12:
#!/usr/bin/env python
import warnings as _warnings
_warnings.resetwarnings()
_warnings.filterwarnings('error')
from tdi.model_adapters import RenderAdapter
from tdi import html
template = html.from_string("""
<anode tdi="level1">
<node tdi="-nested" tdi:scope="foo.bar" tdi:overlay="ov">
<xnode tdi="a" tdi:scope="baz"></xnode>
</node>
<ynode tdi="-:nested">lalala</ynode>
</anode>
""".lstrip()).overlay(html.from_string("""
<znode tdi:scope="zonk">
<widget tdi:overlay="ov">widget!</widget>
</znode>
""".lstrip()))
template.render(None, adapter=RenderAdapter.for_prerender)
示例13: Model
#!/usr/bin/env python
import warnings as _warnings
_warnings.resetwarnings()
_warnings.filterwarnings('error')
from tdi import html
template = html.from_string("""
<anode tdi="level1">
<node tdi="*level2">
<node tdi="level3">
hey.
</node>
</node>
</anode>
""".lstrip())
class Model(object):
def render_level2(self, node):
node['foo'] = 'bar'
def render_level3(self, node):
node.content = 'sup.'
model = Model()
template.render(model)
示例14:
#!/usr/bin/env python
import warnings as _warnings
_warnings.resetwarnings()
_warnings.filterwarnings('error')
from tdi import html
from tdi.tools import javascript
html = html.replace(eventfilters=[javascript.CDATAFilter])
tpl = html.from_string("""
<html>
<script src="foo"></script>
<script><!--
//--></script>
<script><!--
var x=1;
var y = 2;
alert( x + y );
//--></script>
<script tdi="bar"><!--
--></script>
</html>
""".lstrip())
tpl.render()
示例15: list
#!/usr/bin/env python
import warnings as _warnings
_warnings.resetwarnings()
_warnings.filterwarnings('error')
from tdi import html
template = html.from_string("""
<node tdi="item">
<znode tdi:overlay="foo">
<ynode tdi:overlay="bar"></ynode>
<ynode tdi:overlay="<zonk"></ynode>
<ynode tdi:overlay=">plenk"></ynode>
</znode>
<xnode tdi:overlay=">baz"></xnode>
</node>
""".lstrip())
print list(sorted(template.source_overlay_names))
print list(sorted(template.target_overlay_names))