webmcp

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

Version 1.0.0
author jbe/bsw
date Sun Oct 25 12:00:00 2009 +0100 (2009-10-25)
parents
children a29c8ffb3f82
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/framework/env/ui/container.lua	Sun Oct 25 12:00:00 2009 +0100
     1.3 @@ -0,0 +1,90 @@
     1.4 +--[[--
     1.5 +ui.container{
     1.6 +  auto_args = auto_args,
     1.7 +  attr          = attr,           -- HTML attributes for the surrounding div or fieldset
     1.8 +  label         = label,          -- text to be used as label
     1.9 +  label_for     = label_for,      -- DOM id of element to which the label should refer
    1.10 +  label_attr    = label_attr,     -- extra HTML attributes for a label tag
    1.11 +  legend        = legend,         -- text to be used as legend
    1.12 +  legend_attr   = legend_attr,    -- HTML attributes for a legend tag
    1.13 +  content_first = content_first,  -- set to true to place label or legend after the content
    1.14 +  content = function()
    1.15 +    ...                       --
    1.16 +  end
    1.17 +}
    1.18 +
    1.19 +This function encloses content in a div element (or a fieldset element, if 'legend' is given). An additional 'label' or 'legend' can be placed before the content or after the content. The argument 'auto_args' is set by other ui helper functions when calling ui.container automatically.
    1.20 +
    1.21 +--]]--
    1.22 +
    1.23 +function ui.container(args)
    1.24 +  local attr, label, label_attr, legend, legend_attr, content
    1.25 +  local auto_args = args.auto_args
    1.26 +  if auto_args then
    1.27 +    attr        = auto_args.container_attr
    1.28 +    label       = auto_args.label
    1.29 +    label_attr  = auto_args.label_attr
    1.30 +    legend      = auto_args.legend
    1.31 +    legend_attr = auto_args.legend_attr
    1.32 +    if label and auto_args.attr and auto_args.attr.id then
    1.33 +      label_attr = table.new(label_attr)
    1.34 +      label_attr["for"] = auto_args.attr.id
    1.35 +    end
    1.36 +  else
    1.37 +    attr        = args.attr
    1.38 +    label       = args.label
    1.39 +    label_attr  = args.label_attr or {}
    1.40 +    legend      = args.legend
    1.41 +    legend_attr = args.legend_attr
    1.42 +    content     = content
    1.43 +    if args.label_for then
    1.44 +      label_attr["for"] = args.label_for
    1.45 +    end
    1.46 +  end
    1.47 +  local content = args.content
    1.48 +  if label and not legend then
    1.49 +    return ui.tag {
    1.50 +      tag     = "div",
    1.51 +      attr    = attr,
    1.52 +      content = function()
    1.53 +        if not args.content_first then
    1.54 +          ui.tag{ tag = "label", attr = label_attr, content = label }
    1.55 +          slot.put(" ")
    1.56 +        end
    1.57 +        if type(content) == "function" then
    1.58 +          content()
    1.59 +        elseif content then
    1.60 +          slot.put(encode.html(content))
    1.61 +        end
    1.62 +        if args.content_first then
    1.63 +          slot.put(" ")
    1.64 +          ui.tag{ tag = "label", attr = label_attr, content = label }
    1.65 +        end
    1.66 +      end
    1.67 +    }
    1.68 +  elseif legend and not label then
    1.69 +    return ui.tag {
    1.70 +      tag     = "fieldset",
    1.71 +      attr    = attr,
    1.72 +      content = function()
    1.73 +        if not args.content_first then
    1.74 +          ui.tag{ tag = "legend", attr = legend_attr, content = legend }
    1.75 +          slot.put(" ")
    1.76 +        end
    1.77 +        if type(content) == "function" then
    1.78 +          content()
    1.79 +        elseif content then
    1.80 +          slot.put(encode.html(content))
    1.81 +        end
    1.82 +        if args.content_first then
    1.83 +          slot.put(" ")
    1.84 +          ui.tag{ tag = "legend", attr = legend_attr, content = legend }
    1.85 +        end
    1.86 +      end
    1.87 +    }
    1.88 +  elseif fieldset and label then
    1.89 +    error("ui.container{...} may either get a label or a legend.")
    1.90 +  else
    1.91 +    return ui.tag{ tag = "div", attr = attr, content = content }
    1.92 +  end
    1.93 +end

Impressum / About Us