當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。