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


Python html.from_string函数代码示例

本文整理汇总了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"
开发者ID:AvdN,项目名称:tdi,代码行数:31,代码来源:scopes3.py

示例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)
开发者ID:AvdN,项目名称:tdi,代码行数:23,代码来源:prerender4.py

示例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())
开发者ID:AvdN,项目名称:tdi,代码行数:31,代码来源:js_fill_attr.py

示例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)
开发者ID:AvdN,项目名称:tdi,代码行数:27,代码来源:prerender3.py

示例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)
开发者ID:AvdN,项目名称:tdi,代码行数:30,代码来源:callback_done.py

示例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)
开发者ID:AvdN,项目名称:tdi,代码行数:26,代码来源:iterate_interrupted.py

示例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
开发者ID:AvdN,项目名称:tdi,代码行数:30,代码来源:finalize_content.py

示例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()
开发者ID:AvdN,项目名称:tdi,代码行数:30,代码来源:html_tools_minifyfilter_cfilter.py

示例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)
开发者ID:AvdN,项目名称:tdi,代码行数:26,代码来源:render_scope.py

示例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(),
        )
开发者ID:AvdN,项目名称:tdi,代码行数:30,代码来源:htmlform3.py

示例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):
开发者ID:ndparker,项目名称:tdi,代码行数:32,代码来源:overlay_hidden.py

示例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)
开发者ID:AvdN,项目名称:tdi,代码行数:22,代码来源:overlay_scope.py

示例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)
开发者ID:AvdN,项目名称:tdi,代码行数:26,代码来源:noauto.py

示例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()
开发者ID:AvdN,项目名称:tdi,代码行数:26,代码来源:js_filter_cdata.py

示例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))
开发者ID:AvdN,项目名称:tdi,代码行数:20,代码来源:overlay_names.py


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