Source: site.view [edit]
Function name: portlet
Arguments: cmd
Description: Receives a list of commands to display and prepares for display in AJAX portlets. cmd may be actual data or a name of a function to call.
Page type: webl
Render function:  
Module: siteutil

Page source:

var data = "res";

if (Type(cmd) == "string") then
   data = WubCall(cmd, [])
else
   data = cmd
end;


var DefaultRender = fun(obj)
   var result;
   // Default handling for pages, pieces, sttrings, etc.
   if Type(obj) == "page" then
      result = Markup(obj)
   elsif Type(obj) == "piece" then
      result = Markup(obj)
   elsif Type(obj) == "string" then
      result = obj
   elsif obj == nil then
      result = "Function returned nil. "
   else
      // All other types, just print it out using WebL ToString()
      result = ToString(obj)
   end;
   result
end;

var renderEntry = fun(c)
   var item = c;
   var finfo = Wub_GetFunctionInfo(c.cmd);
   var cres = (WubCall(c.cmd, c.args) ? nil);
   if cres == nil then
      item.html := "<b>Error executing " + c.cmd + ToString(c.args) + "</b>"
   elsif (finfo.render != "") then
      item.html := Markup(WubCall(finfo.render, [cres]))
   else
      item.html := DefaultRender(cres)
   end;
   return item
end;

var entries = [];
every c in data.entries do
   entries = entries + [renderEntry(c)]
end;

var leftentries = [];
every c in (data.leftentries ? []) do
   leftentries = leftentries + [renderEntry(c)]
end;


var readonly = (data.readonly ? false);
var editable = (data.editable ? false);

var res =
   [. title=data.title, readonly=readonly, editable=editable, entries=entries .];

if (data.leftwidth ? nil) != nil then
   res["leftwidth"] := data.leftwidth
end;
if (leftentries != []) then
   res["leftentries"] := leftentries
end;

res;