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


Python breve.Template类代码示例

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


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

示例1: test_custom_renderer

    def test_custom_renderer ( self ):
        '''custom renderer'''

        def render_row ( tag, data ):
            T = html
            tag.clear ( )
            return tag [
                [ T.td [ _i ] for _i in data ]
            ]
        register_global ( 'render_row', render_row )

        vars = dict ( 
            title = my_name ( ),
            my_data = [
                range ( 5 ),
                range ( 5, 10 ),
                range ( 10, 15 )
            ]
        )
        t = Template ( html, root = template_root ( ) )
        actual = t.render ( 'index', vars, namespace = 'v' )
        expected = expected_output ( )
        try:
            self.assertEqual ( actual, expected )
        except AssertionError:
            diff ( actual, expected )
            raise
开发者ID:stuffonfire,项目名称:breve,代码行数:27,代码来源:templates.py

示例2: test_let_directive_scope

    def test_let_directive_scope ( self ):
        '''test let directive's scope'''
        
        vars = dict ( 
            message = 'hello, from breve',
            title = my_name ( ),
            do_fail = False
        )

        # don't fail - use variable in scope
        t = Template ( html, root = template_root ( ) )
        actual = t.render ( 'index', vars, namespace = 'v' )
        expected = expected_output ( )
        try:
            self.assertEqual ( actual, expected )
        except AssertionError:
            diff ( actual, expected )
            raise

        # do fail - try to use the variable out of scope
        vars [ 'do_fail' ] = True
        t = Template ( html, root = template_root ( ) )
        self.failUnlessRaises (
            NameError,
            t.render, 'index', vars, namespace = 'v'
        )
开发者ID:stuffonfire,项目名称:breve,代码行数:26,代码来源:templates.py

示例3: render

 def render(value, system):
     value.update(system)
     fragment = value.pop('breve_fragment', self.fragment)
     template = Template(self.tags, xmlns=self.xmlns,
                         doctype=self.doctype)
     return template.render(info.name, vars=value, fragment=fragment,
                            loader=self.loader)
开发者ID:momyc,项目名称:pyramid-breve,代码行数:7,代码来源:renderer.py

示例4: test_encoding

def test_encoding():
    """encoding comments"""
    params = dict(
        title=my_name()
    )
    t = Template(html, root=template_root())
    expected = expected_output()
    actual = t.render('correct', params, namespace='v')
    assert actual == expected
开发者ID:katakumpo,项目名称:breve4py3,代码行数:9,代码来源:test_templates.py

示例5: test_nested_include

def test_nested_include():
    """nested include() directives"""
    params = dict(
        message='hello, from breve',
        title=my_name()
    )
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
开发者ID:katakumpo,项目名称:breve4py3,代码行数:10,代码来源:test_templates.py

示例6: test_loop_include

def test_loop_include():
    """looping over include() with listcomp"""
    params = dict(
        message='hello, from breve',
        title=my_name()
    )
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
开发者ID:katakumpo,项目名称:breve4py3,代码行数:10,代码来源:test_templates.py

示例7: test_simple_template

def test_simple_template():
    """simple template"""
    params = dict(
        message='hello, from breve',
        title=my_name()
    )
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
开发者ID:katakumpo,项目名称:breve4py3,代码行数:10,代码来源:test_templates.py

示例8: test_assign_scope

def test_assign_scope():
    """test assign directive's scope"""
    params = dict(
        message='hello, from breve',
        title=my_name()
    )
    # don't fail - use variable in scope
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
开发者ID:katakumpo,项目名称:breve4py3,代码行数:11,代码来源:test_templates.py

示例9: test_macros_inside_inherits

def test_macros_inside_inherits():
    """test macros inside inherits(): scope issues"""
    # note: I'm not convinced this is the desired behaviour, but
    # it's *compatible* behaviour.
    params = dict(
        title=my_name(),
        message='Hello, from breve'
    )
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
开发者ID:katakumpo,项目名称:breve4py3,代码行数:12,代码来源:test_templates.py

示例10: test_register_global

def test_register_global():
    """register_global() function"""
    params = dict(
        title=my_name()
    )
    register_global('global_message', 'This is a global variable')

    _test_name = my_name()
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
开发者ID:katakumpo,项目名称:breve4py3,代码行数:12,代码来源:test_templates.py

示例11: test_stacks_template

def test_stacks_template():
    """test stacks in template"""
    params = dict(
        title=my_name(),
        message='hello, from breve'
    )
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
    # stack should be empty when we finish
    assert not get_stacks()
开发者ID:katakumpo,项目名称:breve4py3,代码行数:12,代码来源:test_templates.py

示例12: render

def render(template_name, tmpl_params=None, loader=None, fragment=False):
    if tmpl_params is None:
        tmpl_params = {}

    g = pylons_globals()
    tmpl_params.update(g)

    try:
        opts = g['app_globals'].breve_opts
    except AttributeError:
        opts = {}

    t = Template(tags, **opts)
    return t.render(template_name, params=tmpl_params, loader=loader, fragment=fragment)
开发者ID:katakumpo,项目名称:breve4py3,代码行数:14,代码来源:pylons_adapter.py

示例13: test_loop_include

    def test_loop_include ( self ):
        '''looping over include() with listcomp'''

        vars = dict ( 
            message = 'hello, from breve',
            title = my_name ( )
        )
        t = Template ( html, root = template_root ( ) )
        actual = t.render ( 'index', vars, namespace = 'v' )
        expected = expected_output ( )
        try:
            self.assertEqual ( actual, expected )
        except AssertionError:
            diff ( actual, expected )
            raise
开发者ID:stuffonfire,项目名称:breve,代码行数:15,代码来源:templates.py

示例14: test_simple_template

    def test_simple_template ( self ):
        '''simple template'''

        vars = dict ( 
            message = 'hello, from breve',
            title = my_name ( )
        )
        t = Template ( html, root = template_root ( ) )
        actual = t.render ( 'index', vars, namespace = 'v' )
        expected = expected_output ( )
        try:
            self.assertEqual ( actual, expected )
        except AssertionError:
            diff ( actual, expected )
            raise
开发者ID:stuffonfire,项目名称:breve,代码行数:15,代码来源:templates.py

示例15: test_custom_renderer_notag

def test_custom_renderer_notag():
    """custom renderer returning non-Tag type"""
    def render_text(tag, data):
        tag.clear()
        return data
    register_global('render_text', render_text)

    params = dict(
        title=my_name(),
        message='hello, world'
    )
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
开发者ID:katakumpo,项目名称:breve4py3,代码行数:15,代码来源:test_templates.py


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