예제 #1
0
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
예제 #2
0
def test_literal_templating():
    templates = nouns.Templates(folders=example_templates_folder, preprocess=x)

    data = "abc"

    rendered = templates.render(data)
    assert rendered == "abc"
예제 #3
0
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
예제 #4
0
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
예제 #5
0
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"
예제 #6
0
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