示例#1
0
文件: base.py 项目: ksava/PyHAML
 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
     )
示例#2
0
文件: base.py 项目: ksava/PyHAML
 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
     )
示例#3
0
文件: __init__.py 项目: lagra/PyHAML
 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)
示例#4
0
文件: main.py 项目: lagra/PyHAML
        -
            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
示例#5
0
文件: main.py 项目: akubera/PyHAML
    }

'''

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()
示例#6
0
 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)
示例#7
0
 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)
示例#8
0
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()
示例#9
0
 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)