def test_indent_placeholder(self): rendered = "".join( Template.load_and_render( "placeholder_indentation.pyml", context=dict(), search_path=os.path.join(os.path.dirname(__file__)) ) ) expected = '\n<a href="#top">back to top</a>\n<div class="foo" />' self.assertEqual(expected, rendered)
def test_pre_process(self): context = {} expected = '\n<html>\n <head>\n <title>Extending...</title>\n </head> \n <body>\n <div class="content">We are extending templates</div> \n <b>YAY</b> \n <div class="bar" />\n </body>\n</html>' rendered = "".join( Template.load_and_render( "childchildchild.pyml", context, search_path=os.path.join(os.path.dirname(__file__)) ) ) self.assertEqual(rendered, expected)
def test_include(self): context = {} expected = '\n<html>\n <head>\n <link rel="stylesheet" type="text/css" href="/static/base.css" /> \n <title>This is the title</title>\n </head> \n <body>\n <div class="content" /> \n <a href="#top">back to top</a>\n </body>\n</html>' rendered = "".join( Template.load_and_render( "extended_include.pyml", context, search_path=os.path.join(os.path.dirname(__file__)) ) ) self.assertEqual(rendered, expected)
def test_load(self): class Greeting(object): pass greeting = Greeting() greeting.en = lambda: "hello" context = dict(title="Guten Tag", link="http://example.com", greeting=dict(obj=greeting)) expected = '\n<html>\n <body>\n <div class="big boxed" id="title">Guten Tag \n <img src="http://example.com" /> \n <p>Guten Tag bla foo</p>\n </div> \n <a href="http://example.com" target="_blank" class="bold" id="link">hello</a> blub\n </body>\n</html>' rendered = "".join( Template.load_and_render("test.pyml", context, search_path=os.path.join(os.path.dirname(__file__))) ) self.assertEqual(rendered, expected)
def render(self): return ''.join(Template.load_and_render(self.template, self.context, search_path=self.search_path))