Comparison

teal-src/prosody/util/xtemplate.tl @ 13525:0f7e7311eebf

util.xtemplate: Use same argument order in filters even without 'args' This removes the different argument order used between '{x|foo}' and '{x|foo(y)}' because the differing order was awkward and confusing. This util does not seem to be widely used so should not be problematic to change this part. The only known use is in mod_pubsub, which does not use the filter function feature.
author Kim Alvefur <zash@zash.se>
date Wed, 16 Oct 2024 16:15:05 +0200
parent 13501:05f028de4c45
comparison
equal deleted inserted replaced
13524:cfc42ed3892c 13525:0f7e7311eebf
15 local t_concat = table.concat; 15 local t_concat = table.concat;
16 16
17 local st = require "prosody.util.stanza"; 17 local st = require "prosody.util.stanza";
18 18
19 local type escape_t = function (string) : string 19 local type escape_t = function (string) : string
20 local type filter_t = function (string, string | st.stanza_t, string) : string | st.stanza_t, boolean 20 local type filter_t = function (string | st.stanza_t, string | st.stanza_t, string) : string | st.stanza_t, boolean
21 local type filter_coll = { string : filter_t } 21 local type filter_coll = { string : filter_t }
22 22
23 local function render(template : string, root : st.stanza_t, escape : escape_t, filters : filter_coll) : string 23 local function render(template : string, root : st.stanza_t, escape : escape_t, filters : filter_coll) : string
24 escape = escape or st.xml_escape; 24 escape = escape or st.xml_escape;
25 25
83 value = render(tmpl, root, escape, filters); 83 value = render(tmpl, root, escape, filters);
84 is_escaped = true; 84 is_escaped = true;
85 end 85 end
86 elseif filters and filters[func] then 86 elseif filters and filters[func] then
87 local f = filters[func]; 87 local f = filters[func];
88 if args == nil then 88 value, is_escaped = f(value, args, tmpl);
89 value, is_escaped = f(value, tmpl);
90 else
91 value, is_escaped = f(args, value, tmpl);
92 end
93 else 89 else
94 error("No such filter function: " .. func); 90 error("No such filter function: " .. func);
95 end 91 end
96 pipe, pos = s_match(inner, "^(|?)()", p as integer); 92 pipe, pos = s_match(inner, "^(|?)()", p as integer);
97 end 93 end