def assertMako(self, source, expected, *args): node = haml.parse_string(source) mako = haml.generate_mako(node).replace('<%! from haml import runtime as __HAML %>\\\n', '') self.assertEqual( mako.replace(' ', '\t'), expected.replace(' ', '\t'), *args )
def assertHTML(self, source, expected, *args, **kwargs): node = haml.parse_string(source) mako = haml.generate_mako(node) html = Template(mako).render_unicode(**kwargs) self.assertEqual( html.replace(' ', '\t'), expected.replace(' ', '\t'), *args )
def assertMako(self, source, expected, *args): node = haml.parse_string(source) mako = haml.generate_mako(node).replace('<%! from haml.codegen import mako_build_attr_str as __P_attrs %>\\\n', '') self.assertEqual(mako, expected.replace(' ', '\t'), *args)
- range(10) ''' print '===== SOURCE =====' print source.strip() print root = haml.parse_string(source) print '===== NODES =====' root.print_tree() print print '===== MAKO =====' compiled = haml.generate_mako(root) print compiled.strip() print # print '===== COMPILED MAKO =====' template = Template(compiled) # print template._code.strip() # print print '===== RENDERED =====' print template.render_unicode(class_='test', title="MyPage", a='A', b='B', c='C').strip() print
} ''' print('===== SOURCE =====') print(source.strip()) print() root = haml.parse_string(source) print('===== NODES =====') root.print_tree() print() print('===== MAKO =====') compiled = haml.generate_mako(root) print(compiled.strip()) print() template = Template(compiled) if True: print('===== COMPILED MAKO =====') print(template._code.strip()) print() print('===== RENDERED =====') print( template.render_unicode(class_='test', title="MyPage", a='A', b='B', c='C').strip()) print()
def assertHTML(self, source, expected, *args, **kwargs): node = haml.parse_string(source) mako = haml.generate_mako(node) html = Template(mako).render_unicode(**kwargs) self.assertEqual(html.replace(' ', '\t'), expected.replace(' ', '\t'), *args)
def assertMako(self, source, expected, *args): node = haml.parse_string(source) mako = haml.generate_mako(node).replace( '<%! from haml import runtime as __HAML %>\\\n', '') self.assertEqual(mako.replace(' ', '\t'), expected.replace(' ', '\t'), *args)
import haml import mako.template # 1. Write your HAML. haml_source = '.content Hello, World!' # 2. Parse your HAML source into a node tree. haml_nodes = haml.parse_string(haml_source) # 3. Generate Mako template source from the node tree. mako_source = haml.generate_mako(haml_nodes) # 4. Render the template. print mako.template.Template(mako_source).render_unicode()
def assertMako(self, source, expected, *args): node = haml.parse_string(source) mako = haml.generate_mako(node).replace( '<%! from haml.codegen import mako_build_attr_str as __P_attrs %>\\\n', '') self.assertEqual(mako, expected.replace(' ', '\t'), *args)