def test_doctype(): data = """ !!! html body div """.strip() expected = [ 'document', ['doctype', "!!!"], [ 'element', ['open_tag', 'html'], [ 'nested_elements', [ 'element', ['open_tag', 'body'], ['nested_elements', ['element', ['open_tag', 'div']]] ] ] ] ] result = jade.generate_data(data) assert expected == result expected = ''' <!DOCTYPE html> <html> <body> <div></div> </body> </html>'''.strip() result = jade.to_html(data, tidy=True) assert expected == result
def test_doctype(): data = """ !!! html body div """.strip() expected = [ 'document', ['doctype', "!!!"], ['element', ['open_tag', 'html'], ['nested_elements', ['element', ['open_tag', 'body'], ['nested_elements', ['element', ['open_tag', 'div']]]]]]] result = jade.generate_data(data) assert expected == result expected = ''' <!DOCTYPE html> <html> <body> <div></div> </body> </html>'''.strip() result = jade.to_html(data, tidy=True) assert expected == result
def test_simple(self): data = '''(href="foo")''' expected = [ 'attribute_list', ['attribute', "href", ['quoted_string', 'foo']] ] result = jade.generate_data(data, jade.attribute_list) assert expected == result
def do_test(data): expected = ['element', ['open_tag', data]] result = jade.generate_data(data, pattern=jade.element) assert expected == result expected = "<%(data)s></%(data)s>\n" % dict(data=data) result = jade.to_html(data) assert expected == result
def test_multiple(self): data = '''(href="foo", title="Foo!")''' expected = [ 'attribute_list', ['attribute', "href", ['quoted_string', 'foo']], ['attribute', "title", ['quoted_string', "Foo!"]] ] result = jade.generate_data(data, jade.attribute_list) assert expected == result
def do_test(data): tag, tag_class = data.split(".") expected = ['element', ['open_tag', tag, ['tag_class', tag_class]]] result = jade.generate_data(data, pattern=jade.element) assert expected == result expected = """<%(tag)s class="%(tag_class)s"></%(tag)s>\n""" % dict( tag=tag, tag_class=tag_class) result = jade.to_html(data) assert expected == result
def do_test(data): tag, content = [item.strip() for item in data.split("|")] expected = ['element', ['open_tag', tag, ['content', content]]] result = jade.generate_data(data, pattern=jade.element) assert expected == result expected = """<%(tag)s>%(content)s</%(tag)s>\n""" % dict( tag=tag, content=content) result = jade.to_html(data) assert expected == result
def loader(filename, context): src = """ html head title | master_foo body block main block footer """ data = jade.generate_data(src) elements = jade.generate_elements(data, context=context) return elements
def do_test(data): tag, tag_class = data.split(".") expected = [ 'element', ['open_tag', tag, ['tag_class', tag_class]]] result = jade.generate_data(data, pattern=jade.element) assert expected == result expected = """<%(tag)s class="%(tag_class)s"></%(tag)s>\n""" % dict(tag=tag, tag_class=tag_class) result = jade.to_html(data) assert expected == result
def test_attribute_list(self): data = '''a(href='/contact') contact''' expected = [ 'element', [ 'open_tag', 'a', [ 'attribute_list', ['attribute', 'href', ['quoted_string', "/contact"]] ], ['content', 'contact'] ] ] result = jade.generate_data(data, jade.element) assert expected == result
def do_test(data): tag, content = [item.strip() for item in data.split("|")] expected = [ 'element', ['open_tag', tag, ['content', content]]] result = jade.generate_data(data, pattern=jade.element) assert expected == result expected = """<%(tag)s>%(content)s</%(tag)s>\n""" % dict(tag=tag, content=content) result = jade.to_html(data) assert expected == result
def test_text_filter(): src = """ extends anything append main div | foo1 | foo2 p | foo3 p | foo4 replace footer | foo_ter div """.strip() expected = """ <html> <head> <title>master_faa</title> </head> <body> <div> faa1faa2 <p> faa3 </p> <p></p> faa4 </div> <div> faa_ter <div></div> </div> </body> </html> """.strip() context = dict( loader=loader, _text_filter=_text_filter) data = jade.generate_data(src) result = jade.to_html(src, tidy=True, context=context) assert expected == result
def test_nested(): data = """ div#foo.bar p | A paragraph """.strip() expected = [ 'element', ['open_tag', "div", ['tag_id', "foo"], ['tag_class', "bar"]], [ 'nested_elements', ['element', ['open_tag', "p", ['content', "A paragraph"]]] ] ] result = jade.generate_data(data, pattern=jade.element) assert expected == result expected = '''<div id="foo" class="bar"><p>A paragraph</p></div>\n''' result = jade.to_html(data) assert expected == result
def test_text_filter(): src = """ extends anything append main div | foo1 | foo2 p | foo3 p | foo4 replace footer | foo_ter div """.strip() expected = """ <html> <head> <title>master_faa</title> </head> <body> <div> faa1faa2 <p> faa3 </p> <p></p> faa4 </div> <div> faa_ter <div></div> </div> </body> </html> """.strip() context = dict(loader=loader, _text_filter=_text_filter) data = jade.generate_data(src) result = jade.to_html(src, tidy=True, context=context) assert expected == result
def test_nested(): data = """ div#foo.bar p | A paragraph """.strip() expected = [ 'element', ['open_tag', "div", ['tag_id', "foo"], ['tag_class', "bar"]], ['nested_elements', ['element', ['open_tag', "p", ['content', "A paragraph"]]]]] result = jade.generate_data(data, pattern=jade.element) assert expected == result expected = '''<div id="foo" class="bar"><p>A paragraph</p></div>\n''' result = jade.to_html(data) assert expected == result
def loader(filename, context): f = cases / filename src = f.text() data = jade.generate_data(src) elements = jade.generate_elements(data, context) return elements
def _loader(self, filename, context): f = self.directory / filename src = f.text() data = jade.generate_data(src) elements = jade.generate_elements(data, context=context) return elements