Module:Members

-- See the talk page for documentation. local api = require("Module:API") local member_tags = require("Module:Member tags") local types = require("Module:Type") local utils = require("Module:Utils")

--% This function is used to compare two members by their names. --@ member1 (table) the first member --@ member2 (table) the second member --: (boolean) true if the first member's name is sorted before the second's, false otherwise local function compare_members(member1, member2) return member1.Name < member2.Name end

local p = {}

function p.generate_members_list(class_name, descriptions) local class_data = api.get_class_data(class_name) if not class_data then return error("No information is known about class " .. class_name .. ".") end local properties = {} local functions = {} local events = {} local callbacks = {} for _, member in pairs(class_data.Members) do       if member.MemberType == "Property" then table.insert(properties, member) elseif member.MemberType == "Function" then table.insert(functions, member) elseif member.MemberType == "Event" then table.insert(events, member) elseif member.MemberType == "Callback" then table.insert(callbacks, member) end end local output = "" if #properties > 0 then output = output .. p.generate_properties_list(properties, descriptions) end if #functions > 0 then output = output .. "\n" .. p.generate_functions_list(functions, descriptions) end if #events > 0 then output = output .. "\n" .. p.generate_events_list(events, descriptions) end if #callbacks > 0 then output = output .. "\n" .. p.generate_callbacks_list(callbacks, descriptions) end return output end

function p.generate_properties_list(properties, descriptions) table.sort(properties, compare_members) local list = "== Properties ==\n" for _, property in pairs(properties) do       if descriptions and descriptions[property.Name] then list = list .. "\n" .. p.generate_property_section(property, descriptions[property.Name]) else list = list .. "\n" .. p.generate_property_section(property) end end return list end

function p.generate_functions_list return "" end

function p.generate_events_list return "" end

function p.generate_callbacks_list return "" end

function p.generate_property_section(property) -- Start the section heading. local section = "=== "

-- Determine read and write security. local read_security = false local write_security = false if property.Security then if property.Security.Read and property.Security.Read ~= "" and property.Security.Read ~= "None" then read_security = property.Security.Read end if property.Security.Write and property.Security.Write ~= "" and property.Security.Write ~= "None" then write_security = property.Security.Write end end

-- Add an icon. -- Currently, Privfield.gif is not used. local icon_file_name = "Pubfield.gif" if read_security or write_security then icon_file_name = "Protfield.gif" end section = section .. " "

-- Add property type. if property.ValueType then section = section .. types.link_type_with_category(property.ValueType.Name, property.ValueType.Category) .. " "   end

-- Add the member name. section = section .. mw.text.tag("b", {       class = "member-name",        id = property.Name -- Add the member's name as an anchor so that it can be linked to conveniently.    }, property.Name)

-- End the section heading. section = section .. " ===\n"

-- Add category. if property.Category then section = section .. "\nCategory: " .. property.Category .. ".\n" end

-- Add security. if read_security then section = section .. "\nRead security: " .. read_security .. ".\n" end if write_security then section = section .. "\nWrite security: " .. write_security .. ".\n" end

-- Add serialization. if property.Serialization then section = section .. "\nSerialization: " if property.Serialization.CanLoad and property.Serialization.CanSave then section = section .. "can load and save.\n" elseif property.Serialization.CanLoad then section = section .. "can load but not save.\n" elseif property.Serialization.CanSave then section = section .. "can save but not load.\n" else section = section .. "cannot load or save.\n" end end

-- Add tags. if property.Tags then section = section .. "\nTags: " local tag_count = #property.Tags for tag_index, tag in pairs(property.Tags) do           section = section .. member_tags._make_tag{name = tag} if tag_index < tag_count then section = section .. ", "           else section = section .. ".\n" end end end

-- Add the description, if one is provided. if description then section = section .. "\n" .. description .. "\n" end

return section end

function p._members_list(args) return p.generate_members_list(args.name, args) end p.members_list = utils.make_wrapper_function(p._members_list)

return p