Ejemplo n.º 1
0
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>")
Ejemplo n.º 2
0
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>")
Ejemplo n.º 3
0
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: