jbe/bsw@0: --[[-- jbe/bsw@0: ui.tag{ jbe/bsw@0: tag = tag, -- HTML tag, e.g. "a" for ... jbe/bsw@0: attr = attr, -- table of HTML attributes, e.g. { class = "hide" } jbe/bsw@0: content = content -- string to be HTML encoded, or function to be executed jbe/bsw@0: } jbe/bsw@0: jbe/bsw@0: This function writes a HTML tag into the active slot. jbe/bsw@0: jbe/bsw@0: NOTE: ACCELERATED FUNCTION jbe/bsw@0: Do not change unless also you also update webmcp_accelerator.c jbe/bsw@0: jbe/bsw@0: --]]-- jbe/bsw@0: jbe/bsw@0: function ui.tag(args) jbe/bsw@0: local tag, attr, content jbe/bsw@0: tag = args.tag jbe/bsw@0: attr = args.attr or {} jbe/bsw@0: content = args.content jbe/bsw@0: if type(attr.class) == "table" then jbe/bsw@0: attr = table.new(attr) jbe/bsw@0: attr.class = table.concat(attr.class, " ") jbe/bsw@0: end jbe/bsw@0: if not tag and next(attr) then jbe/bsw@0: tag = "span" jbe/bsw@0: end jbe/bsw@0: if tag then jbe/bsw@0: slot.put('<', tag) jbe/bsw@0: for key, value in pairs(attr) do jbe/bsw@0: slot.put(' ', key, '="', encode.html(value), '"') jbe/bsw@0: end jbe/bsw@0: end jbe/bsw@0: if content then jbe/bsw@0: if tag then jbe/bsw@0: slot.put('>') jbe/bsw@0: end jbe/bsw@0: if type(content) == "function" then jbe/bsw@0: content() jbe/bsw@0: else jbe/bsw@0: slot.put(encode.html(content)) jbe/bsw@0: end jbe/bsw@0: if tag then jbe/bsw@0: slot.put('') jbe/bsw@0: end jbe/bsw@0: else jbe/bsw@0: if tag then jbe/bsw@0: slot.put(' />') jbe/bsw@0: end jbe/bsw@0: end jbe/bsw@0: end