Esempio n. 1
0
def jsval(value):
    """Format a value as json, and encode suitably for inserting into a script
    element.

    """
    assert not isinstance(value, jinja2.runtime.Undefined)
    value = json.dumps(value, indent=None)
    value = value.replace('<', '<"+"')
    return jinja2.utils.Markup(value)
Esempio n. 2
0
def jsvalattr(value):
    """Format a value as json, for use in an attribute value.

    """
    assert not isinstance(value, jinja2.runtime.Undefined)
    return json.dumps(value, indent=None, separators=(',', ':'))