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


Python renderer.Renderer类代码示例

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


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

示例1: test

    def test(self):
        template = testData['template']
        partials = testData.has_key('partials') and testData['partials'] or {}
        expected = testData['expected']
        data     = testData['data']

        # Convert code strings to functions.
        # TODO: make this section of code easier to understand.
        new_data = {}
        for key, val in data.iteritems():
            if isinstance(val, dict) and val.get('__tag__') == 'code':
                val = eval(val['python'])
            new_data[key] = val

        renderer = Renderer(partials=partials)
        actual = renderer.render(template, new_data)
        actual = actual.encode('utf-8')

        message = """%s

  Template: \"""%s\"""

  Expected: %s
  Actual:   %s

  Expected: \"""%s\"""
  Actual:   \"""%s\"""
  """ % (description, template, repr(expected), repr(actual), expected, actual)

        self.assertEquals(actual, expected, message)
开发者ID:chuanzhang,项目名称:pystache,代码行数:30,代码来源:test_spec.py

示例2: render

def render(template, context=None, **kwargs):
    """
    Return the given template string rendered using the given context.

    """
    renderer = Renderer()
    return renderer.render(template, context, **kwargs)
开发者ID:SvetlanaM,项目名称:EnabledCityPaloAlto,代码行数:7,代码来源:init.py

示例3: test_read__decode_errors

    def test_read__decode_errors(self):
        filename = 'nonascii.mustache'
        renderer = Renderer()

        self.assertRaises(UnicodeDecodeError, self._read, renderer, filename)
        renderer.decode_errors = 'ignore'
        actual = self._read(renderer, filename)
        self.assertEquals(actual, 'non-ascii: ')
开发者ID:jakearchibald,项目名称:pystache,代码行数:8,代码来源:test_renderer.py

示例4: render

def render(template, context=None, name=None, **kwargs):
    """
    Return the given template string rendered using the given context.

    """
    renderer = Renderer()
    parsed_template = parse(template, name=name)
    return renderer.render(parsed_template, context, **kwargs)
开发者ID:GaloisInc,项目名称:echronos,代码行数:8,代码来源:init.py

示例5: _engine

    def _engine(self):
        """
        Create and return a default RenderEngine for testing.

        """
        renderer = Renderer(string_encoding='utf-8', missing_tags='strict')
        engine = renderer._make_render_engine()

        return engine
开发者ID:SvetlanaM,项目名称:EnabledCityPaloAlto,代码行数:9,代码来源:test_renderengine.py

示例6: crear_plantilla

def crear_plantilla(archivo_fuente='user.c'):
    print "creando plantilla para archivo %s" % archivo_fuente
    renderer = Renderer()
    template = renderer.load_template(SOURCE_TEMPLATE)
    dato_plantilla = renderer.render(template, {'include_path': archivo_fuente})
    archivo = open(SOURCE_FILE, 'w')
    archivo.write(dato_plantilla)
    archivo.close()
    print "plantilla creada"
开发者ID:fitoria,项目名称:icaro-cli,代码行数:9,代码来源:__init__.py

示例7: test_read__file_encoding

    def test_read__file_encoding(self):
        filename = 'nonascii.mustache'

        renderer = Renderer()
        renderer.file_encoding = 'ascii'

        self.assertRaises(UnicodeDecodeError, self._read, renderer, filename)
        renderer.file_encoding = 'utf-8'
        actual = self._read(renderer, filename)
        self.assertEquals(actual, u'non-ascii: é')
开发者ID:jakearchibald,项目名称:pystache,代码行数:10,代码来源:test_renderer.py

示例8: test_make_locator__file_extension

    def test_make_locator__file_extension(self):
        """
        Test that make_locator() respects the file_extension attribute.

        """
        renderer = Renderer()
        renderer.file_extension = 'foo'

        locator = renderer.make_locator()

        self.assertEquals(locator.template_extension, 'foo')
开发者ID:jakearchibald,项目名称:pystache,代码行数:11,代码来源:test_renderer.py

示例9: get

 def get(self):
     pass_phrase = self.authenticate_request()
     if pass_phrase:
         if self.check_setup():
             loader = Loader(extension='html', search_dirs=['view', 'view/setup'])
             renderer = Renderer(file_extension='html',
                 search_dirs=['view/partials', 'view/setup'])
             template = loader.load_name('setup')
             html = renderer.render(template, {"pass": pass_phrase})
             self.write(html)
         else:
             self.write("setup already completed.")
开发者ID:Web5design,项目名称:autopilot,代码行数:12,代码来源:setup.py

示例10: test__escape__uses_renderer_unicode

    def test__escape__uses_renderer_unicode(self):
        """
        Test that escape uses the renderer's unicode function.

        """
        renderer = Renderer()
        renderer.unicode = lambda s: s.upper()

        engine = renderer._make_render_engine()
        escape = engine.escape

        self.assertEquals(escape("foo"), "FOO")
开发者ID:jakearchibald,项目名称:pystache,代码行数:12,代码来源:test_renderer.py

示例11: test__escape__uses_renderer_escape

    def test__escape__uses_renderer_escape(self):
        """
        Test that escape uses the renderer's escape function.

        """
        renderer = Renderer()
        renderer.escape = lambda s: "**" + s

        engine = renderer._make_render_engine()
        escape = engine.escape

        self.assertEquals(escape("foo"), "**foo")
开发者ID:jakearchibald,项目名称:pystache,代码行数:12,代码来源:test_renderer.py

示例12: test__literal__handles_unicode

    def test__literal__handles_unicode(self):
        """
        Test that literal doesn't try to "double decode" unicode.

        """
        renderer = Renderer()
        renderer.default_encoding = 'ascii'

        engine = renderer._make_render_engine()
        literal = engine.literal

        self.assertEquals(literal(u"foo"), "foo")
开发者ID:jakearchibald,项目名称:pystache,代码行数:12,代码来源:test_renderer.py

示例13: test__literal__uses_renderer_unicode

    def test__literal__uses_renderer_unicode(self):
        """
        Test that literal uses the renderer's unicode function.

        """
        renderer = Renderer()
        renderer.unicode = lambda s: s.upper()

        engine = renderer._make_render_engine()
        literal = engine.literal

        self.assertEquals(literal("foo"), "FOO")
开发者ID:jakearchibald,项目名称:pystache,代码行数:12,代码来源:test_renderer.py

示例14: test_make_load_partial

    def test_make_load_partial(self):
        """
        Test the _make_load_partial() method.

        """
        renderer = Renderer()
        renderer.partials = {'foo': 'bar'}
        load_partial = renderer._make_load_partial()

        actual = load_partial('foo')
        self.assertEquals(actual, 'bar')
        self.assertEquals(type(actual), unicode, "RenderEngine requires that "
            "load_partial return unicode strings.")
开发者ID:jakearchibald,项目名称:pystache,代码行数:13,代码来源:test_renderer.py

示例15: test_unicode__default_encoding

    def test_unicode__default_encoding(self):
        """
        Test that the default_encoding attribute is respected.

        """
        renderer = Renderer()
        s = "é"

        renderer.default_encoding = "ascii"
        self.assertRaises(UnicodeDecodeError, renderer.unicode, s)

        renderer.default_encoding = "utf-8"
        self.assertEquals(renderer.unicode(s), u"é")
开发者ID:jakearchibald,项目名称:pystache,代码行数:13,代码来源:test_renderer.py


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