Module:Infoboxes

local p = {}

--Vars-- local _fieldTags = {"<title", "<media", "<image", "<audio", "<video", "<data", "<caption"}

--SUPORTING FUNCTIONS--

--Infobox Functions--

--generateInfoboxExample--

--Makes a good guess at whether a page is an infobox template local function isInfobox(pageContent) return string.match(pageContent, "<infobox") end

--Makes a good guess at whether a string of text contains field data for an infobox local function isFieldData(line) for i, tag in ipairs(_fieldTags) do		if string.match(string.lower(line), tag) then return true end end return false end

--WIP (not functional) local function parseLine(line) matches = {} end

--Makes a good guess at whether a field is an image local function isImage(line) return string.match(string.lower(line), "<image") end

--Makes a good guess at whether a field is the title local function isTitle(line) return string.match(string.lower(line), "<title") end

--Makes a good guess at whether a line opens a tag local function isGroup(line) return string.match(string.lower(line), "<group") end

--Makes a good guess at whether a field is a status field local function isStatus(line) return string.match(string.lower(line), "status") end

--Checks if infobox preview should be generated local function useInfobox(frame) return frame.args[2] ~= "noib" and frame.args[3] ~= "noib" end

--Checks if example usage should be generated local function useExample(frame) return frame.args[2] ~= "noex" and frame.args[3] ~= "noex" end

--For use in Infobox template /doc pages:	Automatically generates a usage example in an Infobox /doc page based on the	tags in the corresponding Infobox template. -- function p.generateInfoboxExample(frame) --Check that both no-use options aren't specified, because if they both are,		it makes running all this code pointless because it's not outputting anything.	-- if useInfobox(frame) or useExample(frame) then --Get page name passed in as first arg and strip "/doc" from it if it's there local pageName = string.gsub(frame.args[1], "/doc", "") --Create a title object with that page name and store the raw contents			of that page in pageContent if the page exists		-- local pageContent = require("Module:Common").getContent(pageName, "Template") --Return if there's no page content because why bother? if not pageContent then --Error: Page doesn't exist return "ERROR: PAGE TITLE " .. pageName .. " DOESN'T EXIST OR PAGE IS EMPTY" end --Initialize variables to store each stage of content parsing.			exampleConcatTable & infoBoxConcatTable: Used as stacks to store				pieces of the docOutput before they	get concatenated into				docOutput because adding directly to docOutput each loop is much				slower due to Lua garbage collecting immutable variables			previousGroup: Flag that gets set to true when the most recent				parsed tag is a "group" tag, then set to false again when				parsing a non-group tag. This is a workaround to not output				multiple linebreaks when there are 2 or more "group" tags parsed				consecutively.			infoBox: Will store the text specific to building the sample infobox				at the last step of the process for code readability.			usageExample: Will store the text specific to displaying the example				infobox in tags for code readability.			docOutput: For storing the final output for the doc page to be				serve as a return value for code readability.		-- local exampleConcatTable = {} local infoBoxConcatTable = {} local previousGroup = false local infoBox = "" local usageExample = useExample(frame) and "Example Usage:  " end if useInfobox(frame) then infoBox = frame:expandTemplate{ title=pageName, args=infoBoxConcatTable} .. "\n" end docOutput = infoBox .. usageExample else --Error: There wasn't an infobox based on the search criteria return "ERROR: NO INFOBOX FOUND" end --Print that pretty doc to the page :)		return docOutput	end end

return p