# HG changeset patch # User Kim Alvefur # Date 1438947072 -7200 # Node ID 805baeca56b602226cce583e9a0f0132b83c79b5 # Parent 60957dd5b41b826eda1dd40e55e4ee03d65bd8d7 util.interpolation: Add support for filter functions diff -r 60957dd5b41b -r 805baeca56b6 util/interpolation.lua --- a/util/interpolation.lua Fri Jul 17 12:43:04 2015 +0200 +++ b/util/interpolation.lua Fri Aug 07 13:31:12 2015 +0200 @@ -24,7 +24,7 @@ local s_sub, s_gsub, s_match = string.sub, string.gsub, string.match; local t_concat = table.concat; -local function new_render(pat, escape) +local function new_render(pat, escape, funcs) -- assert(type(pat) == "string", "bad argument #1 to 'new_render' (string expected)"); -- assert(type(escape) == "function", "bad argument #2 to 'new_render' (function expected)"); local function render(template, values) @@ -42,6 +42,14 @@ if not value then break; end end end + if funcs then + while value ~= nil and opt == '|' do + local f; + f, opt, e = s_match(block, "^([%a_][%w_.]*)(%p?)()", e); + f = funcs[f]; + if f then value = f(value); end + end + end if opt == '#' or opt == '%' then if type(value) ~= "table" then return ""; end local iter = opt == '#' and ipairs or pairs;