Software /
code /
prosody
Changeset
6772:805baeca56b6
util.interpolation: Add support for filter functions
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 07 Aug 2015 13:31:12 +0200 |
parents | 6771:60957dd5b41b |
children | 6774:3965662ae091 |
files | util/interpolation.lua |
diffstat | 1 files changed, 9 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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;