Module:Api

-- See Template:Api and Module:Elinks-api

local module = {}		-- see function module.GetType below

-- public constants

module.TYPE_FUNCTION = "a" module.TYPE_CVAR = "c" module.TYPE_EVENT = "e" module.TYPE_WIDGET = "o" module.TYPE_WIDGETMETHOD = "w" module.TYPE_SCRIPT = "wh" module.TYPE_VARIABLE = "t" module.TYPE_MACROCOMMAND = "m" module.SUBTYPE_MIXIN = "Mixin" module.SUBTYPE_ENUM = "Enum" module.SUBTYPE_CONST = "Const" module.SUBTYPE_STRUCT = "Struct" module.SUBTYPE_LINK = "Link" module.SUBTYPE_STRING = "String" module.SUBTYPE_ID = "ID"

-- private constants

-- lookup for the t= parameter local apiTypes = {	a = module.TYPE_FUNCTION, c = module.TYPE_CVAR, e = module.TYPE_EVENT, o = module.TYPE_WIDGET, w = module.TYPE_WIDGETMETHOD, wh = module.TYPE_SCRIPT, t = module.TYPE_VARIABLE, m = module.TYPE_MACROCOMMAND, }

local apiSubtypes = {	Mixin = module.TYPE_VARIABLE, Enum = module.TYPE_VARIABLE, Const = module.TYPE_VARIABLE, Struct = module.TYPE_VARIABLE, Link = module.TYPE_VARIABLE, String = module.TYPE_VARIABLE, ID = module.TYPE_VARIABLE, }

local apiCategories = {	a = "Category:API functions", c = "Category:Console variables", e = "Category:API events", o = "Category:Widgets", w = "Category:Widget methods", wh = "Category:Widget script handlers", t = "Category:API types", m = "Category:Macro API", Mixin = "Category:Mixins", Enum = "Category:Enumerations", Const = "Category:Constants", Struct = "Category:Structs", Link = "Category:Hyperlinks", String = "Category:Encoded Strings", ID = "Category:Numeric IDs", }

-- lookup for widget types, to unambiguously detect widget methods local widgets = {	Alpha = true, Animation = true, AnimationGroup = true, ArchaeologyDigSiteFrame = true, Browser = true, Button = true, CheckButton = true, Checkout = true, CinematicModel = true, ColorSelect = true, ControlPoint = true, Cooldown = true, DressUpModel = true, EditBox = true, FogOfWarFrame = true, Font = true, FontInstance = true, FontString = true, Frame = true, GameTooltip = true, ItemButton = true, LayeredRegion = true, Line = true, LineScale = true, LineTranslation = true, MaskTexture = true, MessageFrame = true, Minimap = true, Model = true, ModelScene = true, ModelSceneActor = true, MovieFrame = true, OffScreenFrame = true, Path = true, PlayerModel = true, POIFrame = true, QuestPOIFrame = true, Region = true, Rotation = true, Scale = true, ScenarioPOIFrame = true, ScriptObject = true, ScrollFrame = true, ScrollingMessageFrame = true, SimpleHTML = true, Slider = true, StatusBar = true, TabardModel = true, Texture = true, TextureCoordTranslation = true, Translation = true, UIObject = true, UnitPositionFrame = true, WorldFrame = true, }

local function getType(pagename, t)	pagename = pagename or "" t = t or "" local retVal = apiSubtypes[t] or apiTypes[t] or pagename:sub(1, 4) == "API " and (pagename:find(" ", 7) and widgets[pagename:sub(5, pagename:find(" ", 7) - 1)] and module.TYPE_WIDGETMETHOD or module.TYPE_FUNCTION) -- API UIObject GetName or API C Something.DoSomething or pagename:sub(1, 5) == "CVar " and module.TYPE_CVAR or not pagename:find("[^%u%s]") and module.TYPE_EVENT or pagename:sub(1, 9) == "UIOBJECT " and module.TYPE_WIDGET or pagename:sub(1, 10) == "UIHANDLER " and module.TYPE_SCRIPT or pagename:sub(1,6) == "MACRO " and module.TYPE_MACROCOMMAND or pagename:sub(-5, -1) == "Mixin" and module.SUBTYPE_MIXIN			-- subtypes of module.TYPE_VARIABLE or pagename:sub( 1, 4) == "Enum" and module.SUBTYPE_ENUM or pagename:sub(1, 6) == "Struct" and module.SUBTYPE_STRUCT or pagename:sub(1, 6) == "Const " and module.SUBTYPE_CONST or pagename:sub(-4, -1) == "Link" and module.SUBTYPE_LINK or pagename:sub(-6, -1) == "String" and module.SUBTYPE_STRING or pagename:sub(-2, -1) == "ID" and module.SUBTYPE_ID or nil if (retVal and apiSubtypes[retVal]) then -- "t", "mixin" return apiSubtypes[retVal], retVal end -- "a" or nil return retVal end

-- Returns a key representing the API type, using t= or autodetection, as one of the module.TYPE constants -- function module.GetType(frame) return getType(frame.args[1], frame.args[2]) end

-- Returns the name of a category that a page should belong in -- Option 1: -- Option 2: function module.GetCategory(frame) local apiType, apiSubtype = getType(frame.args[1], frame.args[2] or frame.args[1]) return apiSubtype and apiCategories[apiSubtype] or apiType and apiCategories[apiType] end

-- Returns the sortkey that a page should belong in -- function module.GetSortKey(frame) local pagename = frame.args[1] or "" local apiType, apiSubtype = getType(pagename, frame.args[2]) return apiType == module.TYPE_FUNCTION and pagename:sub(5)									-- "API " or apiType == module.TYPE_CVAR and pagename:sub(6)									-- "CVar " or apiType == module.TYPE_WIDGET and pagename:sub(10)								-- "UIOBJECT " or apiType == module.TYPE_WIDGETMETHOD and pagename:sub((pagename:find(" ",5) or 0)+1)		-- "API Frame " or apiType == module.TYPE_SCRIPT and pagename:sub((pagename:find(" ") or 0)+1)		-- "UIHANDLER " or apiType == module.TYPE_MACROCOMMAND and pagename:sub(7)							-- "Macro " or apiSubtype == module.SUBTYPE_ENUM and pagename:sub(6)							-- "Enum." or apiSubtype == module.SUBTYPE_STRUCT and pagename:sub(8)							-- "Struct " or apiSubtype == module.SUBTYPE_CONST and pagename:sub(7)							-- "Const " or apiType and pagename or apiSubType and pagename or " " .. pagename																	-- For articles about the API that are not actually part of the API itself, to appear at the top of the category end

return module