def test_layout_smart_wrapping(page_layout): strings = ["first", "second", "third"] output = page_layout + la.Section( children=[ la.Row(children=[*strings, "fourth"]), "another bit of content", la.Row(children=[la.Column(children=["fifth"]), "sixth"]), ] ) expected = page_layout expected += la.Section( children=[ la.Row(children=[*[co.Markdown(x) for x in strings], "fourth"]), co.Markdown("another bit of content"), la.Row( children=[ la.Column(children=[co.Markdown("fifth")]), la.Column(children=[co.Markdown("sixth")]), ] ), ] ) print(output) print() print(expected) assert output == expected
def page_basic_layout() -> la.Page: page = la.Page( title="Test Page", children=la.Section( title="Section One", children=la.Row( title="Row One", children=la.Column(children=co.Markdown("markdown content")), ), ), ) return page
def test_table_of_contents_numbered(): input_page = la.Page(title="My Page") input_page["Section One"]["Item A"] = "some text" input_page["Section One"]["Item B"] = "more text" input_page["Section Two"]["Item C"]["Item D"] = "and more text" input_page["Section Two"]["Item C"]["Item E"] = "even more text" output_toc = co.table_of_contents(input_page, numbered=True) expected_toc = co.Markdown(" 1. [Section One](#section_one-title)\n\t" " 1. [Item A](#item_a-title)\n\t" " 1. [Item B](#item_b-title)\n" " 1. [Section Two](#section_two-title)\n\t" " 1. [Item C](#item_c-title)\n\t\t" " 1. [Item D](#item_d-title)\n\t\t" " 1. [Item E](#item_e-title)") assert output_toc == expected_toc
def markdown_content() -> co.Markdown: return co.Markdown("A")
import esparto.design.content as co import esparto.design.layout as la from esparto import _INSTALLED_MODULES, _OPTIONAL_DEPENDENCIES _EXTRAS = _OPTIONAL_DEPENDENCIES <= _INSTALLED_MODULES _irises_path = str(Path("tests/resources/irises.jpg").absolute()) _markdown_path = str(Path("tests/resources/markdown.md").absolute()) with Path(_irises_path).open("rb") as f: _irises_binary = BytesIO(f.read()) # Add new content classes here content_list = [ (co.Markdown("this _is_ some **markdown**")), (co.RawHTML("<p>Raw HTML</p>")), ] # Add new layout classes here layout_list = [ (la.Page(children=[*content_list])), (la.Section(children=[*content_list])), (la.Row(children=[*content_list])), (la.Column(children=[*content_list])), (la.Card(children=[*content_list])), (la.CardSection(children=[*content_list])), (la.CardRow(children=[*content_list])), (la.Spacer()), (la.PageBreak()), ]
def test_layout_equality(layout_list_fn): for i, a in enumerate(layout_list_fn): for j, b in enumerate(layout_list_fn): if i == j: assert a == b else: assert a != b layout_add_list = [ ( la.Column(), "miles davis", la.Column(children=co.Markdown("miles davis")), ), ( la.Row(), co.Markdown("ornette coleman"), la.Row(children=la.Column(children=co.Markdown("ornette coleman"))), ), ( la.Page(children=["charles mingus"]), la.Section(children=["thelonious monk"]), la.Page( children=[ la.Section(children=["charles mingus"]), la.Section(children=["thelonious monk"]), ] ),