webmcp

view framework/env/ui/tag.lua @ 569:5b19007574de

New argument active_link_attr for env.ui.paginate{...}
author jbe
date Wed Oct 13 17:21:44 2021 +0200 (2021-10-13)
parents 9fdfb27f8e67
children
line source
1 --[[--
2 ui.tag{
3 tag = tag, -- HTML tag, e.g. "a" for <a>...</a>
4 attr = attr, -- table of HTML attributes, e.g. { class = "hide" }
5 content = content -- string to be HTML encoded, or function to be executed
6 }
8 This function writes a HTML tag into the active slot.
10 NOTE: ACCELERATED FUNCTION
11 Do not change unless also you also update webmcp_accelerator.c
13 --]]--
15 function ui.tag(args)
16 local tag, attr, content
17 tag = args.tag
18 attr = args.attr or {}
19 content = args.content
20 if type(attr.class) == "table" then
21 attr = table.new(attr)
22 attr.class = table.concat(attr.class, " ")
23 end
24 if not tag and next(attr) then
25 tag = "span"
26 end
27 if tag then
28 slot.put('<', tag)
29 for key, value in pairs(attr) do
30 slot.put(' ', key, '="', encode.html(value), '"')
31 end
32 end
33 if content then
34 if tag then
35 slot.put('>')
36 end
37 if type(content) == "function" then
38 content()
39 else
40 slot.put(encode.html(content))
41 end
42 if tag then
43 slot.put('</', tag, '>')
44 end
45 else
46 if tag then
47 slot.put(' />')
48 end
49 end
50 end

Impressum / About Us