webmcp

annotate framework/env/ui/tag.lua @ 14:a29c8ffb3f82

New function ui.filters{...}

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

Impressum / About Us