def test_thing_templating(): templates = nouns.Templates(folders=example_templates_folder, preprocess=x) data = [x.thingy(method="POST")] rendered = templates.render(data) assert rendered == RENDERED_FORM
def test_literal_templating(): templates = nouns.Templates(folders=example_templates_folder, preprocess=x) data = "abc" rendered = templates.render(data) assert rendered == "abc"
def test_dict_templating(): templates = nouns.Templates(folders=example_templates_folder, preprocess=x) data = "a b c".split() data = zip(data, range(len(data))) data = dict(data) rendered = templates.render(data) assert rendered == RENDERED_DICT
def test_table_templating(): templates = nouns.Templates(folders=example_templates_folder, preprocess=x) data = results.Results([dict(a=None, b=2), dict(a=3.5, b="")]) transformed = x(data, style="stylish") transformed["_style"] = x("stylish") rendered = templates.render(transformed) assert rendered == RENDERED_TABLE
def test_iterable_templating(): templates = nouns.Templates(folders=example_templates_folder, preprocess=x) data = "a b c".split() rendered = templates.render(data) assert rendered == "a\nb\nc"
from copy import deepcopy import nouns import results from IPython.core.display import HTML, display x = nouns.get_x() t = nouns.Templates(folders=[nouns.BUILTIN_TEMPLATES_FOLDER], preprocess=x) def get_css(): css = results.resource_text("css/custom.css") return f"<style>{css}</style>" def load_css(css): display(HTML(css)) def render(data): return t.render(deepcopy(data)) def results_object_repr_html(self): return render(self) results.Results._repr_html_ = results_object_repr_html