## template type dispatcher
for need to generate appropriate semantics for different data structures.
we'll use a dispatching dictionary to handle that work. when `int` or `float` types are found then the `numeric` templates is used, `str` types use the `string`, `list` and `dict` handle sequences and containers.
for need to generate appropriate semantics for different data structures.
we'll use a dispatching dictionary to handle that work. when
int
or
float
types are found then the
numeric
templates is used,
str
types use the
string
,
list
and
dict
handle sequences and containers.
templates.update(numeric="""<data value="{{object|dumps}}"></data>""",time="""<time datetime="{{object.isoformat()}}">{{object}}</time>""",format="""{% for f, t in dispatch.items() %}{% if object | isinstance(t) %}{% include f %}{% endif %}{% endfor %}""",mapping="""<dl>{% for object, v in object.items() %}<dt>{% include "format" %}</dt><dd>{% set object = v %}{% include "format" %}</dd>{% endfor %}</dl>""",string="""{% if "://" in object %}<a href="{{object}}">{{object}}</a>{% else %}<samp>{{object}}</samp>{% endif %}""",array="""<ol>{% for object in object %}<li>{% include "format" %}</li>{% endfor %}</ol>""",set="""<ul>{% for object in object %}<li>{% include "format" %}</li>{% endfor %}</ul>""",)