Esempio n. 1
0
def test_loadraw_static():
    @renders(
        loadraw("tests/assets/html_components/component.html", static=True))
    def render_component():
        return {"foo": "bar"}

    assert render_component() == raw("<p>{foo}</p>")
Esempio n. 2
0
def test_loadraw_dynamic():
    @renders(loadraw("tests/assets/html_components/component.html"))
    def render_component():
        return {"foo": "bar"}

    assert render_component() == raw("<p>bar</p>")
Esempio 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: