def test_loadtxt_static(): @renders( loadtxt("tests/assets/html_components/component.html", static=True)) def render_component(): return {"foo": "bar"} assert render_component() == txt("<p>{foo}</p>")
def test_loadtxt_dynamic(): @renders(loadtxt("tests/assets/html_components/component.html")) def render_component(): return {"foo": "bar"} assert render_component() == txt("<p>bar</p>")
import os from collections import namedtuple from types import MappingProxyType from htmldoom.util import loadraw, loadtxt, render from htmldoom.yaml_loader import loadyaml EXTENSION_RENDERERS = MappingProxyType({ "txt": lambda path: render(loadtxt(path)), "html": lambda path: render(loadraw(path)), "css": lambda path: render(loadraw(path)), "js": lambda path: render(loadraw(path)), "yml": lambda path: render(loadyaml(path)), "yaml": lambda path: render(loadyaml(path)), }) def loadvalues(path, extension_renderers=None): """Scan a directory and load the values in a nested namedtuple. Arguments: path: Path to the directory of files containing values. extension_renderers: A map of file extensions and their renderers. Example: