webmcp

diff framework/env/ui/tag.lua @ 0:9fdfb27f8e67

Version 1.0.0
author jbe/bsw
date Sun Oct 25 12:00:00 2009 +0100 (2009-10-25)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/framework/env/ui/tag.lua	Sun Oct 25 12:00:00 2009 +0100
     1.3 @@ -0,0 +1,50 @@
     1.4 +--[[--
     1.5 +ui.tag{
     1.6 +  tag     = tag,     -- HTML tag, e.g. "a" for <a>...</a>
     1.7 +  attr    = attr,    -- table of HTML attributes, e.g. { class = "hide" }
     1.8 +  content = content  -- string to be HTML encoded, or function to be executed
     1.9 +}
    1.10 +
    1.11 +This function writes a HTML tag into the active slot.
    1.12 +
    1.13 +NOTE: ACCELERATED FUNCTION
    1.14 +Do not change unless also you also update webmcp_accelerator.c
    1.15 +
    1.16 +--]]--
    1.17 +
    1.18 +function ui.tag(args)
    1.19 +  local tag, attr, content
    1.20 +  tag     = args.tag
    1.21 +  attr    = args.attr or {}
    1.22 +  content = args.content
    1.23 +  if type(attr.class) == "table" then
    1.24 +    attr = table.new(attr)
    1.25 +    attr.class = table.concat(attr.class, " ")
    1.26 +  end
    1.27 +  if not tag and next(attr) then
    1.28 +    tag = "span"
    1.29 +  end
    1.30 +  if tag then
    1.31 +    slot.put('<', tag)
    1.32 +    for key, value in pairs(attr) do
    1.33 +      slot.put(' ', key, '="', encode.html(value), '"')
    1.34 +    end
    1.35 +  end
    1.36 +  if content then
    1.37 +    if tag then
    1.38 +      slot.put('>')
    1.39 +    end
    1.40 +    if type(content) == "function" then
    1.41 +      content()
    1.42 +    else
    1.43 +      slot.put(encode.html(content))
    1.44 +    end
    1.45 +    if tag then
    1.46 +      slot.put('</', tag, '>')
    1.47 +    end
    1.48 +  else
    1.49 +    if tag then
    1.50 +      slot.put(' />')
    1.51 +    end
    1.52 +  end
    1.53 +end

Impressum / About Us