"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) { var r = []; for (var i in value) { r.push(encodeURIComponent(value[i][0]) + "=" + encodeURIComponent(value[i][1])); } return r.join('&'); } if (typeof value == "object") { var r = []; for (var i in value) { r.push(encodeURIComponent(i) + "=" + encodeURIComponent(value[i])); } return r.join('&'); } return encodeURIComponent(value); }"""), "json": inline('JSON.stringify({{value}})'), "join": function("""function(arr, del, attr) { if (!(arr instanceof Array)) { if (attr) { return arr[attr];
# -*- coding: utf-8 -*- from extends import function # todo: add global functions # http://jinja.pocoo.org/docs/templates/#list-of-global-functions # using "None" in templates default_utils = { "extend": function( """function(base, child) { if (child == undefined) return base; var current = {"blocks": {}}; for (var key in base.blocks) { if (!child.blocks[key]) { current.blocks[key] = base.blocks[key]; } else { current.blocks[key] = child.blocks[key]; } } return current; }""", include="utils", ), "slice": function( """function(val, start, stop) { if (typeof(val) == "string") { return val.substring(start, stop); } else if (val instanceof Array) { return val.slice(start, stop); } }""",
# -*- 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) {