webmcp

view framework/env/ui/tag.lua @ 412:7d43be9afa56

Improved memory cleanup in case of out-of-memory errors (PQnotifies and PQunescapeBytea)
author jbe
date Fri Jan 08 03:10:33 2016 +0100 (2016-01-08)
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