webmcp
view framework/env/format/boolean.lua @ 2:72860d232f32
Version 1.0.2
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
| author | jbe/bsw | 
|---|---|
| date | Thu Dec 10 12:00:00 2009 +0100 (2009-12-10) | 
| parents | 9fdfb27f8e67 | 
| children | 
 line source
     1 --[[--
     2 text =                      -- human text representation of the boolean
     3 format.boolean(
     4   value,                    -- true, false or nil
     5   {
     6     true_as  = true_text,   -- text representing true
     7     false_as = false_text,  -- text representing false
     8     nil_as   = nil_text     -- text representing nil
     9   }
    10 )
    12 Returns a human readable text representation of a boolean value. Additional parameters should be given, unless you like the defaults for false and true, which are "0" and "1".
    14 --]]--
    16 function format.boolean(value, options)
    17   local options = options or {}
    18   local true_text  = options.true_as or "Yes"  -- TODO: localization?
    19   local false_text = options.false_as or "No"  -- TODO: localization?
    20   local nil_text   = options.nil_as or ""
    21   if value == nil then
    22     return nil_text
    23   elseif value == false then
    24     return false_text
    25   elseif value == true then
    26     return true_text
    27   else
    28     error("Value passed to format.boolean(...) is neither a boolean nor nil.")
    29   end
    30 end
