Comparison

util/stanza.lua @ 8645:06c73b010488

util.stanza: Add :text_tag(), a shortcut for adding nodes with text
author Kim Alvefur <zash@zash.se>
date Wed, 21 Mar 2018 23:20:26 +0100
parent 8640:8f13ec2ceb06
child 8889:c4e430c69f88
comparison
equal deleted inserted replaced
8644:3b28c7728e3f 8645:06c73b010488
99 99
100 function stanza_mt:body(text, attr) 100 function stanza_mt:body(text, attr)
101 return self:tag("body", attr):text(text); 101 return self:tag("body", attr):text(text);
102 end 102 end
103 103
104 function stanza_mt:text_tag(name, text, attr, namespaces)
105 return self:tag(name, attr, namespaces):text(text):up();
106 end
107
104 function stanza_mt:tag(name, attr, namespaces) 108 function stanza_mt:tag(name, attr, namespaces)
105 local s = new_stanza(name, attr, namespaces); 109 local s = new_stanza(name, attr, namespaces);
106 local last_add = self.last_add; 110 local last_add = self.last_add;
107 if not last_add then last_add = {}; self.last_add = last_add; end 111 if not last_add then last_add = {}; self.last_add = last_add; end
108 (last_add[#last_add] or self):add_direct_child(s); 112 (last_add[#last_add] or self):add_direct_child(s);