# -*- coding: utf-8 -*- from extends import function, inline # todo: light autoescaping: |safe can be use only in the end of output # todo: check `.toString()` in all filters/test # todo: check `is string` in all filters/test result # todo: default arguments: null -> undefined default_filters = { "safe": inline("{{value}}"), "attr": inline("{{value}}[{{name}}]", spec='name'), "length": inline("{{value}}.length"), "abs": inline("Math.abs({{value}})"), "int": inline("Math.floor({{value}}) || {{default}}", spec="default", defaults={'default': 0}), "float": inline("parseFloat({{value}}) || {{default}}", spec="default", defaults={'default': 0.0}), "string": inline("{{value}}.toString()"), "lower": inline("{{value}}.toLowerCase()"), "upper": inline("{{value}}.toUpperCase()"), "trim": inline("{{value}}.replace(/^\s+|\s+$/g, '')"), "wordcount": inline("{{value}}.split(/\s+/g).length"), "replace": inline("{{value}}.split({{old}}).join({{new}})", spec=('old', 'new')), "urlencode": function("""function(value) { if (value instanceof Array) {
# -*- coding: utf-8 -*- from extends import inline, function default_tests = { "callable": inline("typeof({{value}}) == 'function'"), "number": inline("typeof({{value}}) == 'number'"), "string": inline("typeof({{value}}) == 'string'"), "sequence": function("""function(value) { return typeof(value) == 'string' || typeof(value) == 'object'; }""", include="tests"), "mapping": function("""function(value) { return value instanceof Object && !(value instanceof Array); }""", include="tests"), "sameas": inline("{{value}} === {{other}}", spec=('other',)), "odd": inline("!!({{value}} % 2)"), "even": inline("!({{value}} % 2)"), "divisibleby": inline("!({{value}} % {{num}})", spec=('num',)), "none": inline("{{value}} === null"), "defined": inline("{{value}} !== undefined"), "undefined": inline("{{value}} === undefined"), "lower": function("""function(value) { return value.toLowerCase() == value; }""", include="tests"), "upper": function("""function(value) {